:root {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface-2: #eef1ee;
  --line: #d9dfda;
  --text: #18201b;
  --muted: #5b665f;
  --accent: #1f7a52;
  --accent-ink: #ffffff;
  --accent-soft: #e2f1e9;
  --gold: #c99a12;
  --gold-soft: #fbf1d3;
  --right: #1f7a52;
  --right-soft: #e2f1e9;
  --wrong: #c23b2a;
  --wrong-soft: #fbe5e1;
  --focus: #2563eb;
  --s-accounting: #0e7c86;
  --s-tax: #b45309;
  --s-business: #2f62c9;
  --s-economics: #be3a64;
  --s-corporate-law: #4d7c0f;
  --radius: 8px;
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111513;
    --surface: #1a201c;
    --surface-2: #232a25;
    --line: #333c36;
    --text: #e8ece9;
    --muted: #9aa69e;
    --accent: #3fb07c;
    --accent-ink: #0c1510;
    --accent-soft: #1d3428;
    --gold: #e8b931;
    --gold-soft: #3a3118;
    --right: #4cc28b;
    --right-soft: #1d3428;
    --wrong: #f07a68;
    --wrong-soft: #3d201c;
    --focus: #7aa7ff;
    --s-accounting: #38b2bd;
    --s-tax: #e59a45;
    --s-business: #7aa2f2;
    --s-economics: #ec7fa3;
    --s-corporate-law: #93c24a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  letter-spacing: 0;
}
a { color: inherit; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
main:focus { outline: none; }

.shell { display: flex; min-height: 100vh; }
.sidebar { display: none; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; text-decoration: none; white-space: nowrap; }
.brand img { border-radius: 6px; }
.meters { display: flex; gap: 6px; }
.meter {
  display: inline-flex; align-items: center; gap: 4px;
  height: 30px; padding: 0 10px; border-radius: 15px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.meter svg { width: 16px; height: 16px; }
.meter--streak svg { color: #e8590c; }
.meter--xp svg { color: var(--gold); }

#view { width: 100%; max-width: 760px; margin: 0 auto; padding: 16px 16px 120px; }
.footer { max-width: 760px; margin: 0 auto; padding: 0 16px 110px; color: var(--muted); font-size: 12px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: 58px; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 600;
}
.tab svg { width: 22px; height: 22px; }
.tab[aria-current="page"] { color: var(--accent); }
.tab .badge, .nav-item .badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--wrong); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}
.tab-icon { position: relative; display: inline-flex; }
.tab-icon .badge { position: absolute; top: -6px; right: -12px; }

@media (min-width: 900px) {
  .tabbar { display: none; }
  .topbar .brand--compact { visibility: hidden; }
  .sidebar {
    display: flex; flex-direction: column; gap: 20px;
    position: sticky; top: 0; height: 100vh; width: 232px; flex: none;
    padding: 18px 14px; border-right: 1px solid var(--line); background: var(--surface);
  }
  .nav { display: flex; flex-direction: column; gap: 2px; }
  .nav-item {
    display: flex; align-items: center; gap: 10px; height: 42px; padding: 0 12px;
    border-radius: var(--radius); text-decoration: none; color: var(--muted); font-weight: 600;
  }
  .nav-item svg { width: 20px; height: 20px; }
  .nav-item .badge { margin-left: auto; }
  .nav-item:hover { background: var(--surface-2); color: var(--text); }
  .nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
  #view { padding: 28px 32px 64px; }
  .footer { padding: 0 32px 32px; }
}

h1 { font-size: 22px; line-height: 1.35; margin: 4px 0 12px; }
h2 { font-size: 18px; line-height: 1.4; margin: 28px 0 10px; }
h3 { font-size: 16px; margin: 0 0 6px; }
.eyebrow { color: var(--muted); font-size: 13px; font-weight: 600; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); font-weight: 700; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; }
.btn:hover { border-color: var(--muted); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--primary:hover { filter: brightness(1.06); border-color: var(--accent); }
.btn--block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn--primary:disabled { opacity: 1; background: var(--surface-2); border-color: var(--line); color: var(--muted); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; flex: none;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn[aria-pressed="true"] { color: var(--gold); border-color: var(--gold); background: var(--gold-soft); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row--end { justify-content: flex-end; }
.spacer { flex: 1; }

.chip {
  display: inline-flex; align-items: center; height: 24px; padding: 0 8px; border-radius: 12px;
  font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.chip--subject { color: #fff; background: var(--subject, var(--muted)); }
[data-subject="accounting"] { --subject: var(--s-accounting); }
[data-subject="tax"] { --subject: var(--s-tax); }
[data-subject="business"] { --subject: var(--s-business); }
[data-subject="economics"] { --subject: var(--s-economics); }
[data-subject="corporate-law"] { --subject: var(--s-corporate-law); }
@media (prefers-color-scheme: dark) { .chip--subject { color: #10140f; } }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.panel + .panel { margin-top: 12px; }

.today-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.progress { height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 5px; transition: width .3s; }
.steps { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 8px; }
.step {
  display: grid; grid-template-columns: 32px 1fr auto; align-items: center; gap: 12px;
  padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.step-num {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); font-weight: 800; font-size: 14px;
}
.step--done .step-num { background: var(--accent); color: var(--accent-ink); }
.step-title { font-weight: 700; line-height: 1.35; }
.step-sub { color: var(--muted); font-size: 13px; }

.concept-card { border-left: 4px solid var(--subject, var(--accent)); }
.concept-card .keypoints { margin: 12px 0 0; padding: 12px 14px 12px 30px; background: var(--surface-2); border-radius: var(--radius); }
.concept-card .keypoints li + li { margin-top: 4px; }

.done-banner {
  display: flex; gap: 12px; align-items: center; padding: 14px 16px; border-radius: var(--radius);
  background: var(--gold-soft); border: 1px solid var(--gold); font-weight: 700;
}
.done-banner svg { width: 28px; height: 28px; color: var(--gold); flex: none; }

/* question */
.q-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.q-progress { margin-left: auto; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.md p { margin: 0 0 10px; }
.md blockquote { margin: 10px 0; padding: 10px 14px; border-left: 3px solid var(--line); background: var(--surface-2); border-radius: 0 var(--radius) var(--radius) 0; }
.md blockquote p:last-child { margin-bottom: 0; }
.md ul { margin: 6px 0 10px; padding-left: 22px; }
.md code { font-size: .92em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.table-wrap { overflow-x: auto; margin: 10px 0; -webkit-overflow-scrolling: touch; }
.md table { border-collapse: collapse; font-size: 14px; min-width: 100%; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.md th { background: var(--surface-2); font-weight: 700; }
.md td { font-variant-numeric: tabular-nums; }
.stem { font-size: 16px; }
.premise { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.figure-note { margin: 10px 0; padding: 10px 12px; border: 1px dashed var(--muted); border-radius: var(--radius); font-size: 14px; color: var(--muted); }

.choices { list-style: none; padding: 0; margin: 14px 0; display: grid; gap: 8px; }
.choice {
  width: 100%; display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: start; text-align: left;
  padding: 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  line-height: 1.5;
}
.choice:hover:not(:disabled) { border-color: var(--muted); }
.choice[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.choice-mark {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  border: 1px solid var(--line); font-size: 13px; font-weight: 800; background: var(--surface-2);
}
.choice-body .md p:last-child { margin-bottom: 0; }
.choice-body .table-wrap { margin: 4px 0; }
.choice:disabled { cursor: default; }
.choice--right { border-color: var(--right); background: var(--right-soft); }
.choice--right .choice-mark { background: var(--right); color: #fff; border-color: var(--right); }
.choice--wrong { border-color: var(--wrong); background: var(--wrong-soft); }
.choice--wrong .choice-mark { background: var(--wrong); color: #fff; border-color: var(--wrong); }
.choice-note { grid-column: 2; font-size: 14px; color: var(--muted); border-top: 1px dashed var(--line); padding-top: 6px; margin-top: 2px; }

.verdict { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; margin: 4px 0 10px; }
.verdict svg { width: 26px; height: 26px; }
.verdict--right { color: var(--right); }
.verdict--wrong { color: var(--wrong); }
.explain h2 { margin-top: 18px; }
.basis { font-size: 13px; color: var(--muted); margin-top: 8px; }
.caution { margin-top: 10px; padding: 10px 12px; border-radius: var(--radius); background: var(--gold-soft); font-size: 14px; }

.sticky-actions {
  position: sticky; bottom: 70px; z-index: 4; display: flex; gap: 8px; padding: 10px 0;
  background: linear-gradient(to bottom, transparent, var(--bg) 30%);
}
@media (min-width: 900px) { .sticky-actions { bottom: 0; } }
.sticky-actions .btn--primary { flex: 1; }

/* lists */
.seg { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin: 0 0 12px; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button {
  flex: none; height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 700; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.seg button[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.qgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; }
.qcell {
  aspect-ratio: 1; display: grid; place-items: center; border-radius: 6px; border: 1px solid var(--line);
  background: var(--surface); font-size: 13px; font-weight: 700; text-decoration: none; font-variant-numeric: tabular-nums;
}
.qcell--right { background: var(--right-soft); border-color: var(--right); color: var(--right); }
.qcell--wrong { background: var(--wrong-soft); border-color: var(--wrong); color: var(--wrong); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin: 8px 0 0; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; border: 1px solid var(--line); }
.legend .l-right { background: var(--right-soft); border-color: var(--right); }
.legend .l-wrong { background: var(--wrong-soft); border-color: var(--wrong); }

.list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.list li + li { border-top: 1px solid var(--line); }
.list a, .list .li {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center;
  padding: 12px 14px; text-decoration: none;
}
.list a:hover { background: var(--surface-2); }
.li-title { font-weight: 700; line-height: 1.4; }
.li-sub { grid-column: 1; color: var(--muted); font-size: 13px; }
.li-side { grid-row: 1 / span 2; grid-column: 2; display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.dot--seen { background: var(--accent); }
.topic-head { margin: 18px 0 6px; font-size: 13px; color: var(--muted); font-weight: 700; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-width: 0; }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat span { color: var(--muted); font-size: 12px; }
.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 64px 1fr 92px; gap: 10px; align-items: center; font-size: 14px; }
.bar { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--subject, var(--accent)); }
.bar-val { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.heat { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; max-width: 280px; }
.heat i { aspect-ratio: 1; border-radius: 4px; background: var(--surface-2); }
.heat i.on { background: var(--accent); }
.heat i.today { outline: 2px solid var(--gold); outline-offset: -2px; }
.empty { text-align: center; padding: 28px 12px; color: var(--muted); }
.loading { color: var(--muted); }
.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 20;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: var(--radius); font-weight: 700; font-size: 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,.18); max-width: calc(100vw - 32px);
}
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: rise .25s ease-out; }
  @keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }
}
