/* ==========================================================================
   Vocablos — "cuaderno" (exercise notebook)
   Cool paper, blue fountain-pen ink, the teacher's red pen for mistakes.
   The prompt word is set like a dictionary headword; everything else stays quiet.
   ========================================================================== */

/* --- tokens ------------------------------------------------------------ */

:root {
  /* colour — Basic light: paper + tinta azul */
  --bg: #f2f4f7; /* paper */
  --card: #ffffff;
  --text: #1a2130; /* ink */
  --muted: #647085;
  --line: #dde2ea;
  --accent: #1f4fbf; /* blue fountain-pen ink */
  --accent-soft: #e6ecfa;
  --gold: var(--accent);
  --ok: #1b7a48;
  --ok-bg: #e5f4ec;
  --almost: #a36400;
  --almost-bg: #fbf1dd;
  --bad: #c42d27; /* teacher's red pen */
  --bad-bg: #fbe8e6;
  --new: #2f6fd6;

  /* charts */
  --s-correct: #0ca30c;
  --s-almost: #fab219;
  --s-wrong: #d03b3b;
  --heat-1: #e04848;
  --heat-2: #f4aaa2;
  --heat-3: #ebe8e1;
  --heat-4: #6cc06c;
  --heat-5: #146c14;
  --heat-ink-1: #0b0b0b;
  --heat-ink-2: #0b0b0b;
  --heat-ink-3: #0b0b0b;
  --heat-ink-4: #0b0b0b;
  --heat-ink-5: #ffffff;
  --grid: #e8ecf1;
  --axis: #c3cad6;
  --bar: var(--accent);

  /* type */
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --font-word: "Iowan Old Style", "Charter", "Palatino Linotype", Palatino, Georgia, serif;
  --t-xs: 12px;
  --t-sm: 13px;
  --t-md: 15px;
  --t-base: 16px;
  --t-lg: 20px;
  --t-xl: 25px;
  --t-2xl: 31px;
  --t-word: clamp(36px, 7vw, 52px);

  /* space (4-based) */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;

  /* radii by hierarchy: controls < panels < the practice card */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 18px;

  --page: 820px;
  --card-w: 600px;

  color-scheme: light dark;
}

/* Basic dark: night ink */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #10141b;
    --card: #171c25;
    --text: #e6eaf1;
    --muted: #8d97a9;
    --line: #283040;
    --accent: #8fb0ff;
    --accent-soft: #1e2a44;
    --ok: #5fd08f;
    --ok-bg: #13291d;
    --almost: #e8b54c;
    --almost-bg: #2c2412;
    --bad: #ff7b70;
    --bad-bg: #331a1a;
    --new: #7aa7ff;
    --heat-1: #ff7a7a;
    --heat-2: #b04444;
    --heat-3: #353b47;
    --heat-4: #2f8a3d;
    --heat-5: #5cd679;
    --heat-ink-1: #0b0b0b;
    --heat-ink-2: #ffffff;
    --heat-ink-3: #ffffff;
    --heat-ink-4: #ffffff;
    --heat-ink-5: #0b0b0b;
    --grid: #232a36;
    --axis: #3a4354;
  }
}

:root[data-theme="dark"],
:root[data-theme="espana"] {
  --bg: #10141b;
  --card: #171c25;
  --text: #e6eaf1;
  --muted: #8d97a9;
  --line: #283040;
  --accent: #8fb0ff;
  --accent-soft: #1e2a44;
  --ok: #5fd08f;
  --ok-bg: #13291d;
  --almost: #e8b54c;
  --almost-bg: #2c2412;
  --bad: #ff7b70;
  --bad-bg: #331a1a;
  --new: #7aa7ff;
  --heat-1: #ff7a7a;
  --heat-2: #b04444;
  --heat-3: #353b47;
  --heat-4: #2f8a3d;
  --heat-5: #5cd679;
  --heat-ink-1: #0b0b0b;
  --heat-ink-2: #ffffff;
  --heat-ink-3: #ffffff;
  --heat-ink-4: #ffffff;
  --heat-ink-5: #0b0b0b;
  --grid: #232a36;
  --axis: #3a4354;
}

/* España: dark, warm and muted (built on the dark tokens) */
:root[data-theme="espana"] {
  --bg: #1a1413; /* near-black, oxblood tint */
  --card: #231b19;
  --text: #eee4d3; /* old paper */
  --muted: #a8988a;
  --line: #3a2e2a;
  --accent: #cf6f55; /* dimmed rojo teja */
  --accent-soft: #3a231d;
  --gold: #c9a14a; /* dimmed saffron */
  --ok: #8cc47e;
  --ok-bg: #1f2c1c;
  --almost: #d8ae52;
  --almost-bg: #2f2615;
  --bad: #e07a6a;
  --bad-bg: #36191a;
  --grid: #2e2421;
  --axis: #4a3b35;
  --bar: #c9a14a;
  --heat-3: #3d3330;
}

/* Dusk: between light and dark — slate surfaces, light ink, same blue accent */
:root[data-theme="dusk"] {
  --bg: #3f4655;
  --card: #4a5263;
  --text: #f3f5f9;
  --muted: #c9d0dc;
  --line: #626b7e;
  --accent: #b9cdff;
  --accent-soft: #56607a;
  --ok: #8fe0b0;
  --ok-bg: #3f5a50;
  --almost: #f3cf7a;
  --almost-bg: #5d5440;
  --bad: #ffb8b1;
  --bad-bg: #5a4448;
  --new: #a9c4ff;
  --heat-1: #ff8a80;
  --heat-2: #b4545a;
  --heat-3: #5b6476;
  --heat-4: #3f9a55;
  --heat-5: #74dc8f;
  --heat-ink-1: #0b0b0b;
  --heat-ink-2: #ffffff;
  --heat-ink-3: #ffffff;
  --heat-ink-4: #ffffff;
  --heat-ink-5: #0b0b0b;
  --grid: #555e70;
  --axis: #6f7a8f;
}

:root[data-theme="light"] {
  color-scheme: light;
}

:root[data-theme="dark"],
:root[data-theme="dusk"],
:root[data-theme="espana"] {
  color-scheme: dark;
}

/* --- base ---------------------------------------------------------------- */

* {
  box-sizing: border-box;
}

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

body {
  margin: 0 auto;
  max-width: var(--page);
  padding: var(--s5) var(--s5) var(--s7);
  background: var(--bg);
  color: var(--text);
  font: var(--t-base) / 1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

:root[data-theme="espana"] body {
  /* thin, dimmed rojo-gualda-rojo stripe along the top */
  background:
    linear-gradient(#8e3b2f, #8e3b2f) top / 100% 2px no-repeat,
    linear-gradient(#b08a3e, #b08a3e) 0 2px / 100% 3px no-repeat,
    linear-gradient(#8e3b2f, #8e3b2f) 0 5px / 100% 2px no-repeat,
    var(--bg);
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

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

a {
  color: var(--accent);
}

.muted {
  color: var(--muted);
  font-size: var(--t-sm);
}

kbd {
  font: 11px ui-monospace, SFMono-Regular, monospace;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 5px;
  margin-left: var(--s1);
  color: var(--muted);
}

/* --- buttons ------------------------------------------------------------- */

.ghost {
  background: none;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 6px 12px;
  font-size: var(--t-md);
  line-height: 1.2;
}

.ghost:hover {
  background: var(--accent-soft);
}

.ghost.active {
  border-color: var(--accent);
  color: var(--accent);
}

.primary {
  background: var(--accent);
  color: var(--card);
  border: none;
  border-radius: var(--r-sm);
  padding: 10px 20px;
  font-weight: 600;
}

.primary:hover {
  filter: brightness(1.08);
}

.link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: var(--t-sm);
  padding: 0 var(--s1);
}

.button-link {
  display: inline-block;
  text-decoration: none;
  color: var(--text);
}

/* --- header ------------------------------------------------------------- */

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s2);
  margin-bottom: var(--s5);
}

.logo {
  display: inline-flex;
  align-items: baseline;
  gap: var(--s2);
  background: none;
  border: none;
  padding: 0;
  font: 600 var(--t-xl) / 1 var(--font-word);
  color: var(--text);
}

:root[data-theme="espana"] .logo {
  color: var(--gold);
}

.logo:hover {
  color: var(--accent);
}

.score {
  flex: 1;
  text-align: right;
  white-space: nowrap;
  color: var(--muted);
  font-size: var(--t-md);
  font-variant-numeric: tabular-nums;
}

.goal-badge {
  font-size: var(--t-base);
  line-height: 1;
  cursor: default;
}

.goal-badge[hidden] {
  display: none;
}

.goal-badge.pop {
  animation: goal-pop 0.6s ease-out;
}

@keyframes goal-pop {
  0% { transform: scale(0.4); }
  60% { transform: scale(1.5); }
  100% { transform: scale(1); }
}

/* header actions are quiet text buttons */
header .ghost {
  border-color: transparent;
  color: var(--muted);
}

header .ghost:hover {
  color: var(--text);
}

header .ghost.active {
  color: var(--accent);
  border-color: transparent;
  background: var(--accent-soft);
}

.ghost.icon {
  width: 34px;
  padding: 6px 0;
  text-align: center;
}

/* mode tabs: their own row, text + ink underline */
header .modes {
  order: 10;
  flex-basis: 100%;
  display: flex;
  justify-content: safe center;
  gap: var(--s1);
  margin-top: var(--s2);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}

header .modes[hidden] {
  display: none;
}

.modes button {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  padding: var(--s2) var(--s3);
  font-size: var(--t-md);
  color: var(--muted);
  white-space: nowrap;
}

.modes button:hover {
  color: var(--text);
}

.modes button.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* --- the practice card ------------------------------------------------------ */

main#card {
  max-width: var(--card-w);
  margin: 0 auto;
  padding: var(--s6) var(--s6) var(--s5);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}

.prompt {
  text-align: center;
  margin-bottom: var(--s5);
}

/* the headword — the one bold element */
.verb {
  font: 600 var(--t-word) / 1.05 var(--font-word);
  letter-spacing: -0.01em;
}

.verb.english {
  font-size: clamp(28px, 5.5vw, 38px);
}

.speak {
  background: none;
  border: none;
  font-size: var(--t-lg);
  vertical-align: middle;
  opacity: 0.5;
  padding: 0 var(--s1);
}

.speak.small {
  font-size: var(--t-md);
}

.speak:hover {
  opacity: 1;
}

.meaning {
  margin-top: var(--s2);
  font: italic var(--t-lg) / 1.35 var(--font-word);
  color: var(--muted);
}

.meaning.concealed {
  cursor: pointer;
  font-size: var(--t-md);
  opacity: 0.7;
}

.tags {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: var(--s2);
  margin-top: var(--s4);
}

.tag {
  padding: 2px 10px;
  border-radius: 999px;
  font-size: var(--t-sm);
  color: var(--muted);
  background: var(--bg);
}

.tag.person {
  padding: 4px 14px;
  font-size: var(--t-base);
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
}

:root[data-theme="espana"] .tag.person {
  color: var(--gold);
}

/* answer: written on the line */
.answer {
  width: 100%;
  padding: var(--s2) var(--s2) 10px;
  border: none;
  border-bottom: 2px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font: 500 var(--t-xl) / 1.3 var(--font-ui);
  text-align: center;
  outline: none;
  transition: border-color 0.15s, background-color 0.15s;
}

.answer::placeholder {
  color: var(--muted);
  opacity: 0.55;
  font-weight: 400;
}

.answer:focus {
  border-bottom-color: var(--accent);
}

.answer.correct {
  border-bottom-color: var(--ok);
  background: var(--ok-bg);
}

.answer.almost {
  border-bottom-color: var(--almost);
  background: var(--almost-bg);
}

.answer.wrong {
  border-bottom-color: var(--bad);
  background: var(--bad-bg);
}

.answer.revealed {
  border-bottom-style: dashed;
  border-bottom-color: var(--muted);
  color: var(--muted);
}

.answer.small {
  padding: 6px var(--s2);
  font-size: var(--t-lg);
  text-align: left;
}

.flash-ok {
  animation: flash-ok 0.25s ease-out;
}

@keyframes flash-ok {
  from { background: var(--ok-bg); border-bottom-color: var(--ok); }
}

/* accent keys */
.accents {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: var(--s4);
}

.accents[hidden] {
  display: none;
}

.accents button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: var(--r-sm);
  background: var(--card);
  font-size: var(--t-lg);
  line-height: 1;
}

.accents button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.reveal-row {
  display: flex;
  justify-content: center;
  margin-top: var(--s3);
}

.reveal-row[hidden],
#reveal[hidden] {
  display: none;
}

.reveal-row .ghost {
  border-color: transparent;
  font-size: var(--t-sm);
  color: var(--muted);
}

/* feedback */
.feedback {
  margin-top: var(--s5);
  text-align: center;
  font-size: var(--t-lg);
  font-weight: 600;
}

.feedback.correct { color: var(--ok); }
.feedback.almost { color: var(--almost); }
.feedback.wrong { color: var(--bad); }
.feedback.revealed { color: var(--text); }

/* grammar hint: a margin note in red pen */
.rule {
  max-width: 460px;
  margin: var(--s4) auto 0;
  padding: var(--s3) var(--s4);
  border-left: 3px solid var(--bad);
  border-radius: 0 var(--r-md) var(--r-md) 0;
  background: var(--bg);
  font-size: var(--t-md);
}

.rule-line {
  font-weight: 600;
  margin-bottom: 2px;
}

.rule-note {
  color: var(--muted);
}

/* conjugation table */
.conj {
  margin: var(--s5) auto 0;
  border-collapse: collapse;
  font-size: var(--t-md);
}

.conj caption {
  margin-bottom: var(--s2);
  color: var(--muted);
  font-size: var(--t-sm);
}

.conj tr {
  cursor: pointer;
}

.conj td {
  padding: 5px var(--s4);
  border-bottom: 1px solid var(--line);
}

.conj tr:last-child td {
  border-bottom: none;
}

.conj td:first-child {
  color: var(--muted);
  text-align: right;
}

.conj td:last-child {
  font-family: var(--font-word);
  font-size: var(--t-base);
}

.conj tr:hover td {
  background: var(--bg);
}

.conj tr.asked td {
  font-weight: 700;
  color: var(--accent);
}

.conj mark {
  background: none;
  color: var(--bad);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.hint {
  margin: var(--s5) 0 0;
  text-align: center;
}

/* --- modes ---------------------------------------------------------------- */

/* Frase */
.sentence {
  margin: 0 0 var(--s2);
  font: var(--t-xl) / 1.5 var(--font-word);
}

.blank {
  display: inline-block;
  min-width: 3.5em;
  border-bottom: 2px solid var(--accent);
  color: var(--accent);
  font-weight: 600;
  text-align: center;
}

.blank.correct { color: var(--ok); border-color: var(--ok); }
.blank.almost { color: var(--almost); border-color: var(--almost); }
.blank.wrong { color: var(--bad); border-color: var(--bad); }
.blank.revealed { color: var(--text); border-color: var(--bad); border-style: dashed; }

/* Tabla */
.fill {
  width: 100%;
  border-collapse: collapse;
}

.fill td {
  padding: 5px var(--s2);
}

.fill td:first-child {
  width: 1%;
  white-space: nowrap;
  color: var(--muted);
  font-size: var(--t-md);
  text-align: right;
}

.fill td:last-child {
  width: 100%;
}

.fix {
  padding-left: var(--s2);
  font-weight: 600;
  font-size: var(--t-md);
}

.fix:empty {
  display: none;
}

.fix.almost { color: var(--almost); }
.fix.wrong { color: var(--bad); }

/* Reverso */
.persons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: var(--s4);
}

.persons button {
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  font-size: var(--t-sm);
}

.persons button.selected {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--card);
}

/* Escuchar */
.listen-buttons {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: var(--s3);
}

.play {
  width: 88px;
  height: 88px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: var(--accent-soft);
  font-size: 34px;
}

.play.slow {
  width: 52px;
  height: 52px;
  border-color: var(--line);
  background: var(--card);
  font-size: var(--t-lg);
}

.play:active {
  transform: scale(0.96);
}

/* Rápido */
.speed-bar {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--grid);
}

.speed-fill {
  width: 100%;
  height: 100%;
  background: var(--accent);
  transition: width 0.25s linear;
}

.speed-top {
  display: flex;
  justify-content: space-between;
  margin: var(--s2) 0 var(--s5);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.speed-score b {
  color: var(--ok);
  font-size: var(--t-lg);
}

.speed-panel {
  text-align: center;
}

.speed-panel .big {
  margin: var(--s2) 0;
  font: 600 64px / 1 var(--font-word);
}

/* session summary */
#summary h2,
.summary-title {
  margin: 0 0 var(--s4);
  text-align: center;
  font: 600 var(--t-xl) / 1.2 var(--font-word);
}

.summary-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: var(--s2);
  margin-bottom: var(--s4);
}

.summary-tiles div {
  padding: var(--s3) var(--s1);
  border-radius: var(--r-md);
  background: var(--bg);
  text-align: center;
}

.summary-tiles b {
  display: block;
  font-size: var(--t-xl);
  font-variant-numeric: tabular-nums;
}

.summary-tiles span {
  font-size: var(--t-xs);
  color: var(--muted);
}

.summary-list h3 {
  margin: var(--s4) 0 var(--s1);
  font-size: var(--t-md);
}

.summary-list ul {
  margin: 0;
  padding-left: 18px;
  font-size: var(--t-md);
}

#summary > p.muted {
  text-align: center;
}

.summary-actions {
  display: flex;
  justify-content: center;
  gap: var(--s3);
  margin-top: var(--s5);
}

/* --- Vocab (Anki cards) ----------------------------------------------------- */

.vocab-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s3);
  margin: calc(-1 * var(--s2)) 0 var(--s5);
  padding-bottom: var(--s3);
  border-bottom: 1px solid var(--line);
}

.vocab-bar select {
  flex: 1;
  min-width: 0;
  max-width: 100%;
  padding: 6px var(--s2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: var(--t-md);
}

.vocab-counts {
  font-size: var(--t-md);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--muted);
}

.vocab-counts .c-new { color: var(--new); }
.vocab-counts .c-learn { color: var(--bad); }
.vocab-counts .c-review { color: var(--ok); }

.vocab-card.classic {
  min-height: 160px;
}

.vocab-type[hidden] {
  display: none;
}

.vocab-prompt {
  margin-bottom: var(--s5);
  text-align: center;
  font: 600 clamp(26px, 5vw, 34px) / 1.2 var(--font-word);
}

.vocab-prompt .sub {
  display: block;
  margin-top: var(--s2);
  font: 400 var(--t-sm) var(--font-ui);
  color: var(--muted);
}

#vocab-feedback {
  margin-bottom: var(--s3);
}

.vocab-actions:empty {
  display: none;
}

.vocab-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--s2);
  margin-top: var(--s5);
}

.rate {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 80px;
  padding: var(--s2) var(--s3);
  border: 1px solid var(--line);
  border-top-width: 3px;
  border-radius: var(--r-md);
  background: var(--card);
  font-size: var(--t-md);
  font-weight: 600;
}

.rate small {
  font-size: var(--t-xs);
  font-weight: 400;
  color: var(--muted);
}

.rate.again { border-top-color: var(--bad); }
.rate.hard { border-top-color: var(--almost); }
.rate.good { border-top-color: var(--ok); }
.rate.easy { border-top-color: var(--new); }

.rate:hover {
  background: var(--bg);
}

.rate.suggested {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.vocab-status {
  min-height: 1.2em;
  margin: var(--s3) 0 0;
  text-align: center;
}

/* --- full-screen views: Stats + Ajustes ------------------------------------ */

.view {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}

#stats-view {
  display: flex;
  flex-direction: column;
  gap: var(--s4);
  background: none;
  border: none;
}

#stats-view[hidden] {
  display: none;
}

#settings {
  min-height: 70vh;
  padding: 0 var(--s6) var(--s5);
}

.tabs {
  display: flex;
  gap: var(--s1);
  margin: 0 calc(-1 * var(--s6)) var(--s5);
  padding: 0 var(--s5);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs button {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  padding: var(--s4) var(--s3) var(--s3);
  font-size: var(--t-md);
  color: var(--muted);
  white-space: nowrap;
}

.tabs button:hover {
  color: var(--text);
}

.tabs button.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.view-hint {
  margin: var(--s5) 0 0;
  text-align: center;
}

/* forms in Ajustes */
fieldset {
  min-width: 0;
  margin: 0 0 var(--s5);
  padding: 0;
  border: none;
}

.tab-panel fieldset {
  margin-bottom: var(--s6);
}

legend {
  margin-bottom: var(--s2);
  padding: 0;
  font-size: var(--t-base);
  font-weight: 600;
}

fieldset > label,
.options label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 var(--s4) var(--s1) 0;
  font-size: var(--t-md);
}

/* settings with their own value (day start, goal, session length) get a line each */
fieldset > label:has(select, input.num) {
  display: flex;
  flex-wrap: wrap;
  margin-top: var(--s2);
}

fieldset.stack > label:not(.row) {
  display: flex;
  margin-right: 0;
}

fieldset > p.muted {
  margin: 0 0 var(--s3);
  max-width: 62ch;
}

input[type="checkbox"],
input[type="radio"],
input[type="range"] {
  accent-color: var(--accent);
}

.group-head {
  margin-top: var(--s3);
  font-size: var(--t-sm);
  color: var(--muted);
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s2);
  margin: var(--s2) 0;
  font-size: var(--t-md);
}

.row select,
.row input[type="text"],
.add-editor input,
input.num {
  min-width: 0;
  padding: 6px var(--s2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.row select,
.row input[type="text"],
.row input[type="range"] {
  flex: 1;
}

input.num {
  width: 72px;
}

.anki-body > label:not(.row),
.stack-list label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--t-md);
}

.add-group {
  margin: var(--s4) 0 var(--s1);
  font-size: var(--t-sm);
  color: var(--muted);
}

.add-row {
  padding: var(--s2) 0;
  border-bottom: 1px solid var(--line);
  font-size: var(--t-md);
}

.add-row-head {
  display: flex;
  align-items: center;
  gap: var(--s2);
}

.add-row-head .grow {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.add-editor {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px var(--s3);
  align-items: center;
  max-width: 380px;
  margin: var(--s3) 0 var(--s1);
}

.add-warn {
  margin: var(--s1) 0;
  color: var(--almost);
  font-size: var(--t-sm);
}

.field-map {
  padding: var(--s3) 0;
  border-bottom: 1px solid var(--line);
  font-size: var(--t-md);
}

.field-map .row select {
  flex: 0 1 auto;
}

#lan-urls a {
  display: block;
  margin: var(--s1) 0;
  font: var(--t-sm) ui-monospace, SFMono-Regular, monospace;
  color: var(--accent);
  word-break: break-all;
}

/* --- Stats --------------------------------------------------------------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: var(--s3);
}

.tile,
.stat-section {
  padding: var(--s4) var(--s5);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}

.tile {
  padding: var(--s4);
}

.tile-label {
  font-size: var(--t-sm);
  color: var(--muted);
}

.tile-value {
  font: 600 var(--t-2xl) / 1.2 var(--font-word);
  font-variant-numeric: tabular-nums;
}

.tile-sub {
  font-size: var(--t-xs);
  color: var(--muted);
}

.goal-track {
  height: 6px;
  margin-top: var(--s2);
  overflow: hidden;
  border-radius: 999px;
  background: var(--grid);
}

.goal-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--s-correct);
}

.stat-section h2 {
  margin: 0 0 var(--s3);
  font: 600 var(--t-lg) / 1.3 var(--font-word);
}

.stat-section > p.muted {
  margin: calc(-1 * var(--s2)) 0 var(--s3);
}

.stat-cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--s4);
}

.stat-cols > div {
  display: flex;
  flex-direction: column;
  gap: var(--s4);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s1) var(--s4);
  margin-bottom: var(--s2);
  font-size: var(--t-xs);
  color: var(--muted);
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.swatch.heat-empty {
  box-shadow: inset 0 0 0 1px var(--axis);
}

.chart {
  display: block;
  width: 100%;
  height: auto;
}

.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; }
.chart .hit { fill: transparent; }
.chart .hit:hover { fill: var(--text); fill-opacity: 0.05; }

.chart .goal-line {
  stroke: var(--text);
  stroke-opacity: 0.5;
  stroke-width: 1;
  stroke-dasharray: 4 3;
}

.chart .goal-label {
  fill: var(--muted);
  font-size: 11px;
}

.s-correct { fill: var(--s-correct); background: var(--s-correct); }
.s-almost { fill: var(--s-almost); background: var(--s-almost); }
.s-wrong { fill: var(--s-wrong); background: var(--s-wrong); }

.heat-scroll {
  overflow-x: auto;
}

.heat {
  border-collapse: separate;
  border-spacing: 2px;
  font-size: var(--t-xs);
  font-variant-numeric: tabular-nums;
}

.heat th {
  padding: 0 6px;
  font-weight: 500;
  color: var(--muted);
}

.heat tbody th {
  text-align: right;
  color: var(--text);
}

.heat td {
  width: 52px;
  height: 26px;
  border-radius: 4px;
  text-align: center;
}

.heat td.heat-empty {
  color: var(--muted);
  box-shadow: inset 0 0 0 1px var(--line);
}

.heat td.heat-total {
  width: auto;
  padding: 0 6px;
  color: var(--muted);
}

.heat-1 { background: var(--heat-1); color: var(--heat-ink-1); }
.heat-2 { background: var(--heat-2); color: var(--heat-ink-2); }
.heat-3 { background: var(--heat-3); color: var(--heat-ink-3); }
.heat-4 { background: var(--heat-4); color: var(--heat-ink-4); }
.heat-5 { background: var(--heat-5); color: var(--heat-ink-5); }

.bars {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(90px, 40%) 1fr auto;
  align-items: center;
  gap: var(--s2);
  font-size: var(--t-sm);
}

.bar-label {
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  height: 10px;
  border-radius: 0 4px 4px 0;
  background: var(--grid);
}

.bar-fill {
  display: block;
  height: 100%;
  border-radius: 0 4px 4px 0;
  background: var(--bar);
}

.bar-value {
  min-width: 64px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.patterns {
  display: flex;
  flex-direction: column;
  gap: var(--s4);
}

.pattern-examples {
  margin-top: 2px;
  font-size: var(--t-sm);
}

.pattern-tip {
  font-size: var(--t-xs);
  color: var(--muted);
}

.mistakes {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: var(--t-md);
}

.mistakes li {
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}

.mistakes li:last-child {
  border-bottom: none;
}

.mistakes .given {
  text-decoration: line-through;
  text-decoration-color: var(--bad);
}

.mistakes .given.wrong { color: var(--bad); }
.mistakes .given.almost { color: var(--almost); }

.tooltip {
  position: fixed;
  z-index: 10;
  max-width: 280px;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  background: var(--text);
  color: var(--bg);
  font-size: var(--t-xs);
  pointer-events: none;
}

/* --- small screens --------------------------------------------------------- */

@media (max-width: 560px) {
  body {
    padding: var(--s4) var(--s3) var(--s6);
  }

  header {
    margin-bottom: var(--s4);
  }

  .logo {
    font-size: var(--t-lg);
  }

  header {
    gap: 2px;
  }

  .score {
    font-size: var(--t-sm);
  }

  header .ghost {
    padding: 6px var(--s2);
    font-size: var(--t-sm);
  }

  .ghost.icon {
    width: 30px;
  }

  header .modes {
    justify-content: flex-start;
  }

  main#card {
    padding: var(--s5) var(--s4) var(--s4);
    border-radius: var(--r-md);
  }

  #settings {
    padding: 0 var(--s4) var(--s4);
  }

  .tabs {
    margin: 0 calc(-1 * var(--s4)) var(--s4);
    padding: 0 var(--s2);
  }

  .stat-section {
    padding: var(--s4);
  }

  .conj td {
    padding: 5px var(--s3);
  }
}

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

/* --- Añadir (new Anki cards) ------------------------------------------------ */

.add-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s3);
  margin: calc(-1 * var(--s2)) 0 var(--s5);
  padding-bottom: var(--s3);
  border-bottom: 1px solid var(--line);
}

.add-bar select {
  flex: 1;
  min-width: 0;
  padding: 6px var(--s2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: var(--t-md);
}

.add-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--t-md);
  color: var(--muted);
}

.add-form {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: baseline;
  gap: var(--s3) var(--s4);
}

.add-form label {
  color: var(--muted);
  font-size: var(--t-md);
  text-align: right;
}

.add-form .answer.small {
  font-family: var(--font-word);
  font-size: var(--t-xl);
}

.add-form .answer.tags-input {
  font-family: var(--font-ui);
  font-size: var(--t-md);
}

.add-dupe {
  margin: var(--s3) 0 0;
  padding: var(--s2) var(--s3);
  border-left: 3px solid var(--almost);
  background: var(--almost-bg);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  font-size: var(--t-md);
}

.add-dupe[hidden],
.add-suggest[hidden] {
  display: none;
}

.add-suggest {
  margin: var(--s4) 0 0;
  padding: 0;
  list-style: none;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
}

.add-suggest li + li {
  border-top: 1px solid var(--line);
}

.add-suggest button {
  display: flex;
  align-items: baseline;
  gap: var(--s3);
  width: 100%;
  padding: var(--s2) var(--s3);
  border: none;
  background: none;
  text-align: left;
}

.add-suggest button:hover,
.add-suggest button:focus-visible {
  background: var(--accent-soft);
}

.add-suggest .w {
  font-family: var(--font-word);
  font-size: var(--t-lg);
  font-weight: 600;
}

.add-suggest .d {
  flex: 1;
  min-width: 0;
  color: var(--muted);
  font-size: var(--t-md);
}

.add-suggest .m {
  color: var(--muted);
  font-size: var(--t-xs);
  white-space: nowrap;
}

.add-actions {
  display: flex;
  justify-content: center;
  gap: var(--s3);
  margin-top: var(--s5);
}

.add-status {
  min-height: 1.2em;
  margin: var(--s3) 0 0;
  text-align: center;
}

.add-fields {
  margin: var(--s1) 0 0;
  text-align: center;
  font-size: var(--t-xs);
}

@media (max-width: 560px) {
  .add-form {
    grid-template-columns: 1fr;
    gap: var(--s1);
  }

  .add-form label {
    text-align: left;
    margin-top: var(--s2);
  }
}

/* --- Hoy (header) ------------------------------------------------------------ */

header .ghost.hoy {
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
}

header .ghost.hoy.active {
  font-variant-numeric: tabular-nums;
}

/* --- Leer (reading) ------------------------------------------------------------ */

.read-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  margin: calc(-1 * var(--s2)) 0 var(--s5);
  padding-bottom: var(--s3);
  border-bottom: 1px solid var(--line);
}

.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  overflow: hidden;
}

.seg button {
  border: none;
  border-radius: 0;
  background: none;
  padding: 6px var(--s3);
  font-size: var(--t-md);
  color: var(--muted);
}

.seg button + button {
  border-left: 1px solid var(--line);
}

.seg button.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.read-meta {
  font-size: var(--t-sm);
}

.read-paste[hidden],
.read-new[hidden],
.read-word[hidden] {
  display: none;
}

.read-paste textarea {
  width: 100%;
  box-sizing: border-box;
  padding: var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--card);
  color: var(--text);
  font: var(--t-base) / 1.5 var(--font-word);
  resize: vertical;
}

.read-paste-actions {
  display: flex;
  justify-content: center;
  margin: var(--s3) 0 var(--s5);
}

.read-saved {
  margin: 0;
  padding: 0;
  list-style: none;
}

.read-saved li {
  display: flex;
  align-items: center;
  border-top: 1px solid var(--line);
}

.read-saved-open {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s2) var(--s1);
  border: none;
  background: none;
  text-align: left;
  color: var(--text);
}

.read-saved-open span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.read-saved-open:hover {
  color: var(--accent);
}

.read-text {
  font: var(--t-lg) / 1.65 var(--font-word);
}

.read-sent {
  padding: var(--s2) 0;
}

.read-sent + .read-sent {
  border-top: 1px dashed var(--line);
}

.read-sent p,
.read-para {
  margin: 0;
}

.read-para + .read-para {
  margin-top: var(--s4);
}

.read-sent .link {
  font-family: var(--font-ui);
  font-size: var(--t-xs);
  vertical-align: middle;
}

.read-en {
  margin-top: var(--s1);
  color: var(--muted);
  font: var(--t-md) / 1.4 var(--font-ui);
}

.read-en[hidden] {
  display: none;
}

.w {
  cursor: pointer;
  border-radius: 3px;
}

.w:hover {
  background: var(--accent-soft);
}

.w.new {
  text-decoration: underline dotted var(--almost);
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}

.w.sel,
.chip.sel {
  background: var(--accent-soft);
  color: var(--accent);
}

.read-new {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s1) var(--s2);
  margin-top: var(--s4);
  font-size: var(--t-sm);
}

.chip {
  padding: 2px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: none;
  font: var(--t-md) var(--font-word);
  color: var(--text);
}

.read-word {
  position: sticky;
  bottom: var(--s2);
  margin-top: var(--s4);
  padding: var(--s3) var(--s4);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-md);
  background: var(--card);
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.12);
}

.read-word-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s2);
}

.read-word-head b {
  font: 600 var(--t-xl) var(--font-word);
}

.read-word-head .grow {
  flex: 1;
}

.tag.new {
  color: var(--almost);
  background: var(--almost-bg);
}

.tag.known {
  color: var(--ok);
  background: var(--ok-bg);
}

.read-meanings {
  margin: var(--s2) 0;
  padding-left: var(--s4);
  font-size: var(--t-md);
}

.read-meanings small {
  font-size: var(--t-xs);
}

.read-word-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s3);
  font-size: var(--t-sm);
}

.read-add {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  align-items: end;
  gap: var(--s3);
  margin-top: var(--s3);
}

.read-add .answer.small {
  font: var(--t-base) var(--font-word);
  text-align: left;
}

.read-actions {
  display: flex;
  justify-content: center;
  gap: var(--s3);
  margin-top: var(--s5);
}

.read-status {
  min-height: 1.2em;
  margin: var(--s3) 0 0;
  text-align: center;
}

@media (max-width: 560px) {
  .read-add {
    grid-template-columns: 1fr;
  }

  .read-text {
    font-size: var(--t-base);
  }
}

/* 🔊 inside the Vocab typing answer box */
#vocab-form {
  position: relative;
}

#vocab-form .speak {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
}

/* Classic: 🔊 at the end of the card (where the answer is) */
.vocab-card-wrap {
  position: relative;
}

.vocab-card-wrap > .speak {
  position: absolute;
  right: 0;
  bottom: 0;
}

.vocab-card-wrap > .speak[style*="top"] {
  bottom: auto;
  transform: translateY(-50%);
}

.vocab-bar .ghost.small {
  padding: 3px 10px;
  font-size: var(--t-sm);
  color: var(--muted);
}

.vocab-bar .ghost.small[hidden] {
  display: none;
}

/* --- picture clues (Vocab) ------------------------------------------------------ */

.vocab-clue {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s2);
  margin: var(--s3) 0;
}

.vocab-clue[hidden] {
  display: none;
}

.clue-img {
  width: 150px;
  height: 150px;
  image-rendering: pixelated;
}

.clue-canvas {
  width: min(300px, 80vw);
  height: auto;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  touch-action: none;
  cursor: crosshair;
}

.clue-palette {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--s2);
}

.swatch {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  font-size: var(--t-sm);
  color: var(--muted);
}

.swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.clue-actions {
  display: flex;
  gap: var(--s2);
}

/* Ajustes → Anki: buried notes */
.buried-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.buried-list li {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s1) 0;
  border-top: 1px solid var(--line);
}

.buried-list .bw {
  font-family: var(--font-word);
  font-size: var(--t-base);
}

.buried-list .muted {
  flex: 1;
  min-width: 0;
  font-size: var(--t-sm);
}

/* --- login (AUTH=on) ------------------------------------------------------------ */

#card.login-card {
  max-width: 360px;
  margin-top: 12vh;
}

.login-card .logo {
  display: block;
  margin: 0 0 var(--s5);
  text-align: center;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}

.login-form label {
  margin-top: var(--s2);
  color: var(--muted);
  font-size: var(--t-md);
}

.login-form .answer.small {
  font-size: var(--t-lg);
  text-align: left;
}

.login-form .primary {
  margin-top: var(--s4);
}

.login-error {
  min-height: 1.2em;
  margin: 0;
  color: var(--bad);
  font-size: var(--t-md);
  text-align: center;
}

/* Ajustes → General: keyboard tips off */
.no-tips .hint,
.no-tips .view-hint,
.no-tips kbd {
  display: none;
}
