:root {
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  --bg: #f2f2f0;
  --surface: #ffffff;
  --ink: #1f1f1e;
  --muted: #75736e;
  --line: #dcdbd6;
  --soft: #e9e9e6;
  --ok: #3f7a5a;
  --ok-soft: #e3efe8;
  --bad: #b5483f;
  --bad-soft: #f5e4e2;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171716; --surface: #212120; --ink: #e9e8e4; --muted: #9b9994;
    --line: #33322f; --soft: #2b2b29;
    --ok: #7fb898; --ok-soft: #223428; --bad: #d9847c; --bad-soft: #3a2624;
  }
}
:root[data-theme="dark"] {
  --bg: #171716; --surface: #212120; --ink: #e9e8e4; --muted: #9b9994;
  --line: #33322f; --soft: #2b2b29;
  --ok: #7fb898; --ok-soft: #223428; --bad: #d9847c; --bad-soft: #3a2624;
}
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
*, *::before, *::after { box-sizing: inherit; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font-family: var(--sans); font-size: 16px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; }

.app { max-width: 34rem; margin: 0 auto; padding: 1rem 1.25rem 4rem; }

.top { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; padding: .5rem 0 1.25rem; }
.brand { font-family: var(--serif); font-size: 1.35rem; font-weight: 600; letter-spacing: -.01em; }
.brand button { background: none; border: 0; padding: 0; font: inherit; }
.meta { color: var(--muted); font-size: .9rem; display: flex; gap: 1rem; }
.meta b { color: var(--ink); font-weight: 600; }

h2 { font-family: var(--serif); font-weight: 600; font-size: 1.15rem; margin: 1.75rem 0 .5rem; }
p { margin: .5rem 0; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  border: 1px solid var(--ink); background: var(--ink); color: var(--bg);
  border-radius: .6rem; padding: .7rem 1.1rem; min-height: 2.75rem;
}
.btn:disabled { opacity: .45; cursor: default; }
.btn.secondary { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.quiet { background: transparent; color: var(--muted); border-color: transparent; padding-left: .5rem; padding-right: .5rem; }
.btn.block { width: 100%; }
.btn:focus-visible, .chip:focus-visible, .seg button:focus-visible, .card:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; }
.row > .btn { flex: 1; }

.level { margin-top: .25rem; }
.bar { height: 4px; background: var(--soft); border-radius: 2px; overflow: hidden; margin-top: .35rem; }
.bar > i { display: block; height: 100%; background: var(--ink); width: 0; transition: width .3s ease; }

.list { display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.card {
  display: flex; align-items: center; gap: .75rem; padding: .85rem 0;
  border-bottom: 1px solid var(--line); background: none; border-left: 0; border-right: 0; border-top: 0;
  width: 100%; text-align: left;
}
.card .ref { font-family: var(--serif); font-size: 1.05rem; }
.card .state { color: var(--muted); font-size: .85rem; }
.card .grow { flex: 1; min-width: 0; }
.dots { display: flex; gap: 3px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--soft); display: block; }
.dots i.on { background: var(--ink); }
.dots i.done { background: var(--ok); }
.x { background: none; border: 0; color: var(--muted); font-size: 1.2rem; padding: .25rem .4rem; }

.empty { padding: 1.5rem 0; color: var(--muted); }

/* practice */
.practice .ref { color: var(--muted); font-size: .9rem; display: flex; justify-content: space-between; align-items: center; }
.stagebar { display: flex; gap: 5px; margin: .6rem 0 1.5rem; }
.stagebar i { flex: 1; height: 3px; background: var(--soft); border-radius: 2px; display: block; }
.stagebar i.on { background: var(--ink); }
.verse {
  font-family: var(--serif); font-size: 1.55rem; line-height: 1.6; letter-spacing: -.005em;
  margin: 0 0 1.5rem; word-wrap: break-word;
}
@media (max-width: 420px) { .verse { font-size: 1.35rem; } }
.verse .w { white-space: nowrap; }
.verse .blank {
  display: inline-block; border-bottom: 2px solid var(--muted); min-width: 1.6em; height: 1em;
  vertical-align: -0.1em; margin: 0 .05em; transition: border-color .15s;
}
.verse .blank.active { border-bottom-color: var(--ink); animation: pulse 1.2s ease-in-out infinite; }
.verse .blank.shake { animation: shake .3s; border-bottom-color: var(--bad); }
.verse .filled { color: var(--ok); }
.verse .miss { color: var(--bad); text-decoration: underline; text-decoration-color: var(--bad); text-decoration-thickness: 2px; }
.verse .extra { color: var(--bad); text-decoration: line-through; }
.verse .hint { color: var(--muted); }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .4 } }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-4px)} 75%{transform:translateX(4px)} }
@media (prefers-reduced-motion: reduce) { .verse .blank.active, .verse .blank.shake { animation: none; } .bar > i { transition: none; } }

.bank { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1.5rem; }
.chip {
  font-family: var(--serif); font-size: 1.1rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: .6rem;
  padding: .45rem .85rem; min-height: 2.6rem;
}
.chip:disabled { opacity: 0; pointer-events: none; }
.chip.wrong { border-color: var(--bad); color: var(--bad); }

textarea.type {
  width: 100%; min-height: 8rem; resize: vertical;
  font-family: var(--serif); font-size: 1.25rem; line-height: 1.55;
  background: var(--surface); border: 1px solid var(--line); border-radius: .6rem; padding: .8rem .9rem;
}
textarea.type:focus { outline: 2px solid var(--ink); outline-offset: 1px; border-color: transparent; }
.firstletters { font-family: var(--serif); font-size: 1.35rem; letter-spacing: .08em; color: var(--muted); margin: 0 0 1rem; line-height: 1.7; }

.result { border-radius: .6rem; padding: .9rem 1rem; margin: 0 0 1rem; }
.result.ok { background: var(--ok-soft); color: var(--ok); }
.result.bad { background: var(--bad-soft); color: var(--bad); }
.result b { font-weight: 600; }

.recite { padding: 2rem 0; text-align: center; color: var(--muted); font-family: var(--serif); font-size: 1.2rem; }

/* forms */
label { display: block; font-size: .9rem; color: var(--muted); margin: 1rem 0 .35rem; }
.field {
  width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: .6rem;
  padding: .7rem .85rem; min-height: 2.75rem;
}
.field:focus { outline: 2px solid var(--ink); outline-offset: 1px; border-color: transparent; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: .6rem; overflow: hidden; }
.seg button { background: transparent; border: 0; padding: .5rem .9rem; min-height: 2.5rem; }
.seg button.on { background: var(--ink); color: var(--bg); }
.note { font-size: .875rem; color: var(--muted); }
.attrib { font-size: .78rem; color: var(--muted); margin-top: 2.5rem; line-height: 1.45; }
textarea.io { width: 100%; min-height: 7rem; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .8rem; background: var(--surface); border: 1px solid var(--line); border-radius: .6rem; padding: .6rem; }
.sample { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.sample .t { font-family: var(--serif); }
.sample .btn { padding: .35rem .8rem; min-height: 2.2rem; }
.summary { text-align: center; padding: 2rem 0; }
.summary .big { font-family: var(--serif); font-size: 2.6rem; font-weight: 600; line-height: 1.1; }
.hidden { display: none !important; }

/* timer + match */
.clockwrap { display: inline-flex; align-items: center; gap: .6rem; }
.clock { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 2.2rem; text-align: right; }
.chip.sel { border-color: var(--ink); background: var(--soft); }
.chip.done, .chip.done:disabled { opacity: .35; }
.mcard {
  font-family: var(--serif); font-size: 1.05rem; line-height: 1.45; text-align: left; width: 100%;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: .6rem;
  padding: .75rem .9rem; margin-bottom: .6rem;
}
.mcard.done { border-color: var(--ok); color: var(--muted); }
.mcard .mref { display: block; color: var(--ok); font-size: .85rem; margin-bottom: .2rem; }
.mcard.wrong { border-color: var(--bad); }
.mcard.shake { animation: shake .3s; }
.match .list { border-top: 0; }

/* browse */
.crumbs a { color: inherit; }
.grid { display: grid; gap: .4rem; }
.grid.books { grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); }
.grid.nums { grid-template-columns: repeat(auto-fill, minmax(2.6rem, 1fr)); }
.cell {
  font-family: var(--serif); font-size: 1rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: .5rem;
  min-height: 2.6rem; padding: .35rem .5rem; display: flex; align-items: center; justify-content: space-between; gap: .4rem;
}
.grid.nums .cell { justify-content: center; padding: 0; font-variant-numeric: tabular-nums; }
.cell b { font-size: .8rem; color: var(--muted); font-weight: 500; }
.cell.has { border-color: var(--ink); }
.cell.list { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.cell.cache { background: var(--soft); color: var(--muted); }
.cell.sel { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.cell.list.off { background: transparent; border-style: dashed; }
