:root {
  color-scheme: light dark;
  --bg: #f4efe4;
  --surface: #fffdf8;
  --text: #1f2a44;
  --muted: #6a6557;
  --line: #e2d9c7;
  --primary: #1f2a44;
  --primary-text: #fffdf8;
  --marker: #f6cf4a;
  --marker-text: #1f2a44;
  --rule: #efe8da;
  --margin: #e8a79f;
  --hero: #1f2a44;
  --hero-text: #fffdf8;
  --hero-muted: #c5cbdc;
  --good: #17693f;
  --good-bg: #e0f2e6;
  --bad: #b5301f;
  --bad-bg: #fbe5e0;
  --warn: #6f5200;
  --warn-bg: #fbf0c9;
  --shadow: 0 1px 0 #e2d9c7, 0 8px 20px rgba(31, 42, 68, .07);
  --word-font: "Fraunces", Georgia, "Times New Roman", serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171f;
    --surface: #1e2230;
    --text: #f3efe6;
    --muted: #aeb0b8;
    --line: #353a4b;
    --primary: #f6cf4a;
    --primary-text: #1c1f2a;
    --rule: #272c3b;
    --margin: #7b4a46;
    --hero: #262c3e;
    --hero-text: #f3efe6;
    --hero-muted: #b6bccc;
    --good: #84dca6;
    --good-bg: #17331f;
    --bad: #f8a99e;
    --bad-bg: #3d1f1a;
    --warn: #f3d681;
    --warn-bg: #3a2f12;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  word-break: keep-all;
}

.app { max-width: 520px; margin: 0 auto; padding: 16px 16px 40px; }

h1, h2, h3, p { margin: 0; }
h1 { font-size: 24px; line-height: 1.3; font-weight: 700; }
h2 { font-size: 15px; font-weight: 700; }

.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; min-height: 44px; }
.brand { font-family: var(--word-font); font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.brand mark { background: linear-gradient(transparent 58%, var(--marker) 58%); color: inherit; padding: 0 2px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 18px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; min-width: 0; }
.muted { color: var(--muted); font-size: 14px; }
.center { text-align: center; }
.greeting { margin-bottom: 14px; }

button {
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform .08s ease, border-color .12s ease;
}
button:hover:not(:disabled) { border-color: var(--text); }
button:active:not(:disabled) { transform: translateY(1px); }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid var(--marker);
  outline-offset: 2px;
}
button:disabled { cursor: default; }

.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.primary:hover:not(:disabled) { border-color: var(--primary); }
.marker { background: var(--marker); border-color: var(--marker); color: var(--marker-text); }
.marker:hover:not(:disabled) { border-color: var(--marker); }
.link { min-height: 44px; padding: 6px 4px; border: 0; background: none; color: var(--muted); font-weight: 500; font-size: 14px; text-decoration: underline; text-underline-offset: 3px; }
.full { width: 100%; }

label.field { display: block; font-size: 14px; font-weight: 600; }
label.field select, label.field input { margin-top: 6px; }
.field-label { font-size: 14px; font-weight: 600; margin-bottom: 8px; }

select, input[type="text"] {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.check { display: flex; align-items: center; gap: 8px; min-height: 44px; font-size: 14px; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); }

.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 6px; }
.chips.wide { grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); }
.chip { min-height: 44px; padding: 6px 8px; font-size: 14px; font-weight: 500; }
.chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-text); font-weight: 700; }

.notice { padding: 10px 12px; border-radius: 6px; font-size: 14px; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.notice.good { background: var(--good-bg); color: var(--good); }
.notice.info { background: var(--rule); }

/* 로그인 */
.login-hero { padding: 36px 2px 22px; }
.login-title { font-family: var(--word-font); font-size: 44px; line-height: 1.05; font-weight: 700; letter-spacing: -.02em; }
.login-title mark { background: linear-gradient(transparent 60%, var(--marker) 60%); color: inherit; }
.code-input { font-family: ui-monospace, Consolas, monospace; font-size: 20px !important; letter-spacing: .12em; text-transform: uppercase; }

/* 홈 */
.review-card { background: var(--hero); color: var(--hero-text); border-color: transparent; box-shadow: none; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.review-card h2 { color: var(--hero-muted); font-weight: 500; font-size: 14px; }
.big-count { font-family: var(--word-font); font-size: 44px; font-weight: 700; line-height: 1.1; }
.big-count small { font-family: inherit; font-size: 18px; font-weight: 500; margin-left: 3px; }
.review-card .marker { flex: none; padding: 10px 18px; }
.review-card .muted { color: var(--hero-muted); max-width: 11em; text-align: right; }

.note-link { display: flex; justify-content: space-between; align-items: center; text-align: left; }
.note-link b { font-family: var(--word-font); font-size: 18px; }

/* 진행 */
.progress { height: 6px; border-radius: 6px; background: var(--line); overflow: hidden; margin-bottom: 14px; }
.progress > div { height: 100%; background: var(--primary); transition: width .2s ease; }
.tally { display: flex; gap: 10px; font-size: 14px; font-weight: 700; }
.tally .ok { color: var(--good); }
.tally .no { color: var(--bad); }

/* 단어 */
.word { font-family: var(--word-font); font-size: 38px; font-weight: 700; line-height: 1.15; letter-spacing: -.01em; overflow-wrap: anywhere; }
.index-card {
  position: relative;
  padding-top: 34px;
  background-color: var(--surface);
  background-image: linear-gradient(var(--margin), var(--margin)), repeating-linear-gradient(transparent 0 31px, var(--rule) 31px 32px);
  background-size: 100% 1px, 100% 100%;
  background-position: 0 24px, 0 24px;
  background-repeat: no-repeat, repeat;
}
.flash { min-height: 280px; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 10px; text-align: center; }
.question { min-height: 150px; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 6px; text-align: center; }
.meaning { font-size: 20px; font-weight: 700; }
.pos { display: inline-block; padding: 0 6px; font-size: 13px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; background: var(--surface); }
.example { font-family: var(--word-font); font-style: italic; color: var(--muted); font-size: 15px; }

/* 보기 */
.options { display: grid; gap: 8px; margin-bottom: 12px; }
.option { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; text-align: left; font-weight: 500; }
.option .num { flex: none; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 4px; background: var(--rule); color: var(--muted); font-size: 13px; font-weight: 700; }
.option .label { flex: 1; min-width: 0; }
.option .tag { flex: none; font-size: 13px; font-weight: 700; }
.option.correct { background: var(--good-bg); border: 2px solid var(--good); color: var(--good); font-weight: 700; }
.option.correct .num { background: var(--good); color: var(--surface); }
.option.wrong { background: var(--bad-bg); border: 2px solid var(--bad); color: var(--bad); font-weight: 700; }
.option.wrong .num { background: var(--bad); color: var(--surface); }
.option.dim { opacity: .5; }

.spell-input { font-family: var(--word-font); font-size: 22px !important; text-align: center; }
.spell-input.correct { background: var(--good-bg); border: 2px solid var(--good); color: var(--good); opacity: 1; }
.spell-input.wrong { background: var(--bad-bg); border: 2px solid var(--bad); color: var(--bad); opacity: 1; text-decoration: line-through; }

/* 즉시 피드백 */
.feedback {
  position: sticky;
  bottom: 8px;
  padding: 14px;
  border-radius: 6px;
  border-left: 5px solid;
  box-shadow: 0 8px 24px rgba(31, 42, 68, .16);
  animation: rise .16s ease-out;
}
.feedback.good { background: var(--good-bg); border-color: var(--good); }
.feedback.bad { background: var(--bad-bg); border-color: var(--bad); }
.feedback-title { font-size: 18px; font-weight: 700; }
.feedback.good .feedback-title { color: var(--good); }
.feedback.bad .feedback-title { color: var(--bad); }
.feedback-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.feedback-word { font-family: var(--word-font); font-size: 20px; font-weight: 700; overflow-wrap: anywhere; }
.feedback .example { margin: 2px 0 0; }
.feedback .next { margin-top: 12px; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* 결과 */
.result-card { padding-top: 34px; text-align: center; }
.score { font-family: var(--word-font); font-size: 64px; font-weight: 700; line-height: 1; letter-spacing: -.02em; }
.score small { font-size: 26px; color: var(--muted); font-weight: 500; }
.result-title { font-size: 20px; font-weight: 700; }

.word-list { list-style: none; margin: 0; padding: 0; }
.word-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--rule); }
.word-list li:first-child { border-top: 0; padding-top: 0; }
.word-list strong { display: block; font-family: var(--word-font); font-size: 19px; overflow-wrap: anywhere; }

.icon-btn { flex: none; display: inline-flex; align-items: center; justify-content: center; gap: 5px; min-height: 44px; min-width: 44px; padding: 6px 10px; font-size: 13px; font-weight: 500; background: transparent; color: inherit; }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
