:root {
  --bg: #faf6ee;
  --bg2: #ffffff;
  --ink: #2b2440;
  --muted: #7a7290;
  --accent: #d97e1e;
  --accent-soft: #f6e3c8;
  --indigo: #4b3f72;
  --ok: #4a9d6b;
  --warn: #c8564a;
  --line: #e7dfd0;
  --shadow: 0 2px 12px rgba(43, 36, 64, .08);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14121c;
    --bg2: #1f1a2e;
    --ink: #efe9dc;
    --muted: #9a92ad;
    --accent: #e8a04c;
    --accent-soft: #3a2f1e;
    --indigo: #a99bd6;
    --line: #322b47;
    --shadow: 0 2px 12px rgba(0, 0, 0, .35);
  }
}
* { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font-family: var(--sans); line-height: 1.5;
  min-height: 100dvh;
}
button { font: inherit; cursor: pointer; border: none; border-radius: 12px; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
input {
  font: inherit; color: var(--ink); background: var(--bg2);
  border: 1px solid var(--line); border-radius: 12px; padding: .7rem .9rem; width: 100%;
}
input:focus { outline: 2px solid var(--accent); border-color: transparent; }

#app { max-width: 680px; margin: 0 auto; padding: 0 1rem calc(2rem + env(safe-area-inset-bottom)); }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: .9rem 0 .6rem; gap: .5rem;
}
.brand { font-family: var(--serif); font-weight: 700; font-size: 1.15rem; letter-spacing: .2px; }
.brand small { display: block; font-family: var(--sans); font-weight: 400; font-size: .68rem; color: var(--muted); }
.top .pills { display: flex; gap: .4rem; align-items: center; }
.pill {
  background: var(--bg2); border: 1px solid var(--line); color: var(--ink);
  border-radius: 999px; padding: .35rem .7rem; font-size: .8rem;
}
.pill.on { background: var(--accent); color: #fff; border-color: transparent; }

/* ---------- cards ---------- */
.card {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow); padding: 1.1rem 1.2rem; margin-bottom: .9rem;
}
.card h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: .5rem; }
.row { display: flex; gap: .9rem; align-items: center; }
.grow { flex: 1; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }

.statgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.stat { text-align: center; padding: .5rem .2rem; }
.stat b { display: block; font-size: 1.35rem; font-family: var(--serif); }
.stat span { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

.xpbar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: .45rem; }
.xpbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #eab308); border-radius: 99px; }

.btn {
  display: block; width: 100%; padding: .9rem 1rem; border-radius: 14px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 1rem;
  transition: transform .06s;
}
.btn:active { transform: scale(.98); }
.btn.ghost { background: var(--bg2); color: var(--ink); border: 1px solid var(--line); font-weight: 500; }
.btn.small { padding: .55rem .8rem; font-size: .85rem; width: auto; display: inline-block; }
.btnrow { display: flex; gap: .6rem; }
.btnrow .btn { flex: 1; }

/* ---------- auth ---------- */
.auth { padding-top: 12vh; max-width: 380px; margin: 0 auto; }
.auth .logo { font-size: 2.6rem; text-align: center; }
.auth h1 { font-family: var(--serif); text-align: center; font-size: 1.7rem; margin: .3rem 0 .1rem; }
.auth .sub { text-align: center; color: var(--muted); font-size: .85rem; margin-bottom: 1.6rem; font-style: italic; }
.auth form { display: grid; gap: .7rem; }
.tabs { display: flex; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: .25rem; margin-bottom: 1rem; }
.tabs button { flex: 1; padding: .5rem; border-radius: 9px; background: transparent; color: var(--muted); }
.tabs button.on { background: var(--accent); color: #fff; }
.err { color: var(--warn); font-size: .85rem; text-align: center; min-height: 1.2em; }

/* ---------- library ---------- */
.sheetlist { display: grid; gap: .45rem; }
.sheetrow {
  display: flex; align-items: center; gap: .7rem; text-align: left;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px;
  padding: .6rem .8rem; color: var(--ink); width: 100%;
}
.sheetrow .num {
  font-family: var(--serif); font-size: .8rem; color: var(--muted);
  min-width: 2.2em; text-align: right;
}
.sheetrow .t { flex: 1; font-size: .92rem; }
.sheetrow .t small { display: block; color: var(--muted); font-size: .72rem; }
.sheetrow.locked { opacity: .45; }
.sheetrow.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.sheetrow .badge { font-size: .95rem; }

/* ---------- reader ---------- */
.pre h1 { font-family: var(--serif); font-size: 1.6rem; line-height: 1.25; margin: .2rem 0 .3rem; }
.meta { color: var(--muted); font-size: .82rem; font-style: italic; }
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin: .9rem 0 .6rem; }
.modes button {
  padding: .7rem .3rem; border-radius: 12px; background: var(--bg2);
  border: 1px solid var(--line); color: var(--ink); font-size: .82rem;
}
.modes button.on { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.modes button span { display: block; font-size: 1.25rem; margin-bottom: .15rem; }
.slider { display: flex; align-items: center; gap: .7rem; margin: .5rem 0; }
.slider input[type=range] { flex: 1; accent-color: var(--accent); padding: 0; border: 0; background: none; }
.slider b { font-family: var(--serif); min-width: 4.6em; text-align: right; }
.checkline { display: flex; align-items: center; gap: .5rem; font-size: .85rem; color: var(--muted); margin: .4rem 0; }
.checkline input { width: auto; accent-color: var(--accent); }

.stage {
  position: fixed; inset: 0; background: var(--bg); z-index: 40;
  display: flex; flex-direction: column;
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation; overscroll-behavior: contain;
}
.stage .bar { display: flex; align-items: center; gap: .8rem; padding: .8rem 1rem; }
.stage .bar .progress { flex: 1; height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; }
.stage .bar .progress i { display: block; height: 100%; background: var(--accent); }
.stage .bar button { background: none; color: var(--muted); font-size: 1.2rem; padding: .2rem .4rem; }
.stage .count { color: var(--muted); font-size: .75rem; font-variant-numeric: tabular-nums; }

.flashzone { flex: 1; display: flex; align-items: center; justify-content: center; position: relative; }
.guide { position: absolute; left: 50%; transform: translateX(-50%); width: 2px; height: 14px; background: var(--accent); opacity: .5; }
.guide.topg { top: calc(50% - 3.4rem); }
.guide.botg { top: calc(50% + 2.6rem); }
.rsvp { display: flex; font-family: var(--serif); font-size: clamp(1.5rem, 11vw, 2.7rem); white-space: pre; width: 100%; }
.rsvp .pre { flex: 1; text-align: right; }
.rsvp .piv { color: var(--accent); }
.rsvp .post { flex: 1; text-align: left; }
.chunkword { font-family: var(--serif); font-size: clamp(1.3rem, 6.5vw, 2rem); text-align: center; padding: 0 1rem; line-height: 1.3; }
.bigcount { font-family: var(--serif); font-size: 4rem; color: var(--accent); }

.pacerwrap { flex: 1; overflow-y: auto; padding: 1.2rem 1.3rem 45vh; overscroll-behavior: contain; }
.pacer { font-family: var(--serif); font-size: 1.3rem; line-height: 1.85; max-width: 620px; margin: 0 auto; }
.pacer p { margin-bottom: 1em; }
.pacer .w { opacity: .34; transition: opacity .12s; border-radius: 4px; }
.pacer .w.readd { opacity: .95; }
.pacer .w.cur { opacity: 1; background: var(--accent-soft); box-shadow: 0 0 0 3px var(--accent-soft); color: var(--accent); font-weight: 600; }
.pacer .newsflash { border-left: 3px solid var(--line); padding-left: .8em; font-size: .92em; }

.stage .foot { padding: .8rem 1rem calc(.8rem + env(safe-area-inset-bottom)); }
.paused-hint { text-align: center; color: var(--muted); font-size: .8rem; padding-bottom: .4rem; }
.ctrlbtn {
  background: var(--bg2); border: 1px solid var(--line); color: var(--ink);
  border-radius: 10px; padding: .5rem .75rem; font-size: 1rem; min-width: 44px;
}

/* ---------- post-read / quiz ---------- */
.recallbtns { display: grid; gap: .6rem; margin-top: 1rem; }
.recallbtns .btn { text-align: left; display: flex; gap: .8rem; align-items: center; }
.recallbtns .btn em { font-style: normal; font-size: 1.3rem; }
.qopt { display: grid; gap: .55rem; margin-top: .9rem; }
.qopt button {
  text-align: left; padding: .8rem 1rem; border-radius: 12px;
  background: var(--bg2); border: 1px solid var(--line); color: var(--ink);
}
.qopt button.sel { border-color: var(--accent); background: var(--accent-soft); }
.qopt button.right { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, var(--bg2)); }
.qopt button.wrong { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, var(--bg2)); }
.bigresult { font-family: var(--serif); font-size: 2.4rem; text-align: center; margin: .6rem 0; }

/* ---------- stats ---------- */
canvas.chart { width: 100%; height: 180px; }
table.recent { width: 100%; border-collapse: collapse; font-size: .82rem; }
table.recent td { padding: .35rem .3rem; border-top: 1px solid var(--line); }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(1.4rem + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px); z-index: 60;
  background: var(--indigo); color: var(--bg); padding: .6rem 1.1rem;
  border-radius: 999px; font-size: .88rem; opacity: 0; pointer-events: none;
  transition: all .25s; box-shadow: var(--shadow); white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.fade { animation: fadein .25s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }
