/* Tokens — the only values allowed. Sources and reasons: design/v2/ROUNDS.md */
:root {
  --paper: #FBF7EE;         /* warm cream */
  --surface: #FFFFFF;
  --ink: #23201B;
  --grey: #655F54;          /* text, 6:1 on paper */
  --hair: #E6E0D2;          /* lines, never text */
  --todo: #DFD8C7;          /* a dot not yet lit: quiet, but the field still reads as the picture */
  --lit: #3FA45C;           /* green: a lit dot, and nothing else */
  --lit-pale: #BFE3C8;      /* half lit */
  --blue: #2B4A8B;          /* ink blue: the word being learned, nothing else */
  --blue-tint: #E8EEF8;     /* the gap */
  --lit-text: #256B3A;
  --due: #E3A21A;           /* amber: due for a refresh */
  --due-text: #8A5E0F;      /* 5.6:1 */
  --coral: #B23F28;         /* wrong, 5.3:1 */
  --coral-tint: #FBEAE5;
  --r-btn: 16px; --r-card: 24px;
  --pad: 24px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", Roboto, "Segoe UI", system-ui, sans-serif;
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--paper); }
body { -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
/* A fixed screen, not a page to read: no zoom, by pinch or by double tap (it only ever happened by
   accident). Lists still scroll. */
html, body { touch-action: pan-x pan-y; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

#app {
  max-width: 480px; margin: 0 auto;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
/* Today: a height that never changes when the browser bars come and go */
#app.today { height: 100svh; }
/* The session: exactly the visible height (keyboard included); the page never scrolls */
html.session, html.session body { overflow: hidden; position: fixed; inset: 0; }
#app.session { height: var(--vvh, 100dvh); }

/* ---------- shared ---------- */
.topbar { height: 52px; flex: none; display: flex; align-items: center; gap: 12px; padding: 0 12px; }
.icon { width: 48px; height: 48px; display: grid; place-items: center; color: var(--grey); border-radius: 24px; }
.icon svg { width: 22px; height: 22px; }
.spacer { flex: 1; }
.actions { flex: none; display: flex; flex-direction: column; gap: 4px; padding: 8px var(--pad) 16px; }
.btn { height: 56px; border-radius: var(--r-btn); font-size: 17px; font-weight: 600; display: grid; place-items: center; width: 100%; }
.btn.filled { background: var(--ink); color: #fff; }
.btn.filled:disabled { background: #E4E0D6; color: #8C877C; cursor: default; }
.btn.outlined { box-shadow: inset 0 0 0 1.5px #D5CEBD; color: var(--ink); }
.btn.text { height: 48px; font-weight: 400; font-size: 16px; color: var(--grey); }
.btn:active:not(:disabled) { transform: scale(.98); }

/* ---------- Today ---------- */
.field-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 8px var(--pad); }
.field { display: grid; grid-template-columns: repeat(var(--cols, 25), var(--p)); grid-auto-rows: var(--p); }
/* One mark, four states — the same on the field and in the session:
   not yet (barely there) · waiting for you today (a ring) · due (a ring of light) · lit. */
.dot { display: block; margin: 9%; border-radius: 50%; background: var(--todo); }   /* dots big, gaps small */
.dot.next { background: none; box-shadow: inset 0 0 0 1.5px #A9A294; }
.dot.known, .dot.lit { background: var(--lit); }
.dot.due { background: #FCF0D2; box-shadow: inset 0 0 0 max(1.5px, calc(var(--p, 10px) * 0.16)) var(--due); }
.dot.half { background: var(--lit-pale); }
.dot.lighting { animation: lighting .6s cubic-bezier(.3,1.6,.5,1) both; }
@keyframes lighting { from { transform: scale(.3); background: var(--todo); } 60% { transform: scale(1.45); } to { transform: scale(1); } }

/* ··· floats in its corner, so on short phones the block can use the strip beside it. */
#app.today { position: relative; }
#app.today > .topbar { position: absolute; top: 0; right: 0; z-index: 1; }
#app.today .field-wrap { padding-top: 12px; }
/* Today: one block with one left edge — the count just above the dots, the finish date just below. */
.block { display: flex; flex-direction: column; align-items: flex-start; max-width: 100%; }
/* The captions are always one line each and never widen the block: the grid has the same size
   on a given screen whatever the text says. */
.block .label, .block .under { width: 0; min-width: 100%; white-space: nowrap; }
.block .label { height: 40px; }
.label .n { display: block; background: none; border: 0; padding: 0; color: inherit; font-family: inherit; cursor: pointer; font-size: 26px; font-weight: 800; letter-spacing: -.5px; line-height: 34px; white-space: nowrap; }
.label .n span { font-weight: 400; color: var(--grey); font-size: 17px; letter-spacing: 0; }
/* "347 milatik": the app's name is the caption, in the number's own weight; grey, so the number stays first. */
.label .n span.name { font-weight: 800; font-size: 26px; letter-spacing: -.5px; }
.block .under { height: 30px; padding-top: 8px; box-sizing: border-box; }
.under .when { font-size: 16px; line-height: 22px; color: var(--grey); }
.under .end { color: var(--ink); }

.tryit { flex: none; margin: 16px var(--pad) 0; padding: 14px 18px; background: var(--surface); border-radius: 18px; text-align: center; }
.tryit .k { font-size: 13px; font-weight: 600; color: var(--lit-text); }
.tryit .p { font-size: 20px; margin-top: 4px; }
.tryit .p b { color: var(--blue); }
.tryit .t { font-size: 16px; font-style: italic; color: var(--grey); margin-top: 2px; }
.tryit .t b { color: var(--blue); font-weight: 600; }

/* On Today the dots are the hero: the button is a compact pill, not a black bar
   heavier than the picture. */
#app.today .actions { flex-direction: row; justify-content: center; align-items: center; gap: 12px; padding-top: 16px; }
#app.today .actions .btn { width: auto; min-width: 180px; height: 50px; padding: 0 36px; border-radius: 25px; }
#app.today .actions .btn.text { min-width: 0; height: 44px; }
.plan { flex: none; text-align: center; font-size: 17px; padding: 16px var(--pad) 0; }
.plan small { display: block; font-size: 15px; color: var(--grey); margin-top: 2px; }
.plan .due { color: var(--due-text); font-weight: 600; }

/* ---------- the session ---------- */
/* today's dots, lighting up as you go */
.today-dots { flex: 1; min-width: 0; display: flex; justify-content: center; gap: 10px; margin-right: 48px; }
.today-dots .group { display: flex; gap: 3px; min-width: 0; }
.today-dots .dot { flex: 0 1 10px; width: 10px; min-width: 4px; aspect-ratio: 1; margin: 0; transition: background .3s, box-shadow .3s; --p: 10px; }

.stage { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 20px 8px; }
/* Meeting a word: the card is the whole stage, the word in the middle of it. */
.card.show { min-height: 100%; display: flex; flex-direction: column; justify-content: center; }
.card.show .word { --max: 60px; }
.card { background: var(--surface); border-radius: var(--r-card); padding: 32px 24px; text-align: center; }
.word { font-size: min(var(--max, 48px), calc((min(100vw, 480px) - 136px) / (var(--len, 6) * 0.6)));  /* long words shrink, never break */
  white-space: nowrap; font-weight: 700; letter-spacing: -1px; line-height: 1.1; color: var(--blue); overflow-wrap: anywhere; }
.meaning { font-size: 20px; font-style: italic; color: var(--grey); margin-top: 6px; }
.base { font-size: 15px; color: var(--grey); margin-top: 4px; }
.rule { height: 1px; background: var(--hair); margin: 24px 32px; }
.phrase { font-size: 22px; line-height: 1.5; }
.phrase b { font-weight: 700; color: var(--blue); }
.tr { font-size: 19px; line-height: 1.4; font-style: italic; color: var(--grey); margin-top: 6px; }
.tr b, .cue b { font-weight: 600; color: var(--blue); }
.cue { font-size: 20px; line-height: 1.4; font-style: italic; color: var(--grey); margin-bottom: 14px; }
.gap { display: inline-block; min-width: 4.5ch; padding: 0 8px; border-radius: 10px; background: var(--blue-tint);
  color: var(--blue); font-weight: 700; cursor: text; vertical-align: baseline; }
.typing .gap::after { content: ""; display: inline-block; width: 2px; height: 1em; margin-left: 1px; vertical-align: -0.12em;
  background: var(--blue); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.status-line { font-size: 16px; margin-top: 16px; min-height: 22px; }
/* Right: a dot lights up. The only reward is the real one. */
.pop { display: inline-block; width: 18px; height: 18px; border-radius: 50%; background: var(--lit); position: relative;
  animation: lighting .5s cubic-bezier(.3,1.6,.5,1) both; }
.pop::after { content: ""; position: absolute; inset: 0; border-radius: 50%; box-shadow: 0 0 0 2px var(--lit); animation: ring .7s ease-out both; }
@keyframes ring { from { transform: scale(1); opacity: .8; } to { transform: scale(2.6); opacity: 0; } }

#app.session.typing .card { padding: 24px 20px 16px; }   /* keyboard up: every pixel counts */
/* the action row on the keyboard: quiet way out on the left, the action on the right */
.row { display: flex; align-items: center; gap: 12px; }
.row .btn.text { width: auto; padding: 0 8px; }
.row .btn.filled { flex: 1; max-width: 200px; margin-left: auto; height: 52px; }

/* ---------- sheets ---------- */
.scrim { position: fixed; inset: 0; background: rgba(28,27,25,.18); animation: fade .2s both; z-index: 5; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; max-width: 480px; margin: 0 auto; z-index: 6;
  background: var(--surface); border-radius: 24px 24px 0 0; padding: 24px var(--pad) calc(16px + env(safe-area-inset-bottom));
  animation: up .25s cubic-bezier(.2,.8,.2,1) both; }
.sheet.wrong { background: var(--coral-tint); }
.sheet h2 { font-size: 15px; font-weight: 600; color: var(--coral); }
.sheet .ans { font-size: 28px; font-weight: 700; color: var(--blue); margin-top: 6px; }
.sheet .ans-g { font-size: 19px; font-style: italic; color: var(--grey); margin-top: 2px; }
.sheet .note { font-size: 15px; line-height: 1.45; color: var(--grey); margin: 10px 0 20px; }
.sheet .note s { color: var(--coral); }
.sheet.day { max-height: 85%; display: flex; flex-direction: column; }
/* Up and down only: the highlighted row reaches 10px past the text on each side, so the list keeps
   that room inside itself — otherwise it is a few pixels too wide and slides sideways (an elastic
   wobble on iPhone). */
.daylist { list-style: none; overflow-y: auto; overflow-x: hidden; touch-action: pan-y; margin: 8px -10px 16px; padding: 0 10px; flex: 1; min-height: 0; }
.daylist li { display: flex; flex-direction: column; padding: 12px 0; border-top: 1px solid var(--hair); }
.daylist li:first-child { border-top: 0; }
.daylist .k { font-size: 13px; font-weight: 600; color: var(--lit-text); margin-bottom: 2px; }
.daylist .p { font-size: 19px; }
.daylist .p b { color: var(--blue); }
.daylist .t { font-size: 16px; font-style: italic; color: var(--grey); margin-top: 2px; }
.daylist .t b { color: var(--blue); font-weight: 600; }
.sheet .menu-title { font-size: 17px; font-weight: 600; margin-bottom: 4px; }
.sheet .menu-text { font-size: 15px; color: var(--grey); margin-bottom: 16px; line-height: 1.4; }
.btn.danger { color: var(--coral); box-shadow: inset 0 0 0 1.5px #EBC7BE; }
.btn.danger.filled { background: var(--coral); color: #fff; box-shadow: none; }
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } }

/* The real input: invisible, pinned to the top so the browser never scrolls to it;
   16px so iPhone doesn't zoom in. */
#type { position: fixed; top: 0; left: 0; width: 1px; height: 1px; opacity: 0; font-size: 16px; border: 0; padding: 0; caret-color: transparent; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- laptops and tablets ----------
   The same app, not a phone in the middle of a big screen: the field takes the
   room it has; the card sits in the middle with its actions right under it
   (on a big screen the action belongs next to the content, not at the far bottom). */
@media (min-width: 720px) and (min-height: 560px) {
  #app { max-width: 1040px; }
  #app.today .field-wrap { padding: 16px 48px; }
  #app.today .actions { padding-bottom: 28px; }
  #app.session { max-width: 640px; justify-content: center; }
  #app.session .topbar { position: fixed; top: 0; left: 0; right: 0; max-width: 640px; margin: 0 auto; padding: 16px 12px 0; height: auto; }
  #app.session .stage { flex: none; overflow: visible; padding: 0 20px; }
  #app.session .card.show { min-height: 0; padding: 56px 40px; }
  #app.session .card { padding: 48px 40px; }
  #app.session .actions { padding-top: 16px; }
  .sheet { max-width: 560px; bottom: 50%; transform: translateY(50%); border-radius: 24px; animation: fade .2s both; }
  .sheet.day { max-height: 80vh; }
  /* a wrong answer sits under the card, so the phrase stays in view */
  .sheet.wrong { position: static; transform: none; margin: 16px 20px 0; max-width: none; animation: fade .2s both; }
}

/* ---------- sound ---------- */
/* The word stays on the card's centre line; its speaker hangs in the margin beside it
   (the word's size already leaves that room), and the word itself replays too. */
.word-row { display: flex; justify-content: center; }
.word-row .word { position: relative; min-width: 0; cursor: pointer; }
.word-row .say { position: absolute; left: 100%; top: 50%; transform: translateY(-50%); margin-left: -4px; }
.say { flex: none; color: var(--blue); }
.say svg { width: 24px; height: 24px; }
.say.playing .w1 { animation: wave 1s ease-in-out infinite; }
.say.playing .w2 { animation: wave 1s ease-in-out .25s infinite; }
@keyframes wave { 50% { opacity: .2; } }
.aloud { font-size: 15px; color: var(--grey); margin-top: 16px; }
.ans-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.daylist li { flex-direction: row; align-items: center; justify-content: space-between; gap: 8px; cursor: pointer; }
.daylist li .say { display: none; width: 24px; }                /* shown only on the row that is speaking */
.daylist li.playing .say { display: grid; }
.daylist li.playing .say .w1 { animation: wave 1s ease-in-out infinite; }
.daylist li.playing .say .w2 { animation: wave 1s ease-in-out .25s infinite; }
.sheet .hint { font-size: 15px; color: var(--grey); margin-top: 4px; }
/* the day's list: title with its close button, a quiet heading for the refreshed words, two actions side by side */
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin: -8px -8px 0 0; }
.sheet-head .menu-title { margin: 0; }
.daylist li.sub { padding: 14px 0 2px; font-size: 13px; font-weight: 600; color: var(--grey); cursor: default; border-top: 1px solid var(--hair); }
.daylist li.sub + li { border-top: 0; }
.duo { display: flex; gap: 12px; }
/* the player: a familiar strip — progress, time, previous / play-pause / next, repeat */
.player { padding-top: 4px; }
.player input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 24px; background: transparent; margin: 0; --fill: 0%; }
.player input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, var(--ink) var(--fill), var(--hair) var(--fill)); }
.player input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, var(--ink) var(--fill), var(--hair) var(--fill)); }
.player input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--ink); margin-top: -5px; }
.player input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%; background: var(--ink); }
.player .times { display: flex; justify-content: space-between; font-size: 13px; color: var(--grey); font-variant-numeric: tabular-nums; }
.player .controls { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 2px; }
.player .controls .icon { color: var(--ink); }
.player .controls .icon svg { width: 28px; height: 28px; }
.player .controls .icon.big { width: 64px; height: 64px; border-radius: 32px; background: var(--ink); color: var(--surface); }
.player .controls .icon.big svg { width: 30px; height: 30px; }
.player #repeat { color: var(--grey); }
.player #repeat svg { width: 22px; height: 22px; }
.player #repeat.on { color: var(--ink); }      /* on: dark, with a dot under it; green is only for lit dots */
.player #repeat.on::after { content: ''; position: absolute; bottom: 6px; width: 4px; height: 4px; border-radius: 2px; background: var(--ink); }
.player #repeat { position: relative; }
.icon-space { width: 48px; height: 48px; }
/* the settings list (··· menu): grouped rows, the standard pattern */
.settings section { margin-top: 18px; }
.settings h3 { font-size: 13px; font-weight: 600; color: var(--grey); text-transform: uppercase; letter-spacing: .4px; margin: 0 0 6px 2px; }
.settings .group { border-radius: 14px; box-shadow: inset 0 0 0 1px var(--hair); overflow: hidden; }
.settings .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 52px;
  padding: 10px 14px; background: none; border: 0; font: inherit; font-size: 17px; color: var(--ink); text-align: left; cursor: pointer; }
.settings .row + .row { border-top: 1px solid var(--hair); }
.settings .row .lbl { display: flex; flex-direction: column; }
.settings .row .note { font-size: 13px; color: var(--grey); margin-top: 2px; }
.settings .row .val { color: var(--grey); white-space: nowrap; }
.settings .row.danger { color: var(--coral); justify-content: center; }
/* a switch: on is dark (green is only for lit dots) */
.switch { flex: none; width: 51px; height: 31px; border-radius: 16px; background: var(--hair); position: relative; transition: background .2s; }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
[aria-checked=true] > .switch { background: var(--ink); }
[aria-checked=true] > .switch::after { transform: translateX(20px); }
/* the playlist entry on Today: a play mark before its name */
.btn.playlist { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.playlist .tri svg { width: 14px; height: 14px; display: block; }
/* while it plays: the current phrase is marked; its answer waits until it is spoken */
.daylist li[data-k] { transition: background-color .2s; }
.daylist li.playing { border-radius: 12px; }
.daylist li.playing { background: var(--blue-tint); margin: 0 -10px; padding-left: 10px; padding-right: 10px; }
.daylist li.asking .p { color: transparent; background: var(--hair); border-radius: 6px; }
.daylist li.asking .p b { color: transparent; }
.sheet > .btn.outlined + .btn { margin-top: 8px; }      /* menu choices: stacked, not touching */
.duo .btn { flex: 1; }
.daylist li > div { display: flex; flex-direction: column; min-width: 0; }

/* Today's one row of actions: the main button, and a round ▶ for the playlist when it is not the main one */
#app.today .actions .icon.round { width: 50px; height: 50px; border-radius: 25px; box-shadow: inset 0 0 0 1.5px #D5CEBD; color: var(--ink); flex: none; }
#app.today .actions .icon.round svg { width: 18px; height: 18px; margin-left: 2px; }
#app.today .actions .btn { white-space: nowrap; display: flex; align-items: center; justify-content: center; }
#app.today .actions .btn .count { font-weight: 400; opacity: .75; white-space: pre; }
.sheet .menu-text.fine { font-size: 13px; margin: 12px 2px 0; }

.paste { width: 100%; box-sizing: border-box; height: 52px; border-radius: var(--r-btn); border: 0; box-shadow: inset 0 0 0 1.5px #D5CEBD; background: var(--surface); padding: 0 16px; font: inherit; font-size: 16px; color: var(--ink); margin: 4px 0 8px; }
#copy-msg:empty { display: none; }
/* The actions are controls, not captions: centred, and the button keeps its own width so the dots stay the picture. */
#app.today .actions .icon.round:disabled { color: #CFC8B8; box-shadow: inset 0 0 0 1.5px var(--hair); cursor: default; }
/* "Tus palabras": a page with the playlist's rows — phrase and translation, the word in blue —
   and each word's own dot in front. */
.field[data-act] { cursor: pointer; }
#app.words { height: 100svh; }
#app.words .topbar { gap: 4px; padding: 0 12px 0 4px; border-bottom: 1px solid var(--hair); }
.page-title { font-size: 17px; font-weight: 600; }
.page-title .count { font-weight: 400; color: var(--grey); }
#app.words .daylist { margin: 0; padding: 0 var(--pad) 24px; }
.daylist.words li { justify-content: flex-start; align-items: baseline; gap: 12px; cursor: default; }
.daylist.words li[data-act] { cursor: pointer; }
.daylist.words .dot { flex: none; width: 10px; height: 10px; margin: 0; --p: 10px; }
/* "Now playing": while the track plays, only the phrase being played, large and centred where
   the list was. The same hide-then-reveal as in the list. Pause, and the list is back. */
.sheet.listening .daylist { display: flex; flex-direction: column; justify-content: center; overflow: hidden; }
.sheet.listening .daylist li { display: none; }
.sheet.listening .daylist li.playing { display: flex; justify-content: center; text-align: center; background: none; margin: 0; padding: 0 4px; border: 0; cursor: default; }
.sheet.listening .daylist li.playing > div { align-items: center; gap: 10px; }
.sheet.listening .daylist li.playing .p { font-size: 28px; line-height: 1.25; font-weight: 600; }
.sheet.listening .daylist li.playing .t { font-size: 19px; }
.sheet.listening .daylist li.playing .say, .sheet.listening .daylist li.playing .k { display: none; }
/* A phrase missed in today's session plays once more at the end of the round: "×2" in the list,
   "Una vez más" over the phrase while its second turn plays. */
.daylist .x2 { flex: none; font-size: 13px; font-weight: 600; color: var(--grey); }
.daylist li.playing .x2 { display: none; }
.daylist span.again { display: none; font-size: 13px; font-weight: 600; color: var(--grey); margin-bottom: 2px; }
.daylist li.playing.again span.again { display: block; }
.sheet.listening .daylist li.playing.again span.again { font-size: 15px; }
