/*
 * Signs: a pencil drawing on paper. One focal point per screen (the sign), one primary action
 * (filled ink), everything else quiet. Motion only where it explains a change or confirms a press.
 */
:root {
  color-scheme: only light; /* a pencil drawing on paper: never auto-darkened */
  --paper: #f6f2e9;
  --paper-raised: #fbf8f1;
  --ink: #2f2b25; /* the one strong colour: primary actions and the current choice */
  --fg: #454139;
  --pencil: #665f52;
  --muted: #888175;
  --faint: #b3ab9c;
  --rule: #ddd6c9;
  --line: #c9c0b0;
  --wash: #ebe5d8;
  --similarity-similar-text: #315b47;
  --similarity-similar-fill: #e5eee4;
  --similarity-similar-line: #a8bfa7;
  --similarity-partial-text: #785414;
  --similarity-partial-fill: #f4ebd6;
  --similarity-partial-line: #cfb77b;
  --similarity-different-text: #91483f;
  --similarity-different-fill: #f4e4de;
  --similarity-different-line: #d0aaa2;
  --similarity-review-text: #5d5c57;
  --similarity-review-fill: #eae7e0;
  --similarity-review-line: #bcb6aa;

  --serif: Georgia, "Palatino Linotype", serif;
  --sans: "Avenir Next", Avenir, "Segoe UI", sans-serif;
  --radius: 10px 12px 9px 11px; /* slightly uneven, like a hand-cut card */
  --radius-small: 7px 9px 6px 8px;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --press: 140ms var(--ease-out);

  font-family: var(--sans);
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background-color: var(--paper);
  background-image: radial-gradient(#76695108 0.55px, transparent 0.55px);
  background-size: 5px 5px;
  color: var(--fg);
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

main {
  width: min(100%, 1168px);
  margin: 0 auto;
  padding: 18px 24px 48px;
}

button, canvas, summary, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; font: inherit; }
button, summary { cursor: pointer; }
button:focus-visible, canvas:focus-visible, summary:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--pencil);
  outline-offset: 4px;
}
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  white-space: nowrap;
  border: 0;
  clip-path: inset(50%);
}

/* Pressable things answer the press. */
.views a, .learn-units button, .learn-steps button, #learn-change, .learn-choices button,
.practice-button, .practice-choice, .language-list button, .chips button, .sticker-tile, .text-button,
.variant-controls button, .verdict-toggle {
  transition: transform var(--press), background-color 150ms ease, border-color 150ms ease, color 150ms ease, opacity 150ms ease;
}
:is(.views a, .learn-units button, .learn-steps button, #learn-change, .learn-choices button, .practice-button,
  .practice-choice, .language-list button, .sticker-tile, .text-button, .variant-controls button):active:not(:disabled) {
  transform: scale(0.97);
}

.text-button {
  min-height: 44px;
  padding: 8px 10px;
  border: 0;
  background: none;
  color: var(--pencil);
  font-size: 13px;
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 4px;
}

/* ── Top bar: the name, the two sections, and what is being learned ─────────────────────── */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  margin-bottom: 18px;
}
.wordmark { margin: 0; font: 400 21px/1 var(--serif); letter-spacing: -0.01em; color: var(--ink); }
.views {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--wash);
}
.views a {
  padding: 7px 16px;
  border-radius: 999px;
  color: var(--pencil);
  font-size: 13px;
  font-weight: 500;
  line-height: 18px;
  text-decoration: none;
}
.views a[aria-current="page"] { background: var(--paper-raised); color: var(--ink); box-shadow: 0 1px 2px #52493618, 0 0 0 1px #5249360d; }
.learn-bar { justify-self: end; }
#learn-change {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 6px 12px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
}
.learn-chevron {
  width: 6px;
  height: 6px;
  margin: -3px 1px 0 0;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg);
}
@media (hover: hover) and (pointer: fine) {
  .views a:not([aria-current="page"]):hover { color: var(--ink); }
  #learn-change:hover { border-color: var(--line); background: var(--paper-raised); }
}

.language-label { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.language-flag {
  display: inline-block;
  flex: none;
  width: 18px;
  height: 12px;
  border-radius: 2px;
  box-shadow: 0 0 0 1px #665f5220;
}

/* ── Learn: choosing a language (first visit) ─────────────────────────────────────────────── */
body[data-view="learn"] .languages,
body[data-view="learn"] #comparison-section { display: none; }
body[data-stage="choose"] .concepts { display: none; }
/* In Learn the words are the unit's contents line: small and quiet, the big word below leads. */
body[data-view="learn"] .concepts { margin-top: 10px; }
body[data-view="learn"] .chips { gap: 0 2px; }
body[data-stage="choose"] #signs,
body[data-stage="choose"] #load-status,
body[data-stage="choose"] .learn-units { display: none; }

.learn-choose { max-width: 560px; margin: 8vh auto 0; text-align: center; }
.learn-choose h2 { margin: 0 0 24px; font: 400 clamp(26px, 4vw, 34px)/1.2 var(--serif); color: var(--ink); text-wrap: balance; }
.learn-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.learn-choices button {
  display: grid;
  justify-items: start;
  gap: 6px;
  padding: 16px 18px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--paper-raised);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-align: left;
}
.learn-choices button[aria-current="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.learn-choices button:focus-visible { outline-width: 1.5px; outline-color: var(--muted); outline-offset: 3px; }
.learn-choices button:disabled { cursor: default; border-style: dashed; background: transparent; color: var(--faint); }
.learn-choices button:disabled .language-flag { opacity: 0.5; }
@media (hover: hover) and (pointer: fine) {
  .learn-choices button:hover:not(:disabled) { border-color: var(--line); background: #fdfbf6; }
}
.language-community { color: var(--muted); font-size: 12px; font-weight: 400; letter-spacing: normal; line-height: 1.35; text-align: left; }
.learn-note { margin: 18px 0 4px; color: var(--muted); font-size: 12px; text-wrap: balance; }

/* ── Learn: units, then the sign ─────────────────────────────────────────────────────────── */
.learn-units {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 0 auto;
  overflow-x: auto;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
}
.learn-units::-webkit-scrollbar { display: none; }
.learn-units button {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 6px 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--pencil);
  font-size: 13px;
  line-height: 18px;
}
.learn-units button[aria-current="true"] { background: var(--ink); color: var(--paper); }
.learn-units button:disabled { cursor: default; color: var(--faint); }
@media (hover: hover) and (pointer: fine) {
  .learn-units button:hover:not(:disabled):not([aria-current="true"]) { background: var(--wash); color: var(--ink); }
}

.learn-steps {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px; /* symmetric, so the word sits on the page's centre line */
  align-items: center;
  gap: 12px;
  max-width: 520px;
  margin: 26px auto 0;
}
.learn-steps button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0 0 2px;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  font: 22px/1 var(--serif);
}
.learn-steps button:disabled { cursor: default; opacity: 0.3; }
@media (hover: hover) and (pointer: fine) {
  .learn-steps button:hover:not(:disabled) { border-color: var(--line); background: var(--paper-raised); }
}
.learn-word { margin: 0; text-align: center; }
#learn-word { display: block; font: 400 clamp(38px, 6vw, 52px)/1.05 var(--serif); letter-spacing: -0.015em; color: var(--ink); }
#learn-word:focus { outline: none; }
#learn-translations { display: block; margin-top: 8px; color: var(--muted); font-size: 14px; }
#learn-count { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); } /* read aloud; the dots show it */

.lesson-dots { display: inline-flex; justify-content: center; align-items: center; gap: 7px; }
.lesson-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  transition: background-color 200ms ease, border-color 200ms ease, transform 200ms var(--ease-out);
}
.lesson-dot[data-state="complete"] { background: var(--pencil); border-color: var(--pencil); }
.lesson-dot[data-current="true"] { border-color: var(--ink); transform: scale(1.3); }
.lesson-dot[data-current="true"][data-state="complete"] { background: var(--ink); }
.unit-progress { display: flex; width: fit-content; min-height: 14px; margin: 14px auto 0; }

/* ── The drawing ─────────────────────────────────────────────────────────────────────────── */
.signs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin: 18px auto 8px;
}
.signs[data-count="1"] { grid-template-columns: minmax(0, 560px); justify-content: center; }
.signs[data-count="2"] { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 880px; }
.signs[data-count="4"] { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card { position: relative; min-width: 0; }
.card header { display: flex; justify-content: center; align-items: center; gap: 7px; margin-bottom: 2px; }
.language-name { margin: 0; color: var(--muted); font-size: 11px; font-weight: 500; letter-spacing: 0.1em; line-height: 1.4; }
/* Learn shows one language, named in the top bar: the card keeps only its credits, in a corner. */
body[data-view="learn"] .card header { position: absolute; z-index: 4; top: 4px; right: 4px; margin: 0; }
body[data-view="learn"] .language-name { display: none; }
.drawing { position: relative; }
.card canvas {
  display: block;
  width: 100%;
  height: clamp(300px, 36vw, 410px);
  background: transparent;
  touch-action: none;
  cursor: grab;
}
.card canvas:active { cursor: grabbing; }
.play-indicator {
  position: absolute;
  left: 50%;
  bottom: 10px;
  display: none;
  place-items: center;
  width: 40px;
  height: 40px;
  padding-left: 3px;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: var(--paper-raised);
  color: var(--ink);
  font-size: 12px;
  line-height: 1;
  pointer-events: none;
  transform: translateX(-50%);
  box-shadow: 0 2px 10px #52493614;
}
body[data-playing="false"] .play-indicator { display: grid; }
.card .missing {
  height: clamp(300px, 36vw, 410px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 7px;
  padding: 20px;
  text-align: center;
  color: var(--muted);
  font: italic 15px var(--serif);
}
.missing a { color: var(--pencil); text-underline-offset: 3px; }
.missing + .play-indicator { display: none !important; }
#load-status { text-align: center; color: var(--pencil); font-size: 13px; }
#load-status:empty { display: none; }

.variant-controls { display: flex; justify-content: center; align-items: center; gap: 4px; color: var(--pencil); font-size: 12px; }
.variant-controls button { width: 36px; height: 36px; padding: 0; border: 0; border-radius: 50%; background: transparent; font: 20px/1 var(--serif); }
.variant-controls span { min-width: 3em; text-align: center; font-variant-numeric: tabular-nums; }
@media (hover: hover) and (pointer: fine) { .variant-controls button:hover { background: var(--wash); } }

.credits summary {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1px solid var(--rule);
  border-radius: 50%;
  color: var(--muted);
  font: italic 11px var(--serif);
  list-style: none;
  transition: color 150ms ease, border-color 150ms ease;
}
.credits summary::-webkit-details-marker { display: none; }
.credits summary:hover, .credits[open] summary { color: var(--ink); border-color: var(--line); }
.credit {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 28px;
  width: min(300px, calc(100vw - 48px));
  max-width: calc(100% + 12px);
  padding: 16px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-small);
  background: var(--paper-raised);
  box-shadow: 0 10px 30px #52493618;
  color: var(--pencil);
  font-size: 11px;
  line-height: 1.6;
  overflow-wrap: anywhere;
  transform: translateX(-50%);
  transform-origin: top center;
}
body[data-view="learn"] .credit { left: auto; right: 0; transform: none; transform-origin: top right; }
.credits[open] .credit { animation: pop-in 160ms var(--ease-out); }
.credit a { color: inherit; text-underline-offset: 2px; }
.credit p { margin: 0; }
.credit .variant-note, .credit .original-video { margin-bottom: 8px; }
.credit p + p { margin-top: 8px; }


/* ── The one primary action ─────────────────────────────────────────────────────────────── */
.practice-button, .practice-choice {
  min-height: 48px;
  padding: 12px 24px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-size: 15px;
  font-weight: 500;
  line-height: 1.3;
}
@media (hover: hover) and (pointer: fine) {
  .practice-button:hover { background: #45403a; border-color: #45403a; }
  .practice-secondary:hover, .practice-choice:hover:not(:disabled) { background: var(--paper-raised); border-color: var(--pencil); }
}
.practice-secondary { border-color: var(--line); background: transparent; color: var(--ink); }

.practice-launch { max-width: 520px; margin: 22px auto 0; text-align: center; }
#practice-start { min-width: 220px; }
.practice-launch p { margin: 10px 0 0; color: var(--muted); font-size: 12px; }
.practice-launch p:empty { display: none; }

/* ── Practice: one question at a time ───────────────────────────────────────────────────── */
body[data-practice] .learn-bar,
body[data-practice] .learn-units,
body[data-practice] .concepts,
body[data-practice] .learn-steps,
body[data-practice] #load-status,
body[data-practice] .sticker-book,
body[data-practice] .variant-controls { display: none; }
body[data-practice] .topbar { display: none; } /* a session is a focused mode: "End practice" is the way out */
body[data-practice] .practice-prompt { padding-top: 10px; }

.practice-prompt { max-width: 520px; margin: 0 auto; text-align: center; }
.practice-top { display: flex; align-items: center; justify-content: space-between; gap: 14px; color: var(--muted); font-size: 12px; }
#practice-position { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); } /* read aloud; the stage dots show it */
.practice-top { justify-content: flex-end; }
#practice-end {
  flex-shrink: 0;
  min-height: 40px;
  padding: 6px 14px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: transparent;
  color: var(--pencil);
  font-size: 12px;
  transition: transform var(--press), border-color 150ms ease;
}
#practice-end:active { transform: scale(0.97); }
.practice-progress { display: flex; justify-content: center; align-items: flex-start; gap: 22px; margin: 14px auto 26px; }
.lesson-stage { display: inline-flex; flex-direction: column; align-items: center; gap: 8px; min-width: 64px; }
.lesson-stage-label { color: var(--muted); font-size: 11px; line-height: 1.4; }
#practice-title { margin: 0; color: var(--muted); font-size: 12px; font-weight: 500; letter-spacing: 0.1em; text-transform: uppercase; }
#practice-title:focus { outline: none; }
#practice-word { margin: 10px 0 0; font: 400 clamp(36px, 6vw, 48px)/1.05 var(--serif); letter-spacing: -0.015em; color: var(--ink); }
#practice-translations { margin: 8px 0 0; color: var(--muted); font-size: 14px; }
#practice-word:empty, #practice-translations:empty { display: none; }
#practice-instruction { margin: 12px 0 0; color: var(--pencil); font-size: 14px; text-wrap: balance; }
/* With no word to show, the question is the focal point. */
body[data-practice="recognise"] #practice-title, body[data-practice="complete"] #practice-title { color: var(--ink); font: 400 clamp(28px, 5vw, 36px)/1.15 var(--serif); letter-spacing: -0.01em; text-transform: none; }
body[data-practice="complete"] #practice-word { font-size: 18px; color: var(--pencil); font-family: var(--sans); letter-spacing: 0; }
body[data-practice] .signs { margin-top: 10px; margin-bottom: 4px; }
body[data-practice] .card canvas { height: clamp(250px, 30vw, 340px); }

.practice-controls { max-width: 520px; margin: 18px auto 0; text-align: center; }
.practice-actions, .practice-choices { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.practice-choice { min-width: 112px; border-color: var(--line); background: var(--paper-raised); color: var(--ink); }
.practice-choice:disabled { cursor: default; opacity: 0.45; }
.practice-choice[data-result="correct"] { opacity: 1; background: var(--similarity-similar-fill); border-color: var(--similarity-similar-line); color: var(--similarity-similar-text); }
#practice-feedback { margin: 14px 0; color: var(--pencil); font-size: 14px; }
#practice-feedback:empty { display: none; }
#practice-feedback:not(:empty) { animation: rise-in 220ms var(--ease-out); }
body[data-practice="recall"] #signs[hidden] ~ .practice-controls { margin-top: 48px; }
body[data-practice="complete"] .practice-controls { margin-top: 30px; }
body[data-practice="complete"] .practice-prompt { margin-top: 6vh; }

/* ── Sticker book ───────────────────────────────────────────────────────────────────────── */
.sticker-book { max-width: 560px; margin: 8px auto 0; text-align: center; }
.sticker-book > summary {
  display: inline-block;
  min-height: 44px;
  padding: 11px 12px;
  color: var(--pencil);
  font-size: 13px;
  list-style: none;
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 4px;
}
.sticker-book > summary::-webkit-details-marker { display: none; }
.sticker-book[open] > summary { color: var(--ink); text-decoration: none; }
.sticker-book[open] > :not(summary) { animation: rise-in 240ms var(--ease-out); }
.sticker-note { margin: 4px 0 24px; color: var(--muted); font-size: 12px; text-wrap: balance; }
.sticker-unit { margin: 0 0 28px; }
.sticker-unit, .practice-rewards { --sticker-fill: #e9eadc; }
.sticker-unit[data-unit="meals"], .practice-rewards[data-unit="meals"] { --sticker-fill: #f0e5ce; }
.sticker-unit[data-unit="bath"], .practice-rewards[data-unit="bath"] { --sticker-fill: #e3e8ea; }
.sticker-unit[data-unit="play"], .practice-rewards[data-unit="play"] { --sticker-fill: #eee0d9; }
.sticker-unit h3 { display: flex; align-items: baseline; justify-content: center; gap: 10px; margin: 0 0 12px; color: var(--ink); font: 400 18px/1.4 var(--serif); }
.sticker-unit h3 span { color: var(--muted); font: 12px/1.4 var(--sans); font-variant-numeric: tabular-nums; }
.sticker-grid { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px 10px; }
.sticker-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 3px;
  width: 80px;
  min-height: 104px;
  padding: 7px 4px 8px;
  border: 1px dashed var(--rule);
  border-radius: var(--radius);
  background: transparent;
  color: var(--pencil);
  line-height: 1.35;
}
@media (hover: hover) and (pointer: fine) { button.sticker-tile:hover:not(:disabled) { border-color: var(--pencil); background: var(--wash); } }
.sticker-tile[data-collected="true"] { border-style: solid; border-color: #c4b9a3; background: var(--sticker-fill, #e9eadc); box-shadow: 1px 2px 0 #665f5212; }
.sticker-tile[data-collected="true"]:nth-child(3n + 1) { transform: rotate(-2deg); }
.sticker-tile[data-collected="true"]:nth-child(3n + 2) { transform: rotate(2deg); }
.sticker-art { display: block; flex: none; width: 58px; height: 58px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sticker-tile[data-collected="false"] .sticker-art { opacity: 0.33; }
.sticker-word { font: 13px/1.35 var(--serif); }
.sticker-check { position: absolute; top: 2px; right: 5px; color: #42604a; font-size: 12px; }
.sticker-unavailable { color: var(--muted); font-size: 10px; }
.sticker-tile:disabled { cursor: default; border-style: dotted; }
.sticker-tile:disabled .sticker-art { opacity: 0.2; }
.practice-rewards { margin: 20px auto 26px; }
.practice-rewards h3 { margin: 0 0 12px; color: var(--ink); font: 400 18px/1.4 var(--serif); }
.practice-stickers { display: grid; grid-template-columns: repeat(4, 80px); justify-content: center; gap: 12px; }
.practice-stickers[data-count="1"] { grid-template-columns: 80px; }
.practice-stickers[data-count="2"] { grid-template-columns: repeat(2, 80px); }
.practice-stickers[data-count="3"] { grid-template-columns: repeat(3, 80px); }
/* A new sticker is a rare reward: it lands, one after another. */
.practice-stickers .sticker-tile { animation: sticker-land 420ms var(--ease-out) backwards; }
.practice-stickers .sticker-tile:nth-child(2) { animation-delay: 70ms; }
.practice-stickers .sticker-tile:nth-child(3) { animation-delay: 130ms; }
.practice-stickers .sticker-tile:nth-child(4) { animation-delay: 180ms; }

/* ── Dictionary ─────────────────────────────────────────────────────────────────────────── */
/* Two blocks on one grid: a single filter row, then the index. Same width, same left edge. */
.dictionary-tools, body[data-view="dictionary"] .concepts { max-width: 760px; margin-inline: auto; }
.dictionary-tools { margin-top: 4px; margin-bottom: 0; text-align: left; }
.dictionary-filters { display: flex; align-items: center; gap: 8px; }

/* Every control in the row: 44 px, one border, one radius. */
.dictionary-search, .language-list button {
  min-height: 44px;
  border: 1px solid var(--rule);
  border-radius: 999px;
}
.dictionary-search {
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  min-width: 0;
  background: var(--paper-raised);
  transition: border-color 150ms ease;
}
.dictionary-search:focus-within { border-color: var(--muted); }
#dictionary-search {
  width: 100%;
  min-width: 0;
  height: 42px;
  padding: 0 18px;
  border: 0;
  border-radius: inherit;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* 16px or more: phones do not zoom the page on focus */
}
#dictionary-search:focus { outline: none; }
#dictionary-search::placeholder { color: var(--muted); }
#dictionary-search::-webkit-search-cancel-button { -webkit-appearance: none; }
#dictionary-clear { min-height: 32px; margin-right: 6px; padding: 4px 12px; border: 0; border-radius: 999px; background: var(--wash); color: var(--pencil); font-size: 12px; }
#dictionary-result-status { margin: 10px 0 0; color: var(--muted); font-size: 12px; }
#dictionary-result-status:empty { display: none; }
.dictionary-reset { min-height: 40px; padding: 4px 0; border: 0; background: transparent; color: var(--pencil); font-size: 12px; text-decoration: underline; text-underline-offset: 3px; }
body[data-view="dictionary"][data-dictionary-selection="false"] #comparison-section { display: none; }

/* Languages: plain toggles, outlined when off, inked when on. A missing recording shows on the drawing, not here. */
.languages { flex: none; min-width: 0; margin: 0; padding: 0; border: 0; }
.language-list { display: flex; gap: 6px; }
.language-list button {
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  background: transparent;
  color: var(--pencil);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
}
.language-list .language-community { display: none; } /* in each button's label and tooltip */
.language-list button[aria-pressed="true"] { border-color: var(--pencil); background: var(--paper-raised); color: var(--ink); }
.language-list button[aria-pressed="false"] { color: var(--muted); }
.language-list button[aria-pressed="false"] .language-flag { filter: grayscale(1); opacity: 0.5; }
.language-list button[aria-disabled="true"] { cursor: default; }
@media (hover: hover) and (pointer: fine) { .language-list button[aria-pressed="false"]:hover { border-color: var(--line); color: var(--ink); } }

/* The index: one line per theme, left-aligned under the search field. The label filters to its theme. */
.concepts { margin: 0; }
.chips { display: flex; justify-content: center; flex-wrap: wrap; gap: 2px 6px; max-width: 900px; margin: 0 auto; }
body[data-view="dictionary"] .concepts { margin-top: 20px; }
/* A grid of themes: each cell has its theme as a title, then its words as a short list. */
body[data-view="dictionary"] .chips { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); align-items: start; gap: 20px 16px; max-width: none; }
.word-group { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }
.chips .word-group-title {
  position: static;
  min-height: 30px;
  margin: 0 0 6px -8px;
  padding: 4px 8px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: 500 11px/1.2 var(--sans);
  letter-spacing: 0.06em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
  transition: background-color 150ms ease, color 150ms ease;
}
.chips .word-group-title[aria-pressed="true"] { background: var(--wash); color: var(--ink); }
.chips .word-group-title[aria-pressed="true"]::after { content: " ×"; position: static; border: 0; letter-spacing: 0; transform: none; } /* pressed again, it shows every theme */
@media (hover: hover) and (pointer: fine) { .chips .word-group-title:hover { background: var(--wash); color: var(--ink); } }
.word-group-list { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; margin-left: -8px; }
body[data-view="dictionary"] .signs { margin-top: 30px; }
/* One word style for Learn and the Dictionary: words are content, so serif; the current word is
   inked and underlined in pencil. Labels around them (units, themes) are sans. */
.chips button[data-concept] {
  position: relative;
  padding: 4px 8px 7px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--pencil);
  font: 16px/1.25 var(--serif);
  white-space: nowrap;
}
.chips button[aria-selected="true"] { color: var(--ink); }
.chips button[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 7px;
  right: 7px;
  bottom: 2px;
  height: 4px;
  border-bottom: 1.5px solid var(--ink);
  border-radius: 48%;
  transform: rotate(-2deg);
}
@media (hover: hover) and (pointer: fine) { .chips button[data-concept]:hover { background: var(--wash); color: var(--ink); } }

/* Comparison */
.comparison { max-width: 900px; margin: 28px auto 0; }
.table-wrap { width: 100%; overflow-x: auto; scrollbar-width: thin; }
#comparison { width: 100%; border-collapse: collapse; font-size: 12px; table-layout: fixed; } /* columns keep their width when the details open */
#comparison thead th:first-child { width: 9.5em; }
#comparison th, #comparison td { padding: 9px 12px; border-bottom: 1px solid var(--rule); text-align: center; white-space: nowrap; }
#comparison th { color: var(--muted); font-size: 11px; font-weight: 500; letter-spacing: 0.025em; }
#comparison th:first-child, #comparison td:first-child { text-align: left; }
#comparison tbody th { white-space: normal; }
#comparison td:first-child { color: var(--pencil); }
#comparison .pair > span { display: block; }
#comparison .pair > span + span { margin-top: 3px; padding-top: 3px; border-top: 1px solid rgb(169 157 136 / 0.4); }
#comparison th .pair { display: inline-grid; min-width: 5.5em; text-align: left; }
#comparison th .pair > span + span { border-top-color: transparent; padding-top: 0; margin-top: 1px; }
#comparison td.score { white-space: normal; line-height: 1.35; background: rgb(169 157 136 / calc(var(--amount, 0) * 0.32)); }
#comparison td.alternatives { white-space: normal; font-size: 11px; }
#comparison-details:not([hidden]) { animation: fade-in 200ms ease; }
.closest-pair { display: inline-grid; gap: 5px; max-width: 100%; padding: 6px; border: 1px solid var(--rule); border-radius: var(--radius-small); background: transparent; white-space: normal; }
@media (hover: hover) and (pointer: fine) { .closest-pair:hover { background: var(--wash); } }
#comparison .verdicts td { padding: 0; font-weight: 600; }
#comparison .verdicts td.score { background: transparent; }
#comparison .verdicts th, #comparison .verdicts td { border-bottom-color: var(--line); }
.verdict-toggle { display: block; width: 100%; min-height: 44px; padding: 9px 12px; border: 0; background: none; color: inherit; line-height: inherit; }
.similarity-badge { display: inline-flex; align-items: center; justify-content: center; gap: 6px; max-width: 100%; padding: 5px 10px; border: 1px solid; border-radius: 999px; font-size: 11px; line-height: 1.3; }
.similarity-badge[data-similarity="similar"] { color: var(--similarity-similar-text); background: var(--similarity-similar-fill); border-color: var(--similarity-similar-line); }
.similarity-badge[data-similarity="partial"] { color: var(--similarity-partial-text); background: var(--similarity-partial-fill); border-color: var(--similarity-partial-line); }
.similarity-badge[data-similarity="different"] { color: var(--similarity-different-text); background: var(--similarity-different-fill); border-color: var(--similarity-different-line); }
.similarity-badge[data-similarity="review"] { color: var(--similarity-review-text); background: var(--similarity-review-fill); border-color: var(--similarity-review-line); }
.similarity-symbol { flex: none; font-size: 15px; line-height: 1; }
.similarity-label { min-width: 0; }
@media (hover: hover) and (pointer: fine) { .verdict-toggle:hover .similarity-badge { border-color: currentColor; } }
.details-toggle { display: inline-flex; align-items: center; gap: 6px; padding: 0; border: 0; background: none; color: var(--muted); letter-spacing: inherit; }
.details-toggle:hover { color: var(--ink); }
.details-toggle .chevron { display: inline-block; font-size: 14px; line-height: 1; transition: transform 180ms var(--ease-out); }
.details-toggle[aria-expanded="true"] .chevron { transform: rotate(90deg); }
#comparison .score-same { color: var(--muted); }
#comparison .score-unknown { color: var(--muted); background: transparent; }

/* ── Privacy page ───────────────────────────────────────────────────────────────────────── */
.privacy-page { max-width: 720px; font-size: 15px; line-height: 1.7; }
.privacy-page h1, .privacy-page h2 { font-family: var(--serif); font-weight: 400; line-height: 1.3; color: var(--ink); }
.privacy-page h1 { margin: 30px 0 20px; font-size: 30px; }
.privacy-page h2 { margin: 28px 0 12px; font-size: 21px; }
.privacy-page a { color: var(--pencil); }
.privacy-updated { color: var(--muted); font-size: 12px; margin-top: 28px; }

/* ── Motion ─────────────────────────────────────────────────────────────────────────────── */
@keyframes pop-in { from { opacity: 0; scale: 0.96; } }
@keyframes rise-in { from { opacity: 0; translate: 0 6px; } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes sticker-land { from { opacity: 0; scale: 0.9; } }
/* First visit only: the choices settle in one after another. */
.learn-choose:not([hidden]) h2 { animation: rise-in 360ms var(--ease-out) backwards; }
.learn-choose:not([hidden]) .learn-choices button { animation: rise-in 360ms var(--ease-out) backwards; }
.learn-choose:not([hidden]) .learn-choices button:nth-child(1) { animation-delay: 60ms; }
.learn-choose:not([hidden]) .learn-choices button:nth-child(2) { animation-delay: 100ms; }
.learn-choose:not([hidden]) .learn-choices button:nth-child(3) { animation-delay: 135ms; }
.learn-choose:not([hidden]) .learn-choices button:nth-child(4) { animation-delay: 165ms; }
.practice-prompt:not([hidden]) #practice-word { animation: rise-in 260ms var(--ease-out); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-property: opacity, color, background-color, border-color !important; scroll-behavior: auto !important; }
  :is(.views a, .learn-units button, .learn-steps button, #learn-change, .learn-choices button, .practice-button,
    .practice-choice, .language-list button, .sticker-tile, .text-button, .variant-controls button, #practice-end):active:not(:disabled) { transform: none; }
  .learn-choose:not([hidden]) h2, .learn-choose:not([hidden]) .learn-choices button, .practice-prompt:not([hidden]) #practice-word,
  #practice-feedback:not(:empty), .sticker-book[open] > :not(summary), .practice-stickers .sticker-tile, .credits[open] .credit {
    animation: fade-in 160ms ease backwards;
  }
  .lesson-dot[data-current="true"] { transform: none; outline: 1.5px solid var(--ink); outline-offset: 2px; }
}

/* ── Narrow screens ─────────────────────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  main { padding: 14px 20px 40px; }
  body[data-view="dictionary"] .chips { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .word-group-list { flex-direction: row; flex-wrap: wrap; } /* narrower cells: words wrap instead of stacking */
  .signs, .signs[data-count="4"] { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px 12px; }
  .signs[data-count="1"] { grid-template-columns: minmax(0, 560px); }
  #comparison th, #comparison td { padding-inline: 9px; }
}

@media (max-width: 540px) {
  main { padding: 10px 16px calc(32px + env(safe-area-inset-bottom)); }
  .topbar { grid-template-columns: auto 1fr; margin-bottom: 14px; }
  .wordmark { display: none; } /* the sections and the language matter more at this width */
  .views { justify-self: start; }
  .views a { padding: 7px 13px; }
  .learn-units { justify-content: flex-start; margin-inline: -16px; padding-inline: 16px; mask-image: linear-gradient(90deg, transparent, #000 16px, #000 calc(100% - 24px), transparent); }
  .learn-steps { margin-top: 26px; gap: 8px; }
  .learn-choices { grid-template-columns: minmax(0, 1fr); }
  .learn-choose { margin-top: 4vh; }
  .card canvas { height: 300px; }
  .card .missing { height: 88px; }
  .signs, .signs[data-count="2"], .signs[data-count="4"] { grid-template-columns: minmax(0, 1fr); gap: 22px; margin-top: 14px; }
  /* On a phone the main action stays within thumb reach. */
  body[data-view="learn"]:not([data-practice]) .practice-launch {
    position: sticky;
    bottom: 0;
    z-index: 6;
    margin: 12px -16px 0;
    padding: 14px 16px calc(12px + env(safe-area-inset-bottom));
    background: linear-gradient(#f6f2e900, var(--paper) 30%);
  }
  #practice-start { width: 100%; }
  .practice-choice { min-width: 0; flex: 1 1 28%; padding: 12px 10px; }
  .practice-stickers[data-count="4"] { grid-template-columns: repeat(2, 80px); }
  .practice-progress { gap: 16px; }
  .chips { gap: 0 2px; }
  /* Phone: the search takes the first row, the languages the second; the index keeps its label column. */
  .dictionary-filters { flex-wrap: wrap; }
  .dictionary-search { flex: 1 1 100%; }
  .languages { flex: 1 1 100%; }
  .language-list button { flex: 1 1 0; justify-content: center; padding: 0 6px; }
  body[data-view="dictionary"] .chips { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 12px; }
  .chips .word-group-title { white-space: normal; }
  .word-group-list { flex-direction: row; flex-wrap: wrap; margin-left: -6px; }
  .chips button[data-concept] { padding-inline: 6px; }
  .comparison { margin-top: 20px; }
  #comparison { font-size: 11px; }
  #comparison th { font-size: 10px; }
  #comparison th, #comparison td { padding: 8px 7px; }
  #comparison .verdicts td { padding: 0; }
  .verdict-toggle { padding: 8px 2px; }
  .similarity-badge { flex-direction: column; gap: 3px; padding: 5px 6px; border-radius: 10px; font-size: 10px; line-height: 1.25; }
  #comparison thead th:first-child { width: 7.5em; }
}
