:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --text: #1f2421;
  --muted: #6b716c;
  --line: #dedad0;
  --accent: #0f7b6c;
  --accent-text: #ffffff;
  --ok-bg: #dff3e6;
  --ok: #17663a;
  --bad-bg: #fbe3df;
  --bad: #a3271a;
  --pad: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15191a;
    --surface: #1f2526;
    --text: #e8ebe7;
    --muted: #98a19b;
    --line: #333b3c;
    --accent: #3fb8a4;
    --accent-text: #0c1716;
    --ok-bg: #173526;
    --ok: #8fdcaa;
    --bad-bg: #40201c;
    --bad: #f3a79c;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
#app { max-width: 600px; margin: 0 auto; }
.screen {
  padding: calc(var(--pad) + env(safe-area-inset-top)) calc(var(--pad) + env(safe-area-inset-right))
    calc(32px + env(safe-area-inset-bottom)) calc(var(--pad) + env(safe-area-inset-left));
}

h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 4px; }
h2 { font-size: 1rem; margin: 0 0 8px; }
.sub { color: var(--muted); margin: 0; }
.id { font-family: Georgia, "Times New Roman", serif; }
b.id { font-weight: 600; color: var(--accent); }
button {
  font: inherit; color: inherit; cursor: pointer; touch-action: manipulation;
  user-select: none; -webkit-user-select: none;
}
button:disabled { cursor: default; }

/* Buttons */
.primary, .secondary {
  min-height: 52px; border-radius: 12px; padding: 12px 22px; font-weight: 600; border: 0;
}
.primary { background: var(--accent); color: var(--accent-text); }
.primary:disabled { opacity: .4; }
.secondary { background: var(--surface); border: 1px solid var(--line); }
.wide { width: 100%; }
.link { background: none; border: 0; min-height: 44px; padding: 8px; color: var(--muted); text-decoration: underline; }
.link.danger { color: var(--bad); }
.icon { background: none; border: 0; width: 44px; height: 44px; font-size: 1.7rem; line-height: 1; color: var(--muted); }
.actions { display: flex; align-items: center; gap: 8px; }
.actions.column { flex-direction: column; align-items: stretch; margin-top: 12px; }

/* Home */
.top { margin: 8px 0 20px; }
.actions-main { display: grid; gap: 8px; }
.actions-main .primary { text-align: left; display: grid; }
.actions-main .primary small { font-weight: 400; opacity: .85; }
.phase { margin: 28px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-size: .8rem; }
.list { display: grid; gap: 8px; }
.card {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 64px; text-align: left;
  padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
}
.card:disabled { opacity: .5; }
.card .num {
  flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--bg); font-weight: 600; font-size: .9rem;
}
.card.done .num { background: var(--accent); color: var(--accent-text); }
.card .body { flex: 1; min-width: 0; display: grid; }
.card small { color: var(--muted); line-height: 1.35; }
.card .state { flex: none; color: var(--muted); font-size: .85rem; }
footer { margin-top: 32px; text-align: center; }

/* Intro, progress */
nav { margin: -8px 0 4px -8px; }
section { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin: 16px 0; }
section p { margin: 0 0 10px; }
table { width: 100%; border-collapse: collapse; }
td { padding: 8px 0; border-top: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
tr:first-child td { border-top: 0; }
td.id { width: 42%; padding-right: 12px; font-size: 1.05rem; }
small.root { display: block; color: var(--muted); }
ul { margin: 0; padding-left: 20px; }
.with-cta { padding-bottom: 0; }
.cta {
  position: sticky; bottom: 0; margin: 0 calc(-1 * var(--pad)); padding: 12px var(--pad) calc(12px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--line);
}
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.stats div {
  display: grid; text-align: center; padding: 12px 4px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px;
}
.stats b { font-size: 1.4rem; }
.stats small { color: var(--muted); }

/* Lesson */
.lesson { display: flex; flex-direction: column; min-height: var(--vh, 100dvh); padding-bottom: 0; }
.work { flex: 1; }
.bar { display: flex; align-items: center; gap: 4px; margin: -8px 0 12px -12px; }
.track { flex: 1; height: 12px; background: var(--line); border-radius: 6px; overflow: hidden; }
.fill { height: 100%; background: var(--accent); transition: width .2s; }
.label { color: var(--muted); margin: 0 0 8px; }
.prompt { font-size: 1.6rem; line-height: 1.5; overflow-wrap: anywhere; }
.w { border-bottom: 2px dotted var(--muted); cursor: help; }
.w.on { border-bottom-color: var(--accent); color: var(--accent); }
.hint { min-height: 1.5em; margin: 8px 0 16px; color: var(--muted); }

.ticket {
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: 10px; padding: 12px 14px;
}
.ticket p { margin: 0; font-size: 1.15rem; line-height: 1.75; }
.ticket .translation {
  margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line);
  font-size: 1rem; line-height: 1.5; color: var(--muted);
}
.question { font-weight: 600; margin: 0 0 12px; }

.options { display: grid; gap: 8px; }
.opt {
  display: flex; align-items: center; gap: 12px; min-height: 56px; text-align: left; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
}
.opt kbd {
  flex: none; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 6px;
  border: 1px solid var(--line); color: var(--muted); font: inherit; font-size: .8rem;
}
.opt.right { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.opt.wrong { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }

.slots {
  display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start; min-height: 112px;
  padding: 8px 0; margin-bottom: 20px; border-bottom: 2px solid var(--line);
}
.tiles { display: flex; flex-wrap: wrap; gap: 8px; }
.tile {
  min-height: 46px; padding: 8px 14px; background: var(--surface);
  border: 1px solid var(--line); border-bottom-width: 3px; border-radius: 10px;
}
input[type="text"], input[type="search"] {
  width: 100%; min-height: 52px; padding: 12px 14px; font: inherit; color: inherit;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
}
input[type="search"] { background: var(--bg); margin-bottom: 8px; }
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.foot {
  position: sticky; bottom: 0; margin: 16px calc(-1 * var(--pad)) 0;
  padding: 12px var(--pad) calc(12px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px;
  background: var(--bg); border-top: 1px solid var(--line);
}
.foot:empty { display: none; }
.foot.ok { background: var(--ok-bg); color: var(--ok); }
.foot.bad { background: var(--bad-bg); color: var(--bad); }
.verdict { display: grid; overflow-wrap: anywhere; }
.verdict small { opacity: .85; }
.foot .actions { justify-content: flex-end; }
.foot .actions .primary { flex: 1; }
.foot .link { color: inherit; flex: none; }

.finish { text-align: center; padding-top: 48px; }
.finish section { text-align: left; }
.finish .actions { margin-top: 24px; }
.score { font-size: 3rem; font-weight: 700; margin: 16px 0 0; color: var(--accent); }
.error { color: var(--bad); padding: var(--pad); }

/* Keyboard hints only make sense with a real keyboard */
@media (hover: none) { .opt kbd { display: none; } }
@media (hover: hover) {
  .card:not(:disabled):hover, .opt:not(:disabled):hover, .tile:hover, .secondary:hover { border-color: var(--accent); }
}
