:root {
  color-scheme: light;
  --bg: #f3f1e9;
  --surface: #fffdf8;
  --surface-2: #e9eee8;
  --ink: #17251f;
  --muted: #66736d;
  --line: #d7ded8;
  --brand: #176b52;
  --brand-dark: #0f4939;
  --accent: #dba83b;
  --danger: #b9473f;
  --warning: #9b6b08;
  --success: #26774e;
  --purple: #7356a8;
  --shadow: 0 18px 55px rgba(29, 46, 38, .10);
  --radius: 22px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1714;
  --surface: #14231e;
  --surface-2: #1b3028;
  --ink: #eef7f2;
  --muted: #9db0a7;
  --line: #2a4037;
  --brand: #6ed3ad;
  --brand-dark: #a1e5cb;
  --accent: #efc45f;
  --danger: #ff8f86;
  --warning: #f2ca6c;
  --success: #7bd4a1;
  --purple: #bea8ef;
  --shadow: 0 18px 55px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 10% 0%, color-mix(in srgb, var(--brand) 12%, transparent), transparent 32rem),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.shell { width: min(1080px, 100%); margin: 0 auto; padding: 20px 16px 110px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 22px; }
.brand { display: flex; align-items: center; gap: 11px; font-weight: 850; letter-spacing: -.02em; }
.brand-mark { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 13px; color: #fff; background: var(--brand-dark); }
.top-actions { display: flex; gap: 8px; }
.icon-button, .button, .chip, .choice, .nav-button {
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--surface);
  border-radius: 13px;
  min-height: 44px;
  padding: 10px 14px;
  font-weight: 750;
}
.icon-button { min-width: 44px; padding: 8px; }
.button.primary { background: var(--brand-dark); border-color: var(--brand-dark); color: var(--bg); }
.button.danger { color: var(--danger); }
.button:disabled { cursor: not-allowed; opacity: .46; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(440px, 100%); padding: 34px; border: 1px solid var(--line); background: var(--surface); border-radius: 28px; box-shadow: var(--shadow); }
.login-card .brand-mark { width: 52px; height: 52px; font-size: 1.35rem; }
.login-card h1 { margin: 22px 0 8px; font-size: clamp(1.8rem, 6vw, 2.6rem); }
.login-card p { color: var(--muted); line-height: 1.55; margin: 0 0 24px; }
.field { display: grid; gap: 7px; margin-top: 14px; font-weight: 700; }
.field input { width: 100%; min-height: 48px; border: 1px solid var(--line); border-radius: 13px; background: var(--bg); color: var(--ink); padding: 10px 13px; }
.field input:focus, button:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 35%, transparent); outline-offset: 2px; }
.login-card .button { width: 100%; margin-top: 20px; }
.error-text { min-height: 1.25em; color: var(--danger) !important; margin-top: 12px !important; }
.eyebrow { margin: 0 0 7px; color: var(--brand); text-transform: uppercase; letter-spacing: .12em; font-size: .72rem; font-weight: 850; }
.hero { display: grid; grid-template-columns: 1fr auto; gap: 20px; align-items: end; margin: 22px 0 26px; }
.hero h1 { margin: 0; font-size: clamp(2rem, 8vw, 4.4rem); letter-spacing: -.055em; line-height: .98; }
.hero p { max-width: 670px; margin: 14px 0 0; color: var(--muted); line-height: 1.55; }
.module-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 15px; }
.module-card { display: flex; flex-direction: column; min-height: 245px; padding: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.module-card h2 { margin: 5px 0 9px; font-size: 1.35rem; }
.module-card p { color: var(--muted); line-height: 1.5; margin: 0 0 18px; }
.module-meta { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 20px; }
.pill, .badge { display: inline-flex; align-items: center; width: fit-content; border-radius: 999px; padding: 5px 9px; background: var(--surface-2); color: var(--muted); font-size: .73rem; font-weight: 800; }
.module-card .button { margin-top: auto; width: 100%; }
.study-head { padding: 22px; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.study-title-row { display: flex; justify-content: space-between; gap: 14px; align-items: start; }
.study-head h1 { margin: 3px 0 5px; font-size: clamp(1.45rem, 5vw, 2.3rem); }
.muted { color: var(--muted); }
.progress-line { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; margin-top: 18px; }
.progress-track { height: 11px; overflow: hidden; border-radius: 999px; background: var(--surface-2); }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--brand), var(--accent)); border-radius: inherit; transition: width .25s; }
.stats { display: grid; grid-template-columns: repeat(7, minmax(90px, 1fr)); gap: 8px; overflow-x: auto; padding: 14px 0 3px; scrollbar-width: thin; }
.stat { min-width: 90px; padding: 10px; border-radius: 14px; background: var(--surface-2); }
.stat strong { display: block; font-size: 1.15rem; }
.stat span { color: var(--muted); font-size: .72rem; font-weight: 700; }
.toolbar, .filters { display: flex; gap: 8px; overflow-x: auto; padding: 13px 1px 4px; scrollbar-width: thin; }
.chip { flex: 0 0 auto; min-height: 39px; padding: 8px 12px; border-radius: 999px; color: var(--muted); font-size: .78rem; }
.chip.active { color: var(--bg); background: var(--brand-dark); border-color: var(--brand-dark); }
.question-wrap { width: min(790px, 100%); margin: 22px auto 0; }
.session-label { display: flex; justify-content: space-between; gap: 12px; margin: 0 3px 10px; color: var(--muted); font-size: .82rem; font-weight: 750; }
.question-card { padding: clamp(19px, 4vw, 32px); border: 1px solid var(--line); border-radius: 26px; background: var(--surface); box-shadow: var(--shadow); }
.badges { display: flex; flex-wrap: wrap; gap: 7px; }
.badge.critical { color: var(--danger); }
.badge.high { color: var(--warning); }
.badge.boundary { color: var(--purple); }
.boundary-title { margin: 20px 0 -5px; color: var(--purple); font-size: .8rem; font-weight: 850; text-transform: uppercase; letter-spacing: .07em; }
.question-card h2 { margin: 22px 0; font-size: clamp(1.22rem, 4vw, 1.65rem); line-height: 1.45; letter-spacing: -.018em; }
.think-space { display: flex; align-items: center; gap: 10px; min-height: 62px; margin: 16px 0; padding: 14px; border: 1px dashed var(--line); border-radius: 15px; color: var(--muted); line-height: 1.4; }
.option-list { display: grid; gap: 9px; margin: 16px 0; }
.option { min-height: 50px; padding: 11px 14px; border: 1px solid var(--line); border-radius: 14px; color: var(--ink); background: var(--bg); text-align: left; line-height: 1.4; }
.option.selected { border: 2px solid var(--purple); background: var(--surface-2); }
.option.correct-answer { border-color: var(--success); color: var(--success); }
.option.wrong-answer { border-color: var(--danger); color: var(--danger); }
.reveal { width: 100%; }
.answer { margin-top: 22px; padding-top: 22px; border-top: 1px solid var(--line); }
.answer h3, .evaluation h3 { font-size: .78rem; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); }
.answer p, .answer li { line-height: 1.62; }
.answer ul { padding-left: 22px; }
.note { margin-top: 11px; padding: 13px 15px; border-left: 4px solid var(--brand); border-radius: 4px 14px 14px 4px; background: var(--surface-2); }
.note strong { display: block; margin-bottom: 4px; font-size: .77rem; text-transform: uppercase; letter-spacing: .06em; }
.note.trap { border-color: var(--danger); }
.note.boundary { border-color: var(--purple); }
.note.reference { border-color: var(--accent); }
.evaluation { margin-top: 24px; padding-top: 19px; border-top: 1px dashed var(--line); }
.choice-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.choice { min-height: 52px; padding: 9px; }
.choice.selected { border-width: 2px; background: var(--surface-2); }
.choice.correct.selected { color: var(--success); border-color: var(--success); }
.choice.stuck.selected { color: var(--warning); border-color: var(--warning); }
.choice.incorrect.selected { color: var(--danger); border-color: var(--danger); }
.choice.confidence.selected { color: var(--purple); border-color: var(--purple); }
.save-attempt { width: 100%; margin-top: 12px; }
.bottom-nav { position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; padding: 10px max(14px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); border-top: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(16px); }
.bottom-nav .nav-button:first-child { justify-self: end; }
.bottom-nav .nav-button:last-child { justify-self: start; }
.nav-count { min-width: 68px; text-align: center; color: var(--muted); font-size: .8rem; font-weight: 800; }
.empty { padding: 55px 20px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); background: var(--surface); }
.empty .emoji { font-size: 2rem; }
.empty h2 { margin-bottom: 7px; }
.overview-grid { display: grid; gap: 12px; margin-top: 20px; }
.overview-grid .question-card { box-shadow: none; }
.overview-grid .question-card h2 { font-size: 1.05rem; margin: 13px 0; }
.modal-backdrop { position: fixed; z-index: 50; inset: 0; display: grid; place-items: center; padding: 18px; background: rgba(3, 12, 9, .7); }
.modal { width: min(520px, 100%); max-height: 90vh; overflow: auto; padding: 24px; border: 1px solid var(--line); border-radius: 24px; background: var(--surface); box-shadow: var(--shadow); }
.modal h2 { margin-top: 0; }
.modal-actions { display: flex; justify-content: end; gap: 8px; margin-top: 20px; }
.file-box { display: block; padding: 25px 15px; border: 1px dashed var(--line); border-radius: 15px; text-align: center; color: var(--muted); }
.toast { position: fixed; z-index: 80; left: 50%; bottom: 86px; max-width: calc(100% - 32px); transform: translate(-50%, 20px); padding: 11px 16px; border-radius: 999px; color: var(--bg); background: var(--ink); opacity: 0; pointer-events: none; transition: .2s; font-weight: 750; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 680px) {
  .shell { padding: 14px 12px 104px; }
  .hero { grid-template-columns: 1fr; align-items: start; }
  .hero .button { width: 100%; }
  .study-title-row { display: block; }
  .study-title-row .button { margin-top: 12px; }
  .choice-row { grid-template-columns: 1fr; }
  .choice { min-height: 46px; }
  .question-card { border-radius: 20px; }
  .topbar .user-name { display: none; }
  .nav-button { font-size: .8rem; padding: 9px 11px; }
}
