  :root {
  --bg: #fafafa;
  --fg: #1f2937;
  --muted: #4b5563;
  --accent: #6d28d9;
  --link: #2563eb;
  --link-visited: #7c3aed;
  --maxw: 72ch;
  --lh: 1.8;
  --fs-base: clamp(1rem, 0.95rem + 0.3vw, 1.125rem);
  --fs-h1: clamp(1.875rem, 1.3rem + 2.2vw, 2.5rem);
  --fs-h2: clamp(1.375rem, 1.1rem + 1.2vw, 1.875rem);
  --fs-h3: clamp(1.125rem, 1rem + 0.8vw, 1.375rem);
  --transition: all 0.3s ease;
}

[data-theme="dark"] {
  --bg: #0b0f15;
  --fg: #e5e7eb;
  --muted: #9ca3af;
  --accent: #8b5cf6;
  --link: #38bdf8;
  --link-visited: #a78bfa;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: var(--fs-base);
  line-height: var(--lh);
  transition: var(--transition);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

.wrapper {
  display: flex;
  justify-content: center;
  padding: clamp(16px, 3vw, 40px);
}

.reader {
  max-width: var(--maxw);
  width: 100%;
  position: relative;
}

/* Headings */
header.site {
  text-align: center;
  border-bottom: 1px solid rgba(125,125,125,0.2);
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
}

header.site h1 {
  font-family: 'Merriweather', serif;
  font-size: var(--fs-h1);
  line-height: 1.3;
  margin: 0.5rem 0;
}

header.site p.subtitle {
  color: var(--muted);
  max-width: 60ch;
  margin: 0 auto;
}

/* Content */
article.content h1, article.content h2, article.content h3 {
  line-height: 1.3;
  margin: 2rem 0 1rem;
  font-family: 'Merriweather', serif;
}

article.content h2::after {
  content: '';
  display: block;
  width: 3rem;
  height: 3px;
  background: var(--accent);
  margin-top: 0.4rem;
  border-radius: 2px;
}

article.content p { margin: 1.2rem 0; }

article.content ul, article.content ol {
  padding-left: 1.25rem;
  margin: 1rem 0;
}

/* Links */
a { color: var(--link); text-decoration: underline; }
a:visited { color: var(--link-visited); }

/* Center + Scale Images */
figure,
article.content img {
  display: block;
  margin: 1.5rem auto;
  text-align: center;
}

figure img,
article.content img {
  max-width: 100%;
  height: auto;
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  transition: var(--transition);
}

figure img:hover,
article.content img:hover {
  transform: scale(1.02);
}

/* Ensure images scale responsively */
@media (max-width: 1024px) {
  figure img,
  article.content img {
    width: 100%;
    height: auto;
  }
}

blockquote {
  border-left: 4px solid var(--accent);
  background: rgba(125,125,125,0.08);
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
  font-style: italic;
}

hr {
  border: none;
  height: 1px;
  background: rgba(125,125,125,0.2);
  margin: 2.5rem 0;
}

/* Table of Contents + Buttons */
.toc {
  position: sticky;
  top: 0;
  background: var(--bg);
  padding: 0.5rem 1rem;
  border-bottom: 1px solid rgba(125,125,125,0.2);
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 50;
}

.toc ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  gap: 1rem;
  overflow-x: auto;
}

.toc a {
  color: var(--fg);
  text-decoration: none;
  font-weight: 500;
}

.toc a:hover {
  color: var(--accent);
}

.theme-toggle {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  font-size: 0.9rem;
  transition: var(--transition);
}

.theme-toggle:hover { opacity: 0.9; }

/* Next Chapter Box */
.next-chapter {
  background: rgba(125,125,125,0.08);
  padding: 1rem 1.25rem;
  border-radius: 8px;
  margin: 2rem 0;
  font-weight: 600;
  color: var(--fg);
}

@media (max-width: 768px) {
  .toc ul { flex-wrap: wrap; gap: 0.5rem; }
}

/* Print Mode */
@media print {
  .toc, .theme-toggle, .progress-bar { display: none; }
  body { background: #fff; color: #000; }
}

/* Sticky CTA bottom-left */
#stickyStep1 {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 999;
}

#stickyStep1 a {
  background: #95bf47; /* Shopify green */
  color: #fff;
  font-weight: 600;
  text-decoration: none;
  padding: 10px 16px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
  font-size: 14px;
  transition: background 0.3s ease;
}

#stickyStep1 a:hover {
  background: #7aa63f; /* darker green on hover */
}

/* Exit intent popup */
#exitPopup {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.6);
  z-index: 9999;
  align-items: center;
  justify-content: center;
}

#exitPopup .popup-content {
  background: #fff;
  border-radius: 10px;
  max-width: 850px;
  width: 90%;
  max-height: 650px;
  height: auto;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  animation: fadeIn 0.3s ease;
  display: flex;
  overflow: hidden;
}

#exitPopup .popup-left {
  flex: 60%;
  text-align: left;
  padding: 30px;
  overflow-y: auto;
}

#exitPopup .popup-right {
  flex: 40%;
  display: flex;
}

#exitPopup .popup-right img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: pointer;
}

#exitPopup h2 {
  color: #131311;
  margin-bottom: 20px;
}

#exitPopup ul {
  list-style: none;
  padding: 0;
  font-size: 16px;
  margin-bottom: 20px;
}

#exitPopup ul li {
  margin: 8px 0;
  padding-left: 25px;
  position: relative;
}

#exitPopup ul li::before {
  content: "✔";
  position: absolute;
  left: 0;
  color: #64d295;
}

#exitPopup button {
  background: linear-gradient(90deg, #b686f6, #64d295);
  border: none;
  color: #fff;
  padding: 12px 20px;
  font-size: 16px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
  animation: float 3s ease-in-out infinite;
}

@media (max-width: 768px) {
  #exitPopup .popup-content {
    flex-direction: column;
    max-height: 90vh;
  }
  #exitPopup .popup-right {
    flex: unset;
    width: 100%;
  }
  #exitPopup .popup-right img {
    width: 100%;
    height: auto;
  }
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

/* ===========================================
   RESPONSIVE LAYOUT ENHANCEMENTS
   =========================================== */

/* Make wrapper more fluid on small screens */
.wrapper {
  display: flex;
  justify-content: center;
  padding: clamp(12px, 4vw, 40px);
}

.reader {
  width: 100%;
  max-width: var(--maxw);
  padding: 0 1rem;
}

/* Improve text spacing and readability */
p, li {
  line-height: 1.8;
  word-break: break-word;
}

/* Center and fully scale images in all contexts */
p > img,
span > img,
figure img,
article.content img {
  display: block;
  margin: 1.25rem auto;
  width: 100%;
  height: auto;
  max-width: 720px;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}

/* Prevent large images from overflowing viewport width */
img {
  max-width: 100%;
  height: auto;
}

/* Smaller headline sizes on mobile for balance */
@media (max-width: 1024px) {
  header.site h1 { font-size: 1.9rem; }
  article.content h1 { font-size: 1.75rem; }
  article.content h2 { font-size: 1.4rem; }
  article.content h3 { font-size: 1.2rem; }
}

/* Tighter padding on tablet and mobile */
@media (max-width: 900px) {
  .wrapper { padding: 20px 12px; }
  .reader { padding: 0 0.5rem; }
  header.site p.subtitle { padding: 0 0.5rem; }
}

/* Tablet optimizations */
@media (max-width: 768px) {
  body { font-size: 1rem; line-height: 1.85; }
  header.site h1 { font-size: 1.75rem; }
  header.site p.subtitle { font-size: 1rem; }
  article.content p { margin: 1rem 0; }
  article.content ul, article.content ol { padding-left: 1.1rem; }
  .toc { flex-wrap: wrap; padding: 0.5rem; }
}

/* Mobile optimizations */
@media (max-width: 600px) {
  header.site h1 { font-size: 1.5rem; }
  header.site p.subtitle { font-size: 0.95rem; }
  article.content h1 { font-size: 1.35rem; }
  article.content h2 { font-size: 1.2rem; }
  article.content h3 { font-size: 1.05rem; }
  body { font-size: 0.95rem; }
  .next-chapter { font-size: 0.95rem; }
}

/* Keep CTA button and popup proportional */
@media (max-width: 768px) {
  #stickyStep1 {
    bottom: 15px;
    left: 15px;
  }
  #stickyStep1 a {
    padding: 8px 14px;
    font-size: 13px;
  }
}

/* Popup responsiveness */
@media (max-width: 768px) {
  #exitPopup .popup-content {
    flex-direction: column;
    width: 95%;
    max-width: 480px;
    max-height: 90vh;
  }
  #exitPopup .popup-left {
    padding: 20px;
    font-size: 15px;
  }
  #exitPopup .popup-right {
    width: 100%;
    height: auto;
  }
}

/* Ensure no horizontal scrolling */
html, body {
  overflow-x: hidden;
}

/* ============================
   Top Sticky Advertisement Bar
   ============================ */
.toc {
  position: sticky;
  top: 0;
  background: var(--bg);
  padding: 0.5rem 1rem;
  border-bottom: 1px solid rgba(125,125,125,0.2);
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 50;
}

/* Ad section inside top bar */
.top-ad a {
  color: var(--fg);
  background: linear-gradient(90deg, #b686f6, #64d295);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  transition: opacity 0.2s ease;
}

.top-ad a:hover {
  opacity: 0.8;
}

/* Adjust layout on small screens */
@media (max-width: 600px) {
  .top-ad a {
    font-size: 0.85rem;
    text-align: center;
  }
  .toc {
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.5rem;
  }
}

#stickyStep1 { z-index: 999; }
#exitPopup { z-index: 9999; }

#exitPopup h2 {
  line-height: 1.25; /* tighter spacing */
  font-size: 1.6rem; /* optional: slightly smaller for balance */
  margin-bottom: 16px; /* keeps a clean gap below */
}

.highlight {
  background: linear-gradient(90deg, #fef3c7, #fde68a);
  padding: 0.15em 0.25em;
  border-radius: 4px;
}

/* === Reading Progress Bar (Bottom) === */
#progress-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 0%;
  height: 6px;
  background: linear-gradient(90deg, #b686f6 0%, #64d295 100%);
  z-index: 999999;
  transition: width 0.25s ease;
  border-radius: 3px 3px 0 0;
}
