:root {
  color-scheme: light dark;
  --paper: #f5f1e8;
  --paper-raised: #fffdf7;
  --paper-low: #ece6db;
  --ink: #171614;
  --muted: #6f6b63;
  --line: #d4cdc0;
  --red: #b3262d;
  --red-deep: #8e1c22;
  --red-wash: #f1dcda;
  --green: #26734d;
  --green-wash: #dceadf;
  --amber: #a86600;
  --nav: rgba(250, 247, 240, .94);
  --shadow: 0 16px 34px rgba(50, 41, 30, .11);
}

* { box-sizing: border-box; }
html { background: var(--paper); font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-width: 320px; min-height: 100dvh; color: var(--ink);
  background: linear-gradient(rgba(90, 80, 65, .035) 1px, transparent 1px), var(--paper);
  background-size: 100% 28px;
  font-family: -apple-system, BlinkMacSystemFont, "Noto Sans CJK SC", "PingFang SC", sans-serif;
}
button, input, select { font: inherit; }
button, select, label { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
[hidden] { display: none !important; }

.app-shell { width: min(100%, 520px); min-height: 100dvh; margin: 0 auto; padding: calc(16px + env(safe-area-inset-top)) 18px calc(104px + env(safe-area-inset-bottom)); }
.topbar, .date-line, .card-index, .today-stats, .bottom-nav, .brand, .top-actions, .study-head, .question-meta, .section-title, .sheet-title, .switch-row, .deck-progress-head { display: flex; align-items: center; }
.topbar { justify-content: space-between; margin-bottom: 19px; }
.brand { gap: 10px; border: 0; padding: 0; background: transparent; text-align: left; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 39px; color: white; background: var(--red); font: 800 1.2rem "Yu Mincho", serif; box-shadow: 4px 4px 0 var(--ink); }
.brand small, .brand strong { display: block; }
.brand small { color: var(--red); font: 700 .68rem ui-monospace, monospace; letter-spacing: .1em; }
.brand strong { margin-top: 2px; font-size: 1.1rem; letter-spacing: -.03em; }
.top-actions { gap: 10px; }
.icon-button { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 50%; background: var(--paper-raised); font-size: .75rem; font-weight: 800; }
.countdown { display: flex; align-items: baseline; gap: 3px; min-width: 57px; border-bottom: 3px solid var(--red); padding: 2px 3px 4px; font-family: ui-monospace, monospace; }
.countdown strong { font-size: 1.42rem; line-height: 1; }
.countdown span { color: var(--muted); font-size: .72rem; }

.view { display: none; animation: view-in .18s ease-out; }
.view.active { display: block; }
@keyframes view-in { from { opacity: 0; transform: translateY(4px); } }

.date-line { justify-content: space-between; color: var(--muted); font-size: .84rem; }
.status-dot::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: var(--green); }
.status-dot.offline::before { background: var(--amber); }
.answer-strip { display: grid; grid-template-columns: repeat(15, 1fr); gap: 4px; margin: 12px 0 17px; }
.answer-strip i { min-width: 0; aspect-ratio: 1.05; border: 1px solid var(--line); background: var(--paper-raised); }
.answer-strip .correct { border-color: var(--green); background: var(--green); }
.answer-strip .wrong { border-color: var(--red); background: var(--red); }
.answer-strip .fuzzy { border-color: var(--amber); background: var(--amber); }

.paper-card, .paper-section { border: 1px solid var(--line); border-radius: 3px; background: var(--paper-raised); }
.paper-card { position: relative; overflow: hidden; box-shadow: var(--shadow); }
.paper-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 5px; background: var(--red); }
.mission-card { min-height: 315px; padding: 21px 21px 19px 26px; }
.card-index { justify-content: space-between; border-bottom: 1px solid var(--line); padding-bottom: 11px; color: var(--muted); font: .76rem ui-monospace, monospace; }
.card-index span { color: var(--red); font-weight: 800; letter-spacing: .08em; }
.deck-label { margin: 31px 0 10px; color: var(--red); font-size: .8rem; font-weight: 800; }
.mission-card h1 { margin: 0; font-family: "Yu Mincho", "Hiragino Mincho ProN", serif; font-size: clamp(1.45rem, 6.2vw, 1.8rem); line-height: 1.55; letter-spacing: .01em; }
.microcopy { margin: 18px 0 21px; color: var(--muted); font-size: .83rem; line-height: 1.55; }

.primary-action, .secondary-action { min-height: 52px; border-radius: 3px; padding: 0 17px; font-weight: 800; cursor: pointer; }
.primary-action { width: 100%; border: 0; color: #fff; background: var(--red); text-align: left; box-shadow: 0 6px 0 var(--red-deep); }
.primary-action span { float: right; opacity: .82; font-size: .78rem; font-weight: 600; }
.primary-action:active { transform: translateY(3px); box-shadow: 0 3px 0 var(--red-deep); }
.secondary-action { width: 100%; border: 1px solid var(--ink); background: var(--ink); color: var(--paper-raised); text-align: center; }

.today-stats { margin: 20px 0; border-block: 1px solid var(--line); }
.today-stats div { flex: 1; padding: 13px 4px; text-align: center; }
.today-stats div + div { border-left: 1px solid var(--line); }
.today-stats strong { display: block; font: 700 1.17rem ui-monospace, monospace; }
.today-stats span { color: var(--muted); font-size: .72rem; }
.paper-section { margin-top: 17px; padding: 18px; }
.section-title { justify-content: space-between; margin-bottom: 12px; }
.section-title small, .page-heading small, .sheet-title small { color: var(--red); font: 800 .68rem ui-monospace, monospace; letter-spacing: .11em; }
.section-title h2, .sheet-title h2 { margin: 2px 0 0; font-size: 1.04rem; }
.section-title > span { color: var(--muted); font: .8rem ui-monospace, monospace; }
.schedule-row { display: grid; grid-template-columns: 92px 1fr; gap: 11px; border-top: 1px dashed var(--line); padding: 10px 0; }
.schedule-row time { color: var(--red); font: 700 .7rem/1.5 ui-monospace, monospace; }
.schedule-row b, .schedule-row small { display: block; }
.schedule-row b { font-size: .84rem; }
.schedule-row small { margin-top: 2px; color: var(--muted); font-size: .72rem; line-height: 1.45; }
.schedule-row.now { margin-inline: -8px; padding-inline: 8px; background: var(--red-wash); }
.schedule-note { margin: 8px 0 0; color: var(--muted); font-size: .72rem; line-height: 1.5; }
.minimum-task label { display: flex; align-items: center; min-height: 47px; border-top: 1px dashed var(--line); font-size: .9rem; }
.minimum-task input { width: 19px; height: 19px; margin: 0 11px 0 0; accent-color: var(--red); }
.quick-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.quick-modes button { min-height: 91px; border: 1px solid var(--line); border-radius: 3px; padding: 12px; background: var(--paper-raised); text-align: left; }
.quick-modes span { float: right; display: grid; place-items: center; width: 30px; height: 30px; color: white; background: var(--red); font: 800 .75rem ui-monospace, monospace; }
.quick-modes b, .quick-modes small { display: block; }
.quick-modes b { margin-top: 4px; font-size: .9rem; }
.quick-modes small { clear: both; padding-top: 8px; color: var(--muted); font-size: .7rem; }

.study-head { justify-content: space-between; min-height: 44px; }
.study-head > div { text-align: center; }
.study-head p { margin: 0; font-size: .78rem; font-weight: 800; }
.study-head strong { color: var(--muted); font: .7rem ui-monospace, monospace; }
.text-button { min-width: 54px; min-height: 44px; border: 0; padding: 0; color: var(--red); background: transparent; font-size: .83rem; font-weight: 800; }
.deck-scroller { display: flex; gap: 7px; overflow-x: auto; scrollbar-width: none; margin: 0 -18px 14px; padding: 0 18px 3px; }
.deck-scroller::-webkit-scrollbar { display: none; }
.deck-chip { flex: none; min-height: 36px; border: 1px solid var(--line); border-radius: 99px; padding: 0 13px; background: var(--paper-raised); color: var(--muted); font-size: .75rem; font-weight: 750; }
.deck-chip.active { border-color: var(--ink); color: var(--paper-raised); background: var(--ink); }
.question-card { min-height: 480px; padding: 19px 19px 22px 24px; }
.question-meta { justify-content: space-between; gap: 8px; border-bottom: 1px solid var(--line); padding-bottom: 10px; font-size: .72rem; }
.question-meta span { color: var(--red); font-weight: 800; }
.question-meta b { overflow: hidden; color: var(--muted); font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.question-card h2 { min-height: 110px; margin: 23px 0 17px; font-family: "Yu Mincho", "Hiragino Mincho ProN", serif; font-size: clamp(1.25rem, 5.7vw, 1.58rem); line-height: 1.6; }
.choices { display: grid; gap: 8px; }
.choice { display: grid; grid-template-columns: 30px 1fr; align-items: center; min-height: 52px; border: 1px solid var(--line); border-radius: 2px; padding: 8px 11px; background: transparent; text-align: left; font-size: .9rem; }
.choice i { display: grid; place-items: center; width: 23px; height: 23px; border: 1px solid var(--line); border-radius: 50%; font: normal .7rem ui-monospace, monospace; }
.choice.correct { border-color: var(--green); background: var(--green-wash); color: #163a2a; }
.choice.wrong { border-color: var(--red); background: var(--red-wash); color: #58181b; }
.reveal-button { position: relative; width: 100%; min-height: 150px; overflow: hidden; border: 1px solid var(--red); border-radius: 2px; padding: 22px; background: repeating-linear-gradient(135deg, var(--red), var(--red) 12px, var(--red-deep) 12px, var(--red-deep) 24px); color: white; font-weight: 900; letter-spacing: .08em; }
.flip-answer { min-height: 150px; border: 1px solid var(--line); padding: 18px; background: var(--paper-low); font-size: 1rem; line-height: 1.7; }
.rating-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 10px; }
.rating-row button { min-height: 52px; border: 1px solid var(--line); border-radius: 2px; background: transparent; font-size: .8rem; font-weight: 800; }
.rating-row button[data-rating="again"] { border-color: var(--red); color: var(--red); }
.rating-row button[data-rating="fuzzy"] { border-color: var(--amber); color: var(--amber); }
.rating-row button[data-rating="good"] { border-color: var(--green); color: var(--green); }
.explanation { margin-top: 15px; border-top: 1px solid var(--line); padding-top: 14px; }
.result-line { margin: 0 0 7px; font-weight: 900; }
.result-line.ok { color: var(--green); }
.result-line.no { color: var(--red); }
.explanation > p:not(.result-line) { color: var(--muted); font-size: .85rem; line-height: 1.65; }
.trap { border-left: 3px solid var(--amber); padding-left: 10px; color: var(--ink) !important; }

.page-heading { margin: 12px 0 20px; }
.page-heading h1 { margin: 5px 0 6px; font: 700 1.55rem/1.35 "Yu Mincho", serif; }
.page-heading p { margin: 0; color: var(--muted); font-size: .84rem; }
.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.metric { min-height: 100px; border: 1px solid var(--line); border-radius: 3px; padding: 15px; background: var(--paper-raised); }
.metric strong { display: block; font: 700 1.65rem ui-monospace, monospace; }
.metric span { color: var(--muted); font-size: .76rem; }
.week-chart { display: grid; grid-template-columns: repeat(7, 1fr); align-items: end; gap: 7px; height: 120px; padding-top: 10px; }
.day-bar { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 5px; color: var(--muted); font: .65rem ui-monospace, monospace; }
.day-bar i { width: 100%; min-height: 3px; max-height: 85px; background: var(--red); }
.deck-progress { padding: 12px 0; border-top: 1px dashed var(--line); }
.deck-progress-head { justify-content: space-between; margin-bottom: 7px; font-size: .8rem; }
.deck-progress-head span { color: var(--muted); font: .7rem ui-monospace, monospace; }
.progress-track { display: flex; height: 9px; background: var(--paper-low); }
.progress-track i { display: block; height: 100%; }
.progress-track .solid { background: var(--green); }
.progress-track .learning { background: var(--amber); }
.progress-track .weak { background: var(--red); }
.coach-note { margin: 17px 0; border-left: 5px solid var(--red); padding: 14px 16px; background: var(--ink); color: var(--paper-raised); font-size: .85rem; line-height: 1.6; }

.timeline-item { position: relative; margin-left: 8px; border-left: 1px solid var(--line); padding: 0 0 19px 20px; }
.timeline-item::before { content: ""; position: absolute; left: -5px; top: 5px; width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
.timeline-item.current::before { background: var(--red); box-shadow: 0 0 0 5px var(--red-wash); }
.timeline-item time { color: var(--red); font: 700 .7rem ui-monospace, monospace; }
.timeline-item h3 { margin: 5px 0; font-size: .95rem; }
.timeline-item p { margin: 0; color: var(--muted); font-size: .8rem; line-height: 1.55; }
.timeline-item.future { opacity: .62; }
.mock-entry form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mock-entry form label { color: var(--muted); font-size: .75rem; }
.mock-entry input, .mock-entry select, .settings-group input[type="password"] { display: block; width: 100%; min-height: 46px; margin-top: 5px; border: 1px solid var(--line); border-radius: 2px; padding: 0 10px; color: var(--ink); background: var(--paper); }
.mock-entry form label:first-child, .mock-entry form button { grid-column: 1 / -1; }
.mock-list { margin-top: 13px; }
.mock-row { display: flex; justify-content: space-between; border-top: 1px dashed var(--line); padding: 10px 0; font-size: .78rem; }
.mock-row span { color: var(--muted); }

.bottom-nav { position: fixed; z-index: 20; inset: auto 0 0; justify-content: center; height: calc(70px + env(safe-area-inset-bottom)); padding: 0 max(12px, calc((100vw - 520px) / 2)) env(safe-area-inset-bottom); border-top: 1px solid var(--line); background: var(--nav); backdrop-filter: blur(16px); }
.bottom-nav button { flex: 1; max-width: 130px; min-height: 56px; border: 0; background: transparent; color: var(--muted); font-size: .7rem; font-weight: 750; }
.bottom-nav span { display: block; margin-bottom: 2px; font: 700 .95rem "Yu Mincho", serif; }
.bottom-nav button.active { color: var(--red); }

.sheet { position: fixed; inset: auto 0 0; width: min(100%, 520px); max-height: 88dvh; margin: auto auto 0; overflow-y: auto; border: 1px solid var(--line); border-radius: 13px 13px 0 0; padding: 10px 20px calc(25px + env(safe-area-inset-bottom)); color: var(--ink); background: var(--paper-raised); box-shadow: 0 -20px 60px rgba(0,0,0,.24); }
.sheet::backdrop { background: rgba(10, 9, 8, .58); backdrop-filter: blur(2px); }
.sheet-handle { width: 42px; height: 4px; margin: 0 auto 16px; border-radius: 3px; background: var(--line); }
.sheet-title { justify-content: space-between; margin-bottom: 17px; }
.sheet-title button { width: 44px; height: 44px; border: 0; background: transparent; font-size: 1.6rem; }
.translation-source { border-left: 4px solid var(--red); padding: 12px 14px; background: var(--paper-low); font: 1rem/1.7 "Yu Mincho", serif; }
.translation-body { padding: 16px 2px; line-height: 1.7; }
.translation-body h3 { margin: 18px 0 5px; font-size: .85rem; }
.translation-body p { margin: 0; color: var(--muted); font-size: .88rem; }
.term-list { display: grid; gap: 6px; }
.term-list div { display: grid; grid-template-columns: 110px 1fr; border-bottom: 1px dashed var(--line); padding: 7px 0; font-size: .82rem; }
.term-list b { color: var(--red); }
.loading { color: var(--muted); }
.settings-group { border-top: 1px solid var(--line); padding: 15px 0; }
.settings-group h3 { margin: 0 0 7px; font-size: .95rem; }
.settings-group p, .settings-group li { color: var(--muted); font-size: .78rem; line-height: 1.55; }
.settings-group > label:not(.switch-row) { display: block; color: var(--muted); font-size: .75rem; }
.switch-row { min-height: 44px; gap: 10px; font-size: .85rem; }
.switch-row input { width: 20px; height: 20px; accent-color: var(--red); }
.setting-status { min-height: 19px; margin: 8px 0 0; }
.data-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.data-actions h3 { grid-column: 1 / -1; }
.data-actions button, .file-button { display: grid; place-items: center; min-height: 47px; border: 1px solid var(--line); border-radius: 2px; background: transparent; font-size: .8rem; font-weight: 750; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.toast { position: fixed; z-index: 50; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); max-width: calc(100% - 36px); transform: translate(-50%, 20px); border-radius: 3px; padding: 11px 15px; background: var(--ink); color: var(--paper-raised); opacity: 0; pointer-events: none; font-size: .8rem; transition: .2s ease; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (min-width: 760px) { body { border-inline: 1px solid var(--line); } }
@media (prefers-color-scheme: dark) {
  :root { --paper: #171615; --paper-raised: #211f1c; --paper-low: #2b2925; --ink: #f2eee6; --muted: #aaa398; --line: #444039; --red: #e0525a; --red-deep: #9d272d; --red-wash: #482326; --green: #55a879; --green-wash: #1f3a2c; --amber: #d89b38; --nav: rgba(23, 22, 21, .94); --shadow: 0 18px 38px rgba(0,0,0,.28); }
  .choice.correct { color: #bde6cd; }
  .choice.wrong { color: #ffc3c4; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; scroll-behavior: auto !important; transition: none !important; } }
@media (max-width: 350px) { .app-shell { padding-inline: 12px; } .deck-scroller { margin-inline: -12px; padding-inline: 12px; } .question-card { padding-inline: 18px 14px; } }
