/* Ducky Finance, 2026 redesign
   Tokens first, then base, layout, components, pages. Layers keep specificity predictable. */
@layer reset, tokens, base, layout, components, pages, utilities;

@layer tokens {
  :root {
    color-scheme: light dark; /* follows the system setting until the visitor picks one */

    /* Brand colors, sampled from the logo */
    --duck: #face3d;
    --duck-deep: #e3b51e;
    --bill: #f68812;
    --teal-900: #0e2927;
    --teal-800: #163b38;
    --teal-700: #1f524d;
    --teal-600: #2a7f78;
    --teal-500: #3a9a91;
    --teal-300: #8cc9c0;
    --teal-200: #bfe2db;
    --teal-100: #dcefea;
    --teal-50: #eef6f3;
    --paper: #f6faf8;
    --white: #fff;

    /* Roles. light-dark() picks per color scheme. */
    --bg: light-dark(var(--paper), var(--teal-900));
    --bg-raised: light-dark(var(--white), #132f2c);
    --bg-tint: light-dark(var(--teal-100), var(--teal-800));
    --bg-tint-2: light-dark(var(--teal-50), #10302d);
    --bg-deep: light-dark(var(--teal-900), #081a18);
    --ink: light-dark(var(--teal-900), #e9f3f0);
    --ink-2: light-dark(#3f5e5a, #afcac4);
    --ink-3: light-dark(#6b8782, #83a39d);
    --ink-on-deep: #d6e8e3;
    --line: light-dark(#d3e3df, #27504b);
    --line-strong: light-dark(#b7d0ca, #3a6b64);
    --brand: light-dark(var(--teal-600), var(--teal-300));
    --brand-ink: light-dark(var(--teal-700), var(--teal-200));
    --accent: var(--duck);
    --accent-hover: var(--duck-deep);
    --accent-ink: var(--teal-900);
    --focus: light-dark(var(--teal-600), var(--duck));

    --font-display: "Bricolage Grotesque", "Instrument Sans", system-ui, sans-serif;
    --font-body: "Instrument Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

    --text-sm: 0.9rem;
    --text-base: 1.0625rem;
    --text-lg: 1.2rem;
    --text-xl: clamp(1.25rem, 1.05rem + 0.8vw, 1.5rem);
    --h3: 1.35rem;
    --h2: clamp(1.75rem, 1.2rem + 2vw, 2.5rem);
    --h1: clamp(2.4rem, 1.5rem + 3.6vw, 3.9rem);
    --display: clamp(2.7rem, 1.4rem + 5.5vw, 5.4rem);
    --measure: 66ch;

    --wrap: 1120px;
    --gutter: clamp(16px, 4vw, 40px);
    --radius-lg: 24px;
    --radius: 14px;
    --radius-sm: 8px;
    --space-section: clamp(56px, 9vw, 112px);
    --space-block: clamp(32px, 5vw, 56px);
    --shadow-lift: 0 18px 40px -24px light-dark(rgba(14, 41, 39, 0.35), rgba(0, 0, 0, 0.6));

    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    interpolate-size: allow-keywords;
  }
  /* The header switch sets data-theme; every color above is light-dark(), so this one line flips the whole site */
  :root[data-theme="light"] { color-scheme: light; }
  :root[data-theme="dark"] { color-scheme: dark; }
}

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
  body { margin: 0; }
  img, svg, video { max-width: 100%; height: auto; display: block; }
  button, input, textarea, select { font: inherit; color: inherit; }
  h1, h2, h3, h4, p, figure, dl, dd { margin: 0; }
  ul, ol { margin: 0; }
  [hidden] { display: none !important; }
  @media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  }
}

@view-transition { navigation: auto; }

@layer base {
  body {
    background: var(--bg);
    color: var(--ink);
    font: 400 var(--text-base) / 1.6 var(--font-body);
    font-feature-settings: "ss01";
  }

  a { color: var(--brand-ink); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
  a:hover { text-decoration-thickness: 2px; }

  :focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: 4px; }

  h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-optical-sizing: auto;
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -0.02em;
    color: var(--ink);
    text-wrap: balance;
  }
  h1 { font-size: var(--h1); line-height: 1.02; letter-spacing: -0.03em; }
  h2 { font-size: var(--h2); }
  h3 { font-size: var(--h3); letter-spacing: -0.01em; }
  p { text-wrap: pretty; }
  p + p { margin-top: 1em; }
  strong { font-weight: 600; }

  ::selection { background: var(--duck); color: var(--teal-900); }
}

@layer layout {
  .container {
    width: 100%;
    max-width: var(--wrap);
    margin-inline: auto;
    padding-inline: var(--gutter);
    container-type: inline-size;
  }
  .narrow { max-width: 820px; }
  .section { padding-block: var(--space-section); }
  .section-tight { padding-block: var(--space-block); }
  .section-head { max-width: 60ch; margin-bottom: var(--space-block); }
  .section-head p { margin-top: 0.75em; color: var(--ink-2); font-size: var(--text-lg); }

  .skip-link { position: absolute; left: -9999px; top: 12px; z-index: 100; }
  .skip-link:focus { left: 12px; background: var(--duck); color: var(--teal-900); padding: 10px 14px; border-radius: 999px; font-weight: 600; text-decoration: none; }
  .visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

/* ===================== Components ===================== */
@layer components {

  /* ---------- Buttons ---------- */
  .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5em;
    padding: 0.78em 1.5em;
    border-radius: 999px;
    border: 1.5px solid transparent;
    background: var(--brand-ink);
    color: var(--white);
    font: 600 1rem / 1.2 var(--font-body);
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.18s, color 0.18s, border-color 0.18s, transform 0.18s var(--ease-out), box-shadow 0.18s;
  }
  .button:hover { background: var(--teal-800); color: var(--white); text-decoration: none; transform: translateY(-1px); }
  .button:active { transform: translateY(0); }

  .button-primary, .button-muted { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
  .button-primary:hover, .button-muted:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-ink); }

  .button-outline { background: transparent; border-color: var(--line-strong); color: var(--ink); }
  .button-outline:hover { background: var(--bg-tint); border-color: var(--brand); color: var(--ink); }

  .button-dark { background: var(--ink); color: var(--bg); }
  .button-dark:hover { background: var(--brand-ink); color: var(--white); }

  .button-lg { padding: 0.95em 1.8em; font-size: 1.08rem; }
  .button-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }

  .chip {
    display: inline-block;
    padding: 0.25em 0.75em;
    border-radius: 999px;
    background: var(--bg-tint);
    color: var(--brand-ink);
    font-size: var(--text-sm);
    font-weight: 600;
    line-height: 1.4;
  }
  .chip-accent { background: var(--accent); color: var(--accent-ink); }

  /* ---------- Header ---------- */
  .site-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: color-mix(in srgb, var(--bg) 84%, transparent);
    backdrop-filter: blur(14px) saturate(1.2);
    -webkit-backdrop-filter: blur(14px) saturate(1.2);
    border-bottom: 1px solid transparent;
  }
  @supports (animation-timeline: scroll()) {
    .site-header { animation: header-stick linear both; animation-timeline: scroll(); animation-range: 0 64px; }
    @keyframes header-stick { to { border-bottom-color: var(--line); } }
  }
  .header-inner { display: flex; align-items: center; gap: 24px; min-height: 76px; }
  .logo { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); margin-right: auto; }
  .logo-mark { width: 44px; height: auto; flex: none; }
  .wordmark { font: 700 1.25rem / 1 var(--font-display); letter-spacing: -0.02em; }

  .site-nav { display: flex; gap: 4px; }
  .site-nav a {
    padding: 8px 12px;
    border-radius: 999px;
    color: var(--ink-2);
    font-weight: 500;
    text-decoration: none;
    transition: background-color 0.15s, color 0.15s;
  }
  .site-nav a:hover { color: var(--ink); background: var(--bg-tint-2); }
  .site-nav a.active { color: var(--ink); background: var(--bg-tint); }
  .site-nav .nav-home { display: none; }

  .nav-toggle { display: none; }

  @media (max-width: 900px) {
    .header-inner { min-height: 68px; gap: 12px; }
    .header-cta { display: none; }
    .nav-toggle {
      display: inline-flex; flex-direction: column; justify-content: center; gap: 5px;
      width: 44px; height: 44px; padding: 10px;
      background: none; border: 0; border-radius: 999px; cursor: pointer;
    }
    .nav-toggle:hover { background: var(--bg-tint-2); }
    .nav-toggle span { display: block; height: 2px; background: var(--ink); border-radius: 2px; transition: transform 0.2s, opacity 0.2s; }
    .nav-open .nav-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
    .nav-open .nav-toggle span:nth-child(2) { opacity: 0; }
    .nav-open .nav-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
    .site-nav {
      display: none;
      position: absolute; inset: 100% 0 auto 0;
      flex-direction: column; gap: 2px;
      padding: 8px var(--gutter) 20px;
      background: var(--bg);
      border-bottom: 1px solid var(--line);
      box-shadow: var(--shadow-lift);
    }
    .site-nav a { padding: 12px 14px; font-size: 1.1rem; }
    .site-nav .nav-home { display: block; }
    .nav-open .site-nav { display: flex; }
  }

  /* ---------- Page hero (typographic, optional photo) ---------- */
  .page-hero { background: var(--bg-tint); }
  .page-hero-inner {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr);
    gap: clamp(24px, 5vw, 64px);
    align-items: center;
    padding-block: clamp(40px, 7vw, 88px);
  }
  .page-hero-inner.no-image { grid-template-columns: 1fr; }
  .page-hero h1 { max-width: 14ch; }
  .page-hero .hero-subtitle { margin-top: 0.8em; max-width: 44ch; font-size: var(--text-xl); color: var(--ink-2); line-height: 1.45; }
  .page-hero .hero-actions { margin-top: 28px; }
  .page-hero-image img {
    width: 100%; aspect-ratio: 4 / 3; object-fit: cover;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lift);
  }
  @container (max-width: 720px) {
    .page-hero-inner { grid-template-columns: 1fr; }
    .page-hero-image img { aspect-ratio: 16 / 9; }
  }

  /* ---------- Latest post banner (home, above the hero) ---------- */
  .latest-banner { background: var(--bg-tint); border-bottom: 1px solid var(--line); }
  .latest-banner-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 14px;
    padding-block: 12px;
    color: var(--ink-2);
    font-size: var(--text-sm);
    text-decoration: none;
  }
  .latest-banner-inner time { white-space: nowrap; }
  .latest-banner-title { color: var(--ink); font-weight: 600; }
  .latest-banner-inner:hover .latest-banner-title { color: var(--brand-ink); text-decoration: underline; text-decoration-thickness: 2px; }

  /* ---------- Home hero with the duck on the line ---------- */
  .hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: clamp(32px, 6vw, 80px);
    align-items: center;
    padding-block: clamp(40px, 7vw, 96px) clamp(32px, 5vw, 64px);
  }
  .hero h1 {
    font-size: var(--display);
    line-height: 0.98;
    letter-spacing: -0.035em;
    font-variation-settings: "wdth" 92;
    max-width: 11ch;
  }
  .hero-lede { margin-top: 1.1em; max-width: 42ch; font-size: var(--text-xl); line-height: 1.45; color: var(--ink-2); }
  .hero .button-row { margin-top: 32px; }
  .hero-note { margin-top: 16px; font-size: var(--text-sm); color: var(--ink-3); }
  @container (max-width: 820px) {
    .hero { grid-template-columns: 1fr; }
    .hero h1 { max-width: 14ch; }
  }

  .duck-chart { width: 100%; }
  .duck-chart svg { width: 100%; height: auto; overflow: visible; }
  .duck-chart figcaption { margin-top: 10px; font-size: var(--text-sm); color: var(--ink-3); text-align: right; }
  .dc-grid { stroke: var(--line); }
  .dc-stop-a { stop-color: var(--brand); stop-opacity: 0.32; }
  .dc-stop-b { stop-color: var(--brand); stop-opacity: 0; }
  .dc-area { opacity: 0; animation: dc-fade 0.8s ease-out 1.5s forwards; }
  .dc-line {
    fill: none; stroke: var(--brand); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round;
    stroke-dasharray: 1; stroke-dashoffset: 1;
    animation: dc-draw 1.6s cubic-bezier(0.65, 0, 0.35, 1) 0.2s forwards;
  }
  .dc-dots circle { fill: var(--bg); stroke: var(--brand); stroke-width: 3; opacity: 0; animation: dc-fade 0.4s ease-out forwards; }
  .dc-dots text { font: 600 13px var(--font-body); fill: var(--ink-2); text-anchor: middle; opacity: 0; animation: dc-fade 0.4s ease-out forwards; }
  .dc-dots .dc-1 { animation-delay: 0.65s; }
  .dc-dots .dc-2 { animation-delay: 0.9s; }
  .dc-dots .dc-3 { animation-delay: 1.15s; }
  .dc-dots .dc-4 { animation-delay: 1.4s; }
  .dc-dots .dc-5 { animation-delay: 1.65s; }
  .dc-duck { transform-box: fill-box; transform-origin: center; opacity: 0; animation: dc-rise 0.9s var(--ease-out) 1.6s forwards, dc-bob 3.4s ease-in-out 2.6s infinite; }
  @keyframes dc-draw { to { stroke-dashoffset: 0; } }
  @keyframes dc-fade { to { opacity: 1; } }
  @keyframes dc-rise { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }
  @keyframes dc-bob { 0%, 100% { transform: translateY(0) rotate(0deg); } 50% { transform: translateY(-5px) rotate(-2deg); } }
  @media (prefers-reduced-motion: reduce) {
    .dc-line { stroke-dashoffset: 0; animation: none; }
    .dc-area, .dc-dots circle, .dc-dots text, .dc-duck { opacity: 1; animation: none; }
  }

  /* ---------- Feature row (text + photo) ---------- */
  .split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: clamp(24px, 5vw, 72px);
    align-items: center;
    padding-block: var(--space-block);
  }
  .split + .split { border-top: 1px solid var(--line); }
  .split-text h2 { max-width: 16ch; }
  .split-text p { margin-top: 0.8em; max-width: 40ch; font-size: var(--text-lg); color: var(--ink-2); }
  .split-text .button, .split-text .social { margin-top: 24px; }
  .split-image img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--radius-lg); }
  .split-reverse .split-text { order: 2; }
  @container (max-width: 720px) {
    .split { grid-template-columns: 1fr; gap: 20px; }
    .split-reverse .split-text { order: 0; }
    .split-image img { aspect-ratio: 16 / 9; }
  }

  /* ---------- Social ---------- */
  .social { list-style: none; display: flex; gap: 8px; padding: 0; margin: 0; }
  .social a {
    display: grid; place-items: center;
    width: 44px; height: 44px; border-radius: 999px;
    color: inherit; background: var(--bg-tint-2); border: 1px solid var(--line);
    transition: background-color 0.15s, color 0.15s, border-color 0.15s;
  }
  .social a:hover { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
  .social svg { width: 20px; height: 20px; fill: currentColor; }
  .social svg.icon-stroke { fill: none; }

  /* ---------- Footer ---------- */
  .site-footer { background: var(--bg-deep); color: var(--ink-on-deep); margin-top: var(--space-section); padding-block: 64px 28px; }
  .site-footer a { color: inherit; }
  .footer-inner { display: grid; grid-template-columns: 1.5fr 1fr 1fr 1fr; gap: 40px; }
  .footer-brand .wordmark { font-size: 1.6rem; color: var(--white); display: block; }
  .footer-brand p { margin-top: 14px; max-width: 30ch; color: color-mix(in srgb, var(--ink-on-deep) 80%, transparent); }
  .footer-col h3 { font: 600 0.95rem / 1.4 var(--font-body); color: var(--white); margin-bottom: 12px; }
  .footer-col ul { list-style: none; padding: 0; display: grid; gap: 8px; }
  .footer-col a { text-decoration: none; }
  .footer-col a:hover { text-decoration: underline; }
  .footer-col address { font-style: normal; line-height: 1.5; }
  .footer-col address p + p { margin-top: 8px; }
  .site-footer .social a { background: rgba(255, 255, 255, 0.06); border-color: rgba(255, 255, 255, 0.14); color: var(--white); }
  .site-footer .social a:hover { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
  .footer-bottom {
    margin-top: 48px; padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px 24px;
    font-size: var(--text-sm); color: color-mix(in srgb, var(--ink-on-deep) 75%, transparent);
  }
  .footer-bottom ul { list-style: none; padding: 0; display: flex; gap: 18px; }
  .footer-bottom a { text-decoration: none; }
  .footer-bottom a:hover { text-decoration: underline; }
  .footer-disclaimer { width: 100%; max-width: 70ch; }
  @media (max-width: 860px) { .footer-inner { grid-template-columns: 1fr 1fr; } }
  @media (max-width: 520px) { .footer-inner { grid-template-columns: 1fr; gap: 28px; } }

  /* ---------- Prose (posts, terms, lesson bodies) ---------- */
  .prose { font-size: var(--text-base); line-height: 1.7; }
  .prose > * + * { margin-top: 1em; }
  .prose p, .prose li { max-width: var(--measure); }
  .prose h2 { font-size: var(--h2); margin-top: 1.6em; }
  .prose h3 { font-size: var(--h3); margin-top: 1.4em; }
  .prose h2 + *, .prose h3 + * { margin-top: 0.6em; }
  .prose hr { border: 0; border-top: 1px solid var(--line); margin: 2.2em 0; }
  .prose ul, .prose ol { padding-left: 1.3em; }
  .prose li + li { margin-top: 0.35em; }
  .prose blockquote { border-left: 3px solid var(--brand); padding-left: 1em; color: var(--ink-2); }
  .prose table { width: 100%; border-collapse: collapse; font-size: 0.95rem; display: block; overflow-x: auto; }
  .prose th, .prose td { border-bottom: 1px solid var(--line); padding: 0.6em 0.8em; text-align: left; vertical-align: top; }
  .prose th { background: var(--bg-tint-2); font-weight: 600; }
  .prose img { border-radius: var(--radius); }

  /* ---------- Post list (editorial rows) ---------- */
  .post-list { list-style: none; padding: 0; display: grid; }
  .post-item {
    display: grid;
    grid-template-columns: 170px minmax(0, 1fr);
    gap: 8px 32px;
    padding: 28px 0;
    border-top: 1px solid var(--line);
  }
  .post-item:last-child { border-bottom: 1px solid var(--line); }
  .post-item h3 { font-size: 1.45rem; }
  .post-item h3 a { color: var(--ink); text-decoration: none; }
  .post-item h3 a:hover { color: var(--brand-ink); text-decoration: underline; text-decoration-thickness: 2px; }
  .post-item p { max-width: 62ch; color: var(--ink-2); }
  .post-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; font-size: var(--text-sm); color: var(--ink-3); }
  .post-meta a { color: inherit; text-decoration: none; }
  .post-meta a:hover { text-decoration: underline; }
  .post-item .post-meta { flex-direction: column; align-items: flex-start; gap: 4px; padding-top: 4px; }
  @container (max-width: 640px) {
    .post-item { grid-template-columns: 1fr; gap: 6px; padding: 22px 0; }
    .post-item .post-meta { flex-direction: row; align-items: center; gap: 6px 14px; order: 2; }
  }

  .post-featured {
    display: grid; gap: 14px;
    padding: clamp(28px, 5vw, 48px);
    margin-bottom: var(--space-block);
    background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius-lg);
  }
  .post-featured h2 { font-size: clamp(1.8rem, 1.2rem + 2.4vw, 2.8rem); max-width: 22ch; }
  .post-featured h2 a { color: inherit; text-decoration: none; }
  .post-featured h2 a:hover { color: var(--brand-ink); }
  .post-featured p { max-width: 60ch; font-size: var(--text-lg); color: var(--ink-2); }
  .post-featured .button { justify-self: start; margin-top: 8px; }

  /* ---------- Lessons ---------- */
  .unit-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 24px; }
  .unit-card { position: relative; display: grid; gap: 12px; color: inherit; text-decoration: none; }
  .unit-card-media { position: relative; overflow: hidden; border-radius: var(--radius-lg); aspect-ratio: 4 / 5; background: var(--bg-tint); }
  .unit-card-media img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.5s var(--ease-out); }
  .unit-card:hover .unit-card-media img { transform: scale(1.04); }
  .unit-card-num {
    position: absolute; top: 14px; left: 14px;
    display: grid; place-items: center; min-width: 40px; height: 40px; padding-inline: 12px;
    border-radius: 999px; background: var(--accent); color: var(--accent-ink);
    font: 700 1.1rem var(--font-display);
  }
  .unit-card-title { font: 700 1.5rem / 1.1 var(--font-display); letter-spacing: -0.02em; }
  .unit-card-text { display: grid; gap: 4px; }
  .unit-card-text span:last-child { color: var(--ink-2); }
  .unit-card-soon .unit-card-media img { opacity: 0.55; filter: saturate(0.4); }
  .unit-card-soon .unit-card-num { background: var(--bg-raised); color: var(--ink-3); border: 1px solid var(--line); }
  @container (max-width: 860px) { .unit-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
  @container (max-width: 420px) { .unit-grid { grid-template-columns: 1fr; } .unit-card-media { aspect-ratio: 16 / 10; } }

  .lesson-list { list-style: none; padding: 0; display: grid; gap: 12px; max-width: 760px; }
  .lesson-list a {
    display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; gap: 18px; align-items: center;
    padding: 20px 22px;
    background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius);
    color: inherit; text-decoration: none;
    transition: border-color 0.15s, transform 0.2s var(--ease-out), box-shadow 0.2s;
  }
  .lesson-list a:hover { border-color: var(--brand); transform: translateY(-2px); box-shadow: var(--shadow-lift); }
  .lesson-num { font: 700 1.9rem / 1 var(--font-display); color: var(--brand); }
  .lesson-name { font-weight: 600; font-size: 1.1rem; line-height: 1.3; }
  .lesson-go { font-size: var(--text-sm); color: var(--ink-3); }
  @container (max-width: 520px) { .lesson-list a { grid-template-columns: 44px minmax(0, 1fr); } .lesson-go { display: none; } }

  /* Lesson page */
  .lesson-head { padding-block: clamp(32px, 5vw, 56px) 8px; }
  .lesson-unit { margin-bottom: 14px; }
  .lesson-unit a { text-decoration: none; }
  .lesson-head h1 { max-width: 22ch; }
  .lesson-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 56px; align-items: start; padding-block: 24px 0; }
  .lesson-toc { position: sticky; top: 92px; }
  .lesson-toc h2 { font: 600 0.9rem / 1.4 var(--font-body); color: var(--ink-3); margin-bottom: 10px; }
  .lesson-toc ol { list-style: none; padding: 0; display: grid; gap: 2px; border-left: 1px solid var(--line); }
  .lesson-toc a {
    display: block; padding: 6px 14px; margin-left: -1px;
    border-left: 2px solid transparent;
    color: var(--ink-2); text-decoration: none; font-size: var(--text-sm);
  }
  .lesson-toc a:hover { color: var(--ink); }
  .lesson-toc a[aria-current="true"] { color: var(--ink); border-left-color: var(--brand); font-weight: 600; }
  .lesson-main { max-width: 720px; }
  .lesson-section { display: grid; gap: 10px; padding-bottom: 40px; scroll-margin-top: 96px; }
  .lesson-label { font: 700 1.5rem / 1.2 var(--font-display); letter-spacing: -0.02em; }
  .lesson-body { font-size: var(--text-base); line-height: 1.7; }
  .lesson-body > * + * { margin-top: 0.9em; }
  .lesson-body ul, .lesson-body ol { padding-left: 1.3em; }
  .lesson-body li + li { margin-top: 0.3em; }
  .lesson-body h4 { font: 600 1em / 1.4 var(--font-body); margin-top: 1.2em; }
  .lesson-body blockquote { margin: 1em 0; padding: 14px 18px; border-left: 3px solid var(--brand); background: var(--bg-tint-2); border-radius: 0 var(--radius) var(--radius) 0; color: var(--ink-2); }
  .lesson-section.band { background: var(--bg-tint); padding: 28px clamp(20px, 4vw, 32px); border-radius: var(--radius-lg); margin-bottom: 40px; }
  .lesson-section.band-light { background: var(--bg-deep); color: var(--ink-on-deep); }
  .lesson-section.band-light .lesson-label { color: var(--white); }
  .lesson-section.band-light strong { color: var(--white); }
  .lesson-section.band-light a:not(.button) { color: var(--white); }
  .lesson-section.band-light .button { margin-top: 6px; }
  @container (max-width: 860px) {
    .lesson-layout { grid-template-columns: 1fr; gap: 24px; }
    .lesson-toc { position: static; }
    .lesson-toc ol { display: flex; flex-wrap: wrap; gap: 6px; border: 0; }
    .lesson-toc a { padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; margin: 0; }
    .lesson-toc a[aria-current="true"] { border-color: var(--brand); background: var(--bg-tint); }
  }

  /* ---------- Home ---------- */
  .intro { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: clamp(24px, 5vw, 72px); align-items: start; }
  .intro h2 { max-width: 12ch; }
  .intro-text p { color: var(--ink-2); font-size: var(--text-lg); }
  .features { list-style: none; padding: 0; margin-top: var(--space-block); display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 32px; }
  .features li { display: grid; gap: 10px; padding-top: 18px; border-top: 2px solid var(--brand); }
  .features img { width: 52px; height: 52px; object-fit: contain; }
  .features strong { font: 600 1.2rem / 1.2 var(--font-display); letter-spacing: -0.01em; }
  .features span { color: var(--ink-2); font-size: var(--text-sm); line-height: 1.5; }
  @container (max-width: 760px) { .intro { grid-template-columns: 1fr; } .features { grid-template-columns: 1fr; gap: 20px; } }

  /* ---------- Newsletter ---------- */
  .perks { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
  .perk { padding: 28px; border-radius: var(--radius-lg); background: var(--bg-raised); border: 1px solid var(--line); }
  .perk h3 { font-size: 1.4rem; }
  .perk p { margin-top: 8px; color: var(--ink-2); }
  @container (max-width: 640px) { .perks { grid-template-columns: 1fr; } }

  .cta-band {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 24px 48px; align-items: center;
    padding: clamp(28px, 5vw, 48px);
    background: var(--bg-deep); color: var(--ink-on-deep);
    border-radius: var(--radius-lg);
  }
  .cta-band h2 { color: var(--white); max-width: 18ch; }
  .cta-band p { margin-top: 0.6em; max-width: 48ch; }
  .cta-band-action { display: grid; gap: 10px; justify-items: start; }
  .cta-band-price { font: 700 2.4rem / 1 var(--font-display); color: var(--white); }
  .cta-band-price small { font: 500 1rem var(--font-body); color: var(--ink-on-deep); }
  @container (max-width: 700px) { .cta-band { grid-template-columns: 1fr; } }

  .faq { display: grid; gap: 8px; }
  .faq-item { border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-raised); }
  .faq-item summary {
    display: flex; justify-content: space-between; align-items: center; gap: 16px;
    padding: 18px 22px; cursor: pointer; list-style: none;
    font-weight: 600; font-size: 1.05rem;
  }
  .faq-item summary::-webkit-details-marker { display: none; }
  .faq-item summary::after {
    content: ""; flex: none; width: 12px; height: 12px;
    background:
      linear-gradient(var(--brand), var(--brand)) center / 100% 2px no-repeat,
      linear-gradient(var(--brand), var(--brand)) center / 2px 100% no-repeat;
    transition: transform 0.25s var(--ease-out);
  }
  .faq-item[open] summary::after { transform: rotate(45deg); }
  .faq-item p { padding: 0 22px 20px; max-width: 64ch; color: var(--ink-2); }
  .faq-item::details-content { overflow: hidden; block-size: 0; transition: block-size 0.3s var(--ease-out), content-visibility 0.3s allow-discrete; }
  .faq-item[open]::details-content { block-size: auto; }

  /* ---------- Pricing ---------- */
  .plan-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; max-width: 860px; margin-inline: auto; }
  .plan { display: grid; gap: 10px; align-content: start; padding: clamp(24px, 4vw, 36px); border-radius: var(--radius-lg); background: var(--bg-raised); border: 1px solid var(--line); }
  .plan-featured { background: var(--bg-deep); color: var(--ink-on-deep); border-color: transparent; }
  .plan-featured h2, .plan-featured .plan-price { color: var(--white); }
  .plan img { aspect-ratio: 5 / 2; object-fit: cover; border-radius: var(--radius); margin-bottom: 8px; }
  .plan h2 { font-size: 1.8rem; }
  .plan-price { font: 700 3.2rem / 1 var(--font-display); letter-spacing: -0.03em; font-variant-numeric: lining-nums; margin-top: 6px; }
  .plan-price small { font: 500 1rem var(--font-body); letter-spacing: 0; color: var(--ink-3); margin-left: 6px; }
  .plan-featured .plan-price small { color: var(--ink-on-deep); }
  .plan-desc { color: var(--ink-2); }
  .plan-featured .plan-desc { color: var(--ink-on-deep); }
  .plan .button { justify-self: start; margin-top: 10px; }
  .plan .button:disabled { opacity: 0.5; cursor: not-allowed; }
  .plan-note { font-size: var(--text-sm); color: var(--ink-2); }
  .plan-featured .plan-note { color: var(--ink-on-deep); }
  .plan-featured .plan-note a { color: inherit; }
  .plan-perks { list-style: none; padding: 0; margin-top: 10px; display: grid; gap: 6px; font-size: var(--text-sm); }
  .plan-perks li { padding-left: 1.5em; position: relative; }
  .plan-perks li::before { content: "✓"; position: absolute; left: 0; color: var(--brand); font-weight: 700; }
  .plan-featured .plan-perks li::before { color: var(--accent); }
  @container (max-width: 640px) { .plan-grid { grid-template-columns: 1fr; } }

  /* ---------- About ---------- */
  .about-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: clamp(24px, 5vw, 72px); align-items: center; padding-block: var(--space-block); }
  .about-row + .about-row { border-top: 1px solid var(--line); }
  .about-row h2 { max-width: 18ch; }
  .about-row p { margin-top: 0.8em; max-width: 48ch; color: var(--ink-2); font-size: var(--text-lg); }
  .about-row .button { margin-top: 20px; }
  .about-row img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--radius-lg); }
  .about-row-reverse > div { order: 2; }
  @container (max-width: 720px) {
    .about-row { grid-template-columns: 1fr; gap: 20px; }
    .about-row-reverse > div { order: 0; }
    .about-row img { aspect-ratio: 16 / 9; }
  }
  .offer-grid { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; margin-top: var(--space-block); }
  .offer-grid li { padding: 24px; border-radius: var(--radius-lg); background: var(--bg-tint-2); border: 1px solid var(--line); }
  .offer-grid strong { display: block; font: 600 1.2rem / 1.25 var(--font-display); margin-bottom: 8px; }
  .offer-grid li { color: var(--ink-2); }
  @container (max-width: 640px) { .offer-grid { grid-template-columns: 1fr; } }

  /* ---------- Contact ---------- */
  .contact { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); gap: clamp(32px, 6vw, 80px); align-items: start; }
  .contact-info p { color: var(--ink-2); }
  .contact-info ul { margin-top: 12px; padding-left: 1.2em; display: grid; gap: 6px; color: var(--ink-2); }
  .contact-form { display: grid; gap: 16px; padding: clamp(24px, 4vw, 36px); border-radius: var(--radius-lg); background: var(--bg-raised); border: 1px solid var(--line); }
  .contact-form h2 { font-size: 1.6rem; }
  .contact-form label { display: grid; gap: 6px; font-size: var(--text-sm); font-weight: 600; }
  .contact-form input, .contact-form textarea {
    padding: 12px 14px;
    border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
    background: var(--bg); color: var(--ink);
    font-weight: 400; font-size: 1rem;
    transition: border-color 0.15s, box-shadow 0.15s;
  }
  .contact-form input:focus, .contact-form textarea:focus { outline: 0; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 25%, transparent); }
  .contact-form textarea { resize: vertical; min-height: 140px; }
  .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  .contact-form .button { justify-self: start; margin-top: 4px; }
  @container (max-width: 720px) { .contact, .form-row { grid-template-columns: 1fr; } }

  /* ---------- Author ---------- */
  .author-head { display: flex; align-items: center; gap: 24px; margin-bottom: var(--space-block); }
  .author-avatar { width: 96px; height: auto; flex: none; }
  .author-head p { margin-top: 6px; color: var(--ink-2); }

  /* ---------- Simple notice pages (404, thanks) ---------- */
  .notice { max-width: 560px; margin-inline: auto; text-align: center; padding-block: var(--space-section); }
  .notice p { margin-top: 1em; color: var(--ink-2); font-size: var(--text-lg); }
  .notice .button-row { justify-content: center; margin-top: 28px; }

  /* ---------- Post page ---------- */
  .post-wrap { max-width: 780px; margin-inline: auto; padding-block: clamp(28px, 4vw, 48px) 0; }
  .post-back { margin-bottom: 28px; font-size: var(--text-sm); }
  .post-back a { text-decoration: none; }
  .post-back a:hover { text-decoration: underline; }
  .post-title { margin: 12px 0 28px; max-width: 20ch; }
  .read-time { padding: 0.15em 0.6em; border-radius: 999px; background: var(--bg-tint); color: var(--brand-ink); font-weight: 600; }
  .recent-posts { margin-top: var(--space-section); }
  .recent-head { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; margin-bottom: 8px; }
  .recent-head h2 { font-size: 1.5rem; }
  .recent-head a { font-size: var(--text-sm); text-decoration: none; font-weight: 600; }
  .recent-head a:hover { text-decoration: underline; }

  .page-body { max-width: 780px; padding-block: clamp(28px, 4vw, 48px) 0; }
  .page-title { margin-bottom: 0.6em; }
}

@layer utilities {
  .center { text-align: center; }
  .small { font-size: var(--text-sm); color: var(--ink-3); }
  .mt-block { margin-top: var(--space-block); }
}

/* ---------- Lesson quiz module ---------- */
@layer components {
  .quiz { display: grid; gap: 28px; }
  .quiz-intro { color: var(--ink-2); }
  .quiz-q { border: 0; padding: 0; margin: 0; min-width: 0; display: grid; gap: 10px; }
  .quiz-q legend { display: flex; gap: 12px; align-items: baseline; font-weight: 600; font-size: 1.1rem; line-height: 1.35; margin-bottom: 12px; padding: 0; }
  .quiz-num { flex: none; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 999px; background: var(--bg-tint); color: var(--brand-ink); font: 700 0.95rem var(--font-display); align-self: center; }
  .quiz-opt {
    display: grid; grid-template-columns: auto auto minmax(0, 1fr); gap: 12px; align-items: center;
    padding: 12px 16px;
    border: 1.5px solid var(--line); border-radius: var(--radius);
    background: var(--bg-raised);
    cursor: pointer;
    transition: border-color 0.15s, background-color 0.15s, transform 0.15s var(--ease-out);
  }
  .quiz-opt:hover { border-color: var(--line-strong); }
  .quiz-opt:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
  .quiz-opt:has(input:checked) { border-color: var(--brand); background: var(--bg-tint-2); }
  .quiz-opt input { margin: 0; width: 18px; height: 18px; accent-color: var(--brand); }
  .quiz-letter { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 999px; background: var(--bg-tint); color: var(--brand-ink); font: 700 0.85rem var(--font-body); }
  .quiz-feedback { display: none; margin: 2px 0 0; font-size: var(--text-sm); font-weight: 600; }

  /* After checking: lock the options and color the right and wrong ones */
  .quiz.is-checked .quiz-opt { cursor: default; }
  .quiz.is-checked .quiz-opt:hover { border-color: var(--line); }
  .quiz.is-checked .quiz-opt:has(input:checked) { border-color: var(--line); background: var(--bg-raised); }
  .quiz.is-checked .quiz-feedback { display: block; }
  .quiz-q.is-correct .quiz-opt.is-key { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 14%, var(--bg-raised)); }
  .quiz-q.is-correct .quiz-opt.is-key .quiz-letter { background: var(--brand); color: var(--white); }
  .quiz-q.is-correct .quiz-feedback { color: var(--brand-ink); }
  .quiz-q.is-wrong .quiz-opt.is-chosen { border-color: var(--bill); background: color-mix(in srgb, var(--bill) 12%, var(--bg-raised)); }
  .quiz-q.is-wrong .quiz-opt.is-chosen .quiz-letter { background: var(--bill); color: var(--white); }
  .quiz-q.is-wrong .quiz-opt.is-key { border-color: var(--brand); border-style: dashed; }
  .quiz-q.is-wrong .quiz-feedback, .quiz-q.is-unanswered .quiz-feedback { color: light-dark(#b35d05, #f9b36a); }
  .quiz-q.is-unanswered .quiz-opt.is-key { border-color: var(--brand); border-style: dashed; }

  .quiz-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; }
  .quiz-score { margin: 0; font-weight: 600; }
  .quiz-score strong { font: 700 1.3rem var(--font-display); color: var(--brand-ink); margin-right: 6px; }
  .quiz-key summary { cursor: pointer; font-size: var(--text-sm); color: var(--ink-3); }
  .quiz-key p { margin-top: 6px; font-size: var(--text-sm); color: var(--ink-2); }
  .quiz-section.band-light .quiz-opt { background: var(--bg-deep); }
  @container (max-width: 480px) { .quiz-opt { padding: 10px 12px; } }
}

/* Unit page with no lessons published yet */
@layer components {
  .lesson-empty { display: grid; gap: 16px; justify-items: start; max-width: 52ch; padding: 28px; border-radius: var(--radius-lg); background: var(--bg-tint); }
  .lesson-empty p { color: var(--ink-2); }
}

/* ---------- Lesson extras: subtitles in lists, tables, the candlestick figure ---------- */
@layer components {
  .lesson-sub { display: block; margin-top: 2px; font-weight: 400; font-size: var(--text-sm); color: var(--ink-3); }

  .lesson-body table { width: 100%; border-collapse: collapse; font-size: 0.95rem; display: block; overflow-x: auto; }
  .lesson-body th, .lesson-body td { border-bottom: 1px solid var(--line); padding: 0.6em 0.8em; text-align: left; vertical-align: top; }
  .lesson-body th { background: var(--bg-tint-2); font-weight: 600; }

  .candle-chart { margin: 1.4em 0; padding: 20px clamp(12px, 3vw, 24px) 16px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--bg-raised);
    --cs-up: light-dark(#1f9d63, #35a86c); --cs-down: light-dark(#a32d24, #b94034); }
  .candle-chart svg { width: 100%; height: auto; }
  .candle-chart figcaption { margin-top: 12px; font-size: var(--text-sm); color: var(--ink-3); max-width: 60ch; }
  .cs-grid line { stroke: var(--line); stroke-width: 1; }
  .cs-up line, .cs-down line { stroke-width: 2; stroke-linecap: round; }
  .cs-up line, .cs-up rect { stroke: var(--cs-up); }
  .cs-up rect { fill: var(--bg-raised); stroke-width: 2; }
  .cs-down line, .cs-down rect { stroke: var(--cs-down); }
  .cs-down rect { fill: var(--cs-down); stroke-width: 2; }
  .cs-big line { stroke-width: 3; }
  .cs-leader line { stroke: var(--line-strong); stroke-width: 1; }
  .cs-label { font: 500 13px var(--font-body); fill: var(--ink-2); }
  .cs-label.cs-end { text-anchor: end; }
  .cs-label.cs-muted { fill: var(--ink-3); font-size: 12px; }
  .cs-label.cs-strong { fill: var(--ink); font-weight: 600; }
}

/* ---------- Post figures: photos and inline charts inside blog posts ---------- */
@layer components {
  .post-figure { margin: 1.8em 0; }
  .post-figure img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: var(--radius-lg); background: var(--bg-tint-2); }
  .post-figure figcaption, .post-chart figcaption { margin-top: 10px; font-size: var(--text-sm); color: var(--ink-3); max-width: var(--measure); }
  .figure-credit { display: block; margin-top: 2px; font-size: 0.8rem; }
  .figure-credit a { color: inherit; }

  .post-chart { margin: 1.8em 0; padding: 20px clamp(12px, 3vw, 24px) 16px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--bg-raised); }
  .post-chart svg { display: block; width: 100%; max-width: 560px; height: auto; margin-inline: auto; }
  .post-chart.post-chart-flow svg { max-width: 340px; }
  .pc-grid line { stroke: var(--line); stroke-width: 1; }
  .pc-axis { stroke: var(--line-strong); stroke-width: 1; }
  .pc-bar { fill: var(--brand); }
  .pc-label { font: 500 14px var(--font-body); fill: var(--ink-2); }
  .pc-label.pc-end { text-anchor: end; }
  .pc-label.pc-mid { text-anchor: middle; }
  .pc-value { font: 600 15px var(--font-body); fill: var(--ink); text-anchor: middle; }
  .pc-muted { font: 500 12px var(--font-body); fill: var(--ink-3); text-anchor: middle; }
  .pc-step rect { fill: var(--bg-tint); stroke: var(--line-strong); stroke-width: 1; }
  .pc-step text { font: 600 15px var(--font-body); fill: var(--ink); text-anchor: middle; }
  .pc-step .pc-num { font-weight: 500; fill: var(--ink-3); }
  .pc-link { stroke: var(--brand); stroke-width: 2; fill: none; }
  .pc-arrowhead { fill: var(--brand); }
}

/* Final lesson: outline button on the dark closing panel */
@layer components {
  .lesson-section.band-light .button-outline { border-color: rgba(255, 255, 255, 0.35); color: var(--white); margin-left: 8px; }
  .lesson-section.band-light .button-outline:hover { background: rgba(255, 255, 255, 0.1); border-color: var(--white); color: var(--white); }
}

/* ---------- Light / dark switch in the header ---------- */
@layer components {
  .theme-switch { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg-tint-2); }
  .theme-switch button {
    display: grid; place-items: center; width: 32px; height: 32px;
    border: 0; border-radius: 999px; background: transparent; color: var(--ink-3); cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
  }
  .theme-switch button:hover { color: var(--ink); }
  .theme-switch button[aria-pressed="true"] { background: light-dark(var(--white), var(--teal-700)); color: light-dark(var(--ink), var(--duck)); box-shadow: 0 1px 2px light-dark(rgba(14, 41, 39, 0.12), rgba(0, 0, 0, 0.4)); }
  .theme-switch svg { width: 16px; height: 16px; }
  @media (max-width: 900px) {
    .theme-switch { margin-left: auto; }
    .logo { margin-right: 0; }
  }
}
