:root {
  --bg: #f7f8fc;
  --card: #ffffff;
  --text: #1a1d29;
  --text-dim: #6b7280;
  --border: #e5e7eb;
  --accent: #6366f1;
  --accent-dim: #eef2ff;
  --good: #10b981;
  --good-dim: #ecfdf5;
  --bad: #ef4444;
  --bad-dim: #fef2f2;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14151f;
    --card: #1e2030;
    --text: #eceef5;
    --text-dim: #9198ac;
    --border: #2d2f42;
    --accent: #818cf8;
    --accent-dim: #262a45;
    --good: #34d399;
    --good-dim: #10281f;
    --bad: #f87171;
    --bad-dim: #2b1616;
    --shadow: 0 1px 3px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  --bg: #14151f; --card: #1e2030; --text: #eceef5; --text-dim: #9198ac;
  --border: #2d2f42; --accent: #818cf8; --accent-dim: #262a45;
  --good: #34d399; --good-dim: #10281f; --bad: #f87171; --bad-dim: #2b1616;
}
:root[data-theme="light"] {
  --bg: #f7f8fc; --card: #ffffff; --text: #1a1d29; --text-dim: #6b7280;
  --border: #e5e7eb; --accent: #6366f1; --accent-dim: #eef2ff;
  --good: #10b981; --good-dim: #ecfdf5; --bad: #ef4444; --bad-dim: #fef2f2;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Segoe UI", Pretendard, Roboto, sans-serif;
  line-height: 1.5;
  overflow-x: hidden;
}
a { color: inherit; }
button { font-family: inherit; }

.app-shell { max-width: 960px; margin: 0 auto; padding: 0 16px 60px; }

/* Header / nav */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.05rem; cursor: pointer; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav button {
  background: none; border: none; color: var(--text-dim);
  padding: 8px 12px; border-radius: 999px; cursor: pointer; font-size: .88rem; font-weight: 600;
}
.nav button.active, .nav button:hover { background: var(--accent-dim); color: var(--accent); }

.view { padding-top: 20px; animation: fadein .18s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
.subtitle { color: var(--text-dim); font-size: .92rem; margin: 0 0 20px; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}

/* Dashboard stat row */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px,1fr)); gap: 10px; margin-bottom: 22px; }
.stat-tile { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 14px; text-align: center; }
.stat-tile .num { font-size: 1.5rem; font-weight: 800; color: var(--accent); }
.stat-tile .label { font-size: .78rem; color: var(--text-dim); margin-top: 2px; }

.action-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 24px; }
.btn {
  border: none; border-radius: 10px; padding: 11px 18px; font-weight: 700; font-size: .9rem;
  cursor: pointer; transition: transform .08s ease, opacity .15s ease;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-outline { background: var(--accent-dim); color: var(--accent); }
.btn-ghost { background: transparent; color: var(--text-dim); border: 1px solid var(--border); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* Unit grid */
.unit-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.unit-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; cursor: pointer; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.unit-card:hover { border-color: var(--accent); }
.unit-card .bar { position: absolute; left: 0; top: 0; bottom: 0; width: 5px; }
.unit-card .icon { font-size: 1.6rem; }
.unit-card .name-en { font-weight: 700; margin-top: 8px; font-size: .95rem; }
.unit-card .name-ko { color: var(--text-dim); font-size: .82rem; margin-top: 2px; }
.progress-bar { height: 6px; border-radius: 999px; background: var(--border); margin-top: 12px; overflow: hidden; }
.progress-bar > div { height: 100%; background: var(--accent); }
.unit-card .meta { font-size: .76rem; color: var(--text-dim); margin-top: 6px; }
.unit-card .modes { margin-top: 12px; display: flex; gap: 6px; flex-wrap: wrap; }
.unit-card .modes button { font-size: .74rem; padding: 6px 9px; }

/* Word list / flashcards */
.word-list { display: flex; flex-direction: column; gap: 8px; }
.word-item {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; cursor: pointer;
}
.word-item .row1 { display: flex; align-items: baseline; gap: 8px; justify-content: space-between; }
.word-item .word { font-weight: 800; font-size: 1.02rem; }
.pos-badge {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .03em; font-weight: 700;
  background: var(--accent-dim); color: var(--accent); padding: 2px 7px; border-radius: 6px;
}
.word-item .def { color: var(--text-dim); font-size: .86rem; margin-top: 6px; display: none; }
.word-item.open .def { display: block; }
.word-item .extra { margin-top: 8px; font-size: .84rem; display: none; }
.word-item.open .extra { display: block; }
.word-item .extra .ex { font-style: italic; color: var(--text-dim); }
.mastery-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); display: inline-block; }
.mastery-dot.m0 { background: var(--border); }
.mastery-dot.m1 { background: #fbbf24; }
.mastery-dot.m2 { background: var(--good); }

/* Quiz */
.quiz-progress { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.quiz-progress .bar { flex: 1; height: 8px; border-radius: 999px; background: var(--border); overflow: hidden; }
.quiz-progress .bar > div { height: 100%; background: var(--accent); transition: width .25s ease; }
.quiz-progress .count { font-size: .82rem; color: var(--text-dim); white-space: nowrap; }
.q-stem { font-size: 1.05rem; font-weight: 700; margin-bottom: 10px; }
.q-sub {
  background: var(--accent-dim); border-radius: 10px; padding: 14px 16px; margin-bottom: 16px;
  font-size: .96rem; line-height: 1.65;
}
.q-sub .hl { color: var(--accent); text-decoration: underline; text-decoration-style: dotted; }
.choice-list { display: flex; flex-direction: column; gap: 8px; }
.choice {
  text-align: left; background: var(--card); border: 1.5px solid var(--border); border-radius: 10px;
  padding: 12px 14px; cursor: pointer; font-size: .93rem; display: flex; gap: 10px;
}
.choice .letter {
  width: 22px; height: 22px; border-radius: 50%; background: var(--accent-dim); color: var(--accent);
  font-size: .74rem; font-weight: 800; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.choice:hover:not(.locked) { border-color: var(--accent); }
.choice.correct { border-color: var(--good); background: var(--good-dim); }
.choice.wrong { border-color: var(--bad); background: var(--bad-dim); }
.choice.locked { cursor: default; }
.feedback { margin-top: 14px; padding: 12px 14px; border-radius: 10px; font-size: .88rem; }
.feedback.correct { background: var(--good-dim); color: var(--good); }
.feedback.wrong { background: var(--bad-dim); color: var(--bad); }
.quiz-footer { display: flex; justify-content: flex-end; margin-top: 18px; }

/* Results */
.result-hero { text-align: center; padding: 30px 10px; }
.result-hero .big { font-size: 3rem; font-weight: 800; color: var(--accent); }
.result-list { margin-top: 18px; display: flex; flex-direction: column; gap: 6px; }
.result-row { display: flex; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: 8px; background: var(--card); border: 1px solid var(--border); font-size: .86rem; }
.result-row.wrong { border-color: var(--bad); }
.result-row.right { border-color: var(--good); }

.empty-state { text-align: center; color: var(--text-dim); padding: 40px 20px; }
.empty-state .emoji { font-size: 2.2rem; margin-bottom: 8px; }

footer.site-footer { text-align: center; color: var(--text-dim); font-size: .78rem; padding: 30px 10px 10px; }

@media (max-width: 560px) {
  .stat-row { grid-template-columns: repeat(3, 1fr); }
  h1 { font-size: 1.25rem; }
}

/* Printable worksheet */
.worksheet { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; }
.ws-header { border-bottom: 2px solid var(--text); padding-bottom: 14px; margin-bottom: 20px; }
.ws-header h1 { margin: 0 0 4px; }
.ws-meta { color: var(--text-dim); font-size: .92rem; }
.ws-fields { margin-top: 14px; font-size: .92rem; }
.ws-questions { list-style: none; margin: 0; padding: 0; }
.ws-q { padding: 14px 0; border-bottom: 1px dashed var(--border); }
.ws-q:first-child { padding-top: 0; }
.ws-stem { font-weight: 700; margin-bottom: 6px; }
.ws-sub { background: var(--accent-dim); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; font-size: .92rem; line-height: 1.6; }
.ws-choices { display: flex; flex-direction: column; gap: 4px; padding-left: 4px; }
.ws-choice { font-size: .92rem; }
.ws-letter { font-weight: 700; color: var(--accent); }
.ws-key-list { columns: 2; column-gap: 24px; padding-left: 20px; font-size: .84rem; color: var(--text-dim); }
.ws-key-list li { break-inside: avoid; margin-bottom: 6px; }
.ws-key-list-full { columns: 1; font-size: .92rem; color: var(--text); }
.ws-key-list-full li { margin-bottom: 12px; line-height: 1.6; }

@media print {
  .topbar, .nav, footer.site-footer, .no-print { display: none !important; }
  body, .app-shell { background: #fff !important; color: #000 !important; margin: 0; padding: 0; max-width: none; }
  .worksheet { border: none; box-shadow: none; padding: 0; color: #000; }
  .ws-header { border-color: #000; }
  .ws-sub { background: #f0f0f0; color: #000; }
  .ws-letter { color: #000; }
  .ws-q { border-color: #ccc; }
}
