/* FonoRP · Acta del tribunal
   Mundo: papelería de oposición. Papel de oficio, filetes de tinta de 1.5px, casillas.
   Tinta de tampón violeta = marca y sello APTO. Boli rojo del corrector = error y sello REVISAR.
   Formas: casillas y campos 3px, controles 4px, sello 6px. Nada en píldora. */

@font-face {
  font-family: 'Archivo';
  src: url(fonts/archivo-latin-standard-normal.woff2) format('woff2-variations');
  font-weight: 100 900; font-stretch: 62% 125%; font-display: swap;
}
@font-face {
  font-family: 'IPA';
  src: url(fonts/noto-sans-latin-wght-normal.woff2) format('woff2-variations');
  font-weight: 100 900; font-display: swap; unicode-range: U+0000-00FF;
}
@font-face {
  font-family: 'IPA';
  src: url(fonts/noto-sans-ipa-wght.woff2) format('woff2-variations');
  font-weight: 100 900; font-display: swap; unicode-range: U+014B, U+0250-02FF, U+0329, U+1D00-1DBF;
}
@font-face {
  font-family: 'IPA';
  src: url(fonts/noto-sans-theta-wght.woff2) format('woff2-variations');
  font-weight: 100 900; font-display: swap; unicode-range: U+03B8;
}

:root {
  color-scheme: light dark;
  /* Papel y tinta */
  --bg: #eef1f5;
  --surface: #fbfcfd;
  --surface-2: #dfe5ee;
  --ink: #14171c;
  --muted: #464d58;
  --faint: #59616d;
  --rule: #14171c;
  --rule-soft: rgb(20 23 28 / .16);
  /* Tampón (marca) */
  --stamp: #4a3aa6;
  --stamp-ink: #ffffff;
  --stamp-soft: rgb(74 58 166 / .12);
  --stamp-hover: #3c2e8c;
  /* Boli rojo del corrector */
  --pen: #bf2f1b;
  --pen-soft: rgb(191 47 27 / .1);
  --warn: #8a5808;
  --warn-soft: rgb(138 88 8 / .12);
  /* Bandeja de la tabla fonémica */
  --tray: #14171c;
  --z-vowel: #d9e1ec;
  --z-diph: #cdc5f3;
  --z-cons: #f6f7f9;
  --z-ink: #14171c;
  --z-ex: #3f4752;
  --z-extra-line: #8a93a1;
  --z-extra-ink: #eef1f5;
  --z-mark: #272c35;
  --z-mark-ink: #c3b9f7;
  --z-mark-ex: #b3bac5;
  --shadow: 0 1px 2px rgb(20 23 40 / .06), 0 10px 28px rgb(20 23 40 / .07);

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-stamp: cubic-bezier(0.2, 1.3, 0.4, 1);

  --font-ui: 'Archivo', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-ipa: 'IPA', 'Noto Sans', 'Lucida Sans Unicode', 'Arial Unicode MS', sans-serif;

  --gutter: 16px;
  --line: 1.5px;
  --r-box: 3px;
  --r-ctl: 4px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

/* Modo oscuro: sigue al sistema salvo que el usuario fuerce un tema (data-theme en <html>). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111318;
    --surface: #191c23;
    --surface-2: #252a35;
    --ink: #e9edf3;
    --muted: #b0b8c4;
    --faint: #98a1ae;
    --rule: #aeb7c4;
    --rule-soft: rgb(233 237 243 / .14);
    --stamp: #ab9ff2;
    --stamp-ink: #17122f;
    --stamp-soft: rgb(171 159 242 / .15);
    --stamp-hover: #c0b6f6;
    --pen: #ff7d61;
    --pen-soft: rgb(255 125 97 / .13);
    --warn: #e8b04b;
    --warn-soft: rgb(232 176 75 / .14);
    --tray: #08090c;
    --z-vowel: #2e3a4d;
    --z-diph: #3f3577;
    --z-cons: #1a1d24;
    --z-ink: #e9edf3;
    --z-ex: #aab3bf;
    --z-extra-line: #6b7482;
    --z-extra-ink: #e9edf3;
    --z-mark: #171a21;
    --z-mark-ink: #ab9ff2;
    --z-mark-ex: #a3abb7;
    --shadow: 0 1px 2px rgb(0 0 0 / .35), 0 10px 28px rgb(0 0 0 / .3);
  }
}
:root[data-theme="dark"] {
  --bg: #111318;
  --surface: #191c23;
  --surface-2: #252a35;
  --ink: #e9edf3;
  --muted: #b0b8c4;
  --faint: #98a1ae;
  --rule: #aeb7c4;
  --rule-soft: rgb(233 237 243 / .14);
  --stamp: #ab9ff2;
  --stamp-ink: #17122f;
  --stamp-soft: rgb(171 159 242 / .15);
  --stamp-hover: #c0b6f6;
  --pen: #ff7d61;
  --pen-soft: rgb(255 125 97 / .13);
  --warn: #e8b04b;
  --warn-soft: rgb(232 176 75 / .14);
  --tray: #08090c;
  --z-vowel: #2e3a4d;
  --z-diph: #3f3577;
  --z-cons: #1a1d24;
  --z-ink: #e9edf3;
  --z-ex: #aab3bf;
  --z-extra-line: #6b7482;
  --z-extra-ink: #e9edf3;
  --z-mark: #171a21;
  --z-mark-ink: #ab9ff2;
  --z-mark-ex: #a3abb7;
  --shadow: 0 1px 2px rgb(0 0 0 / .35), 0 10px 28px rgb(0 0 0 / .3);
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; caret-color: var(--stamp); scrollbar-color: var(--rule-soft) transparent; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 16px/1.45 var(--font-ui); font-stretch: 96%;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; overscroll-behavior: none;
}
::selection { background: var(--stamp-soft); color: var(--ink); }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--stamp); outline-offset: 2px; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.ipa { font-family: var(--font-ipa); }
.icon { width: 1.25em; height: 1.25em; fill: currentColor; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
[hidden] { display: none !important; }

/* Etiqueta de campo de formulario: pequeña, condensada, sin mayúsculas forzadas */
.field-label { font-size: 12.5px; font-weight: 600; font-stretch: 80%; color: var(--muted); letter-spacing: .01em; line-height: 1.2; }

/* ---------- Vistas ---------- */
.app { min-height: 100dvh; }
.view { display: none; }
body[data-view="home"] .view-home,
body[data-view="drill"] .view-drill,
body[data-view="summary"] .view-summary,
body[data-view="stats"] .view-stats { display: grid; animation: view-in 240ms var(--ease-out); }
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } }

/* ---------- Botones ---------- */
.btn-primary, .btn-secondary, .btn-ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 52px; padding: 0 20px; border-radius: var(--r-ctl);
  font-weight: 700; font-stretch: 88%; font-size: 17px; white-space: nowrap;
  transition: transform 140ms var(--ease-out), background-color 160ms ease, opacity 160ms ease;
}
.btn-primary { background: var(--stamp); color: var(--stamp-ink); }
.btn-secondary { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 var(--line) var(--rule); }
.btn-ghost { color: var(--muted); }
.btn-primary:active, .btn-secondary:active, .btn-ghost:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: .4; cursor: default; transform: none; }
.icon-btn {
  width: 44px; height: 44px; border-radius: var(--r-ctl); display: grid; place-items: center; color: var(--ink); flex: none;
  transition: transform 140ms var(--ease-out), background-color 160ms ease;
}
.icon-btn:active { transform: scale(0.92); background: var(--surface-2); }
@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover:not(:disabled) { background: var(--stamp-hover); }
  .btn-secondary:hover { background: var(--surface-2); }
  .btn-ghost:hover { color: var(--ink); }
  .icon-btn:hover { background: var(--surface-2); }
}

/* ---------- Inicio ---------- */
.view-home {
  max-width: 560px; margin: 0 auto; min-height: 100dvh; align-content: start; gap: 28px;
  padding: calc(var(--safe-t) + 36px) var(--gutter) calc(var(--safe-b) + 24px);
}
.home-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { margin: 0; line-height: 0; }
.btn-record {
  display: inline-flex; align-items: center; gap: 7px; min-height: 44px; padding: 0 12px 0 10px; border-radius: var(--r-ctl);
  font-size: 15px; font-weight: 700; font-stretch: 88%; color: var(--ink); box-shadow: inset 0 0 0 var(--line) var(--rule);
  transition: transform 140ms var(--ease-out), background-color 160ms ease;
}
.btn-record .icon { color: var(--stamp); }
.btn-record:active { transform: scale(0.97); }
@media (hover: hover) and (pointer: fine) { .btn-record:hover { background: var(--surface-2); } }
.brand-logo { height: 58px; width: auto; color: var(--stamp); }
.brand-word { fill: var(--ink); }
.home-sub { margin: 14px 0 0; color: var(--muted); font-size: 17px; max-width: 34ch; }

.specimen {
  background: var(--surface); box-shadow: inset 0 0 0 var(--line) var(--rule); border-radius: var(--r-box);
  padding: 10px 14px 14px; display: grid; gap: 6px; min-height: 104px;
}
.specimen-row { display: grid; gap: 2px; }
.specimen-word { font-size: 15px; font-weight: 600; transition: opacity 200ms ease; }
.specimen-ipa { font-size: clamp(30px, 9vw, 40px); line-height: 1.2; white-space: nowrap; overflow: hidden; }
.specimen-ipa .tok { display: inline-block; animation: tok-in 180ms var(--ease-out) both; }
.specimen.is-leaving .specimen-word, .specimen.is-leaving #specimen-ipa { opacity: 0; transition: opacity 180ms ease; }
.slash { color: var(--stamp); font-family: var(--font-ipa); font-weight: 300; }

.setup { display: grid; gap: 22px; }
.field .field-label { margin-bottom: 8px; padding: 0; }
.field-row { display: grid; grid-template-columns: 1fr auto; gap: 16px; }

/* Patrones: casillas de formulario que se marcan con una cruz */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px; padding: 0 12px 0 10px; border-radius: var(--r-ctl); display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface); box-shadow: inset 0 0 0 1px var(--rule-soft); font-size: 15px; font-weight: 500;
  transition: transform 140ms var(--ease-out), box-shadow 160ms ease, background-color 160ms ease;
}
.chip-box {
  width: 16px; height: 16px; flex: none; border: var(--line) solid var(--rule); border-radius: 2px; position: relative;
}
.chip-box::before, .chip-box::after {
  content: ''; position: absolute; left: 50%; top: 50%; width: 15px; height: 2px; border-radius: 1px; background: var(--stamp);
  transform: translate(-50%, -50%) rotate(45deg) scaleX(0); transition: transform 160ms var(--ease-out);
}
.chip-box::after { transform: translate(-50%, -50%) rotate(-45deg) scaleX(0); transition-delay: 60ms; }
.chip[aria-checked="true"] { box-shadow: inset 0 0 0 var(--line) var(--rule); }
.chip[aria-checked="true"] .chip-box::before { transform: translate(-50%, -50%) rotate(45deg) scaleX(1); }
.chip[aria-checked="true"] .chip-box::after { transform: translate(-50%, -50%) rotate(-45deg) scaleX(1); }
.chip-count { font-size: 12.5px; color: var(--faint); font-variant-numeric: tabular-nums; }
.chip:active { transform: scale(0.97); }
.chip .ipa { font-size: 15px; }
.pattern-desc { margin: 10px 2px 0; font-size: 14px; color: var(--muted); min-height: 1.45em; }

.segmented {
  display: inline-grid; grid-auto-flow: column; grid-auto-columns: minmax(44px, auto);
  padding: 3px; border-radius: var(--r-ctl); background: var(--surface-2); position: relative; isolation: isolate;
}
.seg { min-height: 38px; padding: 0 14px; border-radius: 3px; font-size: 15px; font-weight: 600; color: var(--muted); transition: color 200ms ease; position: relative; z-index: 1; }
.seg[aria-checked="true"] { color: var(--ink); }
.seg-thumb {
  position: absolute; top: 3px; bottom: 3px; left: 0; border-radius: 3px; z-index: 0;
  background: var(--surface); box-shadow: inset 0 0 0 var(--line) var(--rule);
  transition: transform 240ms var(--ease-out), width 240ms var(--ease-out);
}
.segmented.mode { display: grid; grid-auto-columns: 1fr; }

.btn-start {
  width: 100%; justify-content: space-between; padding: 0 20px 0 22px;
  position: sticky; bottom: calc(var(--safe-b) + 12px); z-index: 3; box-shadow: 0 0 0 12px var(--bg);
}
.btn-count { margin-left: auto; font-weight: 500; opacity: .8; font-variant-numeric: tabular-nums; }
.setup-empty { margin: -8px 0 0; color: var(--pen); font-size: 14px; }

/* ---------- Ejercicio ---------- */
.view-drill { height: 100dvh; grid-template-rows: auto minmax(0, 1fr) auto; padding-top: var(--safe-t); }
.topbar { display: flex; align-items: stretch; gap: 6px; padding: 8px var(--gutter) 4px 6px; }
.formhead {
  flex: 1; display: grid; grid-template-columns: auto auto minmax(0, 1fr); min-width: 0;
  box-shadow: inset 0 0 0 var(--line) var(--rule); border-radius: var(--r-box); background: var(--surface);
}
.fh-cell { padding: 5px 9px 6px; display: grid; align-content: start; gap: 1px; min-width: 0; }
.fh-cell + .fh-cell { box-shadow: inset var(--line) 0 0 var(--rule); }
.fh-val { font-size: 15px; font-weight: 700; font-stretch: 85%; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fh-pats { font-weight: 600; }
.progress { list-style: none; margin: 3px 0 0; padding: 0; display: flex; gap: 3px; }
.progress li { width: 8px; height: 8px; border: 1.5px solid var(--rule); border-radius: 1px; transition: background-color 200ms ease, border-color 200ms ease; }
.progress li.is-current { border-color: var(--stamp); background: var(--stamp-soft); }
.progress li.is-ok, .progress li.is-warn { background: var(--ink); }
.progress li.is-bad { background: var(--pen); border-color: var(--pen); }

.stage { overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.stage-inner { padding: 10px var(--gutter) 20px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-content: start; min-height: 100%; }
.stage-inner > *, .feedback > * { min-width: 0; }
.stage-inner.is-leaving { opacity: 0; transform: translateX(-14px); transition: opacity 150ms ease, transform 150ms ease; }
.stage-inner.is-entering { animation: stage-in 260ms var(--ease-out); }
@keyframes stage-in { from { opacity: 0; transform: translateX(18px); } }

.prompt { background: var(--surface); box-shadow: inset 0 0 0 var(--line) var(--rule); border-radius: var(--r-box); padding: 8px 12px 12px; }
.prompt-row { display: flex; align-items: center; gap: 12px; margin-top: 2px; }
.word {
  margin: 0; font-weight: 850; font-stretch: 70%; letter-spacing: -0.025em; line-height: 1;
  font-size: var(--word-size, 64px); overflow-wrap: anywhere; flex: 1; min-width: 0;
}
.stage.is-review .word { font-size: min(var(--word-size, 64px), 40px); }
.audio-btn {
  width: 48px; height: 48px; border-radius: var(--r-ctl); flex: none; display: grid; place-items: center;
  box-shadow: inset 0 0 0 var(--line) var(--rule); color: var(--stamp); position: relative;
  transition: transform 140ms var(--ease-out);
}
.audio-btn:active { transform: scale(0.92); }
.audio-btn::after { content: ''; position: absolute; inset: 0; border-radius: inherit; box-shadow: 0 0 0 2px var(--stamp); opacity: 0; }
.audio-btn.is-speaking::after { animation: ring 1.1s var(--ease-out) infinite; }
@keyframes ring { 0% { opacity: .55; transform: scale(1); } 100% { opacity: 0; transform: scale(1.4); } }
.voice-note { margin: 6px 0 0; font-size: 12.5px; color: var(--faint); animation: fade-in 240ms ease; }
@keyframes fade-in { from { opacity: 0; } }

/* Transcripción: una casilla por fonema */
.answer-block { position: relative; display: grid; gap: 6px; }
.answer {
  display: flex; align-items: center; flex-wrap: wrap; gap: 4px; min-height: 56px; padding-right: 48px; position: relative;
  font-size: clamp(22px, 6.6vw, 28px); line-height: 1;
}
.answer-tokens { display: contents; }
.answer .tok {
  min-width: 34px; height: 48px; padding: 0 5px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface); box-shadow: inset 0 0 0 var(--line) var(--rule); border-radius: 2px;
}
.answer .tok-mark { min-width: 18px; padding: 0 2px; color: var(--stamp); box-shadow: none; background: transparent; border: var(--line) dashed var(--stamp); }
.answer .tok-dot { min-width: 14px; padding: 0; box-shadow: none; background: transparent; color: var(--faint); }
.answer .tok-new { animation: tok-in 150ms var(--ease-out); }
@keyframes tok-in { from { opacity: 0; transform: translateY(5px); } }
.caret { width: 34px; height: 48px; border-radius: 2px; position: relative; flex: none; box-shadow: inset 0 0 0 var(--line) var(--rule-soft); }
.caret::after {
  content: ''; position: absolute; left: 50%; top: 11px; bottom: 11px; width: 2px; margin-left: -1px; background: var(--stamp);
  animation: blink 1.05s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.answer.is-locked .caret { display: none; }
.answer.is-nudge .caret { box-shadow: inset 0 0 0 var(--line) var(--pen); }
.clear-btn {
  position: absolute; right: 0; top: 50%; translate: 0 -50%; width: 44px; height: 44px; border-radius: var(--r-ctl);
  display: grid; place-items: center; color: var(--muted); transition: transform 140ms var(--ease-out);
}
.clear-btn:active { transform: scale(0.9); }
.answer-hint { margin: -2px 0 0; font-size: 13.5px; color: var(--muted); }
.answer-hint .ipa { color: var(--stamp); font-size: 1.3em; line-height: 1; }
.answer-hint.is-nudge { color: var(--pen); }

/* ---------- El sello (movimiento de firma) ---------- */
.stamp {
  --stamp-c: var(--stamp);
  position: absolute; right: 14px; top: -22px; z-index: 2; pointer-events: none;
  display: grid; justify-items: center; gap: 0; padding: 3px 9px 4px;
  color: var(--stamp-c); border: 3px solid var(--stamp-c); border-radius: 6px;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  transform: rotate(-7deg); opacity: .94;
}
.stamp.is-bad { --stamp-c: var(--pen); }
#stamp { top: -16px; padding: 4px 10px 3px; }
#stamp .stamp-sub { display: none; }
.stamp-main { font-weight: 900; font-stretch: 72%; font-size: 18px; line-height: 1; letter-spacing: .04em; font-variant-numeric: tabular-nums; }
.stamp-sub { font-size: 11px; font-weight: 700; font-stretch: 80%; letter-spacing: .08em; text-transform: uppercase; }
.stamp.is-in { animation: stamp-down 300ms var(--ease-stamp) both; }
@keyframes stamp-down {
  0% { opacity: 0; transform: rotate(-12deg) scale(1.6); }
  60% { opacity: .96; }
  100% { opacity: .94; transform: rotate(-7deg) scale(1); }
}
.answer-block.is-stamped .answer { animation: press 300ms ease-out; }
@keyframes press { 45% { transform: translateY(1.5px); } }

/* ---------- Modo papel ---------- */
.paper-card { background: var(--surface); box-shadow: inset 0 0 0 var(--line) var(--rule); border-radius: var(--r-box); padding: 14px 16px 16px; display: grid; gap: 4px; }
.paper-card strong { font-size: 17px; }
.paper-card p { margin: 0; color: var(--muted); font-size: 15px; max-width: 36ch; }

/* ---------- Corrección ---------- */
.feedback { display: grid; gap: 14px; }
.feedback > * { animation: fb-in 300ms var(--ease-out) both; animation-delay: calc(80ms + var(--d, 0) * 60ms); }
@keyframes fb-in { from { opacity: 0; transform: translateY(6px); } }

.verdict { font-weight: 700; font-stretch: 85%; font-size: 17px; }
.verdict.ok { color: var(--stamp); } .verdict.warn { color: var(--warn); } .verdict.bad { color: var(--pen); } .verdict.neutral { color: var(--ink); }

.model { background: var(--surface); box-shadow: inset 0 0 0 var(--line) var(--rule); border-radius: var(--r-box); padding: 8px 12px 12px; display: grid; gap: 2px; }
.model-ipa { font-family: var(--font-ipa); font-size: clamp(32px, 9.5vw, 44px); line-height: 1.2; }
.model-ipa .tok-mark { color: var(--stamp); }
.model-ipa .tok-dot { color: var(--faint); }
.model-alt { font-size: 14px; color: var(--muted); }
.model-alt .ipa { color: var(--ink); font-size: 17px; }
.model-alt .tok-mark { color: var(--stamp); }

/* Tú / RP en las casillas de la transcripción: misma línea base, salto de línea como la respuesta */
.answer.is-diff { align-items: flex-start; row-gap: 8px; padding-right: 0; }
.dcol { display: inline-grid; grid-template-rows: 13px 44px 26px; gap: 2px; justify-items: stretch; animation: cell-in 240ms var(--ease-out) both; animation-delay: calc(140ms + var(--i, 0) * 30ms); }
@keyframes cell-in { from { opacity: 0; transform: translateY(5px); } }
.dnum { position: relative; z-index: 3; font-family: var(--font-ui); font-size: 12px; font-weight: 800; color: var(--pen); text-align: center; line-height: 14px; font-variant-numeric: tabular-nums; }
.dcell { min-width: 34px; padding: 0 5px; border-radius: 2px; display: flex; align-items: center; justify-content: center; position: relative; }
.dcell.you { background: var(--surface); box-shadow: inset 0 0 0 var(--line) var(--rule); }
.dcell.rp { color: var(--muted); font-size: .78em; }
.dcell.you.is-bad { box-shadow: inset 0 0 0 var(--line) var(--pen); color: var(--pen); background: var(--pen-soft); }
.dcell.you.is-bad::after {
  content: ''; position: absolute; left: 4px; right: 4px; top: 50%; height: 2.5px; border-radius: 2px; background: currentColor;
  transform: rotate(-14deg) scaleX(0); transform-origin: left; animation: strike 220ms var(--ease-out) forwards;
  animation-delay: calc(380ms + var(--i, 0) * 30ms);
}
@keyframes strike { to { transform: rotate(-14deg) scaleX(1); } }
.dcell.you.is-gap { background: transparent; box-shadow: none; border: var(--line) dashed var(--pen); }
.dcell.rp.is-need { color: var(--ink); font-weight: 600; }
.dcell.rp.is-empty { color: var(--faint); }
.dcell .m { color: var(--stamp); }
.dcell .m.is-bad { color: var(--pen); }
.dcell .m.is-warn { color: var(--warn); }
/* Acento primario: más peso que el secundario (sin duplicar el trazo, que se confundiría con ") */
.tok-primary, .m-primary { font-weight: 800; }

.issues { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.issue { display: grid; grid-template-columns: 22px 1fr; gap: 10px; font-size: 15.5px; line-height: 1.45; }
.issue-n {
  width: 22px; height: 22px; border-radius: 2px; display: grid; place-items: center; margin-top: 1px;
  font-size: 12px; font-weight: 800; box-shadow: inset 0 0 0 var(--line) var(--pen); color: var(--pen);
}
.issue.warn .issue-n { box-shadow: inset 0 0 0 var(--line) var(--warn); color: var(--warn); }
.issue.typical .issue-n { background: var(--pen); color: var(--surface); }
.issue .ipa { font-size: 1.08em; }
.issues-toggle, .fix-link {
  justify-self: start; font-size: 15px; font-weight: 700; font-stretch: 88%; color: var(--stamp); min-height: 44px;
  text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1.5px;
}

.note { padding: 10px 12px 12px; border-radius: var(--r-box); background: var(--surface); box-shadow: inset 0 0 0 1px var(--rule-soft); }
.note .field-label { color: var(--stamp); margin-bottom: 3px; }
.note p { margin: 0; font-size: 15.5px; }
.note .ipa { font-size: 1.06em; }

/* ---------- Tabla fonémica: bandeja de tinta con zonas de color plano ---------- */
.keyboard { padding: 8px 8px calc(var(--safe-b) + 8px); display: grid; gap: 7px; background: var(--tray); }
.kb-vowels {
  display: grid; gap: 4px;
  grid-template-columns: repeat(4, minmax(0, 1fr)) 3px repeat(3, minmax(0, 1fr)) 3px minmax(0, 1fr);
}
.kb-consonants, .kb-actions { display: grid; gap: 4px; grid-template-columns: repeat(8, minmax(0, 1fr)); }
.key {
  min-height: 48px; border-radius: 3px; background: var(--z-cons); color: var(--z-ink); position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  overflow: hidden; user-select: none; -webkit-user-select: none;
  transition: transform 110ms var(--ease-out), background-color 200ms ease, color 200ms ease, opacity 220ms ease, box-shadow 200ms ease;
  transition-delay: 0ms, var(--kd, 0ms), var(--kd, 0ms), var(--kd, 0ms), var(--kd, 0ms);
}
.kb-vowels .key { background: var(--z-vowel); }
.kb-vowels .key.key-diph { background: var(--z-diph); }
.kb-vowels .key.key-extra { background: transparent; color: var(--z-extra-ink); box-shadow: none; border: var(--line) dashed var(--z-extra-line); }
.kb-vowels .key.key-extra .key-ex { color: var(--z-mark-ex); }
.key:active { transform: scale(0.93); }
.key-sym { font-family: var(--font-ipa); font-size: 19px; line-height: 1.15; }
.key-ex { font-size: 11px; font-stretch: 85%; line-height: 1.1; color: var(--z-ex); max-width: 100%; padding: 0 2px; white-space: nowrap; overflow: hidden; }
.key-mark, .key-del { background: var(--z-mark); color: var(--z-mark-ink); }
.key-mark .key-ex { color: var(--z-mark-ex); }
.key-mark .key-sym { font-size: 24px; line-height: 1; height: 22px; display: flex; align-items: center; }
.key-mark[data-sym="ˈ"] .key-sym { transform: translateY(5px); }
.key-mark[data-sym="ˌ"] .key-sym { transform: translateY(-7px); }
.key-mark[data-sym="."] .key-sym { transform: translateY(-5px); }
.key-del { color: var(--z-extra-ink); }
.key-del .icon { width: 22px; height: 22px; }
.btn-check { grid-column: span 4; min-height: 48px; font-size: 16.5px; }
.btn-label { display: inline-block; transition: opacity 160ms ease, filter 160ms ease; }
.btn-label.is-swapping { opacity: 0; filter: blur(3px); }
@media (hover: hover) and (pointer: fine) {
  .key:hover { filter: brightness(1.06); }
}

/* Revisión: la tabla resalta los sonidos de la palabra */
.keyboard.is-review .kb-vowels .key, .keyboard.is-review .kb-consonants .key { pointer-events: none; opacity: .28; }
.keyboard.is-review .key.in-word { opacity: 1; box-shadow: inset 0 0 0 2.5px var(--stamp); }
.keyboard.is-review .key.missed { opacity: 1; box-shadow: inset 0 0 0 2.5px var(--pen); }
.keyboard.is-review .key-mark, .keyboard.is-review .key-del { opacity: .3; pointer-events: none; }
.keyboard.is-paper .kb-actions .key { display: none; }
.keyboard.is-paper.is-collapsed .kb-vowels, .keyboard.is-paper.is-collapsed .kb-consonants { display: none; }
.paper-actions { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.paper-actions .btn-primary, .paper-actions .btn-secondary { min-height: 48px; }
.paper-actions .btn-secondary { color: var(--z-extra-ink); box-shadow: inset 0 0 0 var(--line) var(--z-extra-line); }
.paper-actions .wide { grid-column: 1 / -1; }

@media (max-width: 899px) {
  .keyboard.is-review { gap: 4px; padding-top: 6px; }
  .keyboard.is-review .kb-vowels, .keyboard.is-review .kb-consonants { gap: 3px; }
  .keyboard.is-review .kb-vowels .key, .keyboard.is-review .kb-consonants .key { min-height: 25px; }
  .keyboard.is-review .key-sym { font-size: 16px; }
  .keyboard.is-review .key-ex { display: none; }
  .keyboard.is-review .kb-actions .key { min-height: 44px; }
}

/* ---------- Acta de la tanda ---------- */
.view-summary { max-width: 560px; margin: 0 auto; min-height: 100dvh; padding: calc(var(--safe-t) + 40px) var(--gutter) calc(var(--safe-b) + 24px); }
.summary { display: grid; gap: 16px; align-content: start; }
.summary-title { margin: 0; font-size: 34px; font-weight: 850; font-stretch: 72%; letter-spacing: -0.02em; line-height: 1.05; }
.summary-score { display: flex; align-items: center; gap: 22px; padding: 14px 0 6px; }
.stamp-score { position: static; padding: 8px 18px 9px; flex: none; gap: 2px; }
.stamp-score .stamp-main { font-size: 64px; letter-spacing: 0; }
.summary-line { margin: 0; font-size: 16.5px; max-width: 26ch; }
.summary-patterns { display: flex; flex-wrap: wrap; gap: 8px; }
.summary-patterns span { padding: 6px 10px; border-radius: var(--r-ctl); box-shadow: inset 0 0 0 var(--line) var(--pen); color: var(--pen); font-size: 14px; font-weight: 600; }
.summary-misses { list-style: none; margin: 4px 0 0; padding: 0; display: grid; box-shadow: inset 0 0 0 var(--line) var(--rule); border-radius: var(--r-box); background: var(--surface); }
.summary-misses:empty { display: none; }
.summary-misses li {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 11px 12px;
  animation: fb-in 280ms var(--ease-out) both; animation-delay: calc(200ms + var(--i, 0) * 45ms);
}
.summary-misses li + li { box-shadow: inset 0 var(--line) 0 var(--rule); }
.summary-misses .w { font-weight: 700; font-size: 18px; }
.summary-misses .ipa { font-size: 19px; color: var(--muted); }
.summary-actions { display: grid; gap: 10px; margin-top: 14px; }

/* ---------- Expediente ---------- */
.view-stats { max-width: 560px; margin: 0 auto; min-height: 100dvh; padding: calc(var(--safe-t) + 24px) var(--gutter) calc(var(--safe-b) + 24px); }
.stats { display: grid; gap: 18px; align-content: start; }
.stats-top { display: flex; align-items: center; gap: 6px; margin-left: -10px; }
.stats-body { display: grid; gap: 22px; }
.stats-head { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stats-head .fh-val { font-size: 22px; font-weight: 800; font-stretch: 75%; }
.stats-sec { display: grid; gap: 8px; }
.stats-sec h3 { margin: 0; }
.stats-patterns {
  list-style: none; margin: 0; padding: 0; display: grid;
  box-shadow: inset 0 0 0 var(--line) var(--rule); border-radius: var(--r-box); background: var(--surface);
}
.stats-patterns li {
  display: grid; grid-template-columns: minmax(0, 1fr) auto 3.4em 3.4em; align-items: center; gap: 10px; padding: 10px 12px; font-size: 15px;
}
.stats-patterns li + li { box-shadow: inset 0 var(--line) 0 var(--rule); }
.stats-patterns li.is-none { color: var(--faint); }
.st-name { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-ticks { display: inline-flex; gap: 2px; }
.st-ticks i { width: 7px; height: 12px; border: 1.5px solid var(--rule); border-radius: 1px; }
.st-ticks i.on { background: var(--ink); }
.is-low .st-ticks i { border-color: var(--pen); }
.is-low .st-ticks i.on { background: var(--pen); }
.st-pct { font-weight: 800; font-stretch: 85%; text-align: right; font-variant-numeric: tabular-nums; }
.is-low .st-pct { color: var(--pen); }
.st-n { font-size: 13px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.st-none { grid-column: 2 / -1; text-align: right; font-size: 13px; }
.st-hard-r { display: grid; justify-items: end; gap: 1px; }
.stats-reset { justify-self: center; color: var(--pen); }
.stats-start { justify-self: start; margin-top: 10px; }

/* ---------- Escritorio ---------- */
@media (min-width: 900px) {
  .view-drill {
    grid-template-columns: minmax(0, 1fr) 500px; grid-template-rows: auto minmax(0, 1fr);
    max-width: 1180px; margin: 0 auto; column-gap: 32px; padding: 16px 24px;
  }
  .topbar { grid-column: 1 / -1; }
  .stage-inner { padding: 20px 4px; gap: 16px; }
  .keyboard { align-self: start; margin-top: 20px; border-radius: var(--r-box); padding: 12px; box-shadow: var(--shadow); }
  .key { min-height: 54px; }
  .key-sym { font-size: 21px; }
  .key-ex { font-size: 11.5px; }
  .view-home { padding-top: 64px; }
}

/* ---------- Movimiento reducido ---------- */
@media (prefers-reduced-motion: reduce) {
  /* Se mantienen los fundidos (comunican el cambio de estado); se quita todo desplazamiento. */
  body[data-view] .view, .stage-inner.is-entering, .feedback > *, .dcol, .summary-misses li,
  .answer .tok-new, .specimen-ipa .tok, .stamp.is-in { animation-name: fade-in !important; animation-duration: 200ms !important; }
  .dcol { animation-delay: 0ms !important; }
  .dcell.you.is-bad::after { animation: none; transform: rotate(-14deg) scaleX(1); }
  .answer-block.is-stamped .answer { animation: none; }
  .stage-inner.is-leaving { transform: none; }
  .audio-btn.is-speaking::after { animation: none; opacity: .6; }
  .caret::after { animation: none; }
  .key:active, .chip:active, .icon-btn:active, .audio-btn:active, .clear-btn:active,
  .btn-primary:active, .btn-secondary:active, .btn-ghost:active { transform: none; }
  .seg-thumb, .chip-box::before, .chip-box::after { transition-duration: 0ms; }
}
