/* Palette: warm paper in light, cool near-black in dark. One accent (indigo) for the main action;
   green and red carry all feedback and always come with a symbol and a word. */
@import url('https://fonts.googleapis.com/css2?family=Lexend:wght@300..700&display=swap');

:root {
  --bg: #f6f4ee;
  --surface: #ffffff;
  --surface-2: #efece4;
  --text: #1c1b18;
  --muted: #6b6860;
  --border: #e4e0d6;
  --accent: #4f46e5;
  --accent-deep: #3b32c9;
  --on-accent: #ffffff;
  --ok: #15803d;
  --ok-bg: #e8f6ec;
  --miss: #c2410c;
  --miss-bg: #fdeee5;
  --star: #b45309;
  --star-bg: #fdf3e2;
  --shadow: 0 1px 2px rgba(28, 27, 24, 0.06), 0 4px 14px rgba(28, 27, 24, 0.05);
  --radius: 16px;
  --space-1: 8px; --space-2: 16px; --space-3: 24px; --space-4: 40px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1016; --surface: #171a23; --surface-2: #1f2330; --text: #eceef4; --muted: #9aa0b0; --border: #2a2f3d;
    --accent: #8b85ff; --accent-deep: #6f68ee; --on-accent: #0b0d16;
    --ok: #5dd28a; --ok-bg: #143122; --miss: #ff9a6b; --miss-bg: #3a2119; --star: #f2c25e; --star-bg: #33280f;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.4 "Lexend", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
.app { max-width: 560px; margin: 0 auto; padding: var(--space-3) var(--space-2) calc(var(--space-4) + 96px); min-height: 100dvh; display: flex; flex-direction: column; }
h1 { font-size: 28px; line-height: 1.2; margin: 0 0 var(--space-1); font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: var(--space-3) 0 var(--space-1); font-weight: 600; }
p { margin: 0 0 var(--space-2); }
.muted { color: var(--muted); }
.small { font-size: 14px; font-weight: 500; }
.num { font-family: -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; font-variant-numeric: tabular-nums lining-nums; }

button { font: inherit; cursor: pointer; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); padding: 14px 18px; min-height: 48px; text-align: left; touch-action: manipulation;
  box-shadow: var(--shadow); transition: background 150ms ease, transform 60ms ease-out, box-shadow 60ms ease-out; }
button:hover { background: var(--surface-2); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent-deep); font-weight: 600; text-align: center; min-height: 56px;
  box-shadow: 0 4px 0 var(--accent-deep); }
button.primary:hover { background: var(--accent); filter: brightness(1.05); }
button.primary:active { transform: translateY(4px); box-shadow: 0 0 0 var(--accent-deep); }
button.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; font-weight: 600; text-align: center; min-height: 56px; box-shadow: 0 3px 0 color-mix(in srgb, var(--ok) 35%, transparent); }
button.miss { background: var(--miss-bg); color: var(--miss); border-color: transparent; font-weight: 600; text-align: center; min-height: 56px; box-shadow: 0 3px 0 color-mix(in srgb, var(--miss) 35%, transparent); }
button.ok:active, button.miss:active { transform: translateY(3px); box-shadow: 0 0 0 transparent; }
button.link { border: none; background: none; color: var(--accent); padding: 8px 4px; min-height: 40px; box-shadow: none; }
button.link:hover { background: none; text-decoration: underline; }
button[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent), var(--shadow); }

.stack { display: flex; flex-direction: column; gap: var(--space-1); }
.row { display: flex; gap: var(--space-1); flex-wrap: wrap; }
.row > button { flex: 1 1 120px; }
.choice { display: flex; flex-direction: column; gap: 2px; }
.choice .title { font-weight: 600; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-2); }
.topbar { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: var(--space-2); gap: 8px; }
.progress { display: flex; gap: 3px; height: 5px; margin-bottom: var(--space-3); }
.progress > span { flex: 1 1 0; border-radius: 3px; background: var(--surface-2); position: relative; transition: background 180ms ease-out; }
.progress > span.done { background: var(--accent); }
.progress > span.now { background: color-mix(in srgb, var(--accent) 45%, var(--surface-2)); }
.progress > span.star::after { content: ""; position: absolute; right: 0; top: -3px; width: 5px; height: 5px; border-radius: 50%; background: var(--star); }
.prompt { font-size: 26px; line-height: 1.3; font-weight: 600; margin: var(--space-3) 0; letter-spacing: -0.01em; }
.prompt.long { font-size: 24px; }
.answer { font-size: 42px; font-weight: 700; line-height: 1.1; margin: var(--space-2) 0 var(--space-1); letter-spacing: -0.02em; }
.explanation { color: var(--muted); border-left: 3px solid var(--border); padding-left: 12px; margin-bottom: var(--space-2); white-space: pre-wrap; }
.mark { font-weight: 700; margin: var(--space-2) 0 var(--space-1); display: inline-block; padding: 6px 12px; border-radius: 999px; }
.mark.ok { color: var(--ok); background: var(--ok-bg); }
.mark.miss { color: var(--miss); background: var(--miss-bg); }
.star { color: var(--star); font-weight: 600; }
input[type="text"] { font: inherit; font-size: 24px; width: 100%; padding: 12px 14px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
pre { white-space: pre-wrap; font: 15px/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: var(--space-2); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
td, th { text-align: left; padding: 8px 4px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 14px; }
.definition { background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: var(--space-2); }
.spacer { flex: 1; }
.actionbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; padding: 12px var(--space-2) calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-top: 1px solid var(--border); }
.actionbar > .inner { max-width: 560px; margin: 0 auto; display: flex; gap: 12px; }
.actionbar > .inner > * { flex: 1 1 0; margin: 0; }
.actionbar > .inner > form { display: contents; }
.actionbar.settling { pointer-events: none; }
.actionbar.ok { background: color-mix(in srgb, var(--ok-bg) 75%, var(--bg)); border-top-color: color-mix(in srgb, var(--ok) 30%, var(--border)); }
.actionbar.miss { background: color-mix(in srgb, var(--miss-bg) 75%, var(--bg)); border-top-color: color-mix(in srgb, var(--miss) 30%, var(--border)); }
.method.quiet { opacity: 0.85; font-size: 15px; }
.kbd-hint { display: none; }
@media (hover: hover) and (pointer: fine) { .kbd-hint { display: block; } }
.mark svg { width: 18px; height: 18px; vertical-align: -3px; margin-right: 4px; }
.mark.ok svg path { stroke: currentColor; stroke-width: 3; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: var(--space-2) 0; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 8px; text-align: center; }
.tile .v { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.tile .l { font-size: 12px; color: var(--muted); margin-top: 4px; }
.rank { font-size: 22px; font-weight: 700; margin: 0 0 4px; }
.inputrow { display: flex; gap: 8px; }
.inputrow input { flex: 1 1 auto; min-height: 56px; }
.inputrow button { flex: 0 0 56px; min-height: 56px; text-align: center; font-size: 22px; padding: 0; }
td.num, th.num { text-align: right; }
td, th { padding: 12px 4px; }
.spark { width: 72px; height: 22px; display: block; }
.spark polyline { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.empty { text-align: center; padding: var(--space-4) var(--space-2); color: var(--muted); }
.streak-tick { font-weight: 600; color: var(--star); }
@media (prefers-reduced-motion: no-preference) {
  .mark.ok svg path { stroke-dasharray: 30; stroke-dashoffset: 30; animation: draw 300ms ease-out forwards; }
  @keyframes draw { to { stroke-dashoffset: 0; } }
  .shake { animation: shake 250ms ease-in-out; }
  @keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
  .actionbar > .inner { animation: fadein 200ms cubic-bezier(0.05, 0.7, 0.1, 1); }
  .streak-tick { animation: tick 400ms ease-out; }
  @keyframes tick { from { transform: scale(0.9); opacity: 0.4; } to { transform: scale(1); opacity: 1; } }
}
.actionbar .pair { display: flex; gap: 12px; flex: 1; }
.actionbar .pair > button { flex: 1 1 0; }
@media (prefers-reduced-motion: no-preference) { .actionbar .pair { animation: fadein 200ms ease-out; } }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.status { display: flex; gap: 12px; flex-wrap: wrap; font-size: 14px; color: var(--muted); margin-bottom: var(--space-2); }
.status strong { color: var(--text); font-weight: 600; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand svg { width: 28px; height: 28px; flex: none; }
.brand h1 { text-transform: lowercase; letter-spacing: -0.01em; }
.titlerow { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.badge { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); white-space: nowrap; background: var(--surface-2); }
.badge.l2 { color: var(--accent); border-color: var(--accent); background: transparent; }
.badge.l3, .badge.l4 { color: var(--ok); border-color: transparent; background: var(--ok-bg); }
.card.locked { opacity: 0.8; display: flex; flex-direction: column; gap: 4px; background: var(--surface-2); }
.card.notice { border-color: var(--star); background: var(--star-bg); margin-bottom: var(--space-2); }
.card.notice .title { font-weight: 600; margin-bottom: 4px; }
button.card.action { width: 100%; margin-bottom: var(--space-1); }
@media (prefers-reduced-motion: reduce) { button, .progress > span { transition: none; } .actionbar .pair { animation: none; } }

/* Programmatic focus lands on headings for screen readers; no visible ring there. Buttons and inputs keep theirs. */
h1:focus, .prompt:focus { outline: none; }
.method { background: var(--surface-2); border-radius: 12px; padding: 10px 14px; margin: 0 0 var(--space-2); }

/* Dark mode: light-on-dark text looks heavier (halation), so trim the variable weight. Must come after the font shorthand above. */
@media (prefers-color-scheme: dark) { body { font-weight: 370; } .answer { font-weight: 650; } .num { font-weight: 400; } }
.notewrap { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
textarea.note { font: inherit; font-size: 15px; line-height: 1.4; width: 100%; padding: 10px 12px; border-radius: 12px; border: 1px dashed var(--border); background: var(--surface-2); color: var(--text); resize: vertical; }
textarea.note:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-style: solid; }

.dontknow { margin-top: var(--space-2); text-align: center; }
.dontknow button.link { color: var(--muted); }
.dontknow button.link:hover { color: var(--accent); }

/* Tab bar: five visible destinations, thumb height; a left rail on wide screens. Hidden during sessions. */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 9; display: flex; justify-content: space-around; background: color-mix(in srgb, var(--surface) 92%, var(--bg)); border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); backdrop-filter: blur(8px); }
.tabbar a { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 48px; padding: 4px 0; color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600; letter-spacing: 0.02em; border-radius: 10px; }
.tabbar a svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.on { color: var(--accent); }
.tabbar a:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
@media (min-width: 900px) {
  .tabbar { top: 0; bottom: 0; right: auto; width: 88px; flex-direction: column; justify-content: flex-start; gap: 8px; padding: 24px 8px; border-top: none; border-right: 1px solid var(--border); }
  .tabbar a { flex: 0 0 auto; }
  body:has(.tabbar:not([hidden])) .app { margin-left: calc(50% - 280px + 44px); }
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
.chips .chip { min-height: 32px; padding: 4px 12px; font-size: 13px; border-radius: 999px; box-shadow: none; }
.chips .chip[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: transparent; }
.chipgap { width: 8px; }
.tabbar[hidden] { display: none; }
.board { margin: 0; padding-left: 24px; }
.board li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--border); }
