/* =========================================================
   UnderstandIt: design tokens
   ========================================================= */
:root {
  --font-scale: 1;
  --reading-lh: 1.65;

  --bg: #FBF8F3;
  --bg-2: #F5F0E7;
  --surface: #FFFFFF;
  --surface-2: #FAF7F2;
  --surface-3: #F1ECE3;
  --ink: #1D1A2B;
  --ink-2: #48435C;
  --muted: #6F6982;
  --line: #E9E2D6;
  --line-2: #DCD3C4;

  --lav: #7C6CF2;
  --lav-strong: #5B4BD6;
  --lav-soft: #EFECFF;
  --lav-ink: #4A3BC2;
  --blue: #3E7BFA;
  --blue-soft: #E6EEFF;
  --blue-ink: #2356C4;
  --mint: #22A07A;
  --mint-soft: #E0F4EC;
  --mint-ink: #146F54;
  --amber: #D98E1F;
  --amber-soft: #FCF0DA;
  --amber-ink: #8A5606;
  --rose: #DF5269;
  --rose-soft: #FDE8EB;
  --rose-ink: #AE2B42;

  --on-accent: #FFFFFF;
  --accent-grad: linear-gradient(135deg, #8B7BF7 0%, #6A5AE8 55%, #4F7DF3 100%);
  --focus: #5B4BD6;
  --chart-1: #7C6CF2;
  --mark: #FFF1B8;
  --mark-ink: #1D1A2B;

  --shadow-sm: 0 1px 2px rgba(29, 26, 43, .06), 0 1px 1px rgba(29, 26, 43, .04);
  --shadow: 0 12px 30px -14px rgba(52, 40, 120, .22), 0 2px 6px rgba(29, 26, 43, .05);
  --shadow-lg: 0 30px 70px -24px rgba(52, 40, 120, .32), 0 6px 18px rgba(29, 26, 43, .06);

  --r-xs: 8px;
  --r-sm: 12px;
  --r: 16px;
  --r-lg: 22px;
  --r-xl: 30px;

  --font-ui: 'Plus Jakarta Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-display: 'Fraunces', ui-serif, Georgia, serif;
  --font-read: var(--font-ui);
  --letter: normal;
  --word: normal;

  --topbar-h: 64px;
  --ease: cubic-bezier(.2, .75, .2, 1);
  --dur: .22s;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14121C; --bg-2: #191623; --surface: #1D1A28; --surface-2: #221F2F; --surface-3: #2A2639;
    --ink: #F2EFFA; --ink-2: #CCC6DE; --muted: #9D96B3; --line: #2F2B3F; --line-2: #3B3650;
    --lav: #9A8CFA; --lav-strong: #B3A8FF; --lav-soft: #2A2547; --lav-ink: #C7BEFF;
    --blue: #6E9BFF; --blue-soft: #1D2A48; --blue-ink: #A9C3FF;
    --mint: #3CC59A; --mint-soft: #15342B; --mint-ink: #86E0C2;
    --amber: #F0AE48; --amber-soft: #3A2C14; --amber-ink: #F6CD8A;
    --rose: #F27A8E; --rose-soft: #3D1D25; --rose-ink: #FFB3C0;
    --on-accent: #15121F; --focus: #B3A8FF; --mark: #5A4A12; --mark-ink: #FFF6D6; --chart-1: #8C7CF6;
    --accent-grad: linear-gradient(135deg, #A99CFF 0%, #8C7CF6 55%, #7AA2FF 100%);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 14px 34px -16px rgba(0, 0, 0, .7), 0 2px 6px rgba(0, 0, 0, .3);
    --shadow-lg: 0 30px 70px -24px rgba(0, 0, 0, .8);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14121C; --bg-2: #191623; --surface: #1D1A28; --surface-2: #221F2F; --surface-3: #2A2639;
  --ink: #F2EFFA; --ink-2: #CCC6DE; --muted: #9D96B3; --line: #2F2B3F; --line-2: #3B3650;
  --lav: #9A8CFA; --lav-strong: #B3A8FF; --lav-soft: #2A2547; --lav-ink: #C7BEFF;
  --blue: #6E9BFF; --blue-soft: #1D2A48; --blue-ink: #A9C3FF;
  --mint: #3CC59A; --mint-soft: #15342B; --mint-ink: #86E0C2;
  --amber: #F0AE48; --amber-soft: #3A2C14; --amber-ink: #F6CD8A;
  --rose: #F27A8E; --rose-soft: #3D1D25; --rose-ink: #FFB3C0;
  --on-accent: #15121F; --focus: #B3A8FF; --mark: #5A4A12; --mark-ink: #FFF6D6; --chart-1: #8C7CF6;
  --accent-grad: linear-gradient(135deg, #A99CFF 0%, #8C7CF6 55%, #7AA2FF 100%);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 14px 34px -16px rgba(0, 0, 0, .7), 0 2px 6px rgba(0, 0, 0, .3);
  --shadow-lg: 0 30px 70px -24px rgba(0, 0, 0, .8);
  color-scheme: dark;
}

/* High contrast */
:root[data-contrast="high"] {
  --bg: #FFFFFF; --bg-2: #FFFFFF; --surface: #FFFFFF; --surface-2: #FFFFFF; --surface-3: #F0F0F0;
  --ink: #000000; --ink-2: #000000; --muted: #222222; --line: #000000; --line-2: #000000;
  --lav: #3415C4; --lav-strong: #24009A; --lav-soft: #ECE8FF; --lav-ink: #24009A;
  --blue: #0038B8; --blue-soft: #E5ECFF; --blue-ink: #00288A;
  --mint-ink: #00573A; --amber-ink: #6B3F00; --rose-ink: #8C0018;
  --accent-grad: #3415C4; --focus: #D10067; --on-accent: #FFFFFF;
  --shadow-sm: none; --shadow: 0 0 0 2px #000; --shadow-lg: 0 0 0 3px #000;
  color-scheme: light;
}
:root[data-contrast="high"][data-theme="dark"] {
  --bg: #000000; --bg-2: #000000; --surface: #000000; --surface-2: #000000; --surface-3: #111111;
  --ink: #FFFFFF; --ink-2: #FFFFFF; --muted: #E6E6E6; --line: #FFFFFF; --line-2: #FFFFFF;
  --lav: #FFE14D; --lav-strong: #FFE14D; --lav-soft: #222200; --lav-ink: #FFE14D;
  --blue: #7FD4FF; --blue-soft: #001A26; --blue-ink: #7FD4FF;
  --mint-ink: #6BFFB8; --amber-ink: #FFD27F; --rose-ink: #FF9EAE;
  --accent-grad: #FFE14D; --focus: #FF6BD0; --on-accent: #000000;
  --shadow: 0 0 0 2px #FFF; --shadow-lg: 0 0 0 3px #FFF;
  color-scheme: dark;
}

/* Dyslexia-friendly reading */
:root[data-dyslexia="on"] {
  --font-ui: 'Atkinson Hyperlegible', 'Verdana', sans-serif;
  --font-display: 'Atkinson Hyperlegible', 'Verdana', sans-serif;
  --font-read: 'Atkinson Hyperlegible', 'Verdana', sans-serif;
  --letter: .03em;
  --word: .14em;
}
:root[data-dyslexia="on"] em, :root[data-dyslexia="on"] i { font-style: normal; font-weight: 700; }

/* Reduced motion (system or setting) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
:root[data-motion="reduce"] *, :root[data-motion="reduce"] *::before, :root[data-motion="reduce"] *::after {
  animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important;
}

/* =========================================================
   Base
   ========================================================= */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: calc(100% * var(--font-scale)); -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.55;
  letter-spacing: var(--letter);
  word-spacing: var(--word);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  overflow-x: hidden;
}
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; }
a { color: var(--lav-ink); text-underline-offset: 3px; }
h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 .5em; }
p { margin: 0 0 .8em; }
kbd { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8em; padding: 1px 6px; border-radius: 6px; border: 1px solid var(--line-2); background: var(--surface); box-shadow: 0 1px 0 var(--line-2); }
::selection { background: color-mix(in srgb, var(--lav) 30%, transparent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 12px; top: -60px; z-index: 100; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; transition: top var(--dur); }
.skip-link:focus { top: 12px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 24px; }
.ico { width: 1.15em; height: 1.15em; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.stack { display: grid; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }

/* =========================================================
   Buttons & form controls
   ========================================================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 9px 16px; border-radius: 999px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: .94rem; text-decoration: none; white-space: nowrap;
  transition: transform var(--dur) var(--ease), background var(--dur), border-color var(--dur), box-shadow var(--dur);
}
.btn:hover { border-color: var(--lav); box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(1px) scale(.99); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent-grad); border-color: transparent; color: var(--on-accent); box-shadow: 0 8px 20px -10px color-mix(in srgb, var(--lav) 80%, transparent); }
.btn-primary:hover { border-color: transparent; filter: brightness(1.05); box-shadow: 0 12px 24px -10px color-mix(in srgb, var(--lav) 85%, transparent); }
.btn-soft { background: var(--lav-soft); border-color: transparent; color: var(--lav-ink); }
.btn-soft:hover { border-color: var(--lav); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-3); border-color: transparent; box-shadow: none; }
.btn-danger { color: var(--rose-ink); }
.btn-danger:hover { border-color: var(--rose); background: var(--rose-soft); }
.btn-sm { min-height: 34px; padding: 6px 12px; font-size: .85rem; }
.btn-lg { min-height: 52px; padding: 12px 24px; font-size: 1.02rem; }
.btn .ico { width: 1.05em; height: 1.05em; }

.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none;
  border-radius: 12px; border: 1px solid transparent; background: transparent; color: var(--ink-2);
  transition: background var(--dur), color var(--dur), border-color var(--dur);
}
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }
.icon-btn.sm { width: 32px; height: 32px; border-radius: 9px; }
.icon-btn[aria-pressed="true"] { background: var(--lav-soft); color: var(--lav-ink); }

.chip-btn {
  display: inline-flex; align-items: center; gap: 7px; min-height: 38px; padding: 7px 13px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-2);
  font-size: .88rem; font-weight: 600; transition: all var(--dur) var(--ease);
}
.chip-btn:hover { border-color: var(--lav); color: var(--lav-ink); background: var(--lav-soft); }
.chip-btn[aria-pressed="true"], .chip-btn.is-active { background: var(--lav-soft); border-color: var(--lav); color: var(--lav-ink); }
.mic-btn[aria-pressed="true"] { background: var(--rose-soft); border-color: var(--rose); color: var(--rose-ink); animation: pulse 1.4s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--rose) 45%, transparent); } 50% { box-shadow: 0 0 0 7px transparent; } }

.field { display: grid; gap: 6px; }
.field > label, .label { font-weight: 600; font-size: .9rem; color: var(--ink-2); }
.field .hint { font-size: .82rem; color: var(--muted); }
.input, .select, .textarea {
  width: 100%; min-height: 42px; padding: 9px 13px; border-radius: var(--r-sm);
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
  transition: border-color var(--dur), box-shadow var(--dur);
}
.textarea { min-height: 110px; resize: vertical; line-height: 1.55; font-family: var(--font-read); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--lav); box-shadow: 0 0 0 4px color-mix(in srgb, var(--lav) 22%, transparent); }
.select { appearance: none; padding-right: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23736D86' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; background-size: 16px; }
.select.sm, .input.sm { min-height: 36px; padding-top: 6px; padding-bottom: 6px; font-size: .88rem; }

.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: .92rem; }
.check input { width: 18px; height: 18px; accent-color: var(--lav); }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; cursor: pointer; }
.switch + .switch { border-top: 1px solid var(--line); }
.switch .switch-text b { display: block; font-weight: 600; }
.switch .switch-text small { color: var(--muted); font-size: .85rem; }
.switch input { appearance: none; width: 46px; height: 28px; border-radius: 999px; background: var(--line-2); position: relative; flex: none; transition: background var(--dur); cursor: pointer; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform var(--dur) var(--ease); }
.switch input:checked { background: var(--lav); }
.switch input:checked::after { transform: translateX(18px); }

input[type="range"] { width: 100%; accent-color: var(--lav); height: 28px; }

.segmented { display: inline-flex; padding: 4px; gap: 2px; border-radius: 999px; background: var(--surface-3); flex-wrap: wrap; }
.segmented button { border: 0; background: transparent; padding: 7px 14px; border-radius: 999px; font-weight: 600; font-size: .86rem; color: var(--ink-2); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .74rem; font-weight: 700; letter-spacing: .01em; white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-ai { background: var(--lav-soft); color: var(--lav-ink); }
.badge-demo { background: var(--amber-soft); color: var(--amber-ink); }
.badge-sample { background: var(--blue-soft); color: var(--blue-ink); }
.badge-tool { background: var(--mint-soft); color: var(--mint-ink); }
.badge-plain::before { display: none; }
.tag { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px; background: var(--surface-3); color: var(--ink-2); font-size: .76rem; font-weight: 600; }
.tag.easy { background: var(--mint-soft); color: var(--mint-ink); }
.tag.medium { background: var(--amber-soft); color: var(--amber-ink); }
.tag.hard { background: var(--rose-soft); color: var(--rose-ink); }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); }
.card-pad { padding: 20px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 0; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; font-size: 1.1rem; }
.card-body { padding: 16px 20px 20px; }

/* =========================================================
   Top bar & navigation
   ========================================================= */
.topbar { position: sticky; top: 0; z-index: 40; height: var(--topbar-h); background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px); border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent); }
.topbar-inner { height: 100%; max-width: 1440px; margin: 0 auto; padding: 0 20px; display: flex; align-items: center; gap: 20px; }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); flex: none; }
.brand-mark svg { width: 34px; height: 34px; }
.brand-mark rect { fill: var(--lav); }
.brand-mark path { fill: none; stroke: #fff; stroke-width: 3.4; stroke-linecap: round; stroke-linejoin: round; }
:root[data-contrast="high"][data-theme="dark"] .brand-mark path { stroke: #000; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 1.32rem; letter-spacing: -.01em; }
.brand-name span { color: var(--lav); }
.mainnav { display: flex; gap: 4px; margin-left: 12px; }
.mainnav a { padding: 8px 14px; border-radius: 999px; text-decoration: none; color: var(--ink-2); font-weight: 600; font-size: .93rem; transition: background var(--dur), color var(--dur); }
.mainnav a:hover { background: var(--surface-3); color: var(--ink); }
.mainnav a[aria-current="page"] { background: var(--lav-soft); color: var(--lav-ink); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.status-pill { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: .8rem; font-weight: 700; color: var(--ink-2); }
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-pill.is-ai .dot { background: var(--mint); box-shadow: 0 0 0 3px var(--mint-soft); }
.status-pill.is-demo .dot { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-soft); }

.bottomnav { display: none; }
.mobile-only { display: none !important; }

/* =========================================================
   Home
   ========================================================= */
.hero { position: relative; overflow: hidden; padding: 64px 0 56px; }
.hero-glow { position: absolute; inset: -20% -10% auto; height: 640px; pointer-events: none;
  background:
    radial-gradient(40% 50% at 22% 30%, color-mix(in srgb, var(--lav) 22%, transparent), transparent 70%),
    radial-gradient(35% 45% at 80% 20%, color-mix(in srgb, var(--blue) 18%, transparent), transparent 70%),
    radial-gradient(30% 40% at 60% 70%, color-mix(in srgb, var(--rose) 8%, transparent), transparent 70%);
  filter: blur(10px); }
.hero-inner { position: relative; max-width: 880px; text-align: center; }
.eyebrow { display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--lav-ink); font-weight: 700; font-size: .85rem; box-shadow: var(--shadow-sm); margin-bottom: 22px; }
.hero-title { font-family: var(--font-display); font-weight: 600; font-size: clamp(2.35rem, 6.4vw, 4.4rem); letter-spacing: -.025em; line-height: 1.04; margin-bottom: 18px; font-variation-settings: 'opsz' 144; }
.click-word { position: relative; display: inline-block; color: var(--lav); font-style: italic; }
.click-word svg { position: absolute; left: 0; right: 0; bottom: -.12em; width: 100%; height: .3em; overflow: visible; }
.click-word path { fill: none; stroke: var(--blue); stroke-width: 5; stroke-linecap: round; stroke-dasharray: 260; stroke-dashoffset: 260; animation: draw 1.1s .35s var(--ease) forwards; opacity: .75; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.hero-sub { font-size: clamp(1.05rem, 2.2vw, 1.28rem); color: var(--ink-2); max-width: 560px; margin: 0 auto 30px; }

.input-card { text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); box-shadow: var(--shadow-lg); padding: 10px; transition: border-color var(--dur), box-shadow var(--dur); }
.input-card:focus-within { border-color: color-mix(in srgb, var(--lav) 60%, var(--line)); box-shadow: var(--shadow-lg), 0 0 0 5px color-mix(in srgb, var(--lav) 14%, transparent); }
.input-card.is-dragging { border-color: var(--lav); border-style: dashed; background: var(--lav-soft); }
.home-input { display: block; width: 100%; min-height: 168px; max-height: 50vh; resize: vertical; border: 0; background: transparent; padding: 16px 16px 8px; font-size: 1.1rem; line-height: 1.6; font-family: var(--font-read); color: var(--ink); }
.home-input:focus { outline: none; }
.home-input::placeholder { color: var(--muted); }
.input-tools { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 8px 4px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.tool-row { display: flex; gap: 6px; flex-wrap: wrap; }
.char-count { font-size: .82rem; color: var(--muted); padding-right: 6px; }
.url-row { display: flex; gap: 8px; padding: 8px; }
.url-row input { flex: 1; min-width: 0; min-height: 42px; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface-2); }
.url-row input:focus { outline: none; border-color: var(--lav); }
.attach-list { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 12px; }
.attach-list:empty { display: none; }
.attach { display: inline-flex; align-items: center; gap: 8px; padding: 6px 8px 6px 12px; border-radius: 12px; background: var(--surface-3); font-size: .85rem; margin-bottom: 8px; }
.attach.is-error { background: var(--rose-soft); color: var(--rose-ink); }
.attach.is-busy::before { content: ''; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--lav); border-right-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.primary-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 18px; }
.action-btn { display: grid; justify-items: center; gap: 2px; padding: 16px 10px 14px; border-radius: var(--r-lg); border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow-sm); transition: transform var(--dur) var(--ease), box-shadow var(--dur), border-color var(--dur); }
.action-btn .ico { width: 26px; height: 26px; color: var(--lav); margin-bottom: 6px; }
.action-btn b { font-size: 1.02rem; }
.action-btn small { color: var(--muted); font-size: .8rem; }
.action-btn:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--lav) 50%, var(--line)); }
.action-main { background: var(--accent-grad); border-color: transparent; color: var(--on-accent); }
.action-main .ico, .action-main small { color: var(--on-accent); opacity: .92; }
.kbd-hint { margin: 14px 0 0; color: var(--muted); font-size: .85rem; }
.examples { margin-top: 28px; }
.examples-label { font-weight: 700; color: var(--ink-2); font-size: .9rem; margin-bottom: 10px; }
.example-list { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.example { display: inline-flex; align-items: center; gap: 10px; padding: 10px 16px 10px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); text-align: left; transition: all var(--dur) var(--ease); }
.example:hover { border-color: var(--lav); transform: translateY(-2px); box-shadow: var(--shadow); }
.example .ex-ico { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--lav-soft); color: var(--lav-ink); }
.example b { display: block; font-size: .92rem; }
.example small { display: block; color: var(--muted); font-size: .78rem; }

.section { padding: 56px 24px; }
.section-title { font-family: var(--font-display); font-weight: 600; font-size: clamp(1.7rem, 3.6vw, 2.4rem); letter-spacing: -.02em; text-align: center; }
.section-sub { text-align: center; color: var(--ink-2); max-width: 620px; margin: 0 auto 28px; }
.feature-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.feature { padding: 22px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); transition: transform var(--dur) var(--ease), box-shadow var(--dur); }
.feature:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.feature > .ico { width: 44px; height: 44px; padding: 10px; border-radius: 14px; background: var(--tint); color: var(--ink-tint); margin-bottom: 14px; }
.feature h3 { font-size: 1.05rem; margin-bottom: 6px; }
.feature p { color: var(--ink-2); font-size: .92rem; margin: 0; }
.audience-list { list-style: none; padding: 0; margin: 0 auto 18px; display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; max-width: 880px; }
.audience-list li { display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-weight: 600; font-size: .92rem; }
.audience-list .ico { color: var(--lav); }
.privacy-card { display: flex; gap: 20px; align-items: flex-start; padding: 28px; border-radius: var(--r-xl); background: linear-gradient(135deg, var(--lav-soft), var(--blue-soft)); border: 1px solid var(--line); max-width: 880px; margin: 0 auto; }
.privacy-card h2 { font-family: var(--font-display); font-size: 1.5rem; }
.privacy-card p { color: var(--ink-2); }
.privacy-icon .ico, .privacy-card > .ico { width: 52px; height: 52px; padding: 13px; border-radius: 16px; background: var(--surface); color: var(--lav-ink); flex: none; }
.site-footer { padding: 30px 24px 50px; text-align: center; border-top: 1px solid var(--line); font-size: .9rem; }

/* =========================================================
   Workspace
   ========================================================= */
.ws-toolbar { position: sticky; top: var(--topbar-h); z-index: 30; background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.ws-toolbar-inner { max-width: 1440px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ws-title { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1 1 200px; }
.ws-title input { font-family: var(--font-display); font-weight: 600; font-size: 1.15rem; border: 1px solid transparent; background: transparent; padding: 4px 8px; border-radius: 10px; min-width: 0; width: 100%; color: var(--ink); text-overflow: ellipsis; }
.ws-title input:hover { border-color: var(--line); }
.ws-title input:focus { outline: none; border-color: var(--lav); background: var(--surface); }
.ws-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ws-controls .select { width: auto; min-height: 36px; padding-top: 5px; padding-bottom: 5px; font-size: .86rem; border-radius: 999px; }
.ws-controls .divider { width: 1px; height: 24px; background: var(--line); }

.workspace { max-width: 1440px; margin: 0 auto; padding: 18px 20px 40px; display: grid; grid-template-columns: 236px minmax(0, 1fr) 370px; gap: 18px; align-items: start; }
.ws-left, .ws-right { position: sticky; top: calc(var(--topbar-h) + 74px); max-height: calc(100vh - var(--topbar-h) - 92px); }
.ws-left { overflow: auto; padding-right: 2px; scrollbar-width: thin; }
.ws-section-label { font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 800; color: var(--muted); margin: 6px 10px 8px; }
.tool-nav { display: grid; gap: 2px; margin-bottom: 18px; }
.tool-nav button { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 12px; border: 0; background: transparent; color: var(--ink-2); font-weight: 600; font-size: .92rem; text-align: left; transition: background var(--dur), color var(--dur); }
.tool-nav button:hover { background: var(--surface-3); color: var(--ink); }
.tool-nav button[aria-current="true"] { background: var(--surface); color: var(--lav-ink); box-shadow: var(--shadow-sm); border: 1px solid var(--line); }
.tool-nav button[aria-current="true"] .ico { color: var(--lav); }
.tool-nav .count { margin-left: auto; font-size: .74rem; padding: 1px 7px; border-radius: 999px; background: var(--lav-soft); color: var(--lav-ink); }
.saved-list { display: grid; gap: 4px; margin-bottom: 16px; }
.saved-item { display: flex; align-items: center; gap: 6px; padding: 7px 8px 7px 12px; border-radius: 10px; font-size: .86rem; background: transparent; border: 0; text-align: left; color: var(--ink-2); width: 100%; }
.saved-item:hover { background: var(--surface-3); }
.saved-item > span:first-child { flex: none; display: inline-flex; }
.saved-item > span:last-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saved-item.is-current { color: var(--lav-ink); font-weight: 700; }
.saved-empty { font-size: .84rem; color: var(--muted); padding: 2px 12px 10px; }

.ws-center { display: grid; gap: 18px; min-width: 0; }
.source-card .card-head { padding-bottom: 4px; }
.source-meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; color: var(--muted); font-size: .82rem; }
.qa-card { border-color: color-mix(in srgb, var(--lav) 35%, var(--line)); }
.qa-card .card-head h2 { font-family: var(--font-display); font-weight: 600; font-size: 1.25rem; }
.qa-item { display: grid; gap: 10px; }
.qa-item + .qa-item { padding-top: 14px; border-top: 1px dashed var(--line-2); }
.qa-q { display: flex; gap: 10px; align-items: flex-start; margin: 0; font-weight: 700; font-size: 1.08rem; font-family: var(--font-read); }
.qa-q .ico { color: var(--lav); margin-top: 3px; flex: none; }
.qa-short { padding: 12px 16px; border-radius: var(--r); background: linear-gradient(135deg, var(--lav-soft), var(--blue-soft)); }
.qa-short .reading { font-size: 1.04rem; }
.qa-short .reading p:last-child { margin-bottom: 0; }
.qa-source { margin: 0; font-size: .84rem; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.qa-alts { gap: 6px; }
.qa-alts .chip-btn { min-height: 32px; padding: 4px 11px; font-size: .82rem; }
#sourcePanel { display: grid; gap: 18px; }
.source-card.is-editing { border-color: color-mix(in srgb, var(--lav) 55%, var(--line)); box-shadow: 0 0 0 4px color-mix(in srgb, var(--lav) 12%, transparent); }
.editor-body { padding: 12px 20px 16px; display: grid; gap: 10px; }
.editor-actions { justify-content: flex-end; padding-top: 8px; border-top: 1px solid var(--line); }
.source-card { scroll-margin-top: calc(var(--topbar-h) + 76px); }
.editing-material .chat-fab { display: none !important; }
.source-editor { min-height: 280px; max-height: 60vh; font-size: 1.04rem; line-height: var(--reading-lh); }
.editor-body .input-tools { padding: 4px 0 0; border-top: 0; }
.editor-body .url-row { padding: 0; }
.editor-chips { padding: 0; }
.stale-note { margin: 14px 20px 0; align-items: center; flex-wrap: wrap; }
.stale-note p { min-width: 180px; }
.source-text { font-family: var(--font-read); font-size: 1.04rem; line-height: var(--reading-lh); color: var(--ink); max-height: 340px; overflow: auto; padding: 4px 20px 18px; scrollbar-width: thin; }
.source-card.is-expanded .source-text { max-height: none; }
.source-card.is-collapsed .source-text { display: none; }
.source-text p { margin: 0 0 1em; }
.source-text .sent { border-radius: 4px; transition: background .4s; }
.source-text .sent.is-hit { background: var(--mark); color: var(--mark-ink); box-shadow: 0 0 0 3px var(--mark); }
.source-text .sent.is-hard { text-decoration: underline wavy color-mix(in srgb, var(--rose) 70%, transparent); text-decoration-thickness: 1.5px; text-underline-offset: 4px; }
.source-text h3 { font-family: var(--font-ui); font-size: 1.05rem; margin: 1em 0 .4em; }
.term { all: unset; cursor: pointer; border-bottom: 2px dotted color-mix(in srgb, var(--lav) 70%, transparent); color: inherit; border-radius: 3px; transition: background var(--dur); }
.term:hover, .term:focus-visible { background: var(--lav-soft); color: var(--lav-ink); }
.term:focus-visible { outline: 2px solid var(--focus); }
.notice { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r); background: var(--amber-soft); color: var(--amber-ink); font-size: .9rem; margin: 0 20px 14px; }
.notice .ico { margin-top: 2px; }
.notice p { margin: 0; }
.notice.info { background: var(--blue-soft); color: var(--blue-ink); }
.notice.ok { background: var(--mint-soft); color: var(--mint-ink); }
.notice.error { background: var(--rose-soft); color: var(--rose-ink); }
.notice.in-body { margin: 0 0 14px; }

.tool-panel { outline: none; }
.tool-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); animation: rise .35s var(--ease); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.tool-head { display: flex; align-items: flex-start; gap: 14px; padding: 20px 20px 0; flex-wrap: wrap; }
.tool-head .tool-ico { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: var(--lav-soft); color: var(--lav-ink); flex: none; }
.tool-head .tool-ico .ico { width: 22px; height: 22px; }
.tool-head h2 { font-family: var(--font-display); font-weight: 600; font-size: 1.45rem; letter-spacing: -.01em; margin: 0 0 2px; }
.tool-head p { margin: 0; color: var(--muted); font-size: .9rem; }
.tool-head .grow { min-width: 200px; }
.tool-options { display: flex; flex-wrap: wrap; gap: 14px 18px; align-items: flex-end; padding: 16px 20px; margin: 16px 0 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--surface-2); }
.tool-options .field { min-width: 150px; }
.tool-options .field.wide { flex: 1 1 260px; }
.tool-body { padding: 20px; }
.option-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.level-slider { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; font-size: .8rem; color: var(--muted); min-width: 240px; }
.level-value { display: inline-grid; place-items: center; min-width: 30px; height: 26px; padding: 0 8px; border-radius: 999px; background: var(--lav-soft); color: var(--lav-ink); font-weight: 800; font-size: .85rem; }

.output { position: relative; }
.output-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.output-actions { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.reading { font-family: var(--font-read); font-size: 1.08rem; line-height: var(--reading-lh); color: var(--ink); max-width: 72ch; }
.reading p { margin: 0 0 1em; }
.reading ul, .reading ol { padding-left: 1.4em; margin: 0 0 1em; }
.reading li { margin-bottom: .4em; }
.reading h3, .reading h4 { font-family: var(--font-ui); margin: 1.2em 0 .5em; font-size: 1.08rem; }
.reading strong { font-weight: 700; color: var(--ink); }
.reading table { border-collapse: collapse; width: 100%; margin: 0 0 1em; font-size: .95rem; display: block; overflow-x: auto; }
.reading th, .reading td { border: 1px solid var(--line-2); padding: 8px 12px; text-align: left; vertical-align: top; }
.reading th { background: var(--surface-3); }
.reading blockquote { margin: 0 0 1em; padding: 10px 16px; border-left: 4px solid var(--lav); background: var(--surface-2); border-radius: 0 12px 12px 0; }
.reading code { font-family: ui-monospace, Menlo, monospace; font-size: .9em; background: var(--surface-3); padding: 1px 6px; border-radius: 6px; }
.reading[dir="rtl"] { text-align: right; }
.para-wrap { position: relative; }
.src-btn { all: unset; cursor: pointer; display: inline-flex; vertical-align: middle; margin-left: 4px; padding: 2px; border-radius: 6px; color: var(--muted); opacity: .6; }
.src-btn:hover, .src-btn:focus-visible { opacity: 1; color: var(--lav-ink); background: var(--lav-soft); }
.src-btn .ico { width: 15px; height: 15px; }
.keyterms { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.keyterm { all: unset; cursor: pointer; padding: 6px 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); font-size: .88rem; }
.keyterm:hover, .keyterm:focus-visible { border-color: var(--lav); background: var(--lav-soft); }
.keyterm b { color: var(--lav-ink); }
.big-idea { padding: 16px 18px; border-radius: var(--r); background: linear-gradient(135deg, var(--lav-soft), var(--blue-soft)); border: 1px solid color-mix(in srgb, var(--lav) 25%, transparent); }
.big-idea .reading { font-size: 1.16rem; font-weight: 600; }
.big-idea .reading p { margin: 0; }
.big-idea-label { display: inline-flex; align-items: center; gap: 6px; font-size: .74rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--lav-ink); margin-bottom: 6px; }
.check-box { display: grid; gap: 8px; justify-items: start; padding: 14px 16px; border-radius: var(--r); border: 1.5px dashed var(--line-2); background: var(--surface-2); }
.check-box .reading p { margin: 0; }
.check-answer { padding: 10px 14px; border-radius: 12px; background: var(--mint-soft); color: var(--mint-ink); width: 100%; }
.check-answer .reading { color: inherit; font-size: 1rem; }
.check-answer .reading p { margin: 0; }
.meta-note { font-size: .88rem; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 14px; margin-top: 12px; }
.meta-note b { color: var(--ink); }
.output-foot { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 18px; padding-top: 16px; border-top: 1px dashed var(--line-2); }

.way-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.way-btn { display: grid; gap: 6px; padding: 14px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface); text-align: left; transition: all var(--dur) var(--ease); }
.way-btn .ico { width: 22px; height: 22px; color: var(--lav); }
.way-btn b { font-size: .92rem; }
.way-btn small { color: var(--muted); font-size: .78rem; line-height: 1.35; }
.way-btn:hover { border-color: var(--lav); transform: translateY(-2px); box-shadow: var(--shadow); }
.way-btn[aria-pressed="true"] { border-color: var(--lav); background: var(--lav-soft); }

/* Loading */
.loading { padding: 8px 0; }
.loading-msg { display: flex; align-items: center; gap: 10px; color: var(--ink-2); font-weight: 600; margin-bottom: 16px; }
.dots { display: inline-flex; gap: 5px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--lav); animation: bounce 1.1s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; background: color-mix(in srgb, var(--lav) 60%, var(--blue)); }
.dots i:nth-child(3) { animation-delay: .3s; background: var(--blue); }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); opacity: .5; } 40% { transform: translateY(-6px); opacity: 1; } }
.skeleton { height: 14px; border-radius: 8px; margin-bottom: 12px; background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Chat */
.ws-right { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); overflow: hidden; height: calc(100vh - var(--topbar-h) - 92px); }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 14px 14px 12px 18px; border-bottom: 1px solid var(--line); }
.chat-head h2 { font-size: 1rem; margin: 0; }
.chat-head p { margin: 0; font-size: .78rem; color: var(--muted); }
.chat-avatar { width: 34px; height: 34px; border-radius: 11px; background: var(--accent-grad); color: var(--on-accent); display: grid; place-items: center; flex: none; }
.chat-log { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; scrollbar-width: thin; }
.msg { max-width: 92%; padding: 10px 14px; border-radius: 16px; font-size: .94rem; line-height: 1.55; font-family: var(--font-read); }
.msg p:last-child, .msg ul:last-child, .msg ol:last-child { margin-bottom: 0; }
.msg ul, .msg ol { padding-left: 1.2em; margin: 0 0 .6em; }
.msg p { margin: 0 0 .6em; }
.msg-user { align-self: flex-end; background: var(--lav); color: var(--on-accent); border-bottom-right-radius: 6px; }
.msg-ai { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.quote-btn { all: unset; cursor: pointer; font-size: .8rem; padding: 4px 9px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); color: var(--ink-2); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quote-btn:hover, .quote-btn:focus-visible { border-color: var(--lav); color: var(--lav-ink); }
.chat-suggest { display: flex; gap: 6px; padding: 0 14px 10px; overflow-x: auto; scrollbar-width: none; }
.chat-suggest button { flex: none; font-size: .8rem; padding: 6px 11px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-2); font-weight: 600; }
.chat-suggest button:hover { border-color: var(--lav); color: var(--lav-ink); }
.chat-form { display: flex; gap: 6px; align-items: flex-end; padding: 10px; border-top: 1px solid var(--line); background: var(--surface); }
.chat-form textarea { flex: 1; min-height: 44px; max-height: 140px; resize: none; padding: 11px 14px; border-radius: 16px; border: 1px solid var(--line-2); background: var(--surface-2); line-height: 1.4; }
.chat-form textarea:focus { outline: none; border-color: var(--lav); background: var(--surface); }
.chat-form .icon-btn.send { background: var(--accent-grad); color: var(--on-accent); }
.chat-empty { text-align: center; color: var(--muted); font-size: .9rem; padding: 18px 8px; }
.chat-empty .ico { width: 40px; height: 40px; margin: 0 auto 10px; color: var(--lav); }
.chat-fab { display: none; }
.ws-right.is-collapsed { height: auto; }
.ws-right.is-collapsed .chat-log, .ws-right.is-collapsed .chat-suggest, .ws-right.is-collapsed .chat-form { display: none; }
.workspace.chat-collapsed { grid-template-columns: 236px minmax(0, 1fr) 260px; }

/* =========================================================
   Flashcards
   ========================================================= */
.flip-card { perspective: 1400px; width: 100%; aspect-ratio: 16 / 10; max-height: 420px; cursor: pointer; border: 0; padding: 0; background: transparent; }
.flip-inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform .6s var(--ease); }
.flip-card.is-flipped .flip-inner { transform: rotateY(180deg); }
.flip-face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: var(--r-xl); display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 28px 30px; overflow: auto; border: 1px solid var(--line); box-shadow: var(--shadow); font-family: var(--font-read); }
.flip-front { background: var(--surface); }
.flip-back { background: linear-gradient(160deg, var(--lav-soft), var(--blue-soft)); transform: rotateY(180deg); }
.flip-face .face-label { position: absolute; top: 16px; left: 20px; font-size: .72rem; text-transform: uppercase; letter-spacing: .1em; font-weight: 800; color: var(--muted); font-family: var(--font-ui); }
.flip-face .face-text { font-size: clamp(1.15rem, 2.6vw, 1.6rem); font-weight: 600; line-height: 1.4; max-width: 34ch; }
.flip-back .face-text { font-size: clamp(1rem, 2.1vw, 1.25rem); font-weight: 500; }
.flip-face .face-extra { margin-top: 12px; font-size: .92rem; color: var(--ink-2); max-width: 46ch; }
.flip-face .face-hint { position: absolute; bottom: 14px; font-size: .78rem; color: var(--muted); font-family: var(--font-ui); }
.choice-list { display: grid; gap: 8px; width: 100%; max-width: 460px; margin-top: 16px; text-align: left; }
.choice { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-radius: 14px; border: 1.5px solid var(--line-2); background: var(--surface); font-weight: 500; text-align: left; transition: all var(--dur); width: 100%; }
.choice:hover:not(:disabled) { border-color: var(--lav); background: var(--lav-soft); }
.choice .letter { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-3); font-weight: 800; font-size: .8rem; flex: none; }
.choice.is-correct { border-color: var(--mint); background: var(--mint-soft); color: var(--mint-ink); }
.choice.is-wrong { border-color: var(--rose); background: var(--rose-soft); color: var(--rose-ink); }
.choice.is-picked { border-color: var(--lav); background: var(--lav-soft); }
.choice:disabled { cursor: default; }

.cards-layout { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 22px; align-items: start; }
.deck-sidebar { position: sticky; top: calc(var(--topbar-h) + 16px); display: grid; gap: 14px; }
.folder { border-radius: var(--r); }
.folder-name { display: flex; align-items: center; gap: 8px; font-size: .8rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 6px 8px; }
.deck-btn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border-radius: 14px; border: 1px solid transparent; background: transparent; text-align: left; transition: all var(--dur); }
.deck-btn:hover { background: var(--surface); border-color: var(--line); }
.deck-btn[aria-current="true"] { background: var(--surface); border-color: var(--lav); box-shadow: var(--shadow-sm); }
.deck-btn .deck-ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--blue-soft); color: var(--blue-ink); flex: none; }
.deck-btn b { display: block; font-size: .93rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deck-btn small { color: var(--muted); font-size: .78rem; }
.deck-btn .due { margin-left: auto; font-size: .74rem; font-weight: 800; padding: 2px 8px; border-radius: 999px; background: var(--amber-soft); color: var(--amber-ink); }
.deck-main { min-width: 0; display: grid; gap: 18px; }
.deck-hero { padding: 22px; border-radius: var(--r-xl); background: var(--surface); border: 1px solid var(--line); display: grid; gap: 16px; }
.deck-hero h2 { font-family: var(--font-display); font-size: 1.7rem; margin: 0; }
.deck-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.mini-stat { padding: 12px 14px; border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--line); }
.mini-stat b { display: block; font-size: 1.4rem; font-family: var(--font-display); }
.mini-stat small { color: var(--muted); font-size: .8rem; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.mini-card { position: relative; padding: 16px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); display: grid; gap: 8px; align-content: start; min-height: 150px; }
.mini-card .front { font-weight: 700; }
.mini-card .back { color: var(--ink-2); font-size: .9rem; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.mini-card .row { margin-top: auto; }
.mini-card-actions { display: flex; gap: 2px; margin-left: auto; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .ico { width: 54px; height: 54px; margin: 0 auto 12px; color: var(--lav); padding: 12px; border-radius: 18px; background: var(--lav-soft); }
.empty h3 { color: var(--ink); font-family: var(--font-display); font-size: 1.3rem; }

/* Study overlay */
.study-overlay { position: fixed; inset: 0; z-index: 70; background: var(--bg); overflow: auto; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; } }
.study-inner { max-width: 760px; margin: 0 auto; padding: 18px 20px 40px; min-height: 100%; display: flex; flex-direction: column; gap: 18px; }
.study-top { display: flex; align-items: center; gap: 12px; }
.study-top h2 { margin: 0; font-size: 1.05rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent-grad); border-radius: inherit; transition: width .4s var(--ease); }
.rate-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.rate-btn { padding: 14px 10px; border-radius: var(--r); border: 1.5px solid var(--line-2); background: var(--surface); font-weight: 700; display: grid; gap: 2px; justify-items: center; }
.rate-btn small { font-weight: 500; color: var(--muted); font-size: .76rem; }
.rate-btn.hard:hover { border-color: var(--rose); background: var(--rose-soft); }
.rate-btn.medium:hover { border-color: var(--amber); background: var(--amber-soft); }
.rate-btn.easy:hover { border-color: var(--mint); background: var(--mint-soft); }
.study-help { text-align: center; color: var(--muted); font-size: .84rem; }

/* =========================================================
   Quiz
   ========================================================= */
.quiz-q { display: grid; gap: 14px; }
.quiz-progress { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .86rem; font-weight: 600; }
.quiz-progress .progress { flex: 1; }
.quiz-question { font-family: var(--font-read); font-size: 1.22rem; font-weight: 600; line-height: 1.45; }
.quiz-feedback { padding: 14px 16px; border-radius: var(--r); font-size: .95rem; line-height: 1.55; animation: rise .3s var(--ease); }
.quiz-feedback.good { background: var(--mint-soft); color: var(--mint-ink); }
.quiz-feedback.bad { background: var(--rose-soft); color: var(--rose-ink); }
.quiz-feedback.partly { background: var(--amber-soft); color: var(--amber-ink); }
.quiz-feedback b { display: block; margin-bottom: 4px; }
.hint-box { padding: 10px 14px; border-radius: var(--r); background: var(--blue-soft); color: var(--blue-ink); font-size: .92rem; }
.match-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.match-col { display: grid; gap: 8px; align-content: start; }
.match-item { padding: 11px 14px; border-radius: 14px; border: 1.5px solid var(--line-2); background: var(--surface); text-align: left; font-size: .93rem; transition: all var(--dur); }
.match-item:hover:not(:disabled) { border-color: var(--lav); }
.match-item.is-selected { border-color: var(--lav); background: var(--lav-soft); }
.match-item.is-matched { border-color: var(--mint); background: var(--mint-soft); color: var(--mint-ink); }
.match-item.is-wrong { border-color: var(--rose); background: var(--rose-soft); animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.score-ring { --p: 0; width: 132px; height: 132px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--lav) calc(var(--p) * 1%), var(--surface-3) 0); position: relative; flex: none; }
.score-ring::after { content: ''; position: absolute; inset: 12px; border-radius: 50%; background: var(--surface); }
.score-ring span { position: relative; z-index: 1; font-family: var(--font-display); font-size: 1.9rem; font-weight: 700; }
.result-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.result-box { padding: 14px 16px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface-2); }
.result-box h4 { margin: 0 0 8px; font-size: .9rem; display: flex; align-items: center; gap: 6px; }
.result-box ul { margin: 0; padding-left: 1.1em; font-size: .9rem; }
.result-box.good h4 { color: var(--mint-ink); }
.result-box.bad h4 { color: var(--rose-ink); }
.result-box.next h4 { color: var(--blue-ink); }

/* =========================================================
   Diagrams
   ========================================================= */
.diagram-wrap { position: relative; border-radius: var(--r-lg); border: 1px solid var(--line); background:
  radial-gradient(circle at 1px 1px, color-mix(in srgb, var(--ink) 9%, transparent) 1px, transparent 0) 0 0 / 22px 22px, var(--surface-2); overflow: auto; }
.diagram-wrap svg { min-width: 640px; width: 100%; height: auto; }
.dg-node { cursor: pointer; outline: none; }
.dg-node rect, .dg-node circle, .dg-node ellipse { fill: var(--surface); stroke: var(--line-2); stroke-width: 1.5; transition: stroke var(--dur), fill var(--dur); }
.dg-node text { fill: var(--ink); font-family: var(--font-ui); font-size: 16px; font-weight: 600; pointer-events: none; }
.dg-node:hover rect, .dg-node:hover circle, .dg-node:focus-visible rect, .dg-node:focus-visible circle, .dg-node.is-active rect, .dg-node.is-active circle { stroke: var(--lav); stroke-width: 2.5; }
.dg-node:focus-visible { outline: none; }
.dg-node.root rect, .dg-node.root circle, .dg-node.root ellipse { fill: var(--lav); stroke: var(--lav); }
.dg-node.root text { fill: var(--on-accent); font-size: 18px; }
.dg-node.g-a rect { fill: var(--lav-soft); }
.dg-node.g-b rect { fill: var(--blue-soft); }
.dg-node.g-both rect { fill: var(--mint-soft); }
.dg-node.tier-2 rect { fill: var(--surface-2); }
.dg-node .num { fill: var(--lav); }
.dg-node .num-text { fill: var(--on-accent); font-size: 13px; font-weight: 800; }
.dg-edge { stroke: color-mix(in srgb, var(--ink) 30%, transparent); stroke-width: 1.8; fill: none; }
.dg-edge-label { fill: var(--ink-2); font-size: 13px; font-family: var(--font-ui); font-weight: 600; }
.dg-edge-label-bg { fill: var(--surface-2); }
.dg-line { stroke: var(--lav); stroke-width: 3; }
.dg-when { fill: var(--lav-ink); font-size: 14px; font-weight: 800; font-family: var(--font-ui); }
.dg-heading { fill: var(--ink); font-family: var(--font-display); font-size: 18px; font-weight: 700; }
.diagram-detail { margin-top: 14px; padding: 16px 18px; border-radius: var(--r); background: var(--lav-soft); border: 1px solid color-mix(in srgb, var(--lav) 30%, transparent); animation: rise .25s var(--ease); }
.diagram-detail h4 { margin: 0 0 6px; color: var(--lav-ink); }
.diagram-detail p { margin: 0 0 10px; font-family: var(--font-read); line-height: var(--reading-lh); }

/* =========================================================
   Teach me, checkers, fun tools
   ========================================================= */
.lesson-track { display: flex; gap: 6px; margin-bottom: 18px; }
.lesson-track i { flex: 1; height: 6px; border-radius: 999px; background: var(--surface-3); }
.lesson-track i.done { background: var(--mint); }
.lesson-track i.now { background: var(--lav); }
.tutor-bubble { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 14px; }
.tutor-bubble .chat-avatar { width: 38px; height: 38px; }
.tutor-bubble .bubble { padding: 14px 16px; border-radius: 4px 18px 18px 18px; background: var(--surface-2); border: 1px solid var(--line); flex: 1; min-width: 0; }
.example-box { padding: 12px 16px; border-radius: var(--r); background: var(--amber-soft); color: var(--amber-ink); margin: 10px 0; font-size: .95rem; }
.feedback-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.fb-box { padding: 14px 16px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface-2); }
.fb-box h4 { margin: 0 0 8px; font-size: .92rem; display: flex; align-items: center; gap: 8px; }
.fb-box ul { margin: 0; padding-left: 1.1em; font-size: .93rem; }
.fb-box li { margin-bottom: 4px; }
.fb-box.good h4 { color: var(--mint-ink); }
.fb-box.miss h4 { color: var(--amber-ink); }
.fb-box.wrong h4 { color: var(--rose-ink); }
.fb-box.more h4 { color: var(--blue-ink); }
.issue { padding: 14px 16px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface-2); margin-bottom: 10px; }
.issue q { display: block; font-family: ui-monospace, Menlo, monospace; font-size: .9rem; background: var(--rose-soft); color: var(--rose-ink); padding: 6px 10px; border-radius: 8px; margin-bottom: 8px; quotes: none; white-space: pre-wrap; }
.issue p { margin: 0 0 4px; font-size: .94rem; }
.steps-list { counter-reset: s; list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.steps-list li { counter-increment: s; display: flex; gap: 12px; align-items: flex-start; padding: 10px 14px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line); }
.steps-list li::before { content: counter(s); width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--lav); color: var(--on-accent); font-weight: 800; font-size: .82rem; flex: none; }
.fun-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.fun-btn { display: grid; gap: 6px; padding: 16px; border-radius: var(--r-lg); border: 1px solid var(--line); background: var(--surface); text-align: left; transition: all var(--dur) var(--ease); }
.fun-btn .ico { width: 30px; height: 30px; padding: 6px; border-radius: 10px; background: var(--tint, var(--lav-soft)); color: var(--ink-tint, var(--lav-ink)); }
.fun-btn b { font-size: .96rem; }
.fun-btn small { color: var(--muted); font-size: .82rem; line-height: 1.4; }
.fun-btn:hover { border-color: var(--lav); transform: translateY(-2px); box-shadow: var(--shadow); }
.timer { font-family: var(--font-display); font-size: 2rem; font-weight: 700; color: var(--lav-ink); }
.compare-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .94rem; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.compare-table th, .compare-table td { padding: 10px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.compare-table thead th { background: var(--surface-3); font-weight: 800; }
.compare-table tr:last-child td { border-bottom: 0; }
.compare-table td:first-child { font-weight: 700; color: var(--ink-2); width: 22%; }
.table-scroll { overflow-x: auto; }
.confusing-item { padding: 14px 16px; border-left: 4px solid var(--rose); border-radius: 0 var(--r) var(--r) 0; background: var(--surface-2); margin-bottom: 10px; }
.confusing-item blockquote { margin: 0 0 8px; font-family: var(--font-read); }
.confusing-item .why { font-size: .86rem; color: var(--rose-ink); margin-bottom: 6px; }
.confusing-item .plain { font-family: var(--font-read); color: var(--mint-ink); }
.emoji-block { font-size: 1.5rem; line-height: 1.8; padding: 16px 18px; border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--line); white-space: pre-wrap; }

/* Vocabulary */
.vocab-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.vocab-card { padding: 16px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); display: grid; gap: 6px; align-content: start; }
.vocab-card h4 { margin: 0; font-size: 1.1rem; font-family: var(--font-display); }
.vocab-card .pron { color: var(--muted); font-size: .84rem; }
.vocab-card p { margin: 0; font-size: .92rem; color: var(--ink-2); }

/* =========================================================
   Pages: My Learning, Settings
   ========================================================= */
.page { padding-top: 28px; padding-bottom: 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-title { font-family: var(--font-display); font-weight: 600; font-size: clamp(1.9rem, 4vw, 2.6rem); letter-spacing: -.02em; margin: 0; }
.page-sub { color: var(--ink-2); margin: 4px 0 0; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 22px; overflow-x: auto; scrollbar-width: none; }
.tabs button { border: 0; background: transparent; padding: 10px 14px; font-weight: 700; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--lav-ink); border-bottom-color: var(--lav); }
.tabs button:hover { color: var(--ink); }
.stat-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { padding: 18px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); display: flex; gap: 14px; align-items: center; }
.stat .ico { width: 44px; height: 44px; padding: 11px; border-radius: 14px; background: var(--tint, var(--lav-soft)); color: var(--ink-tint, var(--lav-ink)); }
.stat b { display: block; font-family: var(--font-display); font-size: 1.7rem; line-height: 1.1; }
.stat small { color: var(--muted); font-size: .84rem; }
.dash-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
.span-8 { grid-column: span 8; } .span-4 { grid-column: span 4; } .span-6 { grid-column: span 6; } .span-12 { grid-column: span 12; }
.list { list-style: none; margin: 0; padding: 0; display: grid; }
.list li { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .li-main { flex: 1; min-width: 0; }
.list .li-main b { display: block; font-size: .94rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .li-main small { color: var(--muted); font-size: .8rem; }
.li-ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-3); color: var(--ink-2); flex: none; }
.chart { width: 100%; height: auto; }
.chart .bar { fill: var(--chart-1); }
.chart .bar-hit { fill: transparent; cursor: default; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart-wrap { position: relative; }
.chart-tip { position: absolute; pointer-events: none; padding: 6px 10px; border-radius: 10px; background: var(--ink); color: var(--bg); font-size: .8rem; font-weight: 600; white-space: nowrap; transform: translate(-50%, -100%); box-shadow: var(--shadow); }
.chart .axis { fill: var(--muted); font-size: 11px; font-family: var(--font-ui); }
.chart .val { fill: var(--ink-2); font-size: 11px; font-weight: 700; font-family: var(--font-ui); }
.goal { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.goal:last-child { border-bottom: 0; }
.goal.done span { text-decoration: line-through; color: var(--muted); }
.goal span { flex: 1; }
.plan-day { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); overflow: hidden; }
.plan-day-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--surface-2); border-bottom: 1px solid var(--line); font-weight: 700; flex-wrap: wrap; }
.plan-day-head .tag { margin-left: auto; }
.plan-item { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.plan-item:last-child { border-bottom: 0; }
.plan-item .kind { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none; background: var(--tint, var(--lav-soft)); color: var(--ink-tint, var(--lav-ink)); }
.plan-item .pi-main { flex: 1; min-width: 160px; }
.plan-item .pi-main b { display: block; font-size: .93rem; }
.plan-item .pi-main small { color: var(--muted); }
.plan-item.is-done .pi-main b { text-decoration: line-through; color: var(--muted); }
.plan-item.is-skipped { opacity: .55; }
.settings-grid { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; align-items: start; }
.settings-nav { position: sticky; top: calc(var(--topbar-h) + 16px); display: grid; gap: 2px; }
.settings-nav a { padding: 9px 12px; border-radius: 12px; text-decoration: none; color: var(--ink-2); font-weight: 600; font-size: .92rem; }
.settings-nav a:hover { background: var(--surface-3); }
.settings-sections { display: grid; gap: 18px; min-width: 0; }
.settings-sections .card { scroll-margin-top: calc(var(--topbar-h) + 16px); }
.settings-sections h2 { font-family: var(--font-display); font-weight: 600; font-size: 1.3rem; margin: 0 0 4px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.range-row { display: flex; align-items: center; gap: 12px; }
.range-row output { min-width: 48px; text-align: right; font-weight: 700; color: var(--lav-ink); }
.code-box { font-family: ui-monospace, Menlo, monospace; font-size: 1rem; letter-spacing: .04em; padding: 12px 14px; border-radius: var(--r-sm); background: var(--surface-3); word-break: break-all; }
.privacy-list { margin: 0; padding-left: 1.2em; color: var(--ink-2); }
.privacy-list li { margin-bottom: 6px; }
.shortcut-list { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: .92rem; align-items: center; }

/* =========================================================
   Overlays: selection menu, popover, toasts, modal, TTS bar
   ========================================================= */
.selection-menu { position: absolute; z-index: 60; display: flex; gap: 2px; padding: 5px; border-radius: 14px; background: var(--ink); color: var(--bg); box-shadow: var(--shadow-lg); animation: pop .15s var(--ease); max-width: calc(100vw - 16px); overflow-x: auto; scrollbar-width: none; }
.selection-menu button { border: 0; background: transparent; color: inherit; padding: 7px 10px; border-radius: 9px; font-size: .82rem; font-weight: 700; white-space: nowrap; display: inline-flex; align-items: center; gap: 5px; }
.selection-menu button:hover, .selection-menu button:focus-visible { background: color-mix(in srgb, var(--bg) 18%, transparent); }
.selection-menu .ico { width: 14px; height: 14px; }
@keyframes pop { from { opacity: 0; transform: translateY(4px) scale(.97); } }
.popover { position: absolute; z-index: 65; width: min(380px, calc(100vw - 24px)); max-height: min(480px, 70vh); overflow: auto; padding: 18px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-lg); animation: pop .18s var(--ease); }
.popover h3 { font-family: var(--font-display); font-size: 1.3rem; margin: 0 0 2px; padding-right: 30px; }
.popover .pop-close { position: absolute; top: 10px; right: 10px; }
.popover .pron { color: var(--muted); font-size: .88rem; margin-bottom: 10px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.popover .reading { font-size: .98rem; }
.popover .pop-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.toasts { position: fixed; z-index: 90; bottom: 20px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; width: min(440px, calc(100vw - 24px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 14px; background: var(--ink); color: var(--bg); box-shadow: var(--shadow-lg); font-size: .92rem; font-weight: 600; animation: pop .2s var(--ease); }
.toast.error { background: var(--rose-ink); color: #fff; }
.toast.ok .ico { color: var(--mint); }
.toast button { margin-left: auto; border: 0; background: transparent; color: inherit; font-weight: 800; text-decoration: underline; }
.modal { border: 0; padding: 0; border-radius: var(--r-xl); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 40px); }
.modal::backdrop { background: rgba(20, 16, 36, .45); backdrop-filter: blur(3px); }
.modal[open] { animation: pop .2s var(--ease); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 20px 22px 0; }
.modal-head h2 { margin: 0; font-family: var(--font-display); font-size: 1.35rem; flex: 1; }
.modal-body { padding: 16px 22px; display: grid; gap: 14px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 0 22px 20px; flex-wrap: wrap; }
.tts-bar { position: fixed; z-index: 55; left: 50%; bottom: 20px; transform: translateX(-50%); display: flex; align-items: center; gap: 6px; padding: 6px 8px 6px 14px; border-radius: 999px; background: var(--ink); color: var(--bg); box-shadow: var(--shadow-lg); animation: pop .2s var(--ease); max-width: calc(100vw - 24px); }
.tts-bar .icon-btn { color: var(--bg); width: 36px; height: 36px; }
.tts-bar .icon-btn:hover { background: color-mix(in srgb, var(--bg) 18%, transparent); }
.tts-bar select { background: transparent; color: inherit; border: 1px solid color-mix(in srgb, var(--bg) 30%, transparent); border-radius: 999px; padding: 4px 8px; font-size: .82rem; }
.tts-bar select option { color: #000; }
.tts-bar .tts-label { font-size: .84rem; font-weight: 700; white-space: nowrap; }
.wave { display: inline-flex; gap: 2px; align-items: center; height: 16px; }
.wave i { width: 3px; background: var(--lav); border-radius: 2px; animation: wave 1s infinite ease-in-out; }
.wave i:nth-child(2) { animation-delay: .15s; } .wave i:nth-child(3) { animation-delay: .3s; }
@keyframes wave { 0%, 100% { height: 4px; } 50% { height: 14px; } }
.tts-bar.is-paused .wave i { animation-play-state: paused; }

/* Print: flashcards and explanations */
.print-only { display: none; }
@media print {
  body { background: #fff; color: #000; }
  .topbar, .bottomnav, .ws-toolbar, .ws-left, .ws-right, .chat-fab, .toasts, .tts-bar, .selection-menu, .popover, .no-print, .view:not(.print-target) { display: none !important; }
  .print-only { display: block !important; }
  .print-area { display: block !important; }
  .print-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
  .print-card { border: 1px dashed #999; padding: 18px; min-height: 2.4in; page-break-inside: avoid; font-family: Georgia, serif; }
  .print-card small { display: block; color: #666; font-size: 9pt; margin-bottom: 6px; text-transform: uppercase; letter-spacing: .08em; }
}
.print-area { display: none; }

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 1180px) {
  .workspace, .workspace.chat-collapsed { grid-template-columns: 220px minmax(0, 1fr); }
  .ws-right { position: fixed; top: 0; right: 0; bottom: 0; z-index: 75; width: min(420px, 100vw); height: 100%; max-height: none; border-radius: 0; transform: translateX(105%); transition: transform .3s var(--ease); box-shadow: var(--shadow-lg); }
  .ws-right.is-open { transform: none; }
  .ws-right.is-collapsed .chat-log, .ws-right.is-collapsed .chat-suggest, .ws-right.is-collapsed .chat-form { display: flex; }
  .chat-fab { display: grid; place-items: center; position: fixed; z-index: 50; right: 20px; bottom: 24px; width: 58px; height: 58px; border-radius: 20px; border: 0; background: var(--accent-grad); color: var(--on-accent); box-shadow: var(--shadow-lg); transition: transform var(--dur) var(--ease); }
  .chat-fab:hover { transform: scale(1.05); }
  .chat-fab .ico { width: 26px; height: 26px; }
  .feature-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-grid > * { grid-column: span 12; }
  .dash-grid > .span-6 { grid-column: span 6; }
}
@media (max-width: 860px) {
  :root { --topbar-h: 58px; }
  .mainnav { display: none; }
  .mobile-only { display: inline-flex !important; }
  .bottomnav { display: flex; position: fixed; z-index: 45; left: 0; right: 0; bottom: 0; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); }
  .bottomnav a { flex: 1; display: grid; justify-items: center; gap: 2px; padding: 6px 2px; border-radius: 12px; text-decoration: none; color: var(--muted); font-size: .7rem; font-weight: 700; }
  .bottomnav a .ico { width: 22px; height: 22px; }
  .bottomnav a[aria-current="page"] { color: var(--lav-ink); background: var(--lav-soft); }
  body { padding-bottom: calc(70px + env(safe-area-inset-bottom)); }
  .chat-fab { bottom: calc(84px + env(safe-area-inset-bottom)); }
  .toasts { bottom: calc(86px + env(safe-area-inset-bottom)); }
  .tts-bar { bottom: calc(86px + env(safe-area-inset-bottom)); }
  .workspace, .workspace.chat-collapsed { grid-template-columns: minmax(0, 1fr); padding: 12px 14px 30px; gap: 14px; }
  .ws-left { position: static; max-height: none; overflow: visible; }
  .source-text { max-height: 220px; }
  .source-card { scroll-margin-top: calc(var(--topbar-h) + 118px); }
  .ws-left .ws-section-label, .ws-left .saved-list, .ws-left .saved-empty, .ws-left .ws-extra { display: none; }
  .tool-nav { display: flex; overflow-x: auto; gap: 6px; margin: 0 -14px; padding: 2px 14px 6px; scrollbar-width: none; }
  .tool-nav button { flex: none; border: 1px solid var(--line); background: var(--surface); padding: 8px 12px; border-radius: 999px; font-size: .85rem; }
  .tool-nav .count { display: none; }
  .ws-toolbar-inner { padding: 8px 14px; gap: 8px; }
  .ws-controls { flex-wrap: nowrap; overflow-x: auto; width: 100%; scrollbar-width: none; padding-bottom: 2px; }
  .ws-controls .divider { display: none; }
  .cards-layout { grid-template-columns: minmax(0, 1fr); }
  .deck-sidebar { position: static; }
  .settings-grid { grid-template-columns: minmax(0, 1fr); }
  .settings-nav { position: static; display: flex; overflow-x: auto; scrollbar-width: none; }
  .settings-nav a { white-space: nowrap; }
  .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-grid > .span-6 { grid-column: span 12; }
  .result-grid { grid-template-columns: minmax(0, 1fr); }
  .container { padding: 0 16px; }
  .section { padding: 44px 16px; }
}
@media (max-width: 560px) {
  .hero { padding: 36px 0 34px; }
  .primary-actions { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .chip-btn span { display: none; }
  .chip-btn { padding: 8px 11px; }
  .home-input { min-height: 150px; font-size: 1.02rem; padding: 12px; }
  .feature-grid { grid-template-columns: minmax(0, 1fr); }
  .privacy-card { flex-direction: column; padding: 22px; }
  .status-pill .label { display: none; }
  .status-pill { padding: 9px; }
  .deck-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid, .feedback-grid, .match-grid { grid-template-columns: minmax(0, 1fr); }
  .tool-head { padding: 16px 16px 0; }
  .tool-body { padding: 16px; }
  .tool-options { padding: 14px 16px; }
  .tool-head h2 { font-size: 1.25rem; }
  .flip-card { aspect-ratio: 4 / 5; max-height: 460px; }
  .rate-row { gap: 8px; }
  .modal-foot .btn { flex: 1; }
  .brand-name { font-size: 1.15rem; }
  .example { width: 100%; }
}

/* Built-in AI controls fit the regular Settings card layout. */
.local-ai-setup { padding: 16px; border: 1px solid var(--line); border-radius: var(--r); margin: 0 0 12px; }
.local-ai-setup h3 { margin: 0; font-size: 1rem; font-weight: 700; }
.local-ai-setup .btn { max-width: 100%; }
.local-ai-setup .meta-note { margin: 0; }
