/**
 * site.css — design system for thevarunvaria.github.io
 *
 * Editorial garden with studio polish.
 * Reference stack: Maggie Appleton, Works in Progress, Josh W. Comeau,
 * Craig Mod, Robin Sloan, Gwern, Stripe Press.
 *
 * All colors flow through CSS variables. Dark mode is a token swap;
 * components reference variables only.
 */

/* ============================================
   Design tokens — light (default)
   ============================================ */
:root {
  --bg:             #F9F6F0;
  --bg-elevated:    #F4F0E9;
  --surface:        #FFFFFF;
  --text:           #1A1714;
  --text-secondary: #57534E;
  --text-muted:     #65605A;
  --accent:         #115E59;
  --accent-dark:    #0D4F4B;
  --accent-soft:    rgba(17, 94, 89, 0.08);
  --border:         #D4CFC4;
  --border-strong:  #B9B3A6;

  --growth-evergreen: #115E59;
  --growth-budding:   #A16207;
  --growth-seedling:  #78716C;

  --font-prose: 'EB Garamond', 'Iowan Old Style', Georgia, 'Times New Roman', serif;
  --font-ui:    'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono:  'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;

  --measure: 65ch;
  --ease:    cubic-bezier(0.4, 0, 0.2, 1);

  color-scheme: light;
}

/* ============================================
   Design tokens — dark (opt-in)
   ============================================ */
[data-theme="dark"] {
  --bg:             #14110E;
  --bg-elevated:    #1C1814;
  --surface:        #1F1B17;
  --text:           #F4F0E9;
  --text-secondary: #C4BFB3;
  --text-muted:     #8B857A;
  --accent:         #5EBCB6;
  --accent-dark:    #4FA6A0;
  --accent-soft:    rgba(94, 188, 182, 0.10);
  --border:         #2A2520;
  --border-strong:  #3A3530;

  --growth-evergreen: #5EBCB6;
  --growth-budding:   #D6A04E;
  --growth-seedling:  #8B857A;

  color-scheme: dark;
}

/* ============================================
   Base
   ============================================ */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  font-family: var(--font-ui);
  background-color: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "kern" 1, "liga" 1;
  transition: background-color 0.2s var(--ease), color 0.2s var(--ease);
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-dark); }

img { max-width: 100%; height: auto; }

::selection { background: var(--accent-soft); color: var(--text); }

/* ============================================
   Skip link
   ============================================ */
.skip-link {
  position: absolute;
  top: -100px;
  left: 1rem;
  background: var(--accent);
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: 0 0 6px 6px;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 500;
  z-index: 10000;
  transition: top 0.15s var(--ease);
}
.skip-link:focus {
  top: 0;
  color: #fff;
}

/* ============================================
   Sticky nav
   ============================================ */
.minimal-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background-color: color-mix(in srgb, var(--bg) 92%, transparent);
  border-bottom: 1px solid var(--border);
}

.minimal-nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 2rem;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

@media (max-width: 640px) {
  .minimal-nav-inner { padding: 0 1rem; gap: 0.5rem; }
  .brand > span:not(.brand-dot) { display: none; }
  .nav-links { gap: 1rem; }
  .nav-theme { display: none; }
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  font-size: 1.05rem;
  color: var(--text);
}
.brand:hover { color: var(--text); }
.brand-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -1px;
}

/* In dark mode, --accent lightens to mint-teal; flip text on accent-bg
   elements to dark so they stay AA-legible. */
[data-theme="dark"] .brand-dot,
[data-theme="dark"] .widget-actions button.primary,
[data-theme="dark"] .reading-progress {
  color: var(--bg);
}
[data-theme="dark"] .reading-progress {
  background: linear-gradient(to right, var(--accent), var(--accent-dark));
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 1.6rem;
  font-size: 0.92rem;
}
.nav-links a, .nav-links button {
  color: var(--text-secondary);
  font-weight: 500;
  padding: 0.35rem 0.25rem;
  background: none;
  border: 0;
  cursor: pointer;
  transition: color 0.15s var(--ease);
  font-family: inherit;
  font-size: inherit;
}
.nav-links a:hover, .nav-links button:hover { color: var(--text); }
.nav-links a[aria-current="page"] {
  color: var(--accent);
  font-weight: 500;
}

.nav-search, .nav-theme {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.7rem;
  border-radius: 8px;
  border: 1px solid transparent;
  color: var(--text-secondary);
  background: transparent;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: var(--font-ui);
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease);
}
.nav-search:hover, .nav-theme:hover {
  color: var(--text);
  background: var(--bg-elevated);
  border-color: var(--border);
}
.nav-search kbd {
  font-family: var(--font-mono);
  background: var(--bg-elevated);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 500;
}

/* ============================================
   Typography & prose
   ============================================ */
h1, h2, h3, h4 { font-family: var(--font-ui); letter-spacing: -0.025em; color: var(--text); }

.essay-title {
  font-family: var(--font-prose);
  font-size: clamp(2.2rem, 4.2vw, 3.4rem);
  line-height: 1.04;
  letter-spacing: -0.04em;
  font-weight: 600;
  color: var(--text);
}

.hero-headline {
  font-family: var(--font-prose);
  font-size: clamp(2.6rem, 5.6vw, 4.5rem);
  line-height: 1.02;
  letter-spacing: -0.045em;
  font-weight: 600;
  color: var(--text);
  text-wrap: balance;
}

.section-eyebrow {
  font-family: var(--font-ui);
  text-transform: uppercase;
  letter-spacing: 1.6px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
}

.content-measure { max-width: var(--measure); }

.prose-serif {
  font-family: var(--font-prose);
  font-size: 19.5px;
  line-height: 1.82;
  letter-spacing: -0.003em;
  color: var(--text);
}
.prose-serif p { margin-bottom: 1.35em; }
.prose-serif p:last-child { margin-bottom: 0; }
.prose-serif strong { color: var(--text); font-weight: 600; }
.prose-serif em { font-style: italic; }
.prose-serif a {
  color: var(--accent);
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  transition: border-color 0.15s var(--ease);
}
.prose-serif a:hover { border-bottom-color: var(--accent); }
.prose-serif code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-elevated);
  padding: 1px 6px;
  border-radius: 3px;
  color: var(--text);
}
.prose-serif h2 {
  font-family: var(--font-ui);
  font-size: clamp(1.5rem, 2.2vw, 1.85rem);
  letter-spacing: -0.025em;
  margin-top: 2.1em;
  margin-bottom: 0.7em;
  font-weight: 600;
  color: var(--text);
}
.prose-serif h3 {
  font-family: var(--font-ui);
  font-size: 1.18rem;
  letter-spacing: -0.015em;
  margin-top: 1.6em;
  margin-bottom: 0.5em;
  font-weight: 600;
  color: var(--text);
}
.prose-serif ul, .prose-serif ol {
  margin: 0 0 1.35em 0;
  padding-left: 1.5em;
}
.prose-serif li { margin-bottom: 0.4em; line-height: 1.7; }
.prose-serif .lead {
  font-size: 1.28rem;
  line-height: 1.62;
  color: var(--text-secondary);
}

@media screen and (max-width: 640px) {
  .prose-serif { font-size: 18px; line-height: 1.78; }
}

/* ============================================
   Essay card
   ============================================ */
.essay-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.5rem 1.75rem;
  color: var(--text);
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease), border-color 0.15s var(--ease);
}
.essay-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
  box-shadow: 0 10px 15px -3px rgba(0,0,0,0.05), 0 4px 6px -4px rgba(0,0,0,0.05);
  color: var(--text);
}

/* ============================================
   Pull quote
   ============================================ */
.pull-quote {
  font-family: var(--font-prose);
  font-size: 1.5rem;
  line-height: 1.35;
  font-style: italic;
  color: var(--text);
  border-left: 3px solid var(--accent);
  padding: 0.2rem 0 0.2rem 1.35rem;
  margin: 2.4rem 0;
  max-width: 38rem;
}

/* ============================================
   Framework note (Stripe Press sidebar feel)
   ============================================ */
.framework-note {
  background: var(--bg-elevated);
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
  padding: 1rem 1.2rem;
  margin: 1.75rem 0;
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--text);
}
.framework-note .eyebrow {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.4rem;
}

/* ============================================
   Sidenote (Gwern pattern)
   ============================================ */
.sidenote {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  line-height: 1.55;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border-left: 2px solid var(--border-strong);
  padding: 0.65rem 0.85rem;
  border-radius: 0 4px 4px 0;
  margin: 1.1rem 0;
}
@media (min-width: 1180px) {
  .sidenote {
    float: right;
    clear: right;
    width: 220px;
    margin: 0.3rem -260px 1.1rem 1.5rem;
    background: transparent;
    border-left: 2px solid var(--border-strong);
    padding-left: 0.85rem;
  }
}

/* ============================================
   Collapsible details (Gwern pattern)
   ============================================ */
.collapsible {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  margin: 1.5rem 0;
}
.collapsible > summary {
  cursor: pointer;
  padding: 0.85rem 1.1rem;
  list-style: none;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}
.collapsible > summary::-webkit-details-marker { display: none; }
.collapsible > summary::after {
  content: "▾";
  color: var(--accent);
  font-size: 0.75rem;
  transition: transform 0.15s var(--ease);
}
.collapsible[open] > summary::after { transform: rotate(180deg); }
.collapsible > .collapsible-body {
  padding: 0 1.1rem 1rem 1.1rem;
}

/* ============================================
   Growth-stage tag
   ============================================ */
.growth-tag {
  display: inline-block;
  font-family: var(--font-ui);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid currentColor;
}
.growth-tag.evergreen { color: var(--growth-evergreen); }
.growth-tag.budding   { color: var(--growth-budding); }
.growth-tag.seedling  { color: var(--growth-seedling); }

/* ============================================
   Reading progress bar
   ============================================ */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2.5px;
  background: linear-gradient(to right, var(--accent), var(--accent-dark));
  z-index: 9999;
  transition: width 0.06s linear;
  width: 0%;
}

/* ============================================
   Back-to-top button
   ============================================ */
.back-to-top {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--accent);
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease), background 0.15s var(--ease);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  z-index: 90;
}
.back-to-top.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
.back-to-top:hover { background: var(--bg-elevated); border-color: var(--border-strong); }

/* ============================================
   Command palette
   ============================================ */
.command-palette {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: color-mix(in srgb, var(--text) 25%, transparent);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 14vh;
}
.command-palette[hidden] { display: none; }
.command-palette-card {
  width: 100%;
  max-width: 540px;
  margin: 0 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
  overflow: hidden;
  animation: palettePop 0.18s cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes palettePop {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.command-palette-input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  padding: 1rem 1.1rem;
  font-size: 1.05rem;
  color: var(--text);
  font-family: var(--font-ui);
  border-bottom: 1px solid var(--border);
}
.command-palette-input::placeholder { color: var(--text-muted); }
.command-palette-results {
  max-height: 320px;
  overflow-y: auto;
  padding: 0.4rem 0;
}
.command-palette-results .cat {
  padding: 0.5rem 1rem 0.25rem;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--text-muted);
  font-weight: 600;
}
.command-palette-results .item {
  padding: 0.55rem 1rem;
  margin: 0 0.25rem;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
  font-size: 0.92rem;
  font-family: var(--font-ui);
}
.command-palette-results .item:hover,
.command-palette-results .item.is-active {
  background: var(--bg-elevated);
}
.command-palette-results .item .tag {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}
.command-palette-footer {
  border-top: 1px solid var(--border);
  padding: 0.55rem 1rem;
  background: var(--bg-elevated);
  display: flex;
  justify-content: space-between;
  font-size: 0.66rem;
  color: var(--text-muted);
  font-family: var(--font-ui);
}
.command-palette-footer kbd {
  font-family: var(--font-mono);
  font-weight: 600;
}

/* ============================================
   Last-good-room footer
   ============================================ */
.last-good-footer {
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-elevated) 70%, var(--bg));
  margin-top: 4rem;
}
.last-good-footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 3rem 2rem 2.5rem;
  font-family: var(--font-ui);
  font-size: 0.92rem;
}
.last-good-footer-grid {
  display: grid;
  grid-template-columns: 5fr 3fr 4fr;
  gap: 2.5rem;
}
@media (max-width: 768px) {
  .last-good-footer-grid { grid-template-columns: 1fr; gap: 2rem; }
}
.last-good-footer h3 {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  margin: 0 0 0.85rem 0;
}
.last-good-footer ul { list-style: none; padding: 0; margin: 0; }
.last-good-footer li { margin-bottom: 0.55rem; }
.last-good-footer a {
  color: var(--text-secondary);
  transition: color 0.15s var(--ease);
}
.last-good-footer a:hover { color: var(--accent); }
.last-good-footer .footer-meta {
  margin-top: 2.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-wrap: wrap;
  gap: 0.75rem;
}
.newsletter-form {
  display: flex;
  gap: 6px;
  margin-top: 0.75rem;
}
.newsletter-form input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.8rem;
  font-size: 0.85rem;
  color: var(--text);
  font-family: var(--font-ui);
}
.newsletter-form input:focus { outline: none; border-color: var(--border-strong); }
.newsletter-form button {
  background: var(--text);
  color: var(--bg);
  border: 0;
  border-radius: 8px;
  padding: 0 1.1rem;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font-ui);
}
.newsletter-disclaimer {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
}

/* ============================================
   Premium underline link
   ============================================ */
.premium-link {
  position: relative;
  color: var(--accent);
  text-decoration: none;
  display: inline-block;
}
.premium-link::after {
  content: '';
  position: absolute;
  width: 0;
  height: 1.5px;
  bottom: -1px;
  left: 0;
  background: var(--accent);
  transition: width 0.2s var(--ease);
}
.premium-link:hover::after { width: 100%; }

/* ============================================
   Pills & filters
   ============================================ */
.filter-pill {
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.4rem 1rem;
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s var(--ease);
}
.filter-pill:hover { background: var(--border); color: var(--text); }
.filter-pill.is-active {
  background: var(--text);
  color: var(--bg);
}

/* ============================================
   Essay-page components (llm-inference and future essays)
   ============================================ */

/* Section-transition (light variant of framework-note with "Up next" eyebrow) */
.section-transition {
  margin: 2rem 0 0 0;
  padding: 0.95rem 1.1rem;
  background: var(--bg-elevated);
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
  font-style: italic;
  color: var(--text);
  font-size: 1rem;
  line-height: 1.55;
}
.section-transition::before {
  content: "Up next →";
  display: block;
  font-style: normal;
  font-size: 0.7rem;
  letter-spacing: 1.3px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.4rem;
}

/* Section dividers */
section.post + section.post {
  margin-top: 2.5rem;
  padding-top: 2.5rem;
  border-top: 1px solid var(--border);
}

/* Stat-card row */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin: 0 0 2.5rem 0;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  text-align: center;
}
.stat-card .stat-num {
  display: block;
  font-size: 1.85rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
  margin-bottom: 4px;
  font-family: var(--font-ui);
  font-variant-numeric: tabular-nums;
}
.stat-card .stat-label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.35;
}

/* Hero "what you'll learn" callout */
.hero-learn-box {
  background: var(--bg-elevated);
  border-left: 4px solid var(--accent);
  border-radius: 0 8px 8px 0;
  padding: 1.5rem 1.75rem;
  margin-bottom: 2.5rem;
}
.hero-learn-box h3 {
  margin-top: 0;
  margin-bottom: 0.6rem;
  color: var(--accent);
  font-size: 1.1rem;
  font-family: var(--font-ui);
}
.hero-learn-box ul {
  margin: 0;
  padding-left: 1.25rem;
}
.hero-learn-box li {
  margin-bottom: 0.5rem;
  color: var(--text);
  line-height: 1.55;
}
@media screen and (max-width: 640px) {
  .hero-learn-box { padding: 1.1rem 1.1rem; }
}

/* Article (essay) layout */
.article-body section.post {
  margin-bottom: 0;
}
.article-body section.post header.major h2 {
  font-family: var(--font-ui);
  font-size: clamp(1.6rem, 2.4vw, 2rem);
  letter-spacing: -0.025em;
  margin-top: 0;
  margin-bottom: 0.65em;
  font-weight: 600;
  color: var(--text);
}

.article-body figure.image img,
.article-body figure img {
  border-radius: 6px;
  border: 1px solid var(--border);
}
.article-body figure figcaption {
  margin-top: 0.6rem;
  text-align: center;
  font-size: 0.85em;
  color: var(--text-muted);
  font-style: italic;
}

/* ============================================
   Interactive widget shell + parts (light)
   ============================================ */
.interactive-widget {
  font-family: var(--font-ui);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.4rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  margin: 2rem 0;
}
.interactive-widget h4 {
  margin: 0 0 6px 0;
  color: var(--text);
  font-size: 0.95rem;
  letter-spacing: 0.2px;
  font-weight: 600;
  text-transform: none;
}

.widget-controls {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  margin-bottom: 12px;
}
.control-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 12px;
}
.control-row:last-child { margin-bottom: 0; }
.control-group label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 5px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.widget-controls input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  cursor: pointer;
}
.slider-values {
  display: flex;
  justify-content: space-between;
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 3px;
  font-family: var(--font-mono);
}

.widget-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.widget-actions button {
  flex: 1;
  min-width: 110px;
  padding: 9px 14px;
  font-size: 0.8rem;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s var(--ease);
  letter-spacing: 0.2px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-ui);
}
.widget-actions button:hover {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
}
.widget-actions button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.widget-actions button.primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  color: #fff;
}
.widget-actions button.success {
  background: var(--bg-elevated);
  border-color: var(--accent);
  color: var(--accent);
}
.widget-actions button.success:hover {
  background: color-mix(in srgb, var(--accent) 10%, var(--bg-elevated));
}

.widget-canvas-container {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 10px;
}

.widget-metrics {
  display: flex;
  gap: 20px;
  font-size: 0.82rem;
  margin-bottom: 8px;
  padding: 0 4px;
}
.widget-metrics .metric { display: flex; gap: 6px; }
.widget-metrics .metric-label { color: var(--text-muted); }
.widget-metrics .metric-value { font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.widget-metrics .metric-value.bad { color: #B45309; }

.widget-status {
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--text-secondary);
  min-height: 22px;
  padding: 0 2px;
}

/* Comparison panel */
.comparison-summary {
  margin-top: 14px;
  padding: 14px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--text);
}
.comparison-summary .comp-header {
  font-weight: 600;
  font-size: 0.72rem;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}
.comparison-summary .comp-row {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.comparison-summary .comp-stat {
  flex: 1;
  min-width: 200px;
  padding: 6px 10px;
  background: var(--surface);
  border-radius: 4px;
  border: 1px solid var(--border);
}
.comparison-summary .comp-improvement {
  flex: 1;
  font-weight: 600;
  color: var(--accent);
  padding: 4px 0;
}
.comparison-summary .comp-insight {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  font-size: 0.82rem;
  color: var(--text-secondary);
  font-style: italic;
}

/* Batching color legend */
.batching-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  margin: 8px 0 4px 0;
  font-size: 0.72rem;
}
.batching-legend .legend-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 18px;
  border-radius: 3px;
  color: #111;
  font-weight: 700;
}
.batching-legend .legend-note {
  margin-left: 6px;
  color: var(--text-muted);
}

/* KV split-grid responsive */
.kv-split-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 12px;
}
@media screen and (max-width: 640px) {
  .kv-split-grid { grid-template-columns: 1fr; }
}

/* Master's Checklist specifics */
#masters-checklist label {
  display: block;
  margin: 0 0 0.9rem 0;
  cursor: pointer;
  line-height: 1.4;
}
#masters-checklist input[type="checkbox"] {
  margin-right: 8px;
  accent-color: var(--accent);
}

/* ============================================
   Sticky TOC + mobile TOC for essays
   ============================================ */
.llm-toc-mobile { display: none; }

@media (min-width: 1180px) {
  .llm-toc {
    position: fixed;
    top: 100px;
    right: 36px;
    width: 240px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
    font-size: 0.85rem;
    max-height: 65vh;
    overflow-y: auto;
    z-index: 50;
    box-shadow: 0 10px 30px rgba(0,0,0,0.05);
  }
  .llm-toc h4 {
    margin: 0 0 10px 0;
    font-size: 0.7rem;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: var(--text-muted);
    font-family: var(--font-ui);
  }
  .llm-toc ul { list-style: none; margin: 0; padding: 0; }
  .llm-toc li { margin: 4px 0; }
  .llm-toc a {
    color: var(--text-secondary);
    text-decoration: none;
    display: block;
    padding: 2px 0 2px 10px;
    border-left: 2px solid transparent;
    transition: all 0.15s var(--ease);
  }
  .llm-toc a:hover { color: var(--text); }
  .llm-toc a.active {
    color: var(--accent);
    border-left-color: var(--accent);
    font-weight: 500;
  }
}

@media (max-width: 1179px) {
  .llm-toc { display: none; }
  .llm-toc-mobile {
    display: block;
    margin: 1rem 0 1.5rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem 1rem;
  }
  .llm-toc-mobile summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--accent);
    font-size: 0.92rem;
    padding: 0.5rem 0;
    list-style: none;
    position: relative;
    padding-right: 1.5rem;
  }
  .llm-toc-mobile summary::-webkit-details-marker { display: none; }
  .llm-toc-mobile summary::after {
    content: "▾";
    position: absolute;
    right: 0; top: 50%;
    transform: translateY(-50%);
    color: var(--accent);
    font-size: 0.7rem;
    transition: transform 0.15s var(--ease);
  }
  .llm-toc-mobile[open] summary::after { transform: translateY(-50%) rotate(180deg); }
  .llm-toc-mobile ul {
    list-style: none;
    margin: 0.5rem 0 0.5rem 0;
    padding-left: 12px;
    border-left: 2px solid var(--border);
  }
  .llm-toc-mobile a {
    display: block;
    padding: 5px 0;
    color: var(--text-secondary);
    font-size: 0.92rem;
  }
  .llm-toc-mobile a.active { color: var(--accent); font-weight: 500; }
}

/* ============================================
   Reduced motion
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .essay-card:hover { transform: none; }
  .back-to-top { transition: opacity 0.001ms !important; }
}
