:root {
  color-scheme: light;
  --ink: #18202a;
  --muted: #657080;
  --paper: #ffffff;
  --canvas: #f4f1ed;
  --line: #ded8d1;
  --red: #9f1f2e;
  --red-dark: #771522;
  --red-soft: #f9e9eb;
  --gold: #bb7b16;
  --gold-soft: #fff7e7;
  --green: #287554;
  --green-soft: #eaf6ef;
  --blue: #2d5f8b;
  --blue-soft: #edf5fb;
  --shadow: 0 16px 42px rgba(42, 30, 24, .08);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font: 16px/1.55 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body:not(.is-authenticated) > :not(.auth-screen):not(.toast):not(script) { display: none !important; }
.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 1.25rem; background: radial-gradient(circle at 80% 15%, rgba(255,255,255,.16), transparent 24%), linear-gradient(145deg, #72131f, #a92334 55%, #58101a); }
body.is-authenticated .auth-screen { display: none; }
.auth-card { width: min(480px, 100%); padding: clamp(1.4rem, 5vw, 2.4rem); border-radius: 22px; background: #fff; box-shadow: 0 28px 90px rgba(0,0,0,.3); }
.auth-card h1 { margin: 0; font: 700 clamp(2rem, 7vw, 3.2rem)/1.05 Georgia, serif; }
.auth-card > p:not(.kicker):not(.form-message) { color: var(--muted); }
.auth-form { display: grid; gap: .9rem; margin-top: 1.25rem; }
.auth-form label { display: grid; gap: .35rem; font-weight: 750; }
.auth-form input { min-height: 46px; padding: .7rem .8rem; border: 1px solid #cfc7bf; border-radius: 9px; }
.text-button { text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 3px solid rgba(45, 95, 139, .35);
  outline-offset: 3px;
}
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; left: 1rem; top: -5rem; z-index: 100; background: var(--ink); color: #fff; padding: .8rem 1rem; border-radius: 8px; }
.skip-link:focus { top: 1rem; }

.hero {
  padding: 3.4rem max(1.25rem, calc((100vw - 1120px) / 2));
  color: #fff;
  background:
    radial-gradient(circle at 85% 15%, rgba(255,255,255,.12), transparent 28%),
    linear-gradient(135deg, #7e1422, #a92334 58%, #72131f);
}
.hero__eyebrow, .kicker { margin: 0 0 .35rem; text-transform: uppercase; letter-spacing: .12em; font-size: .76rem; font-weight: 800; }
.hero h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(2.25rem, 6vw, 4.3rem); line-height: 1; }
.hero p { margin: .8rem 0 0; max-width: 680px; color: rgba(255,255,255,.84); }
.hero__meta { display: flex; align-items: center; gap: 1rem; margin-top: 1.4rem; flex-wrap: wrap; }
.status-pill { padding: .38rem .72rem; border: 1px solid rgba(255,255,255,.35); border-radius: 999px; background: rgba(0,0,0,.16); font-size: .85rem; }
.status-pill[data-state="ok"]::before { content: ""; display: inline-block; width: .5rem; height: .5rem; margin-right: .45rem; border-radius: 50%; background: #8ee0ac; }
.status-pill[data-state="error"]::before { content: ""; display: inline-block; width: .5rem; height: .5rem; margin-right: .45rem; border-radius: 50%; background: #ffd073; }
.text-button { padding: 0; border: 0; border-bottom: 1px solid currentColor; color: #fff; background: transparent; }

.shell { width: min(1120px, calc(100% - 2rem)); margin: -1.4rem auto 4rem; }
.dashboard, .library, .legal-note { background: var(--paper); border: 1px solid rgba(126, 103, 89, .14); border-radius: var(--radius); box-shadow: var(--shadow); }
.dashboard, .library { padding: clamp(1.15rem, 3vw, 2rem); }
.library { margin-top: 1.4rem; }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 1rem; }
.section-heading--wrap { flex-wrap: wrap; }
.section-heading h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.6rem, 3vw, 2.2rem); }
.kicker { color: var(--red); }
.due-label { color: var(--red); font-weight: 750; }
.daily-mood { display: flex; align-items: center; gap: 1rem; margin-top: 1.25rem; padding: .9rem 1rem; border: 1px solid #eadbc1; border-radius: 14px; background: linear-gradient(135deg, #fffaf0, #fff); }
.daily-mood[data-level="done"] { border-color: #9ecfb2; background: linear-gradient(135deg, #eaf7ef, #fff); }
.daily-mood__face { flex: 0 0 auto; width: 54px; text-align: center; font-size: 2.6rem; line-height: 1; filter: saturate(.9); }
.daily-mood__content { min-width: 0; flex: 1; }
.daily-mood__content strong, .daily-mood__content span { display: block; }
.daily-mood__content span { margin-top: .12rem; color: var(--muted); font-size: .86rem; }
.daily-mood__track { height: 7px; margin-top: .55rem; overflow: hidden; border-radius: 999px; background: #ebe5dd; }
.daily-mood__track span { width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--gold), #e2ad3e); transition: width .3s ease; }
.daily-mood[data-level="done"] .daily-mood__track span { background: var(--green); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .75rem; margin-top: 1.5rem; }
.stat { padding: 1rem; background: #faf9f7; border: 1px solid var(--line); border-radius: 12px; }
.stat strong, .stat span { display: block; }
.stat strong { font-size: 1.65rem; line-height: 1.1; color: var(--red); }
.stat span { margin-top: .2rem; color: var(--muted); font-size: .84rem; }
.progress { height: .62rem; margin: 1rem 0 1.35rem; overflow: hidden; background: #e9e4df; border-radius: 999px; }
.progress__bar { width: 0; height: 100%; background: linear-gradient(90deg, var(--red), #d2704f, #d1a73f); transition: width .3s ease; }
.action-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .75rem; }
.action { min-height: 96px; padding: .95rem; text-align: left; border: 1px solid var(--line); border-radius: 13px; background: #fff; color: var(--ink); transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease; }
.action:hover { transform: translateY(-2px); border-color: #baaaa0; box-shadow: 0 7px 18px rgba(42,30,24,.08); }
.action span, .action small { display: block; }
.action span { font-weight: 800; }
.action small { margin-top: .28rem; color: var(--muted); line-height: 1.35; }
.action--primary { color: #fff; border-color: var(--red); background: var(--red); }
.action--primary small { color: rgba(255,255,255,.78); }

.search-row { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.search input, select, .settings input { min-height: 44px; border: 1px solid #cfc7bf; border-radius: 9px; background: #fff; color: var(--ink); padding: .65rem .8rem; }
.search input { width: min(320px, 70vw); }
.question-list { margin-top: 1.4rem; }
.chapter-block + .chapter-block { margin-top: 2rem; }
.chapter-title { margin: 0 0 .8rem; padding-bottom: .55rem; border-bottom: 3px solid var(--red); font-family: Georgia, "Times New Roman", serif; font-size: 1.45rem; }
.question-card { margin: .65rem 0; border: 1px solid var(--line); border-radius: 12px; background: #fff; overflow: clip; }
.question-card[open] { border-color: #cbbcb2; box-shadow: 0 7px 20px rgba(42,30,24,.05); }
.question-card summary { display: grid; grid-template-columns: 1fr auto auto; gap: .75rem; align-items: center; padding: 1rem; list-style: none; cursor: pointer; }
.question-card summary::-webkit-details-marker { display: none; }
.question-card summary::after { content: "+"; font-size: 1.35rem; color: var(--red); }
.question-card[open] summary::after { content: "−"; }
.summary-rating { min-width: 5.4rem; color: var(--gold); font-size: 1.02rem; letter-spacing: .04em; text-align: right; white-space: nowrap; }
.summary-rating.is-unrated { color: #c7c0ba; }
.question-card__title { font-weight: 750; }
.question-card__meta { display: flex; gap: .5rem; margin-top: .3rem; color: var(--muted); font-size: .78rem; }
.mastery { display: inline-flex; gap: 2px; margin-top: .45rem; }
.mastery-label { margin-top: .8rem; color: var(--muted); font-size: .78rem; font-weight: 750; }
.mastery button { width: 23px; height: 23px; padding: 0; border: 0; background: transparent; color: #c7c0ba; font-size: 1.05rem; line-height: 1; }
.mastery button[aria-pressed="true"], .mastery button.is-filled { color: var(--gold); }
.question-card__body { padding: 0 1rem 1rem; }
.answer-box { margin-top: .8rem; padding: 1rem; border-radius: 11px; border-left: 4px solid; }
.answer-box h3 { margin: 0 0 .45rem; font-size: .92rem; }
.answer-box p:first-child, .answer-box ul:first-child { margin-top: 0; }
.answer-box p:last-child, .answer-box ul:last-child { margin-bottom: 0; }
.answer-box--quick { background: var(--gold-soft); border-color: var(--gold); }
.answer-box--detail { background: #f6f7f8; border-color: #6f7882; }
.answer-box--english { background: var(--green-soft); border-color: var(--green); }
.answer-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .65rem; }
.speak-button { padding: .36rem .62rem; border: 1px solid currentColor; border-radius: 8px; background: transparent; color: var(--blue); font-size: .82rem; }
.audio-player { display: flex; align-items: center; gap: .65rem; width: min(100%, 430px); }
.audio-progress { position: relative; flex: 1; height: 6px; overflow: hidden; border-radius: 999px; background: rgba(45, 95, 139, .15); }
.audio-progress span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--blue); transition: width .1s linear; }
.audio-progress.is-indeterminate span { width: 35%; animation: audio-pulse 1.1s ease-in-out infinite alternate; }
.speak-button.is-playing { color: #fff; background: var(--blue); }
@keyframes audio-pulse { from { transform: translateX(-100%); } to { transform: translateX(285%); } }
.legal-update { padding: .85rem 1rem; margin-top: .8rem; border: 1px solid #a5c8e5; border-radius: 10px; background: var(--blue-soft); color: #214866; font-size: .9rem; }
.empty-state { padding: 2rem; text-align: center; color: var(--muted); }
.legal-note { margin-top: 1.4rem; padding: 1rem 1.25rem; color: #5b4c42; background: #fffaf2; }
.legal-note p { margin: .3rem 0 0; }

.primary-button, .secondary-button, .danger-button, .walk-controls button { min-height: 44px; padding: .65rem 1rem; border-radius: 9px; font-weight: 750; }
.primary-button { border: 1px solid var(--red); background: var(--red); color: #fff; }
.primary-button:hover { background: var(--red-dark); }
.secondary-button { border: 1px solid #bdb3ab; background: #fff; color: var(--ink); }
.danger-button { border: 1px solid #c34a55; color: #98202c; background: #fff3f4; }

.dialog { width: min(760px, calc(100% - 1.5rem)); max-height: 90vh; padding: 0; border: 0; border-radius: 18px; color: var(--ink); background: #fff; box-shadow: 0 28px 90px rgba(0,0,0,.32); }
.dialog--wide { width: min(1020px, calc(100% - 1.5rem)); }
.dialog::backdrop { background: rgba(22,25,29,.66); backdrop-filter: blur(3px); }
.dialog__top { position: sticky; top: 0; z-index: 3; display: flex; justify-content: space-between; align-items: center; padding: .8rem 1rem; border-bottom: 1px solid var(--line); background: #fff; font-weight: 800; }
.dialog__body { padding: clamp(1rem, 4vw, 2rem); overflow-y: auto; }
.dialog__body h2 { margin-top: 0; font-family: Georgia, "Times New Roman", serif; }
.icon-button { width: 40px; height: 40px; border: 0; border-radius: 50%; background: #f0eeeb; color: var(--ink); font-size: 1.45rem; }
.dialog__progress { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: .8rem; color: var(--muted); font-size: .88rem; }
.source { color: var(--muted); font-size: .88rem; }
.rating-panel, .score-panel { margin: 1.5rem 0 0; padding: 0; border: 0; }
.rating-panel legend, .score-panel legend { margin-bottom: .75rem; font-weight: 800; }
.rating-actions { display: grid; grid-template-columns: repeat(5, 1fr); gap: .55rem; }
.rating-actions button, .score-actions button { padding: .8rem .45rem; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.rating-actions strong, .rating-actions span, .score-actions small { display: block; }
.rating-actions span, .score-actions small { margin-top: .2rem; color: var(--muted); font-size: .72rem; }
.notice { margin: 1rem 0; padding: .85rem 1rem; border-radius: 10px; background: var(--blue-soft); color: #214866; }
.textarea-label { display: block; margin-bottom: .35rem; font-weight: 750; }
textarea { width: 100%; margin-bottom: .8rem; padding: .85rem; resize: vertical; border: 1px solid #bbb2aa; border-radius: 10px; }
.comparison { display: grid; grid-template-columns: 1fr 1.25fr; gap: 1rem; }
.comparison h3 { margin-top: 0; }
.comparison__box { max-height: 48vh; padding: 1rem; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; background: #faf9f7; white-space: pre-wrap; }
.score-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: .65rem; }
.exam-result { text-align: center; }
.exam-result h2 { font-size: 2.3rem; }
.exam-review { margin: .6rem 0; padding: .8rem; text-align: left; border: 1px solid var(--line); border-radius: 9px; }

.dialog--dark { color: #f3f4f7; background: #171b25; }
.dialog--dark .dialog__top { color: #fff; border-color: #333a4a; background: #171b25; }
.dialog--dark .icon-button { color: #fff; background: #303645; }
.dialog--dark select { color: #fff; border-color: #4d566b; background: #252b39; }
.dialog--dark .muted { color: #aeb6c7; }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; }
.form-grid label, .settings label { display: grid; gap: .35rem; font-weight: 700; }
.check { display: flex; align-items: center; gap: .6rem; margin: .9rem 0; }
.check input { width: 18px; height: 18px; }
.walk-answer { max-height: 42vh; padding: 1rem; overflow-y: auto; border: 1px solid #3c4559; border-radius: 11px; background: #222837; }
.walk-controls, .button-row { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1rem; }
.walk-controls button { color: #fff; border: 1px solid #59647b; background: #2d3444; }

.settings section + section { margin-top: 1.5rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }
.settings input { width: 100%; margin-top: .3rem; }
.form-message { min-height: 1.5rem; color: var(--muted); }
.danger-zone h2 { color: var(--red); }
.toast { position: fixed; right: 1rem; bottom: 1rem; z-index: 100; max-width: min(420px, calc(100% - 2rem)); padding: .85rem 1rem; border-radius: 10px; color: #fff; background: #202733; box-shadow: var(--shadow); }

@media (max-width: 820px) {
  .action-grid { grid-template-columns: repeat(2, 1fr); }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .rating-actions { grid-template-columns: repeat(2, 1fr); }
  .comparison, .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .hero { padding-top: 2.5rem; }
  .shell { width: min(100% - 1rem, 1120px); }
  .dashboard, .library { border-radius: 14px; }
  .action-grid, .score-actions { grid-template-columns: 1fr; }
  .section-heading { align-items: stretch; }
  .search-row { display: grid; grid-template-columns: 1fr; width: 100%; }
  .search input, .search, .search-row select, .search-row button { width: 100%; }
  .question-card summary { padding: .85rem; }
  .summary-rating { min-width: 4.9rem; font-size: .9rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

@media print {
  body { background: #fff; font-size: 10pt; }
  .hero { padding: 0 0 1rem; color: #000; background: none; }
  .hero__eyebrow, .hero__meta, .dashboard, .search-row, .legal-note, .mastery, .speak-button, .audio-progress, dialog, .toast { display: none !important; }
  .shell { width: 100%; margin: 0; }
  .library { padding: 0; border: 0; box-shadow: none; }
  .question-card { break-inside: avoid; border-color: #aaa; }
  .question-card summary { padding: .55rem; }
  .question-card summary::after { display: none; }
  .question-card__body { display: block !important; padding: 0 .55rem .55rem; }
  .answer-box { padding: .55rem; margin-top: .35rem; }
  .answer-box--english { display: none; }
  .chapter-block { break-before: page; }
  .chapter-block:first-child { break-before: auto; }
}
