:root {
  --bg: #f6f7f9; --surface: #fff; --text: #1b2430; --muted: #5b6676; --line: #dde2ea;
  --accent: #2f5fd0; --accent-ink: #fff; --accent-soft: #e8eefc;
  --at: #b42318; --at-bg: #fde8e6; --some: #8a5a00; --some-bg: #fff1cf; --low: #1b6b3a; --low-bg: #dff3e6;
  --err: #b42318; --err-bg: #fde8e6; --radius: 14px; --shadow: 0 1px 2px rgba(20,30,50,.08), 0 4px 16px rgba(20,30,50,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161d; --surface: #1a2029; --text: #e8ecf2; --muted: #9aa5b5; --line: #2b3441;
    --accent: #7ea2ff; --accent-ink: #0d1424; --accent-soft: #1f2a44;
    --at: #ff9f95; --at-bg: #3a1c1a; --some: #ffd279; --some-bg: #3a2e12; --low: #8fdca9; --low-bg: #16301f;
    --err: #ff9f95; --err-bg: #3a1c1a; --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .5rem; }
p { margin: .25rem 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

.top { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; padding: .6rem 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 800; letter-spacing: .02em; text-decoration: none; color: var(--text); font-size: 1.1rem; }
.brand span { font-weight: 500; color: var(--muted); font-size: .8rem; margin-left: .4rem; }
.moments { display: flex; gap: .25rem; margin-left: auto; }
.moments button { padding: .35rem .75rem; border: 1px solid var(--line); background: transparent; color: var(--text); border-radius: 999px; font: inherit; font-size: .875rem; }
.moments button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.moments button:disabled { opacity: 1; color: var(--text); border: 1.5px dashed var(--muted); background: var(--surface); cursor: not-allowed; }
.tabs button[aria-pressed="true"] .muted { color: inherit; opacity: .85; }
.nav { display: flex; gap: .25rem; width: 100%; }
.nav a { padding: .4rem .8rem; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 600; }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
@media (min-width: 760px) { .nav { width: auto; } .moments { margin-left: 0; } .top .nav { margin-left: auto; } }

main { max-width: 1080px; margin: 0 auto; padding: 16px; outline: none; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }

button, .btn { font: inherit; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: .6rem 1rem; min-height: 44px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: .4rem; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
button.danger { color: var(--err); border-color: var(--err); }
button:disabled { opacity: .5; cursor: not-allowed; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
input, textarea, select { font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .55rem .75rem; min-height: 44px; }
textarea { width: 100%; min-height: 120px; }
label { display: block; font-weight: 600; margin-bottom: .2rem; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 16px; }
.tabs button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list a.name { font-weight: 600; text-decoration: none; color: var(--text); }

.chip { display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 700; white-space: nowrap; }
.chip.at { color: var(--at); background: var(--at-bg); }
.chip.some { color: var(--some); background: var(--some-bg); }
.chip.low { color: var(--low); background: var(--low-bg); }
.chip.none { color: var(--muted); background: var(--accent-soft); }

.banner { background: var(--at-bg); color: var(--at); border-bottom: 2px solid var(--at); padding: 10px 16px; font-weight: 600; text-align: center; }
.banner[hidden] { display: none; }
.note { border-left: 4px solid var(--some); background: var(--some-bg); color: var(--text); padding: 8px 12px; border-radius: 8px; font-size: .9rem; margin: 8px 0; }

/* ---- aplicación ---- */
.runner-bar { position: sticky; top: 0; z-index: 4; background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius); padding: 8px 16px 14px; margin: 8px 0; display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; position: sticky; box-shadow: var(--shadow); }
.timer-wrap { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.timer { font-variant-numeric: tabular-nums; font-size: clamp(4.5rem, 20vw, 8rem); line-height: 1; font-weight: 800; letter-spacing: -.02em; }
.timer.low { color: var(--err); }
.alert-tag { display: none; font-size: 1.6rem; font-weight: 800; color: #fff; background: var(--at-solid, #c0261a); padding: .35rem .9rem; border-radius: 10px; }
.prog { position: absolute; left: 0; right: 0; bottom: 0; height: 6px; background: var(--line); border-radius: 0 0 12px 12px; overflow: hidden; }
.prog > div { height: 100%; width: 0; background: var(--accent); transition: width .1s linear; }
.runner-bar.warn .prog > div { background: var(--err); }
/* Últimos 5 s: marco y fondo rojos que laten ~1 vez por segundo (visual, sin sonido) */
.runner-bar.alert { border-color: #c0261a; animation: pili-pulse 1s ease-in-out infinite; }
.runner-bar.alert .alert-tag { display: inline-block; }
.runner-bar.alert .timer { color: #c0261a; }
@keyframes pili-pulse { 0%, 100% { background: var(--surface); box-shadow: 0 0 0 0 rgba(192,38,26,.0); } 50% { background: var(--at-bg); box-shadow: 0 0 0 8px rgba(192,38,26,.35); } }
@media (prefers-reduced-motion: reduce) { .runner-bar.alert { animation: none; background: var(--at-bg); box-shadow: 0 0 0 6px rgba(192,38,26,.45); } }
@media (prefers-color-scheme: dark) { .runner-bar.alert .timer { color: #ff8a7d; } .runner-bar.alert { border-color: #ff8a7d; } }
.stim { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stim .title { text-align: center; font-weight: 800; font-size: 1.4rem; margin: 4px 0 12px; }
.script { margin: 8px 0; background: var(--accent-soft); border-radius: 10px; padding: 8px 12px; }
.script summary { cursor: pointer; font-weight: 600; }
.script p { margin: 8px 0 4px; }
.stim { --ts: 1; }
.tok { min-height: 52px; min-width: 52px; padding: .25rem .6rem; border-radius: 10px; border: 2px solid transparent; background: transparent; font-size: calc(1.7rem * var(--ts)); line-height: 1.1; font-weight: 600; color: var(--text); touch-action: manipulation; }
.layout-grid .grp { display: flex; flex-wrap: wrap; gap: 4px 10px; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.layout-grid .grp:last-child { border-bottom: 0; }
.tok.end { margin-right: 18px; }
.layout-words .grp { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.layout-words .lab { font-weight: 800; font-size: calc(1.4rem * var(--ts)); min-width: 4.5ch; margin-right: 8px; }
.layout-words .tok { font-size: calc(1.35rem * var(--ts)); font-weight: 600; }
.layout-flow .grp { margin: 0 0 14px; }
.layout-flow .tok { font-size: calc(1.5rem * var(--ts)); min-height: 46px; min-width: 0; padding: .15rem .35rem; font-weight: 500; }
.tok.err { background: var(--err-bg); color: var(--err); border-color: var(--err); text-decoration: line-through; }
.tok.beyond { opacity: .35; }
.tok.last { outline: 3px solid var(--accent); outline-offset: 1px; }
.tok:disabled { cursor: default; opacity: 1; }
.tok.beyond:disabled { opacity: .35; }

.score-panel { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; }
.score-big { font-size: 3rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; min-height: 40px; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.q { padding: 12px 0; border-bottom: 1px solid var(--line); }
.q:last-child { border-bottom: 0; }
.opts { display: grid; gap: 6px; margin-top: 8px; }
.opt { justify-content: flex-start; text-align: left; }
.opt[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.stepper { display: inline-flex; align-items: center; gap: 12px; }
.stepper output { font-size: 1.6rem; font-weight: 800; min-width: 1.5ch; text-align: center; }

table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: middle; }
th { position: sticky; top: 0; background: var(--surface); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.cut-table td, .cut-table th { white-space: nowrap; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; opacity: 0; pointer-events: none; transition: .2s; z-index: 20; max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
