/* Chunk Reader — warm paper, one accent, a serif for the words you read and a
   sans for everything that is not reading. No web fonts: it has to work with
   the network off. */

:root {
  --paper: #f6f1e8;
  --paper-2: #efe8db;
  --paper-3: #e6ddcc;
  --ink: #1e1a15;
  --ink-2: #5d564c;
  --ink-3: #8f877b;
  --line: #d9d0c1;
  --accent: #c2410c;
  --accent-ink: #fff;
  --accent-soft: #f7d9c4;
  --good: #2f7a4a;
  --bad: #b3261e;
  --mark: #ffe08a;
  /* chunk size 1-6 in the progress chart: one hue, light to dark, validated as an ordinal ramp on --paper */
  --cs-1: #6da7ec; --cs-2: #3987e5; --cs-3: #256abf; --cs-4: #184f95; --cs-5: #0d366b; --cs-6: #06203f;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
  --radius: 12px;
  --gutter: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #16130f;
    --paper-2: #1f1b15;
    --paper-3: #2a251d;
    --ink: #ece5d8;
    --ink-2: #b3a996;
    --ink-3: #7f7666;
    --line: #35302a;
    --accent: #f1875a;
    --accent-ink: #1a120c;
    --accent-soft: #4a2a1a;
    --good: #6fc48a;
    --bad: #f27d75;
    --mark: #5a4a12;
    --cs-1: #184f95; --cs-2: #256abf; --cs-3: #3987e5; --cs-4: #6da7ec; --cs-5: #9ec5f4; --cs-6: #cde2fb;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #16130f; --paper-2: #1f1b15; --paper-3: #2a251d; --ink: #ece5d8; --ink-2: #b3a996; --ink-3: #7f7666;
  --line: #35302a; --accent: #f1875a; --accent-ink: #1a120c; --accent-soft: #4a2a1a; --good: #6fc48a; --bad: #f27d75; --mark: #5a4a12;
  --cs-1: #184f95; --cs-2: #256abf; --cs-3: #3987e5; --cs-4: #6da7ec; --cs-5: #9ec5f4; --cs-6: #cde2fb;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.5 var(--sans);
  min-height: 100dvh;
  overflow-x: hidden;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h2 { font-family: var(--serif); font-weight: 500; letter-spacing: -.01em; font-size: 1.6rem; margin: 0 0 .5rem; }
h3 { font-size: 1.05rem; font-weight: 600; margin: 0 0 .6rem; }
kbd { font-family: var(--mono); font-size: .78em; padding: .05em .4em; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; background: var(--paper-2); }

.app { max-width: 960px; margin: 0 auto; padding: 0 var(--gutter) 3rem; }

/* header ------------------------------------------------------------------ */
.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .9rem 0 .6rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem;
  flex-wrap: wrap;
}
.brand { display: inline-flex; align-items: center; gap: .55rem; color: inherit; text-decoration: none; }
.brand svg { width: 26px; height: 26px; fill: var(--ink); stroke: var(--ink); stroke-width: 1.6; }
.brand svg .mid { fill: var(--accent); stroke: var(--accent); }
.brand b { font-weight: 600; letter-spacing: -.01em; }
.tabs { display: flex; gap: .25rem; }
.tabs button {
  border: 0; background: transparent; padding: .45rem .8rem; border-radius: 999px; color: var(--ink-2);
}
.tabs button:hover { background: var(--paper-2); color: var(--ink); }
.tabs button[aria-selected="true"] { background: var(--ink); color: var(--paper); }
@media (max-width: 420px) {
  .bar { gap: .5rem; }
  .tabs { width: 100%; justify-content: space-between; }
  .tabs button { flex: 1; padding: .45rem .3rem; }
}

/* buttons ----------------------------------------------------------------- */
.primary, .ghost {
  border-radius: 999px; padding: .55rem 1.05rem; border: 1px solid var(--line);
  background: var(--paper-2); color: var(--ink); white-space: nowrap;
}
.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.primary:hover { filter: brightness(1.06); }
.ghost:hover { background: var(--paper-3); }
.ghost.small { padding: .3rem .7rem; font-size: .85rem; }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

/* the picked text --------------------------------------------------------- */
.picked { display: flex; align-items: baseline; gap: .6rem .9rem; flex-wrap: wrap; margin: 0 0 .9rem; }
.ptitle { font-family: var(--serif); font-weight: 500; font-size: 1.15rem; }
.pmeta { color: var(--ink-3); font-size: .85rem; }
.picked .ghost { margin-left: auto; }

@media (max-width: 640px) {
  /* title and button share a row, the figures go under: the text starts higher */
  .picked { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: .2rem .6rem; }
  .picked .pmeta { grid-column: 1 / -1; grid-row: 2; }
}

/* Read: the stage --------------------------------------------------------- */
.stage {
  position: relative; height: clamp(220px, 38vh, 340px);
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper-2);
  display: grid; place-items: center; overflow: hidden; outline: none; cursor: pointer;
  user-select: none; -webkit-user-select: none;
}
.stage:focus-visible { box-shadow: 0 0 0 3px var(--accent-soft); }
.reticle { position: absolute; inset: 0; pointer-events: none; }
.reticle i { position: absolute; left: 50%; width: 1px; height: 18px; background: var(--ink-3); opacity: .55; }
.reticle i:first-child { top: 22%; }
.reticle i:last-child { bottom: 22%; }
.flash {
  font-family: var(--serif); font-size: clamp(1.6rem, 5.4vw, 3.4rem); line-height: 1.15; letter-spacing: -.01em;
  white-space: nowrap; text-align: center; padding: 0; max-width: 100%;
}
.flash .mid { color: var(--accent); }
.stage-hint { position: absolute; bottom: .8rem; left: 0; right: 0; text-align: center; color: var(--ink-3); font-size: .85rem; }
.stage.playing .stage-hint { opacity: 0; }
.by-touch { display: none; }
@media (hover: none) { .by-key { display: none; } .by-touch { display: inline; } }
.stage.done .flash { opacity: .45; }

/* transport --------------------------------------------------------------- */
.transport {
  display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: .8rem 1rem;
  margin: .9rem 0; padding: .7rem .9rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper);
}
.tbtns { display: flex; gap: .3rem; }
.tb {
  border: 1px solid var(--line); background: var(--paper-2); border-radius: 999px; width: 40px; height: 40px;
  display: grid; place-items: center; padding: 0;
}
.tb svg { width: 18px; height: 18px; fill: currentColor; }
.tb.play { width: auto; padding: 0 1rem 0 .8rem; gap: .4rem; grid-auto-flow: column; background: var(--ink); color: var(--paper); border-color: var(--ink); font-weight: 600; }
.tb.play[data-playing="true"] { background: var(--paper-2); color: var(--ink); border-color: var(--line); }
.prog { display: grid; gap: .3rem; min-width: 120px; }
.prog .track { height: 6px; border-radius: 3px; background: var(--paper-3); overflow: hidden; }
.prog .track i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s linear; }
.prog .under { display: flex; justify-content: space-between; color: var(--ink-3); font-size: .78rem; font-variant-numeric: tabular-nums; }
.knob { display: grid; grid-template-columns: auto auto auto; grid-template-rows: auto auto; align-items: center; column-gap: .25rem; }
.knob > span:first-child { grid-column: 1 / -1; font-size: .7rem; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.knob button { width: 30px; height: 30px; border-radius: 999px; border: 1px solid var(--line); background: var(--paper-2); padding: 0; font-size: 1.05rem; line-height: 1; }
.knob b { font-variant-numeric: tabular-nums; min-width: 3.4ch; text-align: center; font-size: 1.05rem; }
.knob small { color: var(--ink-3); font-size: .72rem; margin-left: .2rem; }
.knob .val { display: inline-flex; align-items: baseline; justify-content: center; }
@media (max-width: 640px) {
  .transport { grid-template-columns: 1fr 1fr; }
  .tbtns { grid-column: 1 / -1; justify-content: center; }
  .prog { grid-column: 1 / -1; }
}

/* summary ----------------------------------------------------------------- */
.summary { margin: 1rem 0; padding: 1rem 1.1rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper-2); }
.figures { display: flex; flex-wrap: wrap; gap: 1.2rem 2rem; margin: .4rem 0 1rem; }
.figures div span { display: block; font-size: .7rem; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.figures div b { font-size: 1.5rem; font-weight: 500; font-family: var(--serif); font-variant-numeric: tabular-nums; }
.keys { color: var(--ink-3); font-size: .82rem; margin: .8rem 0 0; }
@media (hover: none) { .keys { display: none; } }

/* Pace: the page ---------------------------------------------------------- */
.pagebox { border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper-2); max-height: 62vh; overflow: auto; overscroll-behavior: contain; }
.page { max-width: 66ch; margin: 0 auto; padding: 1.6rem clamp(1rem, 4vw, 2.2rem) 40vh; font-family: var(--serif); font-size: 1.22rem; line-height: 1.75; }
.page p { margin: 0 0 1.2em; }
.page .c { border-radius: 4px; padding: .05em .1em; margin: 0 -.1em; cursor: pointer; transition: background .08s; }
.page .c.on { background: var(--mark); color: var(--ink); box-shadow: 0 0 0 1px var(--mark); }
.page .c.was { color: var(--ink-3); }
.page .c:hover { background: var(--paper-3); }
.page .c.on:hover { background: var(--mark); }

/* Train ------------------------------------------------------------------- */
.train-head p { color: var(--ink-2); max-width: 60ch; margin: 0 0 .5rem; }
.stats { font-size: .9rem; color: var(--ink-3); }
.stage-title { display: flex; align-items: baseline; gap: .8rem; margin: 1.6rem 0 .3rem; }
.stage-title h3 { margin: 0; font-family: var(--serif); font-weight: 500; font-size: 1.3rem; }
.stage-title p { margin: 0; color: var(--ink-3); font-size: .9rem; }
.steps .step {
  display: grid; grid-template-columns: 2.2rem 1fr auto; gap: .2rem .8rem; align-items: center;
  padding: .8rem .2rem; border-bottom: 1px solid var(--line);
}
.step .n { font-family: var(--mono); font-size: .8rem; color: var(--ink-3); }
.step .t { font-weight: 600; }
.step .b { grid-column: 2; color: var(--ink-2); font-size: .9rem; }
.step .best { grid-column: 2; font-size: .82rem; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.step .best.pass { color: var(--good); }
.step .best.fail { color: var(--bad); }
.step .go { grid-column: 3; grid-row: 1 / span 3; }
.step.passed .n::before { content: "✓ "; color: var(--good); }
.step.next .t::after { content: "next"; font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); margin-left: .6rem; }

.drill { margin: .5rem 0 1.5rem; padding: 1.1rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper-2); }
.drill .dh { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: .6rem; }
.drill .dh b { font-family: var(--serif); font-weight: 500; font-size: 1.2rem; }
.drill .dh span { color: var(--ink-3); font-size: .85rem; font-variant-numeric: tabular-nums; }
.drill .field-area { position: relative; height: 170px; border-radius: 8px; background: var(--paper); border: 1px solid var(--line); display: grid; place-items: center; overflow: hidden; }
.sweep-row { display: flex; justify-content: space-between; width: 100%; padding: 0 8%; }
.sweep-row .dot {
  width: 48px; height: 48px; border-radius: 999px; border: 1px solid var(--line); display: grid; place-items: center;
  font-family: var(--serif); font-size: 1.6rem; color: transparent; transition: background .08s;
}
.sweep-row .dot.lit { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.span-word { font-family: var(--serif); font-size: clamp(1.5rem, 5vw, 2.6rem); }
.drill .answer { margin-top: .8rem; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.drill .answer input { font-family: var(--mono); font-size: 1.3rem; letter-spacing: .3em; width: 9ch; padding: .4rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); }
.drill .opt { padding: .55rem 1rem; border: 1px solid var(--line); border-radius: 999px; background: var(--paper); font-family: var(--serif); font-size: 1.1rem; }
.drill .opt.right { border-color: var(--good); background: color-mix(in srgb, var(--good) 14%, var(--paper)); }
.drill .opt.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, var(--paper)); }
.drill .msg { margin-top: .7rem; color: var(--ink-2); }
.drill .msg.pass { color: var(--good); font-weight: 600; }
.drill .msg.fail { color: var(--bad); font-weight: 600; }
.drill .drill-foot { margin-top: .8rem; display: flex; gap: .5rem; flex-wrap: wrap; }

/* Texts ------------------------------------------------------------------- */
.texts-head p { color: var(--ink-2); max-width: 60ch; margin: 0 0 1rem; }
.lib { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .7rem; margin-bottom: 1.6rem; }
.card {
  text-align: left; padding: .9rem 1rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper-2);
  display: grid; gap: .25rem; align-content: start; position: relative;
}
.card:hover { border-color: var(--ink-3); }
.card.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.card .ct { font-family: var(--serif); font-size: 1.1rem; font-weight: 500; line-height: 1.25; }
.card .cm { color: var(--ink-3); font-size: .82rem; }
.card .cl {
  position: absolute; top: .6rem; right: .6rem; font-size: .62rem; font-weight: 600; letter-spacing: .1em;
  padding: .1rem .35rem; border: 1px solid var(--line); border-radius: 4px; color: var(--ink-3); background: var(--paper);
}
.card .cl[title="German"] { color: var(--accent); border-color: var(--accent); }
.card .ct { padding-right: 2.2rem; hyphens: auto; }
.page[lang="de"] { hyphens: auto; }
.card .cq { color: var(--ink-3); font-size: .78rem; }
.card .cx { position: absolute; top: .5rem; right: .5rem; border: 0; background: transparent; color: var(--ink-3); padding: .2rem .4rem; border-radius: 6px; }
.card .cx:hover { background: var(--paper-3); color: var(--bad); }
.add { padding: 1rem 1.1rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper-2); display: grid; gap: .8rem; }
.add.drop { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.field { display: grid; gap: .3rem; }
.field span { font-size: .85rem; color: var(--ink-2); }
.field em { color: var(--ink-3); font-style: normal; }
.field input, .field textarea { padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); width: 100%; resize: vertical; }
.file { position: relative; overflow: hidden; display: inline-flex; align-items: center; }
.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.count { color: var(--ink-3); font-size: .85rem; }

/* Quiz -------------------------------------------------------------------- */
.quiz { position: fixed; inset: 0; background: color-mix(in srgb, var(--ink) 45%, transparent); display: grid; place-items: center; padding: var(--gutter); z-index: 10; overflow: auto; }
.quiz[hidden] { display: none; }
.quiz-card { width: min(640px, 100%); max-height: calc(100dvh - 2 * var(--gutter)); overflow: auto; background: var(--paper); border: 1px solid var(--line); border-radius: 16px; padding: 1.2rem 1.3rem; }
.quiz-sub { color: var(--ink-3); margin: 0; font-size: .9rem; }
.qs { list-style: none; padding: 0; margin: 1rem 0; display: grid; gap: 1rem; }
.qs li { display: grid; gap: .4rem; }
.qs .q { font-weight: 600; }
.qs .opts { display: grid; gap: .3rem; }
.qs .opts button { text-align: left; padding: .5rem .8rem; border: 1px solid var(--line); border-radius: 8px; background: var(--paper-2); }
.qs .opts button[aria-pressed="true"] { border-color: var(--ink); background: var(--paper-3); }
.qs .opts button.right { border-color: var(--good); background: color-mix(in srgb, var(--good) 14%, var(--paper)); }
.qs .opts button.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, var(--paper)); }
.quiz-foot { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.score { margin-left: auto; font-family: var(--serif); font-size: 1.3rem; font-weight: 500; }
.score.pass { color: var(--good); }
.score.fail { color: var(--bad); }

/* Progress ---------------------------------------------------------------- */
.progress { margin: 1.2rem 0 .4rem; padding: 1rem 0 1.1rem; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.progress h3 { font-family: var(--serif); font-weight: 500; font-size: 1.3rem; margin: 0 0 .5rem; }
.progress h4 { font-size: .7rem; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); font-weight: 400; margin: 0 0 .45rem; }
.pg-totals { margin: 0 0 .9rem; }
.pg-totals b small, .pg-best b small { font-family: var(--sans); font-size: .8rem; color: var(--ink-3); font-weight: 400; }
.pg-chart { position: relative; margin: 0 0 .9rem; touch-action: pan-y; }
.pg-cap, .pg-empty, .pg-note { color: var(--ink-2); font-size: .9rem; max-width: 60ch; margin: 0 0 .6rem; }
.pg-note { color: var(--ink-3); font-size: .82rem; margin: .6rem 0 0; }
.pg-svg { display: block; max-width: 100%; height: auto; overflow: visible; font-family: var(--sans); }
.pg-grid { stroke: var(--line); stroke-width: 1; }
.pg-pass { stroke: var(--ink-3); stroke-width: 1; }
.pg-tick { fill: var(--ink-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.pg-tick.strong { fill: var(--ink); font-weight: 600; }
.pg-axis { fill: var(--ink-3); font-size: 11px; }
.pg-dot { stroke: var(--paper); stroke-width: 2; }
.pg-halo { fill: none; stroke: var(--ink); stroke-width: 1.5; pointer-events: none; }
.pg-dot.s1, .sw.s1 { fill: var(--cs-1); background: var(--cs-1); }
.pg-dot.s2, .sw.s2 { fill: var(--cs-2); background: var(--cs-2); }
.pg-dot.s3, .sw.s3 { fill: var(--cs-3); background: var(--cs-3); }
.pg-dot.s4, .sw.s4 { fill: var(--cs-4); background: var(--cs-4); }
.pg-dot.s5, .sw.s5 { fill: var(--cs-5); background: var(--cs-5); }
.pg-dot.s6, .sw.s6 { fill: var(--cs-6); background: var(--cs-6); }
.pg-tip {
  position: absolute; z-index: 2; pointer-events: none; max-width: min(260px, 100%);
  background: var(--ink); color: var(--paper); border-radius: 8px; padding: .45rem .6rem; font-size: .8rem; line-height: 1.35;
}
.pg-tip b, .pg-tip span { display: block; }
.pg-tip b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pg-best ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: .5rem; }
.pg-best li { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: .1rem .4rem; }
.pg-best .sw { width: 10px; height: 10px; border-radius: 50%; }
.pg-best li span { font-size: .85rem; color: var(--ink-2); white-space: nowrap; }
.pg-best li b { grid-column: 1 / -1; font-family: var(--serif); font-weight: 500; font-size: 1.15rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pg-table { margin: .9rem 0 0; font-size: .85rem; }
.pg-table summary { cursor: pointer; color: var(--ink-2); padding: .35rem 0; }
.pg-scroll { max-height: 16rem; overflow: auto; border: 1px solid var(--line); border-radius: 8px; margin-top: .3rem; }
.pg-scroll table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.pg-scroll th, .pg-scroll td { text-align: left; padding: .3rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.pg-scroll td:nth-child(2) { white-space: normal; min-width: 9rem; }
.pg-scroll th { position: sticky; top: 0; background: var(--paper-2); font-weight: 600; color: var(--ink-2); }
.pg-actions { margin-top: .9rem; }
.pg-msg { font-size: .88rem; color: var(--ink-2); }
.pg-msg.pass { color: var(--good); }
.pg-msg.fail { color: var(--bad); }
@media (max-width: 640px) {
  .pg-best ul { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .7rem .5rem; }
  .pg-table summary { padding: .6rem 0; }
  .pg-totals { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem 1rem; }
  .pg-scroll { font-size: .78rem; }
  .pg-scroll th, .pg-scroll td { padding: .3rem .35rem; }
  .pg-scroll td:nth-child(2) { min-width: 0; }
}

/* Fingers: nothing you have to hit is smaller than 40 px on a phone. */
@media (pointer: coarse), (max-width: 640px) {
  .tabs button { min-height: 40px; }
  .knob button { width: 40px; height: 40px; }
  .ghost.small { padding: .55rem .9rem; }
  .card .cx { top: .15rem; right: .15rem; min-width: 40px; min-height: 40px; display: grid; place-items: center; font-size: 1.2rem; }
  .qs .opts button { padding: .7rem .8rem; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
