:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0eee9;
  --text: #1d1d1f;
  --muted: #6b6b70;
  --border: #e2dfd8;
  --accent: #c8102e;      /* taegeuk red */
  --accent-2: #0047a0;    /* taegeuk blue */
  --accent-3: #3a3a40;    /* trigram black */
  --accent-soft: #fbe9ec;
  --good: #1b7f4b;
  --good-soft: #e5f4ec;
  --bad: #b3261e;
  --bad-soft: #fbeaea;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 4px 16px rgb(0 0 0 / 0.04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141416;
    --surface: #1e1e21;
    --surface-2: #29292d;
    --text: #f2f2f4;
    --muted: #a0a0a8;
    --border: #34343a;
    --accent: #ff5a6e;
    --accent-2: #6aa5ff;
    --accent-3: #c9c9d1;
    --accent-soft: #3a1d23;
    --good: #5fd39a;
    --good-soft: #17301f;
    --bad: #ff7b72;
    --bad-soft: #3a1c1c;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
}

[lang="ko"] { word-break: keep-all; }
[hidden] { display: none !important; }

h2 { font-size: 1.15rem; margin: 0 0 0.75rem; }

.container { max-width: 880px; margin: 0 auto; padding: 24px 16px 64px; }
.muted { color: var(--muted); }

/* Header */
.site-header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 1.1rem;
}
.brand-sub { color: var(--muted); font-weight: 500; font-size: 0.85rem; }
.site-nav { display: flex; gap: 4px; }
.site-nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
.site-nav a[aria-current] { background: var(--surface-2); color: var(--text); }

/* Buttons */
.button {
  font: inherit; font-weight: 600; padding: 10px 18px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.button:hover:not(:disabled) { background: var(--surface-2); }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.button:disabled { opacity: 0.55; cursor: not-allowed; }
.button.large { padding: 12px 24px; font-size: 1.05rem; }
.link-button { font: inherit; background: none; border: none; color: var(--accent-2); cursor: pointer; padding: 4px; }
.link-button:hover { text-decoration: underline; }
.icon-button {
  font-size: 1.3rem; width: 46px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); cursor: pointer;
}
.icon-button[aria-pressed="true"] { color: var(--accent-2); border-color: var(--accent-2); }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent-2) 50%, transparent); outline-offset: 2px;
}

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); margin-bottom: 20px;
}

/* Overview */
.overview { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat-value { display: block; font-size: 1.5rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 0.85rem; }

/* Practice options */
.option-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.option-label { width: 90px; color: var(--muted); font-size: 0.9rem; }
.toggles, .segmented { display: flex; flex-wrap: wrap; gap: 6px; }
.toggle, .segment {
  font: inherit; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer;
}
.toggle[aria-pressed="true"], .segment[aria-pressed="true"] {
  background: var(--accent-2); border-color: var(--accent-2); color: #fff;
}
.start-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.form-error { color: var(--bad); margin: 0; }

/* Topics */
.section-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0 12px; }
.section-header h2 { margin: 0; }
.section-description { margin: -4px 0 12px; }
.topic-grid + .section-header { margin-top: 28px; }
.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.topic-card {
  font: inherit; color: inherit; text-align: left; cursor: pointer;
  display: flex; flex-direction: column; gap: 4px;
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); padding: 16px;
  transition: border-color 0.15s, transform 0.15s;
}
.topic-card:hover { transform: translateY(-1px); }
.topic-card[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.topic-unit { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); }
.topic-title { font-size: 1.35rem; font-weight: 700; }
.topic-subtitle { font-weight: 500; }
.topic-description { color: var(--muted); font-size: 0.88rem; }
.topic-stats { color: var(--muted); font-size: 0.8rem; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0; }
.chip {
  font-size: 0.78rem; padding: 2px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
}
.chip-vocab { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.chip-grammar { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip-drill { background: var(--accent-3); border-color: var(--accent-3); color: var(--surface); }
.chip-direction { color: var(--muted); }

.progress-bar {
  display: block; height: 6px; border-radius: 999px; background: var(--surface-2);
  overflow: hidden; margin: 8px 0 4px;
}
.progress-fill { display: block; height: 100%; background: var(--good); border-radius: 999px; transition: width 0.3s; }

/* Quiz */
.quiz-header { display: flex; align-items: center; justify-content: space-between; }
.quiz-counter { color: var(--muted); font-variant-numeric: tabular-nums; }
.quiz-card { margin-top: 12px; }
.instruction { color: var(--muted); margin: 12px 0 4px; font-size: 0.95rem; }
.prompt { font-size: 1.7rem; font-weight: 700; margin: 0 0 8px; }
.prompt-ko { font-size: 2.1rem; }
.sentence { font-size: 1.4rem; margin: 4px 0 8px; }
.blank {
  display: inline-block; min-width: 3.5em; text-align: center; padding: 0 6px; margin: 0 2px;
  border-bottom: 3px solid var(--accent); color: var(--muted);
}
.blank.filled { color: var(--good); font-weight: 700; border-color: var(--good); }
.hint { color: var(--muted); font-style: italic; margin: 0 0 8px; }

.answer-form { margin-top: 16px; }
.answer-row { display: flex; gap: 8px; }
.answer-input {
  flex: 1; min-width: 0; font: inherit; font-size: 1.35rem; padding: 12px 14px;
  border: 2px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text);
}
.answer-input:focus { border-color: var(--accent-2); outline: none; }
.answer-input:disabled { opacity: 0.75; }
.ime-toggle {
  font: inherit; font-weight: 700; width: 52px; border-radius: 12px; cursor: pointer;
  border: 2px solid var(--border); background: var(--surface-2); color: var(--muted);
}
.ime-toggle.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.answer-actions { display: flex; align-items: center; gap: 12px; margin-top: 12px; }

.keyboard {
  margin-top: 14px; padding: 10px; border-radius: 12px; background: var(--surface-2);
  display: flex; flex-direction: column; gap: 6px; user-select: none;
}
.key-row { display: flex; justify-content: center; gap: 5px; }
.key {
  font: inherit; flex: 0 1 48px; height: 48px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1;
}
.key:active { transform: translateY(1px); background: var(--accent-soft); }
.key .jamo { font-size: 1.15rem; }
.key .latin { font-size: 0.65rem; color: var(--muted); }
.key-wide { flex-basis: 64px; font-size: 1.1rem; }
.key-wide[aria-pressed="true"] { background: var(--accent-2); color: #fff; }
.key-space { flex-basis: 320px; color: var(--muted); }

/* Pronunciation */
.speak-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.speak-row .prompt, .speak-row .sentence { margin-bottom: 8px; }
.speak-button {
  flex: none; width: 36px; height: 36px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); font-size: 1rem; line-height: 1;
  margin-bottom: 8px;
}
.review-answers .speak-button, .answer-compare .speak-button { width: 30px; height: 30px; font-size: 0.85rem; margin: 0 0 0 8px; vertical-align: middle; }
.speak-button:hover { background: var(--surface-2); }
.speak-button:active { transform: scale(0.94); }
.listen-text { font-size: 1.2rem; margin-bottom: 8px; }

/* Feedback */
.feedback-area:empty { display: none; }
.feedback { margin-top: 18px; padding: 16px 18px; border-radius: 12px; border: 1px solid; }
.feedback h3 { margin: 0 0 8px; }
.feedback.correct { background: var(--good-soft); border-color: var(--good); }
.feedback.correct h3 { color: var(--good); }
.feedback.wrong { background: var(--bad-soft); border-color: var(--bad); }
.feedback.wrong h3 { color: var(--bad); }
.answer-compare { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0 0 10px; }
.answer-compare dt { color: var(--muted); }
.answer-compare dd { margin: 0; font-size: 1.2rem; }
.given { color: var(--bad); }
.expected { color: var(--good); font-weight: 700; }
.explanation { margin: 8px 0; padding-left: 20px; }
.explanation li { margin-bottom: 4px; }
.grammar-box {
  margin-top: 12px; padding: 12px 14px; border-radius: 10px;
  background: var(--surface); border-left: 4px solid var(--accent);
}
.grammar-box h4 { margin: 0 0 4px; font-size: 1.1rem; }
.grammar-box p { margin: 4px 0; }
.next-row { display: flex; align-items: center; gap: 12px; margin-top: 16px; }

/* Summary & mistakes */
.summary { text-align: center; }
.score { display: flex; flex-direction: column; align-items: center; margin: 8px 0; }
.score-value { font-size: 3rem; font-weight: 800; }
.summary-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.review-list { list-style: none; padding: 0; margin: 0; }
.review-list li {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.review-list li:last-child { border-bottom: none; }
.review-answers { display: flex; gap: 12px; align-items: baseline; margin: 0; }
.select {
  font: inherit; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); max-width: 100%;
}
.mistake-list { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.mistake { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px; }
.mistake-meta { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; font-size: 0.82rem; }
.mistake-prompt { margin: 8px 0 4px; font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 32px 0; }

.error-box {
  background: var(--bad-soft); border: 1px solid var(--bad); border-radius: var(--radius); padding: 16px 20px;
}
.error-box p { margin: 6px 0; }

@media (max-width: 600px) {
  .overview { grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
  .stat { padding: 10px; }
  .stat-value { font-size: 1.15rem; }
  .option-label { width: 100%; }
  .prompt { font-size: 1.4rem; }
  .prompt-ko { font-size: 1.7rem; }
  .key { flex-basis: 32px; height: 44px; }
  .key-wide { flex-basis: 44px; }
  .brand-sub { display: none; }
}

/* Access token */
.token-form { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.token-form .answer-input { flex: 1 1 240px; }
.site-nav a.nav-quiet { font-weight: 400; font-size: 0.9rem; }

/* Memory aids */
.memory-hint-button { padding: 0; margin: 0 0 8px; }
.memory-hint { color: var(--muted); margin: 0 0 8px; }
.memory-box {
  margin-top: 12px; padding: 12px 14px; border-radius: 10px;
  background: var(--surface); border-left: 4px solid var(--accent-2);
}
.memory-box h4 { margin: 0 0 6px; font-size: 1rem; }
.memory-box p { margin: 4px 0; }
.memory-parts { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.memory-part {
  display: inline-flex; flex-direction: column; align-items: center; padding: 4px 10px;
  border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border);
}
.memory-ko { font-size: 1.15rem; font-weight: 700; }
.memory-en { font-size: 0.8rem; color: var(--muted); }
.memory-join { color: var(--muted); }
.memory-word { font-size: 1.15rem; font-weight: 700; color: var(--good); }
