/* =========================================================
   AuslanBotAI — main.css
   Mobile-first, dark-by-default, respects reduced motion.
   ========================================================= */

:root {
  /* Palette — calm, high-contrast, Auslan-friendly */
  --bg: #0b0d10;
  --bg-2: #12161c;
  --bg-3: #1a1f27;
  --line: #232a34;
  --line-strong: #313a47;
  --fg: #eef2f7;
  --fg-2: #b9c2cf;
  --fg-3: #8d96a3;
  --accent: #ff7a59;        /* warm "start" accent */
  --accent-2: #ffb199;
  --success: #3ecf8e;
  --warn:   #f5c451;
  --danger: #ff5f6d;
  --info:   #6aa7ff;
  --focus:  #84b8ff;

  --rad-sm: 8px;
  --rad: 14px;
  --rad-lg: 22px;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --shadow-soft: 0 2px 10px rgba(0,0,0,.25);

  --fs-xs: .78rem;
  --fs-sm: .875rem;
  --fs-md: 1rem;
  --fs-lg: 1.125rem;
  --fs-xl: 1.375rem;
  --fs-2xl: 1.75rem;
  --fs-3xl: 2.25rem;
  --fs-4xl: 3rem;

  --maxw: 1200px;
  --bar-h: 60px;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #fbfaf7;
    --bg-2: #ffffff;
    --bg-3: #f3f1ec;
    --line: #e4e1d9;
    --line-strong: #c9c5b8;
    --fg: #0c1218;
    --fg-2: #3a4450;
    --fg-3: #6b7583;
    --shadow: 0 10px 30px rgba(30,30,30,.08);
    --shadow-soft: 0 2px 10px rgba(30,30,30,.06);
  }
}
/* Manual theme overrides — user setting trumps system preference */
:root[data-theme="light"] {
  --bg: #fbfaf7;
  --bg-2: #ffffff;
  --bg-3: #f3f1ec;
  --line: #e4e1d9;
  --line-strong: #c9c5b8;
  --fg: #0c1218;
  --fg-2: #3a4450;
  --fg-3: #6b7583;
  --shadow: 0 10px 30px rgba(30,30,30,.08);
  --shadow-soft: 0 2px 10px rgba(30,30,30,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: ui-sans-serif, system-ui, -apple-system, "SF Pro Text", "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  font-size: var(--fs-md);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
a { color: var(--fg); text-decoration: none; }
a:hover { color: var(--accent-2); }
button { font: inherit; color: inherit; }
img, svg, video { max-width: 100%; display: block; }

/* Auslan is silent — every video in the app is permanently muted, so
   hide the volume/mute UI in the native media controls. A greyed-out
   mute button on every card just invites questions. Non-WebKit browsers
   don't let us style their controls, but the global volumechange guard
   in main.js re-mutes anything a user tries to unmute anyway. */
video::-webkit-media-controls-volume-slider,
video::-webkit-media-controls-volume-control-container,
video::-webkit-media-controls-volume-control-hover-background,
video::-webkit-media-controls-mute-button {
  display: none !important;
}
input, select, textarea, button { font: inherit; color: inherit; }
::selection { background: color-mix(in oklab, var(--accent) 40%, transparent); }

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

/* Skip link (keyboard accessibility) */
.skip-link {
  position: absolute;
  top: -100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #0b0d10;
  padding: 8px 20px;
  border-radius: 0 0 var(--rad-sm) var(--rad-sm);
  font-weight: 700;
  z-index: 9999;
  transition: top .15s;
}
.skip-link:focus {
  top: 0;
}

/* ============================= APP BAR ============================ */
.appbar {
  position: sticky; top: 0; z-index: 50;
  display: grid; grid-template-columns: auto 1fr auto;
  align-items: center; gap: 8px;
  height: var(--bar-h);
  padding: 0 clamp(12px, 3vw, 24px);
  background: color-mix(in oklab, var(--bg) 85%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: var(--fs-lg); letter-spacing: -0.01em;
  color: var(--fg);
}
.brand-mark { width: 30px; height: 30px; color: var(--accent); }
.brand-ai { color: var(--accent); }
.topnav {
  display: flex; gap: 4px; justify-content: center;
}
.topnav a {
  padding: 8px 14px; border-radius: 999px;
  color: var(--fg-2); font-weight: 600;
}
.topnav a.active, .topnav a:hover {
  background: var(--bg-3); color: var(--fg);
}
.appbar-right { display: flex; gap: 4px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 999px;
  background: transparent; border: 1px solid transparent;
  display: inline-grid; place-items: center;
  cursor: pointer; color: var(--fg-2);
}
.icon-btn:hover { background: var(--bg-3); color: var(--fg); }

/* Account button — prominent sign-in state */
#account-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: auto;
  padding: 0 12px;
  height: 36px;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: var(--fs-sm);
  font-weight: 600;
  border-radius: 999px;
}
#account-btn:hover { background: color-mix(in oklab, var(--accent) 12%, transparent); }
.appbar-signin-label { white-space: nowrap; }
.appbar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}
.appbar-avatar-text {
  width: 32px;
  height: 32px;
  border-color: var(--line);
  color: var(--fg);
  font-weight: 700;
  font-size: var(--fs-sm);
  padding: 0;
  justify-content: center;
}

@media (max-width: 640px) {
  .appbar { grid-template-columns: auto 1fr auto; gap: 0; height: var(--bar-h); }
  .brand-text { display: none; }
  /* Hide desktop topnav on mobile — bottomnav replaces it */
  .topnav { display: none; }
}

/* =========================== MAIN VIEW ============================ */
.view {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(14px, 3vw, 28px);
  min-height: calc(100dvh - var(--bar-h) - 40px);
  padding-bottom: 60px;
}

/* ============================= HERO =============================== */
.hero {
  display: grid; gap: 18px;
  padding: clamp(20px, 4vw, 48px) 0 8px;
}
.hero h1 {
  font-size: clamp(2rem, 5vw, 3.6rem);
  line-height: 1.04; letter-spacing: -0.02em;
  margin: 0;
  font-weight: 800;
}
.hero h1 .accent { color: var(--accent); }
.hero p.lede { color: var(--fg-2); font-size: var(--fs-lg); max-width: 62ch; margin: 0; }

.hero-search {
  display: flex; align-items: center;
  gap: 10px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--rad-lg);
  padding: 10px 10px 10px 18px;
  max-width: 680px;
  box-shadow: var(--shadow-soft);
}
.hero-search input {
  flex: 1; background: transparent; border: 0; outline: 0;
  font-size: var(--fs-lg); color: var(--fg);
  padding: 10px 0;
}
.hero-search input::placeholder { color: var(--fg-3); }
.hero-search button {
  background: var(--accent); color: #0b0d10; font-weight: 700;
  border: 0; border-radius: 999px; padding: 10px 18px; cursor: pointer;
  transition: transform .08s ease;
}
.hero-search button:hover { transform: translateY(-1px); }
.hero-search button:active { transform: translateY(0); }

/* ============================ BIG BUTTONS ========================= */
.big-actions {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  margin-top: 28px;
}
.big-btn {
  display: block;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--rad-lg);
  padding: 22px;
  text-align: left;
  cursor: pointer;
  transition: transform .12s ease, border-color .12s ease, background .12s ease;
}
.big-btn:hover { transform: translateY(-2px); border-color: var(--line-strong); background: var(--bg-3); }
.big-btn .kicker { color: var(--fg-3); font-size: var(--fs-sm); text-transform: uppercase; letter-spacing: .08em; }
.big-btn h2 { margin: 6px 0 4px; font-size: var(--fs-2xl); font-weight: 800; }
.big-btn p { margin: 0; color: var(--fg-2); font-size: var(--fs-md); }
.big-btn .meta { margin-top: 14px; font-size: var(--fs-sm); color: var(--fg-3); }

/* ============================ DAILY CARD ========================== */
.daily {
  display: grid; gap: 14px;
  grid-template-columns: 1fr;
  background: linear-gradient(180deg, color-mix(in oklab, var(--accent) 10%, var(--bg-2)) 0%, var(--bg-2) 60%);
  border: 1px solid var(--line-strong);
  border-radius: var(--rad-lg);
  padding: 22px;
  margin-top: 28px;
}
.daily-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; }
.daily h2 { margin: 0; font-size: var(--fs-xl); }
.daily .stats { display: flex; gap: 16px; color: var(--fg-2); font-size: var(--fs-sm); }
.daily .stats b { color: var(--fg); font-size: var(--fs-md); }
.daily .cta {
  display: inline-flex; align-items: center; gap: 10px;
  background: var(--accent); color: #0b0d10; font-weight: 800;
  border: 0; border-radius: 999px; padding: 12px 20px; cursor: pointer;
  align-self: start;
}
.daily .cta:hover { filter: brightness(1.05); }

/* ============================ LIBRARIES =========================== */
.section-head {
  display: flex; justify-content: space-between; align-items: baseline; margin: 32px 0 12px;
}
.section-head h2 { margin: 0; font-size: var(--fs-xl); }
.section-head a { color: var(--fg-3); font-size: var(--fs-sm); }
.section-head a:hover { color: var(--fg); }

.tile-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.tile {
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: var(--rad); padding: 14px; cursor: pointer;
  transition: border-color .12s ease, transform .12s ease;
}
.tile:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.tile.skeleton {
  cursor: default; pointer-events: none;
  background: linear-gradient(90deg, var(--bg-2) 0%, var(--bg-3) 50%, var(--bg-2) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.6s linear infinite;
  min-height: 66px;
}
.tile.skeleton h3, .tile.skeleton p { color: transparent; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.tile h3 { margin: 0 0 4px; font-size: var(--fs-md); font-weight: 700; }
.tile p { margin: 0; color: var(--fg-3); font-size: var(--fs-sm); }
.tile .tile-bar { margin-top: 10px; height: 6px; background: var(--bg-3); border-radius: 999px; overflow: hidden; }
.tile .tile-bar span { display: block; height: 100%; background: var(--accent); }

/* ============================ LOOKUP ============================= */
.lookup-bar {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  margin-bottom: 16px;
}
.lookup-bar .search {
  flex: 1 1 300px;
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--rad);
  padding: 8px 12px;
}
.lookup-bar input {
  flex: 1; background: transparent; border: 0; outline: 0;
  font-size: var(--fs-md); color: var(--fg);
  padding: 6px 0;
}
.lookup-bar select, .filter-chip {
  background: var(--bg-2); border: 1px solid var(--line); color: var(--fg-2);
  border-radius: 999px; padding: 8px 14px; cursor: pointer;
}
.filter-chip.active { background: var(--bg-3); color: var(--fg); border-color: var(--line-strong); }

/* Sort row */
.sort-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.sort-label {
  font-size: var(--fs-sm);
  color: var(--fg-3);
  font-weight: 600;
  margin-right: 4px;
}
.sort-chip {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--fg-3);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: var(--fs-xs);
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
  white-space: nowrap;
}
.sort-chip:hover { background: var(--bg-3); color: var(--fg-2); }
.sort-chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.in-lib-badge {
  font-size: var(--fs-xs);
  color: var(--accent);
  margin-top: 4px;
}

/* Contextual AI buttons — subtle but discoverable */
.ai-context-btn {
  background: color-mix(in oklab, var(--accent) 12%, var(--bg-2));
  border-color: color-mix(in oklab, var(--accent) 40%, var(--line));
  color: var(--accent);
  font-weight: 600;
}
.ai-context-btn:hover {
  background: color-mix(in oklab, var(--accent) 22%, var(--bg-2));
  border-color: var(--accent);
}
/* AI mode card in Learn chooser — subtle accent border */
.ai-mode-card {
  border-color: color-mix(in oklab, var(--accent) 40%, var(--line));
}

/* Theme sort row (learn tab) */
.theme-sort-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.theme-search-input {
  flex: 1 1 160px;
  min-width: 120px;
  max-width: 280px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-2);
  color: var(--fg);
  font-size: var(--fs-sm);
}
.theme-search-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

.results {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.result {
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: var(--rad); padding: 10px; cursor: pointer;
  display: grid; grid-template-columns: auto 1fr; gap: 10px;
  align-items: center;
}
.result:hover { border-color: var(--line-strong); }
.result .thumb {
  width: 72px; aspect-ratio: 1 / 1; border-radius: var(--rad-sm);
  overflow: hidden; background: #000;
  display: grid; place-items: center; color: var(--fg-3);
}
.result .thumb video { width: 100%; height: 100%; object-fit: cover; }
.result .gloss { font-weight: 700; font-size: var(--fs-md); }
.result .kw { color: var(--fg-3); font-size: var(--fs-sm); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.result .tag { display: inline-block; font-size: var(--fs-xs); color: var(--fg-3); border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; margin-right: 4px; }

/* ============================ SIGN DETAIL ========================= */
.sign-detail {
  display: grid; gap: 20px;
  grid-template-columns: minmax(260px, 46%) 1fr;
}
@media (max-width: 820px) { .sign-detail { grid-template-columns: 1fr; } }

.sign-detail .video-card {
  background: #000; border-radius: var(--rad);
  overflow: hidden; position: relative; aspect-ratio: 4 / 3;
}
.sign-detail video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.sign-detail .video-controls {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; gap: 6px; padding: 8px;
  background: linear-gradient(transparent, rgba(0,0,0,.6));
}
.sign-detail .video-controls button {
  background: rgba(255,255,255,.15); color: #fff;
  border: 0; border-radius: 999px; padding: 6px 12px; cursor: pointer;
  backdrop-filter: blur(6px);
}
.sign-detail .video-controls button:hover { background: rgba(255,255,255,.25); }
.sign-detail .variant-row {
  display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px;
  align-items: center;
}
.sign-detail .variant-hint {
  font-size: var(--fs-xs); color: var(--fg-3);
  padding: 4px 4px 4px 0;
}
.sign-detail .variant-hint.solo {
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 12px;
}

/* Persistent "Variants" chip that sits at the front of the strip.
   Its colour tells the learner whether pressing V will actually do
   something, so they're not left wondering whether the shortcut
   worked. `multi` = accent-tinted and hints the cycle count; `solo`
   = muted so it visually recedes. */
.sign-detail .variant-chip {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: var(--fs-xs); font-weight: 600;
  padding: 5px 12px 5px 6px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--fg-2);
}
.sign-detail .variant-chip.multi {
  background: color-mix(in oklab, var(--accent) 14%, var(--bg-2));
  border-color: color-mix(in oklab, var(--accent) 45%, var(--line));
  color: var(--fg);
}
.sign-detail .variant-chip.solo { color: var(--fg-3); }
.sign-detail .variant-kbd {
  display: inline-grid; place-items: center;
  min-width: 20px; height: 20px; padding: 0 5px;
  font-family: var(--mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 11px; font-weight: 800;
  background: var(--bg-1); color: var(--fg-2);
  border: 1px solid var(--line); border-radius: 5px;
  box-shadow: 0 1px 0 var(--line);
}
.sign-detail .variant-chip.multi .variant-kbd {
  background: var(--accent);
  border-color: color-mix(in oklab, var(--accent) 60%, #000);
  color: #fff;
}
.sign-detail .variant-chip.pulse {
  animation: variant-chip-pulse .5s ease-out;
}
@keyframes variant-chip-pulse {
  0%   { transform: scale(1);    box-shadow: 0 0 0 0   color-mix(in oklab, var(--accent) 45%, transparent); }
  30%  { transform: scale(1.06); box-shadow: 0 0 0 6px color-mix(in oklab, var(--accent) 0%,  transparent); }
  100% { transform: scale(1);    box-shadow: 0 0 0 0   transparent; }
}

.sign-detail .variant-btn {
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 12px; cursor: pointer;
  font-size: var(--fs-sm); color: var(--fg-2);
  display: inline-flex; align-items: center; gap: 6px;
}
.sign-detail .variant-btn:hover { background: var(--bg-3); }
.sign-detail .variant-btn.active {
  background: var(--bg-3); color: var(--fg);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}

.sign-detail .video-card { position: relative; }

/* ------ Badges (region, lexis tags) ------ */
.badge-row {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin: 8px 0 4px;
}
.lex-badge {
  font-size: var(--fs-xs); font-weight: 600;
  padding: 3px 10px; border-radius: 999px;
  background: var(--bg-2); border: 1px solid var(--line);
  color: var(--fg-2);
}
.lex-badge.region {
  background: color-mix(in oklab, var(--accent) 15%, var(--bg-2));
  border-color: color-mix(in oklab, var(--accent) 40%, var(--line));
  color: var(--fg);
}

/* ------ Inline note editor ------ */
.note-block {
  margin-top: 18px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--rad);
  padding: 12px 14px;
}
.note-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: var(--fs-sm); color: var(--fg-3); margin-bottom: 6px;
}
.note-head label { font-weight: 600; color: var(--fg-2); }
.note-hint { font-size: var(--fs-xs); color: var(--accent); min-width: 60px; text-align: right; }
.note-editor {
  width: 100%; box-sizing: border-box;
  background: var(--bg-3); color: var(--fg);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; font-family: inherit; font-size: var(--fs-sm);
  resize: vertical; min-height: 54px;
}
.note-editor:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in oklab, var(--accent) 35%, transparent);
}

/* ------ Related concepts ------ */
.related-block { margin-top: 18px; }
.related-block h3 { font-size: var(--fs-md); color: var(--fg-2); margin: 0 0 8px; }
.related-btn { font-size: var(--fs-sm); }

.sign-detail h1 { margin: 0 0 4px; font-size: var(--fs-2xl); font-weight: 800; }
.sign-detail .gloss-number { color: var(--fg-3); font-size: var(--fs-sm); }
.sign-detail .keywords { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.sign-detail .keywords span {
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 10px; font-size: var(--fs-sm); color: var(--fg-2);
}
.sign-detail .defs { margin-top: 14px; }
.sign-detail .defs h3 { margin: 14px 0 4px; font-size: var(--fs-md); color: var(--fg-2); }
.sign-detail .defs ol { margin: 0; padding-left: 20px; color: var(--fg); }
.sign-detail .defs li { margin: 4px 0; }
.sign-detail .tags { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 6px; }
.sign-detail .tag-pill {
  font-size: var(--fs-xs); color: var(--fg-3);
  border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px;
}

.sign-actions {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px;
}
.btn {
  background: var(--bg-2); border: 1px solid var(--line-strong); color: var(--fg);
  border-radius: 999px; padding: 10px 18px; cursor: pointer; font-weight: 600;
}
.btn:hover { background: var(--bg-3); }
.btn-primary { background: var(--accent); color: #0b0d10; border-color: transparent; }
.btn-primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-danger { color: var(--danger); border-color: color-mix(in oklab, var(--danger) 30%, var(--line)); }
.bm-active { color: var(--warn); border-color: color-mix(in oklab, var(--warn) 40%, var(--line)); }

/* ============================ LIBRARY ============================ */
.lib-head {
  display: grid; gap: 14px;
  grid-template-columns: 1fr auto;
  align-items: center; margin-bottom: 14px;
}
.lib-head h1 { margin: 0; font-size: var(--fs-2xl); }
.lib-head p { margin: 4px 0 0; color: var(--fg-3); }
.lib-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.lib-card {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--rad);
  padding: 16px; cursor: pointer; transition: border-color .12s;
  display: flex; flex-direction: column; justify-content: space-between;
  min-height: 140px;
}
.lib-card:hover { border-color: var(--line-strong); }
.lib-card .title-row { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.lib-card h3 { margin: 0 0 4px; font-size: var(--fs-md); font-weight: 700; }
.lib-card .lib-meta { color: var(--fg-3); font-size: var(--fs-sm); }
.lib-card .lib-stats { display: flex; gap: 12px; margin-top: 10px; font-size: var(--fs-xs); color: var(--fg-3); }
.lib-card .lib-stats b { color: var(--fg); }
.lib-card .new-lib { font-size: var(--fs-xl); color: var(--fg-3); text-align: center; padding: 20px; }

.lib-viewer { display: grid; gap: 14px; }
.lib-viewer .tool-row {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
.lib-viewer .list {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--rad);
}
.lib-viewer .row {
  display: grid; grid-template-columns: 56px 1fr auto; gap: 12px;
  padding: 10px 14px; align-items: center; cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.lib-viewer .row:last-child { border-bottom: 0; }
.lib-viewer .row:hover { background: var(--bg-3); }
.lib-viewer .row .thumb { width: 56px; aspect-ratio: 1; border-radius: 8px; background: #000; overflow: hidden; }
.lib-viewer .row .thumb video { width: 100%; height: 100%; object-fit: cover; }
.lib-viewer .row .gloss { font-weight: 700; }
.lib-viewer .row .kw { color: var(--fg-3); font-size: var(--fs-sm); }
.lib-viewer .row .row-actions { display: flex; gap: 4px; }

/* ============================ LEARN ============================== */
.learn-chooser h1 { margin: 6px 0 4px; font-size: var(--fs-2xl); }
.learn-chooser p.lede { color: var(--fg-2); margin: 0 0 16px; }
.mode-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.mode-card {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--rad);
  padding: 18px; cursor: pointer; transition: border-color .12s, transform .12s;
}
.mode-card:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.mode-card .mode-emoji { font-size: 1.6rem; }
.mode-card h3 { margin: 8px 0 4px; font-size: var(--fs-lg); }
.mode-card p { color: var(--fg-3); font-size: var(--fs-sm); margin: 0; }

/* Session */
.session {
  display: grid; gap: 14px;
  max-width: 780px; margin: 0 auto;
}
.session-head {
  display: flex; justify-content: space-between; align-items: center;
}
.session-progress {
  height: 6px; background: var(--bg-3); border-radius: 999px; overflow: hidden;
}
.session-progress span { display: block; height: 100%; background: var(--accent); transition: width .25s ease; }
.session-counter { color: var(--fg-3); font-size: var(--fs-sm); }

.card {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--rad-lg);
  padding: clamp(14px, 3vw, 24px);
  display: grid; gap: 16px;
}
.card .video-card {
  background: #000; border-radius: var(--rad);
  overflow: hidden; aspect-ratio: 4 / 3; max-height: 62vh;
}
.card video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.card .prompt {
  font-size: var(--fs-xl); font-weight: 700; text-align: center;
}
.card .sub {
  text-align: center; color: var(--fg-3); font-size: var(--fs-sm);
  min-height: 1.2em;
}
.card .revealed {
  text-align: center;
  padding-top: 6px; border-top: 1px dashed var(--line);
}
.card .revealed h2 { margin: 4px 0; font-size: var(--fs-2xl); }
.card .revealed .keywords { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 8px 0; }

.rating-row, .show-row {
  display: grid; gap: 8px;
  grid-template-columns: repeat(4, 1fr);
}
.show-row { grid-template-columns: 1fr; }
.rating-btn {
  background: var(--bg-3); border: 1px solid var(--line-strong);
  color: var(--fg);
  border-radius: var(--rad); padding: 14px 8px; cursor: pointer;
  font-weight: 700; display: grid; gap: 2px;
}
.rating-btn .lbl { font-size: var(--fs-md); }
.rating-btn .sub { font-size: var(--fs-xs); color: var(--fg-3); font-weight: 400; }
.rating-btn:hover { background: var(--line); }
.rating-btn.again  { border-color: color-mix(in oklab, var(--danger) 40%, var(--line)); }
.rating-btn.hard   { border-color: color-mix(in oklab, var(--warn) 40%, var(--line)); }
.rating-btn.good   { border-color: color-mix(in oklab, var(--info) 40%, var(--line)); }
.rating-btn.easy   { border-color: color-mix(in oklab, var(--success) 40%, var(--line)); }

.session-done {
  text-align: center; padding: 32px 0;
}
.session-done h2 { font-size: var(--fs-3xl); margin: 0 0 10px; }
.session-done p { color: var(--fg-2); max-width: 56ch; margin: 0 auto; }

/* ============================ SESSION — VIEWPORT-FIT ============== */
/* When a practice session is active, everything lives inside the
   viewport exactly, with zero page-scroll. The --session-offset
   custom property is set at runtime to the live appbar height so
   the math is correct on both one-row (desktop) and two-row
   (mobile) appbars. */
body.in-session { overflow: hidden; height: 100dvh; }
body.in-session .view {
  height: calc(100dvh - var(--session-offset, 60px));
  max-height: calc(100dvh - var(--session-offset, 60px));
  min-height: 0;
  padding: clamp(8px, 2vw, 16px);
  padding-bottom: max(clamp(8px, 2vw, 16px), env(safe-area-inset-bottom));
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
body.in-session .ack { display: none; }

.session.in-session {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 780px;
  width: 100%;
  margin: 0 auto;
  flex: 1 1 auto;
  min-height: 0;
  position: relative; /* anchor for .variant-picker overlay */
}

.session.in-session .session-head {
  flex: 0 0 auto;
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px;
  font-size: var(--fs-sm);
  color: var(--fg-2);
}
.session.in-session .session-head .mode-pill strong { color: var(--fg-3); font-weight: 600; }
.session-exit-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--fg-2);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.session-exit-btn:hover { background: var(--bg-3); color: var(--fg); }
.session.in-session .session-progress { flex: 0 0 auto; }

.session.in-session .session-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
  overflow: hidden;
}

.session.in-session .video-card {
  flex: 1 1 0;
  min-height: 140px;
  background: #000;
  border: 1px solid var(--line);
  border-radius: var(--rad);
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  aspect-ratio: auto;
  max-height: none;
}
.session.in-session .video-card video {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  background: #000;
  margin: auto;
}
.session.in-session .video-card.text-mode {
  color: var(--fg-2);
  font-size: var(--fs-lg);
  font-weight: 600;
  text-align: center;
  padding: 24px;
  background: var(--bg-3);
  border-style: dashed;
}

.session.in-session .session-copy {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: center;
}
.session.in-session .session-copy .prompt {
  font-size: clamp(var(--fs-md), 2.4vw, var(--fs-xl));
  font-weight: 700;
}
.session.in-session .session-copy .sub {
  color: var(--fg-3);
  font-size: var(--fs-sm);
  min-height: 1.2em;
}

.session.in-session .revealed {
  flex: 0 0 auto;
  text-align: center;
  padding-top: 6px;
  border-top: 1px dashed var(--line);
}
.session.in-session .revealed h2 {
  margin: 2px 0;
  font-size: clamp(var(--fs-lg), 2.4vw, var(--fs-2xl));
}
.session.in-session .revealed .keywords {
  display: flex; flex-wrap: wrap; gap: 6px;
  justify-content: center;
  margin: 4px 0;
}
.session.in-session .revealed .def {
  font-size: var(--fs-sm);
  max-width: 60ch;
  margin: 4px auto 0;
}

.session.in-session .session-footer {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.session.in-session .show-row,
.session.in-session .rating-row {
  display: grid; gap: 8px;
}
.session.in-session .show-row { grid-template-columns: 1fr; }
.session.in-session .show-btn {
  min-height: 52px;
  font-size: var(--fs-md);
}

/* Two big thumb-zone rating buttons: D = needs practice, F = known.
   Tuned for speed — one glance, one tap. */
.session.in-session .rating-row {
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.session.in-session .rating-btn {
  position: relative;
  min-height: 84px;
  background: var(--bg-3);
  border: 1.5px solid var(--line-strong);
  color: var(--fg);
  border-radius: var(--rad);
  padding: 14px 10px 12px;
  cursor: pointer;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  transition: transform .08s ease, background .12s ease, filter .12s ease;
}
.session.in-session .rating-btn:active { transform: scale(0.97); }
.session.in-session .rating-btn .kbd {
  position: absolute;
  top: 6px; right: 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--fg-3);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 6px;
  line-height: 1.4;
  min-width: 18px;
  text-align: center;
  letter-spacing: 0;
}
.session.in-session .rating-btn .lbl {
  font-size: var(--fs-lg);
  font-weight: 800;
  letter-spacing: -0.01em;
}
.session.in-session .rating-btn .sub {
  font-size: var(--fs-xs);
  color: var(--fg-3);
  font-weight: 500;
}
.session.in-session .rating-btn:hover { filter: brightness(1.12); }
.session.in-session .rating-btn.again {
  border-color: color-mix(in oklab, var(--danger) 65%, var(--line));
  background: color-mix(in oklab, var(--danger) 18%, var(--bg-3));
}
.session.in-session .rating-btn.good {
  border-color: color-mix(in oklab, var(--success) 65%, var(--line));
  background: color-mix(in oklab, var(--success) 18%, var(--bg-3));
}

/* Secondary action row — prev / next / library / ask AI.
   Thumb-zone docked, large enough tap targets per HIG/Material. */
.session-actions {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
.session-action {
  position: relative;
  min-height: 44px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--fg-2);
  border-radius: 999px;
  padding: 6px 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: var(--fs-sm);
  font-weight: 600;
  transition: transform .08s ease, background .12s ease, color .12s ease;
}
.session-action:hover {
  background: var(--bg-3);
  color: var(--fg);
  border-color: var(--line-strong);
}
.session-action:active { transform: scale(0.97); }
.session-action .icon {
  font-size: 1.1em;
  line-height: 1;
}
.session-action .kbd {
  font-size: 10px;
  font-weight: 700;
  color: var(--fg-3);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  line-height: 1.4;
  min-width: 16px;
  text-align: center;
  letter-spacing: 0;
}

/* Variants button lights up blue when the current card actually has
   other forms to switch to. Applied per-card in renderOne(). Uses
   solid blue so it's impossible to miss at a glance — the subtle
   tinted version was too easy to overlook during real practice. */
.session-action.has-variants {
  background: #2563eb;
  border-color: #60a5fa;
  color: #fff;
  box-shadow:
    0 0 0 1px #60a5fa inset,
    0 0 14px -2px rgba(59, 130, 246, .55);
}
.session-action.has-variants:hover {
  background: #1d4ed8;
  border-color: #93c5fd;
}
.session-action.has-variants .icon { color: #fff; }
.session-action.has-variants .lbl { color: #fff; font-weight: 700; }
.session-action.has-variants .kbd {
  background: #0b1530;
  border-color: rgba(255, 255, 255, .45);
  color: #fff;
}

/* Small screens — two big rating buttons stay full-width,
   secondary-action labels collapse to icons. */
@media (max-width: 560px) {
  .session.in-session .rating-btn {
    min-height: 76px;
    padding: 12px 8px 10px;
  }
  .session.in-session .rating-btn .lbl { font-size: var(--fs-md); }
  .session.in-session .rating-btn .sub { font-size: 10px; }
  .session-action {
    padding: 8px 4px;
    font-size: var(--fs-xs);
  }
  .session-action .lbl { font-size: 11px; }
  .session-action .kbd { display: none; }
}

/* Short-height screens (laptops with devtools / split view) */
@media (max-height: 720px) {
  .session.in-session { gap: 8px; }
  .session.in-session .video-card { min-height: 110px; }
  .session.in-session .rating-btn { min-height: 68px; }
  .session.in-session .show-btn { min-height: 46px; }
}

/* Touch devices — suppress keyboard-hint badges entirely */
@media (hover: none) {
  .session.in-session .rating-btn .kbd,
  .session-action .kbd {
    display: none;
  }
  .session-action { min-height: 48px; }
  .session-exit-btn { width: 44px; height: 44px; font-size: 24px; }
}

/* Session variant picker — overlay opened with V or the Variants action */
.variant-picker {
  position: absolute;
  left: 12px; right: 12px; bottom: calc(var(--session-footer-h, 120px) + 8px);
  max-height: 60vh;
  background: color-mix(in oklab, var(--bg-1) 94%, transparent);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.55);
  backdrop-filter: blur(12px);
  padding: 14px 16px 18px;
  z-index: 40;
  overflow: auto;
  animation: variant-picker-in .18s ease-out;
}
.variant-picker.hidden { display: none; }
@keyframes variant-picker-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.variant-picker-head {
  display: flex; align-items: flex-start; gap: 12px; margin-bottom: 12px;
}
.variant-picker-head h3 { margin: 0 0 4px; font-size: var(--fs-md); }
.variant-picker-head p  { margin: 0; font-size: var(--fs-sm); }
.variant-picker-head p.muted { color: var(--fg-3); }
.variant-picker-close {
  margin-left: auto;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--bg-2); border: 1px solid var(--line);
  color: var(--fg-2); font-size: 22px; line-height: 1;
  cursor: pointer;
}
.variant-picker-close:hover { background: var(--bg-3); color: var(--fg); }
.variant-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.variant-picker-card {
  display: flex; flex-direction: column;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 10px; overflow: hidden; cursor: pointer;
  padding: 0; color: inherit; text-align: left;
  transition: border-color .15s, transform .15s;
}
.variant-picker-card:hover { transform: translateY(-1px); border-color: var(--fg-3); }
.variant-picker-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
/* Keyboard-highlight: the card the user will select if they press
   Enter right now. Uses the same blue as the Variants button so
   learners can see exactly what V is doing. */
.variant-picker-card.focused {
  border-color: #60a5fa;
  box-shadow:
    0 0 0 2px #60a5fa inset,
    0 0 18px -2px rgba(59, 130, 246, .55);
  transform: translateY(-1px);
}
.variant-picker-card.focused.active {
  /* When focus lands on the currently-active variant, layer both
     rings so it's obvious this is the current selection. */
  box-shadow:
    0 0 0 2px #60a5fa inset,
    0 0 0 4px var(--accent) inset,
    0 0 18px -2px rgba(59, 130, 246, .55);
}
.variant-picker-thumb {
  aspect-ratio: 16 / 10;
  background: #000;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.variant-picker-thumb video {
  width: 100%; height: 100%; object-fit: cover;
}
.variant-picker-meta {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 8px 10px;
}
.variant-picker-lbl {
  font-size: var(--fs-sm); color: var(--fg-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Add-to-library picker panel (opened from the L-key or Library action) */
.add-lib-panel {
  display: grid;
  gap: 14px;
  max-width: 480px;
}
.add-lib-panel h2 {
  margin: 0;
  font-size: var(--fs-lg);
}
.add-lib-panel .lib-pick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.add-lib-panel .divider {
  border-top: 1px dashed var(--line);
}
.add-lib-panel .add-lib-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.add-lib-panel .add-lib-form input {
  flex: 1 1 200px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--fg);
  border-radius: var(--rad-sm);
  padding: 10px 12px;
  font-size: var(--fs-md);
}

/* ============================ MODAL =============================== */
.modal-root { position: fixed; inset: 0; pointer-events: none; z-index: 100; }
.modal-root[aria-hidden="false"] { pointer-events: auto; }
.modal-bg {
  position: absolute; inset: 0; background: rgba(0,0,0,.55);
  opacity: 0; transition: opacity .2s ease;
}
.modal-root[aria-hidden="false"] .modal-bg { opacity: 1; }
.modal-panel {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -48%);
  background: var(--bg-2); border: 1px solid var(--line-strong);
  border-radius: var(--rad-lg);
  max-width: min(820px, calc(100vw - 24px));
  max-height: calc(100dvh - 40px); overflow: auto;
  box-shadow: var(--shadow);
  padding: clamp(14px, 3vw, 24px);
  opacity: 0; transition: transform .2s ease, opacity .2s ease;
  width: 100%;
}
.modal-root[aria-hidden="false"] .modal-panel { transform: translate(-50%, -50%); opacity: 1; }
/* The panel takes programmatic focus as a fallback when it has no
   focusable children — suppress the default ring, but keep focus
   rings on the actual interactive elements inside it. */
.modal-panel:focus { outline: none; }
.modal-panel:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.modal-close {
  position: absolute; right: 10px; top: 10px;
  background: transparent; border: 0; color: var(--fg-2);
  width: 34px; height: 34px; border-radius: 999px; cursor: pointer;
}
.modal-close:hover { background: var(--bg-3); color: var(--fg); }

/* ============================ AI SHEET ============================ */
.ai-sheet {
  display: grid; gap: 14px; max-width: 720px;
}
.ai-sheet h2 { margin: 0; font-size: var(--fs-xl); }
.ai-sheet .conv {
  display: flex; flex-direction: column; gap: 10px;
  max-height: 60vh; overflow: auto; padding-right: 4px;
}
.ai-sheet .msg {
  padding: 10px 14px; border-radius: var(--rad); max-width: 92%;
}
.ai-sheet .msg.user { background: var(--bg-3); align-self: flex-end; }
.ai-sheet .msg.asst { background: color-mix(in oklab, var(--accent) 12%, var(--bg-3)); align-self: flex-start; }
.ai-sheet form {
  display: flex; gap: 8px;
}
.ai-sheet textarea {
  flex: 1; background: var(--bg-2); color: var(--fg);
  border: 1px solid var(--line); border-radius: var(--rad);
  padding: 10px 12px; resize: vertical; min-height: 44px; max-height: 180px;
  font-family: inherit;
}
.ai-suggest {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.ai-suggest button {
  background: var(--bg-3); border: 1px solid var(--line);
  color: var(--fg-2); border-radius: 999px; padding: 6px 12px;
  font-size: var(--fs-sm); cursor: pointer;
}
.ai-suggest button:hover { color: var(--fg); background: var(--line); }

/* ============================ SETTINGS ============================ */
.settings { display: grid; gap: 14px; max-width: 680px; margin: 0 auto; }
.settings h1 { margin: 0 0 4px; }
.settings section { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--rad); padding: 16px; }
.settings h2 { margin: 0 0 8px; font-size: var(--fs-lg); }
.settings p { color: var(--fg-3); font-size: var(--fs-sm); margin: 0 0 8px; }
.settings .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.settings input[type="text"], .settings input[type="password"], .settings input[type="email"] {
  background: var(--bg-3); border: 1px solid var(--line); color: var(--fg);
  border-radius: var(--rad-sm); padding: 10px 12px;
  min-width: 240px; flex: 1 1 240px;
}
.settings select {
  background: var(--bg-3); border: 1px solid var(--line); color: var(--fg);
  border-radius: var(--rad-sm); padding: 10px 12px;
  min-width: 240px; font: inherit;
}
.settings .stack-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.settings .stack-field > span { font-size: var(--fs-sm); color: var(--fg-2); font-weight: 600; }
.settings .check-row { gap: 10px; margin: 8px 0; }
.settings .check-row input[type="checkbox"] { width: 18px; height: 18px; }
.settings .small { font-size: var(--fs-xs); }

/* ============================ ONBOARDING ========================== */
.onboard { max-width: 640px; margin: 0 auto; }
.onboard h1 { margin: 0 0 6px; font-size: var(--fs-2xl); }
.onboard .lede { color: var(--fg-2); margin: 0 0 18px; }
.onboard-grid {
  display: grid; gap: 10px;
  grid-template-columns: 1fr;
}
@media (min-width: 620px) { .onboard-grid { grid-template-columns: 1fr 1fr; } }
.onboard-card {
  text-align: left; background: var(--bg-2); border: 1px solid var(--line);
  border-radius: var(--rad); padding: 14px 16px; cursor: pointer;
  color: inherit; font: inherit;
  transition: transform .15s, border-color .15s, background .15s;
}
.onboard-card:hover {
  background: var(--bg-3); border-color: var(--accent); transform: translateY(-1px);
}
.onboard-card h3 { margin: 0 0 4px; font-size: var(--fs-md); }
.onboard-card p { margin: 0; color: var(--fg-3); font-size: var(--fs-sm); }
.onboard-footnote {
  margin: 16px 0 0; font-size: var(--fs-xs); color: var(--fg-3);
  border-top: 1px dashed var(--line); padding-top: 12px;
}

/* ============================ SESSION NOTE ======================== */
.session-note {
  background: color-mix(in oklab, var(--accent) 10%, var(--bg-2));
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 8px 12px; margin: 10px 0 0;
  font-size: var(--fs-sm); color: var(--fg-2);
}

/* ============================ TOAST =============================== */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 40px);
  background: var(--bg-2); border: 1px solid var(--line-strong);
  padding: 10px 16px; border-radius: 999px; box-shadow: var(--shadow);
  opacity: 0; transition: opacity .2s, transform .2s;
  z-index: 200; pointer-events: none; font-weight: 600;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ============================ BOOT ================================ */
.boot {
  position: fixed; inset: 0; background: var(--bg);
  display: grid; place-items: center; z-index: 300;
  transition: opacity .3s ease;
}
.boot.hide { opacity: 0; pointer-events: none; }
.boot-inner { text-align: center; max-width: 440px; padding: 20px; }
.boot-spinner {
  width: 42px; height: 42px; margin: 0 auto 16px;
  border: 3px solid var(--line); border-top-color: var(--accent);
  border-radius: 999px; animation: spin 1s linear infinite;
}
.boot-text { margin: 0 0 10px; color: var(--fg-2); }
.boot-sub { margin: 12px 0 0; color: var(--fg-3); font-size: var(--fs-sm); }
progress {
  width: 100%; height: 6px; border: 0;
  background: var(--bg-3); border-radius: 999px; overflow: hidden;
}
progress::-webkit-progress-bar { background: var(--bg-3); border-radius: 999px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Inline waiting state shown on data-dependent views when the
   dictionary is still loading. */
.pending-data {
  max-width: 440px; margin: 80px auto; text-align: center;
  color: var(--fg-2); padding: 24px;
}
.pending-data h2 { margin: 0 0 6px; }
.pending-data p { margin: 0 0 14px; }
.pending-data progress {
  width: 100%; height: 4px; border: 0;
  background: var(--bg-3); border-radius: 999px; overflow: hidden;
}

/* Slim, non-blocking top progress bar for the background dictionary
   download. It sits under the appbar so the user can interact with
   the shell while it ticks. */
.load-bar {
  position: fixed; top: 0; left: 0; right: 0; height: 3px;
  background: transparent; z-index: 200; pointer-events: none;
  transition: opacity .4s ease;
}
.load-bar-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .2s ease;
}
.load-bar.done { opacity: 0; }
.load-bar.hidden { display: none; }

/* ============================ FOOTER ============================== */
.ack {
  max-width: var(--maxw);
  margin: 0 auto; padding: 0 clamp(14px, 3vw, 28px) 24px;
  color: var(--fg-3); font-size: var(--fs-sm);
}
.ack details { border-top: 1px dashed var(--line); padding-top: 16px; }
.ack summary { cursor: pointer; color: var(--fg-2); font-weight: 600; padding: 4px 0; }
.ack p { margin: 10px 0; max-width: 80ch; }
.ack a { color: var(--fg-2); text-decoration: underline; }
.ack a:hover { color: var(--fg); }
.ack-small { font-size: var(--fs-xs); color: var(--fg-3); }

/* ============================ CHEATSHEET ========================== */
.cheatsheet h2 { margin: 0 0 4px; }
.cs-cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 22px;
  margin: 16px 0 10px;
}
.cs-cols h3 { font-size: var(--fs-md); margin: 0 0 8px; color: var(--fg-2); }
.cs-row {
  display: flex;
  gap: 12px;
  align-items: baseline;
  padding: 4px 0;
  border-bottom: 1px dashed var(--line);
}
.cs-row:last-child { border-bottom: 0; }
.cs-key {
  font-family: ui-monospace, monospace;
  font-size: var(--fs-xs);
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--bg-3);
  min-width: 46px;
  text-align: center;
  white-space: nowrap;
}

/* ============================ WALKTHROUGH ========================= */
.walkthrough { text-align: center; padding: 6px 10px 10px; }
.walkthrough-dots {
  display: flex; justify-content: center; gap: 6px; margin-bottom: 18px;
}
.walkthrough-dots .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--line-strong); transition: background .15s;
}
.walkthrough-dots .dot.on { background: var(--accent); }
.walkthrough-emoji { font-size: 54px; line-height: 1; margin-bottom: 6px; }
.walkthrough h1 { margin: 2px 0 4px; font-size: var(--fs-2xl); }
.walkthrough .lede { margin: 0 auto; max-width: 40ch; color: var(--fg-2); }

/* ============================ WHY / ICONICITY ===================== */
.why-block {
  margin: 10px 0 6px;
  border-top: 1px dashed var(--line);
  padding-top: 10px;
}
.why-toggle { padding: 4px 0; color: var(--fg-2); }
.why-body { padding: 6px 0 2px; }
.why-body.hidden { display: none; }
.why-row {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 10px;
  padding: 3px 0;
  font-size: var(--fs-sm);
  color: var(--fg-2);
}
.why-kind {
  text-transform: uppercase;
  font-size: 10px;
  font-weight: 700;
  color: var(--fg-3);
  letter-spacing: .06em;
  padding-top: 2px;
}

/* ============================ SESSION VIDEO CONTROLS ============== */
.session-video-controls {
  display: flex; gap: 6px; flex-wrap: wrap;
  padding: 6px 4px 0;
  justify-content: center;
}
.vctl {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: var(--fs-xs);
  color: var(--fg-2);
  cursor: pointer;
}
.vctl.on {
  background: color-mix(in oklab, var(--accent) 18%, var(--bg-3));
  border-color: color-mix(in oklab, var(--accent) 40%, var(--line));
  color: var(--fg);
}

/* ============================ PRODUCTIVE HINT ===================== */
.prod-hint {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 36px 20px;
  color: var(--fg-2);
  text-align: center;
}
.prod-icon { font-size: 52px; line-height: 1; }

/* ============================ BUTTON SIZES ======================== */
.btn-small {
  font-size: var(--fs-xs);
  padding: 5px 10px;
}

/* ============================ LOOKUP RESULT ADD =================== */
.result-add {
  margin-left: auto;
  align-self: center;
  font-size: var(--fs-xs);
  padding: 6px 12px;
}
.result-add.added { color: var(--success); }
.chip-count { color: var(--fg-3); font-size: var(--fs-xs); margin-left: 4px; }
.context-head { border-bottom: 1px solid var(--line); padding-bottom: 10px; }

/* ============================ INTERLEAVE PICKER =================== */
.interleave-grid .tile.active {
  border-color: var(--accent);
  background: color-mix(in oklab, var(--accent) 12%, var(--bg-2));
}
.interleave-grid .tile { cursor: pointer; }

/* ============================ SIGN OF THE DAY ===================== */
.sign-of-day .sod-card {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 16px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--rad);
  overflow: hidden;
  cursor: pointer;
  transition: border-color .15s ease;
}
.sign-of-day .sod-card:hover { border-color: var(--line-strong); }
.sod-thumb {
  aspect-ratio: 4 / 3;
  background: var(--bg-3);
}
.sod-thumb video { width: 100%; height: 100%; object-fit: cover; }
.sod-body { padding: 14px 18px; }
.sod-body h3 { margin: 0 0 4px; font-size: var(--fs-xl); }
@media (max-width: 720px) {
  .sign-of-day .sod-card { grid-template-columns: 1fr; }
  .sod-thumb { aspect-ratio: 16 / 9; }
}

/* ============================ RECENTS RAIL ======================== */
.recents-row {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 4px 2px 10px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}
.recent-card {
  flex: 0 0 140px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--rad);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  scroll-snap-align: start;
}
.recent-card .thumb {
  aspect-ratio: 1 / 1;
  background: var(--bg-3);
  display: flex; align-items: center; justify-content: center;
}
.recent-card .thumb video { width: 100%; height: 100%; object-fit: cover; }
.recent-lbl {
  padding: 6px 10px;
  font-size: var(--fs-sm);
  color: var(--fg-2);
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

/* ============================ GOAL RING =========================== */
.goal-ring-wrap { flex-shrink: 0; }
.goal-ring { display: block; }

/* ============================ STATS =============================== */
.stat-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin: 0 0 24px;
}
.stat-tile {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--rad);
  padding: 14px 16px;
}
.stat-big { font-size: var(--fs-2xl); font-weight: 800; letter-spacing: -0.02em; }
.stat-label { color: var(--fg-2); font-size: var(--fs-sm); margin-top: 2px; }
.stat-hint { color: var(--fg-3); font-size: var(--fs-xs); margin-top: 4px; }

.heatmap {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14px, 1fr));
  gap: 3px;
  padding: 6px 0 10px;
}
.heat-cell { aspect-ratio: 1 / 1; border-radius: 3px; background: var(--bg-3); }
.heat-0 { background: var(--bg-3); }
.heat-1 { background: color-mix(in oklab, var(--accent) 22%, var(--bg-3)); }
.heat-2 { background: color-mix(in oklab, var(--accent) 40%, var(--bg-3)); }
.heat-3 { background: color-mix(in oklab, var(--accent) 65%, var(--bg-3)); }
.heat-4 { background: var(--accent); }

.state-bar {
  display: flex;
  width: 100%;
  height: 18px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-3);
  border: 1px solid var(--line);
  margin: 8px 0 10px;
}
.state-seg { height: 100%; transition: width .25s ease; }
.seg-new        { background: var(--fg-3); }
.seg-learning   { background: var(--warn); }
.seg-review     { background: var(--success); }
.seg-relearning { background: var(--danger); }
.state-legend { display: flex; gap: 14px; flex-wrap: wrap; color: var(--fg-2); font-size: var(--fs-sm); }
.state-legend-item { display: flex; gap: 6px; align-items: center; }
.state-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.leech-list { display: flex; flex-direction: column; gap: 6px; }
.leech-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--rad-sm);
  cursor: pointer;
  text-align: left;
}
.leech-row:hover { border-color: var(--line-strong); }
.leech-main { display: flex; gap: 4px; align-items: baseline; }
.small { font-size: var(--fs-xs); }

/* ============================ ACHIEVEMENTS ========================= */
.achievements-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}
.achievement {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--rad-sm);
  opacity: 0.4;
  filter: grayscale(1);
  transition: opacity .2s, filter .2s;
}
.achievement.earned {
  opacity: 1;
  filter: none;
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--accent) 15%, transparent);
}
.ach-icon { font-size: 1.6rem; flex-shrink: 0; }
.ach-body { min-width: 0; }
.ach-name { font-weight: 700; font-size: var(--fs-sm); }
.ach-desc { font-size: var(--fs-xs); }
.ach-date { font-size: 10px; margin-top: 2px; }

/* ============================ AI TOOL TRACE ======================== */
/* Inline chip shown in the AI conversation each time Claude invokes a
   dictionary tool, so the user can see exactly what the assistant is
   doing under the hood. */
.tool-trace {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  margin: 4px 0;
  font-size: var(--fs-xs);
  color: var(--fg-2);
  background: color-mix(in oklab, var(--accent) 10%, var(--bg-2));
  border: 1px solid color-mix(in oklab, var(--accent) 25%, var(--line));
  border-radius: 999px;
  width: fit-content;
}
.tool-trace .tool-label {
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
  font-size: 10px;
  color: var(--accent);
}
.tool-trace code {
  background: transparent;
  padding: 0;
  font-family: var(--mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  color: var(--fg-1);
}
.tool-trace .muted { color: var(--fg-3); }

/* ============================ FINGERSPELL GAME =================== */

/* Picker */
.fs-picker { max-width: 720px; margin: 0 auto; padding: 0 clamp(14px, 3vw, 28px); }
.fs-picker-head { margin-bottom: 20px; }
.fs-picker-head h1 { margin: 12px 0 6px; }
.fs-picker-head .lede { color: var(--fg-2); max-width: 54ch; }

.fs-speed-control {
  margin: 24px 0 10px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--rad);
  padding: 16px 20px;
}
.fs-speed-title {
  font-weight: 700;
  font-size: var(--fs-sm);
  color: var(--fg-2);
  margin-bottom: 8px;
  display: block;
}
.fs-speed-slider {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}
.fs-speed-info {
  display: flex;
  gap: 4px;
  align-items: baseline;
  margin-top: 6px;
  font-size: var(--fs-sm);
}
.fs-speed-label { font-weight: 700; color: var(--fg); }
.fs-speed-desc  { color: var(--fg-3); }

/* Loading */
.fs-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 60px 20px;
  min-height: 50vh;
}
.fs-load-icon { font-size: 48px; margin-bottom: 12px; }
.fs-loading h2 { margin: 0 0 16px; }
.fs-load-bar {
  width: min(320px, 80%);
  height: 6px;
  background: var(--bg-3);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 12px;
}
.fs-load-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 999px;
  transition: width .15s ease;
}

/* Session layout */
.fs-session.in-session {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--session-offset, 60px));
  padding: 0 clamp(10px, 3vw, 24px);
  overflow: hidden;
}
.fs-body {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 0;
  padding: 10px 0;
}

/* Image display area */
.fs-image-area {
  width: min(320px, 80vw);
  aspect-ratio: 4 / 3;
  background: #4a6b96;
  border-radius: var(--rad);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex-shrink: 1;
  min-height: 0;
  box-shadow: 0 2px 12px rgba(0,0,0,.25);
}
.fs-display-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}
/* Missing-letter fallback */
.fs-image-area.fs-show-letter::after {
  content: attr(data-letter);
  font-size: 80px;
  font-weight: 800;
  color: #fff;
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg-3);
}

/* In-session speed pill */
.fs-speed-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-3);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--fg);
  cursor: pointer;
  transition: background .15s, border-color .15s;
  user-select: none;
  white-space: nowrap;
}
.fs-speed-pill:hover, .fs-speed-pill:focus-visible {
  background: var(--bg-2);
  border-color: var(--accent);
  outline: none;
}
.fs-speed-pill:active { transform: scale(0.96); }
.fs-speed-pill-icon { font-size: 1em; }
.fs-speed-pill-arrows {
  font-size: 0.6em;
  letter-spacing: 1px;
  opacity: 0.5;
  color: var(--fg-3);
}

/* Attribution line */
.fs-attribution {
  text-align: center;
  font-size: var(--fs-xs);
  padding: 6px 0;
  opacity: 0.7;
}
.fs-attribution a { color: var(--accent); text-decoration: none; }
.fs-attribution a:hover { text-decoration: underline; }

/* Letter dots */
.fs-dots {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.fs-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--line-strong);
  transition: background .15s, transform .15s;
}
.fs-dot.active {
  background: var(--accent);
  transform: scale(1.3);
}
.fs-dot.done {
  background: var(--success);
}

/* Messages */
.fs-message {
  font-size: var(--fs-lg);
  font-weight: 700;
  text-align: center;
  min-height: 1.8em;
}
.fs-message.fs-ready { color: var(--fg-2); }
.fs-message.fs-correct { color: var(--success); }
.fs-message.fs-wrong { color: var(--danger); }
.fs-check, .fs-cross { font-size: 1.2em; }

/* Input row */
.fs-input-row {
  display: flex;
  gap: 8px;
  width: min(400px, 90vw);
}
.fs-input {
  flex: 1;
  background: var(--bg-2);
  border: 2px solid var(--line-strong);
  color: var(--fg);
  border-radius: var(--rad);
  padding: 12px 16px;
  font-size: var(--fs-lg);
  font-weight: 600;
  text-align: center;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  caret-color: var(--accent);
  transition: border-color .15s;
}
.fs-input:focus {
  outline: none;
  border-color: var(--accent);
}
.fs-input.correct { border-color: var(--success); background: color-mix(in oklab, var(--success) 10%, var(--bg-2)); }
.fs-input.wrong   { border-color: var(--danger);  background: color-mix(in oklab, var(--danger) 10%, var(--bg-2)); }

/* Replay / next rows */
.fs-replay-row {
  display: flex;
  gap: 8px;
  justify-content: center;
}
.fs-next-row {
  display: flex;
  justify-content: center;
}
.fs-next-btn { min-width: 180px; }

/* Feedback breakdown */
.fs-feedback { width: 100%; max-width: 500px; }
.fs-breakdown {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 10px;
}
.fs-break-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}
.fs-break-img {
  width: 56px;
  height: 42px;
  object-fit: cover;
  border-radius: 6px;
  background: #4a6b96;
  border: 1px solid var(--line);
}
.fs-break-lbl {
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--fg-2);
}
.fs-break-weak { position: relative; }
.fs-break-weak .fs-break-img {
  border-color: var(--danger);
  box-shadow: 0 0 0 1px var(--danger);
}
.fs-break-weak .fs-break-lbl { color: var(--danger); }
.fs-break-weak-tag {
  font-size: 9px;
  color: var(--danger);
  opacity: 0.8;
  white-space: nowrap;
}

/* Streak badge — progressive difficulty indicator */
.fs-streak-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 10px;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--accent), var(--warn));
  color: #fff;
  font-size: var(--fs-xs);
  font-weight: 600;
  animation: fs-streak-pop .35s ease-out;
}
.fs-streak-count {
  margin-left: 6px;
  font-size: var(--fs-xs);
}
@keyframes fs-streak-pop {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}
/* Level-up suggestion */
.fs-level-up {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: var(--fs-sm);
  color: var(--fg-2);
}
.btn-accent {
  background: var(--accent);
  color: #fff;
  border: none;
  font-weight: 600;
}
.btn-accent:hover { background: var(--accent-2); color: #000; }

/* Missed words summary */
.fs-missed {
  margin-top: 16px;
  text-align: center;
}
.fs-missed h3 { margin: 0 0 8px; font-size: var(--fs-md); color: var(--fg-2); }
.fs-missed-list { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.fs-missed-item { display: flex; align-items: baseline; gap: 4px; }

/* Fingerspell mode picker (modal from Learn chooser) */
.fs-mode-pick { max-width: 540px; }
.fs-mode-pick h2 { margin: 0 0 4px; }

/* ---- Responsive tweaks ---- */
@media (max-height: 640px) {
  .fs-image-area { width: min(260px, 70vw); }
  .fs-body { gap: 8px; padding: 4px 0; }
  .fs-message { font-size: var(--fs-md); }
}
@media (max-width: 400px) {
  .fs-input { font-size: var(--fs-md); padding: 10px 12px; }
  .fs-break-img { width: 42px; height: 32px; }
}

/* ============================ UTIL ================================ */
.hidden { display: none !important; }
.muted { color: var(--fg-3); }
.row-gap { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.center { text-align: center; }

/* ---- About / credits ---- */
.credits-table { width: 100%; border-collapse: collapse; margin: 12px 0 18px; font-size: var(--fs-sm); }
.credits-table th,
.credits-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.credits-table th { color: var(--fg-2); font-weight: 600; }
.credits-table td:first-child { white-space: nowrap; font-weight: 500; }
.credits-table a { color: var(--accent); }

/* ============================ PHRASE BUILDER ====================== */
.phrase-grammar-note {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--rad);
  padding: 16px 20px;
  margin-top: 16px;
}
.phrase-grammar-note h3 { margin: 0 0 8px; font-size: var(--fs-md); }
.phrase-grammar-note ul { margin: 0; padding-left: 18px; }
.phrase-grammar-note li { margin-bottom: 4px; font-size: var(--fs-sm); color: var(--fg-2); }

.phrase-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  max-width: 640px;
  margin: 0 auto;
}
.phrase-english {
  font-size: var(--fs-xl);
  font-weight: 700;
  text-align: center;
  padding: 16px;
  background: var(--bg-2);
  border-radius: var(--rad);
  border: 1px solid var(--line);
}
.phrase-instruct {
  text-align: center;
  font-size: var(--fs-sm);
  margin: 4px 0 0;
}
.phrase-build-area {
  min-height: 60px;
  padding: 12px;
  background: var(--bg-3);
  border: 2px dashed var(--line-strong);
  border-radius: var(--rad);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
  transition: border-color .15s;
}
.phrase-build-area:has(.phrase-chip) {
  border-style: solid;
  border-color: var(--accent);
}
.phrase-drop-hint {
  font-size: var(--fs-sm);
  padding: 8px;
}
.phrase-bank {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.phrase-chip {
  display: inline-flex;
  align-items: center;
  padding: 8px 16px;
  background: var(--bg-2);
  border: 2px solid var(--line-strong);
  border-radius: 999px;
  font-weight: 700;
  font-size: var(--fs-sm);
  cursor: pointer;
  transition: transform .1s, border-color .15s, background .15s;
  user-select: none;
}
.phrase-chip:hover { border-color: var(--accent); transform: scale(1.04); }
.phrase-chip:active { transform: scale(0.96); }
.phrase-chip.placed { background: color-mix(in oklab, var(--accent) 12%, var(--bg-2)); border-color: var(--accent); }
.phrase-chip.correct { border-color: var(--success); background: color-mix(in oklab, var(--success) 15%, var(--bg-2)); }
.phrase-chip.wrong { border-color: var(--danger); background: color-mix(in oklab, var(--danger) 15%, var(--bg-2)); }

.phrase-btn-row {
  display: flex;
  gap: 8px;
  justify-content: center;
}
.phrase-feedback { text-align: center; }
.phrase-result {
  font-size: var(--fs-lg);
  font-weight: 700;
  margin-bottom: 8px;
}
.phrase-result.correct { color: var(--success); }
.phrase-result.wrong { color: var(--danger); }
.phrase-correct-order {
  font-size: var(--fs-sm);
  margin-bottom: 12px;
}
.phrase-tip {
  background: color-mix(in oklab, var(--info) 8%, var(--bg-2));
  border: 1px solid color-mix(in oklab, var(--info) 25%, var(--line));
  border-radius: var(--rad-sm);
  padding: 12px 16px;
  font-size: var(--fs-sm);
  text-align: left;
  margin-top: 8px;
  line-height: 1.5;
}
.phrase-nmm-label {
  background: color-mix(in oklab, var(--warn) 10%, var(--bg-2));
  border: 1px solid color-mix(in oklab, var(--warn) 25%, var(--line));
  border-radius: var(--rad-sm);
  padding: 10px 14px;
  font-size: var(--fs-sm);
  line-height: 1.5;
}
.phrase-nmm-icon { font-size: 1.1em; }
.phrase-review { margin-top: 16px; text-align: left; }
.phrase-review h3 { margin: 0 0 10px; }
.phrase-review-item {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--rad-sm);
  padding: 12px 16px;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.phrase-review-item .phrase-tip { margin-top: 6px; }

/* ============================ MINIMAL PAIRS ======================= */
.mp-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  max-width: 720px;
  margin: 0 auto;
  align-items: center;
}
.mp-question {
  font-size: var(--fs-sm);
  color: var(--fg-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: center;
}
.mp-target-word {
  font-size: var(--fs-2xl);
  font-weight: 800;
  text-align: center;
}
.mp-hint {
  text-align: center;
  font-size: var(--fs-xs);
}
.mp-video-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  width: 100%;
}
.mp-choice {
  position: relative;
  background: var(--bg-2);
  border: 3px solid var(--line-strong);
  border-radius: var(--rad);
  cursor: pointer;
  overflow: hidden;
  transition: border-color .15s, transform .1s;
  padding: 0;
}
.mp-choice:hover { border-color: var(--accent); transform: scale(1.02); }
.mp-choice:active { transform: scale(0.98); }
.mp-choice video {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  display: block;
}
.mp-choice-label {
  position: absolute;
  top: 8px;
  left: 8px;
  background: var(--bg);
  color: var(--fg);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--fs-sm);
  opacity: 0.85;
}
.mp-choice.correct { border-color: var(--success); box-shadow: 0 0 0 2px color-mix(in oklab, var(--success) 30%, transparent); }
.mp-choice.wrong { border-color: var(--danger); opacity: 0.6; }
.mp-feedback { text-align: center; }
.mp-next-row { display: flex; justify-content: center; }
@media (max-width: 500px) {
  .mp-video-row { gap: 10px; }
  .mp-target-word { font-size: var(--fs-xl); }
}

/* =========================================================
   Account / Auth UI
   ========================================================= */
.account-section h2 { margin-bottom: 8px; }

.account-card {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--rad);
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.account-info {
  display: flex;
  align-items: center;
  gap: 14px;
}
.account-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.account-avatar-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  font-size: var(--fs-lg);
  font-weight: 700;
}
.account-details strong { display: block; font-size: var(--fs-lg); }
.account-details p { margin: 2px 0 0; }
.account-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.account-unconfigured {
  background: var(--bg-3);
  border: 1px dashed var(--line-strong);
  border-radius: var(--rad);
  padding: 20px;
}
.account-unconfigured code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: var(--fs-sm);
}

/* Auth provider buttons */
.auth-providers {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin: 16px 0;
}
.auth-provider-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: var(--rad-sm);
  font-weight: 600;
  font-size: var(--fs-sm);
  background: var(--bg-3);
  border: 1px solid var(--line);
  transition: background .15s, border-color .15s;
}
.auth-provider-btn:hover {
  background: var(--bg-2);
  border-color: var(--line-strong);
}
.auth-provider-icon { display: flex; align-items: center; }
.auth-provider-icon svg { display: block; }

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--fg-3);
  font-size: var(--fs-sm);
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.auth-email-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 360px;
}
.settings .auth-email-form input[type="email"],
.settings .auth-email-form input[type="password"] {
  padding: 10px 14px;
  border-radius: var(--rad-sm);
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--fg);
  font-size: var(--fs-md);
  flex: 0 0 auto;
  min-width: 0;
  height: auto;
  width: 100%;
}
.auth-email-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in oklab, var(--accent) 25%, transparent);
}
.auth-error {
  color: var(--danger);
  font-size: var(--fs-sm);
  margin: 0;
  padding: 8px 12px;
  background: color-mix(in oklab, var(--danger) 10%, transparent);
  border-radius: var(--rad-sm);
}
.auth-footer {
  display: flex;
  gap: 16px;
  margin-top: 8px;
}
.auth-toggle {
  font-size: var(--fs-sm);
  color: var(--accent);
  cursor: pointer;
}
.auth-toggle:hover { text-decoration: underline; }
.auth-privacy { margin-top: 16px; }

@media (max-width: 500px) {
  .account-card { flex-direction: column; align-items: flex-start; }
  .auth-providers { grid-template-columns: 1fr 1fr; }
}

/* =========================================================
   MOBILE BOTTOM TAB BAR
   Fixed at the bottom on screens < 640px. Hidden on desktop
   and during active practice sessions.
   ========================================================= */
.bottomnav {
  display: none;  /* hidden on desktop */
}

@media (max-width: 640px) {
  .bottomnav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    width: 100%;
    z-index: 50;
    height: calc(56px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: color-mix(in oklab, var(--bg) 92%, transparent);
    backdrop-filter: saturate(140%) blur(12px);
    border-top: 1px solid var(--line);
    justify-content: space-around;
    align-items: stretch;
  }
  .bottomnav-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    flex: 1;
    min-height: 56px;
    color: var(--fg-3);
    font-size: 10px;
    font-weight: 600;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    transition: color .15s;
  }
  .bottomnav-tab svg { color: inherit; }
  .bottomnav-tab.active { color: var(--accent); }
  .bottomnav-tab:active { opacity: .7; }

  /* Add bottom padding to main view so content isn't hidden behind tab bar */
  .view {
    padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px) + 16px);
  }

  /* Move toast above the bottom bar */
  .toast { bottom: calc(68px + env(safe-area-inset-bottom, 0px)); }

  /* Hide bottom bar during active practice sessions */
  body.in-session .bottomnav { display: none; }
  body.in-session .view {
    padding-bottom: max(clamp(8px, 2vw, 16px), env(safe-area-inset-bottom));
  }
}

/* =========================================================
   TOUCH TARGETS — minimum 44px on touch devices
   ========================================================= */
@media (hover: none), (max-width: 640px) {
  .icon-btn {
    width: 44px;
    height: 44px;
  }
  #account-btn {
    height: 40px;
    padding: 0 14px;
  }
  .modal-close {
    width: 44px;
    height: 44px;
    font-size: 28px;
  }
  .variant-picker-close {
    width: 44px;
    height: 44px;
    font-size: 26px;
  }
  /* Sort & filter chips — larger tap area */
  .sort-chip {
    padding: 8px 14px;
    font-size: var(--fs-sm);
    min-height: 36px;
  }
  .filter-chip {
    padding: 10px 16px;
    font-size: var(--fs-sm);
    min-height: 36px;
  }
  /* Video overlay controls */
  .sign-detail .video-controls button {
    padding: 10px 16px;
    font-size: var(--fs-sm);
  }
  /* Variant buttons */
  .sign-detail .variant-btn {
    padding: 10px 16px;
    min-height: 40px;
  }
  /* Session video controls */
  .vctl {
    padding: 8px 16px;
    font-size: var(--fs-sm);
    min-height: 36px;
  }
  /* AI suggest buttons */
  .ai-suggest button {
    padding: 10px 16px;
    min-height: 40px;
  }
  /* Small button class */
  .btn-small {
    font-size: var(--fs-sm);
    padding: 8px 14px;
    min-height: 36px;
  }
  /* Result add button */
  .result-add {
    font-size: var(--fs-sm);
    padding: 10px 16px;
  }
}

/* =========================================================
   FULL-SCREEN MOBILE MODAL
   On screens < 640px, modals become slide-up sheets that
   fill the screen for comfortable mobile interaction.
   ========================================================= */
@media (max-width: 640px) {
  .modal-panel {
    position: fixed;
    left: 0; right: 0; bottom: 0; top: 0;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    border-radius: 0;
    padding: 6px 16px 24px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    margin: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    transform: none;
    animation: modal-slide-up .25s ease-out;
  }
  /* Override the open-state transform — must match specificity */
  .modal-root[aria-hidden="false"] .modal-panel {
    transform: none;
    opacity: 1;
  }
  @keyframes modal-slide-up {
    from { transform: translateY(100%); opacity: 0; }
    to   { transform: none; opacity: 1; }
  }
  /* Drag handle hint at top of sheet */
  .modal-panel::before {
    content: "";
    display: block;
    width: 36px;
    height: 4px;
    background: var(--line-strong);
    border-radius: 999px;
    margin: 10px auto 4px;
    flex-shrink: 0;
  }
  .modal-close {
    position: sticky;
    top: 0;
    float: right;
    z-index: 10;
    background: var(--bg-2);
    border: 1px solid var(--line);
  }
  /* Sign detail: single column always on mobile */
  .sign-detail {
    grid-template-columns: 1fr;
  }
}

/* =========================================================
   RESPONSIVE GRIDS — prevent overflow on small screens
   ========================================================= */
@media (max-width: 640px) {
  /* Lookup results: 2 cards side-by-side on most phones */
  .results {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
  }
  /* Search bar: reduce flex-basis to prevent overflow */
  .lookup-bar .search {
    flex: 1 1 200px;
  }
  /* Big action buttons on home */
  .big-actions {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
  }
  .big-btn {
    padding: 16px;
  }
  .big-btn h2 {
    font-size: var(--fs-xl);
  }
  /* Tile grid (libraries etc.) */
  .tile-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
  }
  /* Cheatsheet columns */
  .cs-cols {
    grid-template-columns: 1fr;
  }
  /* Achievements grid */
  .achievements-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  }
  /* Auth providers */
  .auth-providers {
    grid-template-columns: 1fr;
  }
}

/* =========================================================
   MOBILE TYPOGRAPHY — minimum readable sizes
   ========================================================= */
@media (max-width: 640px) {
  /* Bump xs to 13px minimum on mobile for readability */
  :root {
    --fs-xs: .8125rem;
  }
  /* Tags, badges — ensure minimum size */
  .result .tag,
  .lex-badge,
  .in-lib-badge,
  .variant-hint,
  .stat-hint,
  .ach-desc,
  .chip-count {
    font-size: max(var(--fs-xs), .8125rem);
  }
  /* Variant kbd */
  .sign-detail .variant-kbd {
    font-size: 12px;
  }
  /* Session sub labels */
  .session.in-session .rating-btn .sub {
    font-size: var(--fs-xs);
  }
  /* Why-kind labels */
  .why-kind {
    font-size: 11px;
  }
}

/* =========================================================
   LANDSCAPE MODE — optimize for phone landscape
   ========================================================= */
@media (orientation: landscape) and (max-height: 500px) {
  /* Keep appbar as single compact row */
  .appbar {
    height: 46px;
    --bar-h: 46px;
  }
  /* Hide bottom nav in landscape to save vertical space */
  .bottomnav { display: none; }
  .view {
    padding-bottom: 24px;
  }
  /* Practice session: side-by-side layout */
  .session.in-session .session-body {
    flex-direction: row;
    gap: 12px;
  }
  .session.in-session .video-card {
    flex: 1 1 50%;
    min-height: 100px;
  }
  .session.in-session .session-copy,
  .session.in-session .revealed {
    text-align: left;
  }
  .session.in-session .session-footer {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 45%;
  }
  .session.in-session .rating-row {
    grid-template-columns: 1fr 1fr;
  }
  .session.in-session .rating-btn {
    min-height: 60px;
  }
  /* Session actions: narrower */
  .session-actions {
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
  }
  /* Hero smaller in landscape */
  .hero h1 {
    font-size: clamp(1.5rem, 4vw, 2.5rem);
  }
  .hero-search {
    max-width: 100%;
  }
  /* Sign of day: single row */
  .sign-of-day .sod-card {
    grid-template-columns: 180px 1fr;
  }
}

/* =========================================================
   MOBILE MODAL — AI sheet full-height
   ========================================================= */
@media (max-width: 640px) {
  .ai-sheet .conv {
    max-height: calc(100dvh - 220px);
  }
  .ai-sheet textarea {
    min-height: 48px;
  }
}

/* =========================================================
   MOBILE LEARN SESSION — extra refinements
   ========================================================= */
@media (max-width: 640px) {
  /* Ensure session actions show icon labels on slightly larger phones */
  .session-action {
    min-height: 48px;
    gap: 4px;
  }
  /* Variant picker — full-width bottom sheet on mobile */
  .variant-picker {
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: var(--rad-lg) var(--rad-lg) 0 0;
    max-height: 70vh;
    padding: 14px 16px calc(18px + env(safe-area-inset-bottom, 0px));
  }
  .variant-picker-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }
}

/* =========================================================
   MOBILE — Sign of day card
   ========================================================= */
@media (max-width: 480px) {
  .sign-of-day .sod-card {
    grid-template-columns: 1fr;
  }
  .sod-thumb { aspect-ratio: 16 / 9; }
  .sod-body { padding: 12px 14px; }
  .sod-body h3 { font-size: var(--fs-lg); }
}

/* =========================================================
   MOBILE — Settings / account on small screens
   ========================================================= */
@media (max-width: 640px) {
  .settings section {
    padding: 14px;
  }
  .settings input[type="text"],
  .settings input[type="password"],
  .settings input[type="email"] {
    min-width: 0;
    flex: 1 1 100%;
  }
  .settings select {
    min-width: 0;
    width: 100%;
  }
}

/* =========================================================
   MOBILE — Onboarding tweaks
   ========================================================= */
@media (max-width: 640px) {
  .onboard h1 {
    font-size: var(--fs-xl);
  }
  .walkthrough h1 {
    font-size: var(--fs-xl);
  }
  .walkthrough-emoji {
    font-size: 42px;
  }
}

/* =========================================================
   MOBILE — Lookup bar sort row wrapping
   ========================================================= */
@media (max-width: 480px) {
  .sort-row {
    gap: 6px;
    padding-bottom: 10px;
  }
  .sort-label {
    width: 100%;
    margin-bottom: 2px;
  }
  /* Lookup result cards: tighter on narrow phones */
  .result {
    padding: 8px;
    gap: 8px;
  }
  .result .thumb {
    width: 60px;
  }
}

/* =========================================================
   MOBILE — Fingerspell tweaks
   ========================================================= */
@media (max-width: 640px) {
  .fs-picker { padding: 0 clamp(10px, 3vw, 20px); }
  .fs-input-row { width: min(340px, 94vw); }
}

/* =========================================================
   MOBILE — Recents rail bigger cards on touch
   ========================================================= */
@media (hover: none) {
  .recent-card {
    flex: 0 0 152px;
  }
  .recent-lbl {
    padding: 8px 12px;
  }
}

/* =========================================================
   MOBILE — Stats page refinements
   ========================================================= */
@media (max-width: 640px) {
  .stat-tiles {
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 10px;
  }
  .stat-tile {
    padding: 12px 14px;
  }
  .state-legend {
    gap: 10px;
    font-size: var(--fs-xs);
  }
}

/* =========================================================
   MOBILE — Minimal pairs better touch on small screens
   ========================================================= */
@media (max-width: 480px) {
  .mp-video-row {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .mp-choice {
    border-width: 3px;
  }
}

/* =========================================================
   MOBILE — Footer acknowledgement
   ========================================================= */
@media (max-width: 640px) {
  .ack {
    padding-bottom: calc(24px + 56px + env(safe-area-inset-bottom, 0px));
  }
}

/* =========================================================
   DESKTOP ONLY — hide bottom nav
   ========================================================= */
@media (min-width: 641px) {
  .bottomnav { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
