/* 文法 — mobile-first, iOS-like. Washi paper and sumi ink, 藍 indigo and 朱 vermilion.
   Light/dark via prefers-color-scheme. */

:root {
  --bg: #f5f1e8;
  --surface: #fffdf8;
  --surface-2: #efe9dc;
  --surface-3: #e5ddcc;
  --text: #1f1c17;
  --text-2: #6c665c;
  --text-3: #a39c8f;
  --line: rgba(60, 45, 15, 0.09);
  --line-strong: rgba(60, 45, 15, 0.16);
  --accent: #2d4a86;          /* 藍 */
  --accent-ink: #ffffff;
  --accent-soft: rgba(45, 74, 134, 0.1);
  --shu: #d4553a;             /* 朱 */
  --shu-soft: rgba(212, 85, 58, 0.12);
  --ok: #3b8a5c;
  --ok-soft: rgba(59, 138, 92, 0.12);
  --bad: #c43d3d;
  --bad-soft: rgba(196, 61, 61, 0.1);
  --st-new: #b9b1a2;
  --st-learning: #d99a2b;     /* 山吹 */
  --st-review: #2d4a86;
  --st-known: #5a9a86;        /* 若竹 */
  --track: rgba(60, 45, 15, 0.08);
  --shadow: 0 1px 2px rgba(60, 45, 15, 0.05), 0 8px 24px rgba(60, 45, 15, 0.06);
  --sheet-shadow: 0 -10px 40px rgba(0, 0, 0, 0.18);
  --blur-bg: rgba(245, 241, 232, 0.8);
  --hero-1: #2d4a86;
  --hero-2: #1e3361;
  --radius: 22px;
  --radius-s: 14px;
  --tabbar-h: 58px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Segoe UI", Roboto, "Noto Sans JP", sans-serif;
  --font-jp: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", var(--font);
  --font-serif: "Hiragino Mincho ProN", "Hiragino Mincho Pro", "Yu Mincho", "YuMincho", "Noto Serif JP", "Songti SC", serif;
  --font-num: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121214;
    --surface: #1c1c1f;
    --surface-2: #26262a;
    --surface-3: #313136;
    --text: #f1ede4;
    --text-2: #aaa59b;
    --text-3: #6f6b64;
    --line: rgba(255, 255, 255, 0.07);
    --line-strong: rgba(255, 255, 255, 0.13);
    --accent: #8ea8f0;
    --accent-ink: #10172a;
    --accent-soft: rgba(142, 168, 240, 0.14);
    --shu: #f07a5c;
    --shu-soft: rgba(240, 122, 92, 0.15);
    --ok: #5cc286;
    --ok-soft: rgba(92, 194, 134, 0.14);
    --bad: #f27171;
    --bad-soft: rgba(242, 113, 113, 0.13);
    --st-new: #57534d;
    --st-learning: #e8b04a;
    --st-review: #8ea8f0;
    --st-known: #72bba5;
    --track: rgba(255, 255, 255, 0.08);
    --shadow: none;
    --sheet-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
    --blur-bg: rgba(18, 18, 20, 0.8);
    --hero-1: #2a3f70;
    --hero-2: #1a2747;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 var(--font);
  letter-spacing: -0.01em;
  min-height: 100dvh;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; letter-spacing: inherit; text-align: inherit; }
button:disabled { cursor: default; }
input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; }
[hidden] { display: none !important; }
.ic { display: inline-flex; flex: none; }
.ic svg { display: block; }
.muted { color: var(--text-2); }
.small { font-size: 13.5px; }
.center { text-align: center; }
.mt { margin-top: 12px; }
b { font-weight: 650; }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

.jp { font-family: var(--font-jp); letter-spacing: 0.01em; }
.serif, .serif .jp, .jp.serif { font-family: var(--font-serif); }
ruby { ruby-position: over; }
rt { font-size: 0.5em; color: var(--text-2); letter-spacing: 0; font-family: var(--font-jp); font-weight: 400; }
body.no-furigana rt { display: none; }

#view { max-width: 640px; margin: 0 auto; padding-left: var(--safe-l); padding-right: var(--safe-r); }
.view { min-height: 100dvh; }
.scroll { padding: 4px 16px 0; }
.bottom-space { height: calc(var(--tabbar-h) + var(--safe-b) + 28px); }
body[data-tab=""] .bottom-space { height: calc(var(--safe-b) + 32px); }
.view.selecting .bottom-space { height: calc(var(--safe-b) + 150px); }

.splash { min-height: 100dvh; display: grid; place-items: center; font: 600 44px var(--font-serif); color: var(--text-3); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }

/* ---------- headers ---------- */

.large-title {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
  padding: calc(var(--safe-t) + 20px) 16px 14px;
}
.large-title h1 { font-size: 34px; letter-spacing: -0.03em; font-weight: 780; line-height: 1.1; }
.eyebrow { font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 2px; }
.eyebrow::first-letter { text-transform: uppercase; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: grid; grid-template-columns: 44px 1fr minmax(44px, auto); align-items: center; gap: 4px;
  padding: calc(var(--safe-t) + 6px) 8px 8px;
  background: var(--blur-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
}
.top-title { text-align: center; font-weight: 650; font-size: 17px; min-width: 0; display: flex; flex-direction: column; align-items: center; }
.top-title > .jp, .top-title > span:first-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-title .serif { font-size: 20px; }
.top-sub { font-size: 12px; color: var(--text-2); font-weight: 500; }
.top-actions { display: flex; justify-content: flex-end; }
.top-save { font-weight: 650; color: var(--accent); padding: 8px 10px; font-size: 16px; }

.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 22px; color: var(--text); flex: none; }
.icon-btn:active { background: var(--surface-2); }
.icon-btn.small { width: 34px; height: 34px; color: var(--text-2); }
.round-btn {
  width: 42px; height: 42px; border-radius: 21px; display: grid; place-items: center; flex: none;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 16px rgba(45, 74, 134, 0.3);
}
.round-btn:active { transform: scale(0.95); }

/* ---------- cards & lists ---------- */

.card { display: block; width: 100%; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 14px; }
.card.pad { padding: 18px; }
button.card { text-align: left; }
button.card:active:not(:disabled) { transform: scale(0.99); }
.card-title { font-size: 17px; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 2px; }
.card .muted.small { margin: 0 0 14px; }

.list { overflow: hidden; }
.list-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 4px 8px; }
.list-title { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-2); }
.list .list-title { display: block; padding: 14px 16px 4px; }
.list-empty { padding: 22px 16px; text-align: center; font-size: 14.5px; }
.link { color: var(--accent); font-weight: 600; font-size: 15px; display: inline-flex; align-items: center; gap: 4px; }

.prow {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 16px; text-align: left;
  border-bottom: 1px solid var(--line);
}
.prow:last-child { border-bottom: 0; }
.prow:active { background: var(--surface-2); }
.prow.sel { background: var(--accent-soft); }
.prow-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.prow-form { font-size: 17px; font-weight: 600; font-family: var(--font-serif); }
.prow-form .jp { font-family: var(--font-serif); }
.prow-form rt { display: none; }
.prow-mean { font-size: 13.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prow-side { display: flex; align-items: center; gap: 8px; color: var(--text-3); flex: none; }
.prow > .ic:last-child { color: var(--text-3); }
.check {
  width: 24px; height: 24px; border-radius: 12px; border: 2px solid var(--line-strong); flex: none;
  display: grid; place-items: center; color: var(--accent-ink);
}
.prow.sel .check { background: var(--accent); border-color: var(--accent); }
.lvl-tag { font-size: 11px; font-weight: 700; color: var(--text-2); background: var(--surface-2); padding: 2px 6px; border-radius: 6px; }
.soon-tag { color: var(--text-3); display: inline-flex; }
.miss { display: inline-flex; align-items: center; gap: 3px; color: var(--bad); font: 600 13px var(--font-num); background: var(--bad-soft); padding: 3px 8px; border-radius: 10px; }

.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--st-new); }
.dot.st-learning, .st-learning > i, .legend i.st-learning { background: var(--st-learning); }
.dot.st-review { background: var(--st-review); }
.dot.st-known { background: var(--st-known); }
.dot.st-new { background: transparent; box-shadow: inset 0 0 0 1.5px var(--st-new); }

.badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600;
  padding: 3px 9px 3px 7px; border-radius: 20px; background: var(--surface-2); color: var(--text-2);
}
.badge.st-learning { color: #9a6a10; background: rgba(217, 154, 43, 0.14); }
.badge.st-review { color: var(--accent); background: var(--accent-soft); }
.badge.st-known { color: #3d7a67; background: rgba(90, 154, 134, 0.14); }
@media (prefers-color-scheme: dark) {
  .badge.st-learning { color: var(--st-learning); }
  .badge.st-known { color: var(--st-known); }
}
.badge.soon { padding-left: 7px; }
.level { font: 700 11.5px var(--font-num); letter-spacing: 0.04em; padding: 3px 8px; border-radius: 7px; background: var(--text); color: var(--bg); }

/* stacked progress */
.stack { display: flex; height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; gap: 2px; }
.stack span { display: block; height: 100%; }
.stack .st-review { background: var(--st-review); }
.stack .st-learning { background: var(--st-learning); }
.stack .st-known { background: var(--st-known); }

/* ---------- home ---------- */

.hero {
  padding: 20px 20px 18px; color: #fff;
  background: radial-gradient(120% 140% at 100% 0%, rgba(255, 255, 255, 0.12), transparent 50%), linear-gradient(160deg, var(--hero-1), var(--hero-2));
  box-shadow: 0 12px 30px rgba(30, 51, 97, 0.28);
  position: relative; overflow: hidden;
}
.hero::after {
  content: "復習"; position: absolute; right: -6px; bottom: -22px; font: 700 96px/1 var(--font-serif);
  color: rgba(255, 255, 255, 0.06); pointer-events: none; letter-spacing: -0.04em;
}
.hero-top { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 16px; }
.hero-num { font: 700 56px/1 var(--font-num); letter-spacing: -0.04em; }
.hero-lbl { font-size: 15px; opacity: 0.8; margin-top: 4px; }
.forecast { display: flex; gap: 6px; align-items: flex-end; height: 64px; }
.fc-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; height: 100%; }
.fc-col span { font-size: 10px; opacity: 0.65; text-transform: lowercase; }
.fc-bar { width: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.35); }
.fc-bar.today { background: #fff; }
.hero-done { display: flex; align-items: center; gap: 8px; font-weight: 600; opacity: 0.9; position: relative; z-index: 1; }
.btn.light { background: #fff; color: #1e3361; position: relative; z-index: 1; }

.note { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text-2); padding: 0 6px 14px; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.tiles.three { grid-template-columns: repeat(3, 1fr); }
.tiles .card { margin: 0; }
.tile { padding: 16px; display: flex; flex-direction: column; align-items: flex-start; }
.tile.small { align-items: center; padding: 14px 8px; }
.tile:disabled { opacity: 1; }
.tile-ic { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; margin-bottom: 10px; }
.tile-ic.flame { color: var(--text-3); background: var(--surface-2); }
.tile-ic.flame.on { color: var(--shu); background: var(--shu-soft); }
.tile-ic.err { color: var(--bad); background: var(--bad-soft); }
.tile:disabled .tile-ic.err { color: var(--text-3); background: var(--surface-2); }
.tile-num { font: 700 30px/1 var(--font-num); letter-spacing: -0.03em; }
.tile.small .tile-num { font-size: 24px; }
.tile-lbl { font-size: 14px; color: var(--text-2); margin-top: 3px; }
.tile-sub { font-size: 12.5px; color: var(--text-3); margin-top: 8px; font-weight: 500; }
button.tile:not(:disabled) .tile-sub { color: var(--accent); }

.decks-seg { margin-bottom: 14px; }
.decks-seg button small { margin-left: 6px; font: 600 11px var(--font-num); color: var(--text-3); }
.decks-seg button.on small { color: var(--text-2); }
.stepper { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.stepper-ctl { display: flex; align-items: center; gap: 4px; background: var(--surface-2); border-radius: 20px; padding: 2px; }
.stepper-ctl .icon-btn.small { color: var(--text); }
.stepper-val { min-width: 28px; text-align: center; font: 700 17px var(--font-num); }

.row-link { display: flex; align-items: center; gap: 14px; padding: 14px 16px; }
.row-link > span:nth-child(2) { flex: 1; display: flex; flex-direction: column; }
.row-link small { font-size: 13px; }
.row-link > .ic:last-child { color: var(--text-3); }
.row-ic { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }

/* ---------- decks ---------- */

.search {
  display: flex; align-items: center; gap: 8px; background: var(--surface-2); border-radius: 13px;
  padding: 0 4px 0 12px; height: 44px; margin-bottom: 14px; color: var(--text-3);
}
.search.small { height: 38px; border-radius: 11px; }
.search-input { flex: 1; min-width: 0; border: 0; background: none; outline: none; height: 100%; font-size: 16px; color: var(--text); -webkit-appearance: none; appearance: none; }
.search-input::-webkit-search-cancel-button { display: none; }
.search .clear { visibility: hidden; }
.search:has(.search-input:not(:placeholder-shown)) .clear { visibility: visible; }

.deck { padding: 18px; }
.deck-top { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.deck-name { font: 600 30px/1 var(--font-serif); letter-spacing: -0.01em; }
.deck-total { flex: 1; color: var(--text-2); font-size: 14px; }
.deck-top .ic { color: var(--text-3); align-self: center; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 12px; font-size: 12.5px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 8px; height: 8px; border-radius: 50%; background: var(--st-new); }
.legend i.st-new { background: transparent; box-shadow: inset 0 0 0 1.5px var(--st-new); }
.legend i.st-review { background: var(--st-review); }
.legend i.st-known { background: var(--st-known); }
.deck-soon { display: flex; align-items: center; gap: 6px; margin-top: 10px; font-size: 12.5px; color: var(--text-3); }

.deck-summary { margin: 4px 0 14px; }
.filter-chips { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px 14px; padding: 0 16px; scrollbar-width: none; }
.filter-chips::-webkit-scrollbar { display: none; }
.filter-chips.tight { margin: 0 0 4px; padding: 0; }
.fchip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 17px;
  background: var(--surface); box-shadow: inset 0 0 0 1px var(--line-strong); font-size: 14px; font-weight: 550; color: var(--text-2);
}
.fchip small { font: 600 12px var(--font-num); color: var(--text-3); }
.fchip i { width: 8px; height: 8px; border-radius: 50%; background: var(--st-new); }
.fchip.st-new i { background: transparent; box-shadow: inset 0 0 0 1.5px var(--st-new); }
.fchip.st-review i { background: var(--st-review); }
.fchip.st-known i { background: var(--st-known); }
.fchip.on { background: var(--text); color: var(--bg); box-shadow: none; }
.fchip.on small { color: var(--bg); opacity: 0.7; }

.select-bar:empty { display: none; }
.select-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  padding: 10px 16px calc(var(--safe-b) + 10px);
  background: var(--blur-bg); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
}
.select-head { display: flex; justify-content: space-between; align-items: center; max-width: 608px; margin: 0 auto 8px; font-size: 14px; }
.select-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; max-width: 608px; margin: 0 auto; }
.select-actions button {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px; border-radius: 14px;
  font-size: 12px; font-weight: 600; color: var(--accent); background: var(--surface);
}
.select-actions button:disabled { color: var(--text-3); }
body:has(.select-bar:not(:empty)) .tabbar { display: none; }

/* ---------- point card ---------- */

.pcard { display: flex; flex-direction: column; gap: 4px; }
.pcard-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 8px; }
.pcard-form { font-size: 32px; font-weight: 600; line-height: 1.25; letter-spacing: 0.01em; }
.pcard.compact .pcard-form { font-size: 24px; }
.pcard-kana { font-size: 14px; color: var(--text-2); margin-top: -2px; }
.pcard-mean { font-size: 18px; margin: 6px 0 10px; line-height: 1.4; }
.pcard.compact .pcard-mean { font-size: 16px; margin-bottom: 8px; }
.pcard-rule, .pcard-confuse { display: flex; flex-direction: column; gap: 6px; padding: 12px 0 2px; border-top: 1px solid var(--line); }
.lbl { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-3); }
.rule { font-size: 16.5px; font-weight: 500; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 12px;
  background: var(--surface-2); font-size: 15px; font-family: var(--font-serif);
}
.chip .jp { font-family: var(--font-serif); }
.chip small { font: 700 10.5px var(--font-num); color: var(--text-3); }
.chip:active { background: var(--surface-3); }
.pcard-labels { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 12px; font-size: 13px; color: var(--text-2); }
.pcard-labels span:not(.ic) { background: var(--accent-soft); color: var(--accent); padding: 3px 9px; border-radius: 8px; font-weight: 550; }

.point-sheet { padding: 4px 4px 0; }
.back-link { display: inline-flex; align-items: center; gap: 2px; color: var(--accent); font-weight: 600; font-size: 15px; margin: 0 0 10px -4px; }
.sheet-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn-grid .btn { font-size: 14.5px; padding: 0 10px; }
.danger-text { color: var(--bad) !important; }

/* ---------- study ---------- */

.study { display: flex; flex-direction: column; }
.study-top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: calc(var(--safe-t) + 6px) 8px 8px; background: var(--blur-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
}
.progress { flex: 1; height: 6px; background: var(--track); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width 0.4s cubic-bezier(.2, .8, .2, 1); }
.counter { font: 600 13px var(--font-num); color: var(--text-2); min-width: 38px; text-align: right; }
.furi { font: 600 15px var(--font-jp); color: var(--text-3); }
.furi[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }

.stage { padding: 10px 20px calc(var(--safe-b) + 24px); display: flex; flex-direction: column; animation: rise 0.28s cubic-bezier(.2, .8, .2, 1); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.mode-tag { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-2); margin: 8px 0 18px; }
.mode-tag .level { margin-left: auto; }
.sentence {
  font: 500 23px/2.05 var(--font-serif); margin: 0 0 26px; letter-spacing: 0.02em; word-break: break-all; line-break: strict;
}
.sentence .jp { font-family: var(--font-serif); }
.sentence rt { font-size: 0.48em; }
.blank {
  display: inline-block; min-width: 3.4em; padding: 0 0.3em; margin: 0 0.1em; line-height: 1.5;
  border-bottom: 2.5px solid var(--accent); color: var(--accent); text-align: center;
  background: var(--accent-soft); border-radius: 6px 6px 0 0;
}
.blank.ok { color: var(--ok); border-color: var(--ok); background: var(--ok-soft); }
.blank.bad { color: var(--ok); border-color: var(--ok); background: var(--ok-soft); }
.blank .jp { font-family: var(--font-serif); font-weight: 600; }

.options { display: flex; flex-direction: column; gap: 10px; }
.option {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 58px; padding: 12px 16px;
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow), inset 0 0 0 1px var(--line);
  font-size: 18.5px; transition: background 0.15s, box-shadow 0.15s, opacity 0.2s, transform 0.1s;
}
.option .jp { font-family: var(--font-jp); }
.option:active:not(:disabled) { transform: scale(0.985); background: var(--surface-2); }
.opt-key {
  width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; flex: none;
  font: 700 13px var(--font-num); color: var(--text-3); background: var(--surface-2);
}
.option.ok { background: var(--ok-soft); box-shadow: inset 0 0 0 2px var(--ok); }
.option.ok .opt-key { background: var(--ok); color: #fff; }
.option.bad { background: var(--bad-soft); box-shadow: inset 0 0 0 2px var(--bad); }
.option.bad .opt-key { background: var(--bad); color: #fff; }
.option.dim { opacity: 0.45; }
.options.answered .option.dim { display: none; }
.option:disabled { cursor: default; color: var(--text); }

.feedback { display: none; margin-top: 20px; scroll-margin-top: 70px; }
.feedback.show { display: block; animation: rise 0.3s cubic-bezier(.2, .8, .2, 1); }
.fb-head { display: flex; align-items: center; gap: 8px; font-size: 19px; font-weight: 750; margin-bottom: 8px; }
.fb-head.ok { color: var(--ok); }
.fb-head.bad { color: var(--bad); }
.fb-tr { margin: 0 0 12px; color: var(--text-2); font-style: italic; }
.fb-why { margin: 0 0 8px; font-size: 16px; }
.fb-trap { margin: 0 0 8px; font-size: 15px; color: var(--text-2); }
.fb-trap b { color: var(--shu); font-weight: 650; }
.fb-card { margin-top: 16px; padding: 16px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow), inset 0 0 0 1px var(--line); }
.fb-card-lbl { font-size: 12px; font-weight: 700; color: var(--shu); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 10px; }
.stage-foot { margin-top: 22px; }
.feedback .stage-foot { position: sticky; bottom: 0; margin: 22px -20px 0; padding: 12px 20px calc(var(--safe-b) + 12px); background: linear-gradient(to bottom, transparent, var(--bg) 30%); }
.stage > .pcard { background: var(--surface); padding: 20px; border-radius: var(--radius); box-shadow: var(--shadow); }

.summary { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding-top: 24px; }
.summary h2 { font-size: 24px; letter-spacing: -0.02em; margin-top: 8px; }
.summary > p { margin: 0 0 12px; }
.summary .btn { margin-top: 10px; }
.sum-ic { width: 64px; height: 64px; border-radius: 32px; display: grid; place-items: center; background: var(--ok-soft); color: var(--ok); }
.sum-wrong { text-align: left; margin-top: 4px; }
.ring { position: relative; width: 150px; height: 150px; }
.ring svg { width: 100%; height: 100%; }
.ring circle { fill: none; stroke-width: 10; stroke-linecap: round; }
.ring-track { stroke: var(--track); }
.ring-val { stroke: var(--ok); transition: stroke-dasharray 0.6s; }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-center b { font: 700 34px var(--font-num); letter-spacing: -0.03em; }
.ring-center span { font-size: 12px; color: var(--text-2); }

/* ---------- book ---------- */

.label-card { padding: 16px 18px; }
.label-top { display: flex; align-items: center; gap: 10px; color: var(--accent); }
.label-top > .ic:last-child { color: var(--text-3); }
.label-name { flex: 1; font-size: 17px; font-weight: 650; color: var(--text); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.label-meta { font-size: 13.5px; margin: 6px 0 12px 28px; }
.label-card .stack { margin-left: 28px; }
.study-card .stack { margin-bottom: 12px; }
.study-card p { margin: 0 0 14px; }

.name-form { display: flex; flex-direction: column; gap: 12px; }
.text {
  width: 100%; height: 50px; border-radius: 14px; border: 0; padding: 0 16px; font-size: 17px;
  background: var(--surface-2); outline: none; color: var(--text);
}
.text:focus { box-shadow: inset 0 0 0 2px var(--accent); }

.picker { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.picker-head { flex: none; }
.picker-head .sheet-title { margin-bottom: 12px; }
.picker-head .search { margin-bottom: 10px; }
.picker-list { flex: 1; overflow-y: auto; margin: 8px -20px 0; border-top: 1px solid var(--line); -webkit-overflow-scrolling: touch; }
.picker-list .prow { padding-left: 20px; padding-right: 20px; }
.picker-foot { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.picker-foot .btn { min-width: 120px; }

/* ---------- stats ---------- */

.activity { display: flex; align-items: flex-end; gap: 3px; height: 72px; margin-top: 14px; }
.act-col { flex: 1; display: flex; align-items: flex-end; height: 100%; }
.act-bar { width: 100%; background: var(--accent); border-radius: 3px; min-height: 2px; }
.act-bar[style*="height: 2px"] { background: var(--track); }
.act-bar.today { background: var(--shu); }
.act-axis { display: flex; justify-content: space-between; font-size: 11.5px; margin-top: 6px; }
.acc-row { display: grid; grid-template-columns: 38px 1fr 44px; grid-template-rows: auto auto; align-items: center; column-gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.acc-row:last-child { border-bottom: 0; padding-bottom: 0; }
.acc-name { font: 600 20px var(--font-serif); grid-row: span 2; }
.acc-bar { height: 8px; background: var(--track); border-radius: 4px; overflow: hidden; }
.acc-bar span { display: block; height: 100%; background: var(--ok); border-radius: 4px; }
.acc-val { font: 700 15px var(--font-num); text-align: right; }
.acc-n { font-size: 12px; grid-column: 2 / 4; }
.loading { display: grid; place-items: center; padding: 60px 0; }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--track); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- empty ---------- */

.empty { text-align: center; padding: 40px 24px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty.full { min-height: 80dvh; justify-content: center; }
.empty-ic { width: 60px; height: 60px; border-radius: 20px; display: grid; place-items: center; background: var(--surface-2); color: var(--text-2); margin-bottom: 6px; }
.empty h3 { font-size: 19px; letter-spacing: -0.02em; }
.empty p { margin: 0 0 10px; max-width: 340px; font-size: 15px; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 50px; padding: 0 20px;
  border-radius: 15px; font-weight: 650; font-size: 16.5px; transition: transform 0.1s, opacity 0.2s;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; }
.btn.block { width: 100%; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--bad); color: #fff; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }

/* segmented */
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; }
.seg button { flex: 1; height: 36px; border-radius: 9px; font-size: 15px; font-weight: 600; color: var(--text-2); text-align: center; display: inline-flex; align-items: center; justify-content: center; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); }
@media (prefers-color-scheme: dark) { .seg button.on { background: var(--surface-3); } }

/* ---------- tab bar ---------- */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: center; gap: 0;
  padding: 6px max(8px, var(--safe-l)) calc(var(--safe-b) + 4px);
  background: var(--blur-bg); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; max-width: 140px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--text-3); text-decoration: none; font-size: 10.5px; font-weight: 600; padding: 2px 0;
}
.tabbar a.on { color: var(--accent); }
body[data-tab=""] .tabbar { display: none; }

/* ---------- sheets ---------- */

.sheet-wrap { position: fixed; inset: 0; z-index: 100; pointer-events: none; }
.backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.35); opacity: 0; transition: opacity 0.28s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-width: 640px; margin: 0 auto;
  background: var(--surface); border-radius: 26px 26px 0 0; box-shadow: var(--sheet-shadow);
  padding: 8px 20px calc(var(--safe-b) + 20px); max-height: 88dvh; overflow-y: auto;
  transform: translateY(100%); transition: transform 0.3s cubic-bezier(.2, .8, .2, 1);
  overscroll-behavior: contain;
}
.sheet.tall { height: 88dvh; display: flex; flex-direction: column; overflow: hidden; }
.sheet.tall > :last-child { flex: 1; min-height: 0; }
.sheet-wrap.open { pointer-events: auto; }
.sheet-wrap.open .backdrop { opacity: 1; }
.sheet-wrap.open .sheet { transform: none; }
.grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--line-strong); margin: 0 auto 14px; flex: none; }
.sheet-title { font-size: 20px; font-weight: 750; letter-spacing: -0.02em; margin-bottom: 14px; }
.sheet-title.small { font-size: 15px; color: var(--text-2); font-weight: 600; text-align: center; }

.group { background: var(--surface-2); border-radius: 16px; overflow: hidden; margin-bottom: 14px; }
@media (prefers-color-scheme: dark) { .group { background: var(--surface-2); } }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 52px; padding: 8px 16px; border-bottom: 1px solid var(--line); text-align: left; }
.row:last-child { border-bottom: 0; }
.row.action { justify-content: flex-start; font-size: 16.5px; }
.row.action:active { background: var(--surface-3); }
.row.action.danger { color: var(--bad); }
.row.action .ic { color: var(--accent); }
.row.action.danger .ic { color: var(--bad); }
.actions .btn { margin-top: 2px; }

.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 16px; background: var(--track); transition: background 0.2s; }
.switch i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); transition: transform 0.2s; }
.switch input:checked + i { background: var(--ok); }
.switch input:checked + i::after { transform: translateX(20px); }
.switch input:focus-visible + i { outline: 2.5px solid var(--accent); outline-offset: 2px; }

.confirm p { margin: -6px 0 14px; }

/* ---------- toast ---------- */

#toast {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px); z-index: 200;
  display: flex; justify-content: center; pointer-events: none; padding: 0 16px;
  transform: translateY(20px); opacity: 0; transition: transform 0.25s, opacity 0.25s;
}
#toast.top { bottom: auto; top: calc(var(--safe-t) + 12px); transform: translateY(-20px); }
#toast.show { transform: none; opacity: 1; }
body[data-tab=""] #toast:not(.top) { bottom: calc(var(--safe-b) + 20px); }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 14px; max-width: 520px;
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 16px; font-size: 15px; font-weight: 550;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}
.toast.error { background: var(--bad); color: #fff; }
.toast button { color: var(--accent); font-weight: 700; }

/* ---------- offline & login ---------- */

.offline-pill {
  position: fixed; top: calc(var(--safe-t) + 6px); left: 0; right: 0; z-index: 150; display: flex; justify-content: center;
  pointer-events: none; transform: translateY(-60px); transition: transform 0.3s;
}
.offline-pill span { background: var(--text); color: var(--bg); font-size: 12.5px; font-weight: 600; padding: 6px 12px; border-radius: 14px; }
body.is-offline .offline-pill { transform: none; animation: fadeout 0.4s 4s forwards; }
@keyframes fadeout { to { opacity: 0; } }

.login {
  position: fixed; inset: 0; z-index: 300; display: grid; place-items: center; padding: 24px;
  background: var(--bg); transition: opacity 0.25s;
}
.login.leaving { opacity: 0; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-logo { width: 84px; height: 84px; border-radius: 20px; box-shadow: 0 10px 30px rgba(30, 51, 97, 0.3); }
.login h1 { font: 600 40px var(--font-serif); margin: 16px 0 4px; }
.login p { margin: 0 0 28px; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.form-error { display: flex; align-items: center; gap: 8px; color: var(--bad); font-size: 14.5px; text-align: left; }

@media (min-width: 700px) {
  .sentence { font-size: 26px; }
  .stage { padding-top: 24px; }
}
@media (hover: hover) {
  .option:hover:not(:disabled) { box-shadow: var(--shadow), inset 0 0 0 1.5px var(--accent); }
  .prow:hover { background: var(--surface-2); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
