:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0efe9;
  --text: #1d2125;
  --muted: #5f6670;
  --line: #e2e0d8;
  --brand: #1f5f4a;
  --brand-soft: #e3efe9;
  --accent: #b8860b;
  --ok: #1e7a46;
  --ok-soft: #e4f3ea;
  --bad: #b3261e;
  --bad-soft: #fbe9e7;
  --focus: #2f6fdb;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 14px rgba(0, 0, 0, .04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141716;
    --surface: #1c201f;
    --surface-2: #252a28;
    --text: #e8eae8;
    --muted: #a3aaa6;
    --line: #313735;
    --brand: #6cc4a1;
    --brand-soft: #1f3a30;
    --accent: #e2b34a;
    --ok: #5fcf8e;
    --ok-soft: #17321f;
    --bad: #ff8a80;
    --bad-soft: #3a1d1a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

a { color: inherit; }

.wrap { width: 100%; max-width: 760px; margin: 0 auto; padding: 0 16px; }

/* 상단 */
.topbar { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 56px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; text-decoration: none; letter-spacing: -.02em; }
.brand-mark { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--brand); color: var(--surface); font-size: 15px; }
.nav { display: flex; gap: 4px; }
.nav a { padding: 6px 10px; border-radius: 999px; text-decoration: none; font-size: 14px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.nav a.active { background: var(--brand-soft); color: var(--brand); }

main { padding-top: 24px; padding-bottom: 48px; min-height: 60vh; }

h1 { font-size: 26px; line-height: 1.3; margin: 0 0 6px; letter-spacing: -.03em; }
h2 { font-size: 18px; margin: 32px 0 12px; letter-spacing: -.02em; }
.lead { color: var(--muted); margin: 0 0 20px; }

/* 그룹 카드 */
.groups { display: grid; gap: 12px; }
.group-card { display: flex; align-items: center; gap: 16px; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); text-decoration: none; transition: border-color .15s, transform .15s; }
.group-card:hover { border-color: var(--brand); transform: translateY(-1px); }
.group-card .tag { flex: none; display: grid; place-items: center; width: 52px; height: 52px; border-radius: 12px; background: var(--brand-soft); color: var(--brand); font-weight: 800; font-size: 14px; text-align: center; line-height: 1.2; }
.group-card .body { flex: 1; min-width: 0; }
.group-card .title { font-weight: 700; font-size: 17px; }
.group-card .desc { color: var(--muted); font-size: 14px; }
.group-card .go { color: var(--muted); font-size: 20px; }
.group-card .done { font-size: 13px; color: var(--ok); font-weight: 700; }

/* 문제 */
.quiz-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 8px; margin-bottom: 16px; }
.back { display: inline-block; margin-bottom: 8px; color: var(--muted); text-decoration: none; font-size: 14px; }
.counter { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }

.q { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 14px; scroll-margin-top: 72px; }
.q.correct { border-color: var(--ok); }
.q.wrong { border-color: var(--bad); }
.q-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 10px; }
.q-num { font-weight: 800; color: var(--brand); margin-right: 4px; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-weight: 600; }
.badge.practice { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.q-text { white-space: pre-line; margin: 0 0 14px; font-size: 16.5px; }

.choices { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.choice { width: 100%; display: flex; gap: 10px; align-items: flex-start; text-align: left; padding: 12px 14px; min-height: 48px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); font: inherit; font-size: 15.5px; cursor: pointer; transition: border-color .12s, background .12s; }
.choice:hover { border-color: var(--muted); }
.choice:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.choice .n { flex: none; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; border: 1.5px solid var(--line); font-size: 13px; font-weight: 700; color: var(--muted); }
.choice[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); }
.choice[aria-pressed="true"] .n { background: var(--brand); border-color: var(--brand); color: var(--surface); }
.choice:disabled { cursor: default; }
.choice.is-answer { border-color: var(--ok); background: var(--ok-soft); }
.choice.is-answer .n { background: var(--ok); border-color: var(--ok); color: var(--surface); }
.choice.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.choice.is-wrong .n { background: var(--bad); border-color: var(--bad); color: var(--surface); }

.result-line { margin-top: 14px; font-weight: 700; }
.result-line.ok { color: var(--ok); }
.result-line.bad { color: var(--bad); }
.explain { margin-top: 10px; padding: 14px; background: var(--surface-2); border-radius: 10px; font-size: 15px; }
.explain strong { display: block; margin-bottom: 4px; }

.entry { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 14.5px; font-variant-numeric: tabular-nums; }
.entry th, .entry td { border: 1px solid var(--line); padding: 6px 8px; }
.entry th { background: var(--surface); font-weight: 700; width: 50%; }
.entry td.amt { text-align: right; }

.q-tools { margin-top: 12px; display: flex; justify-content: flex-end; }
.linkbtn { border: 0; background: none; color: var(--muted); font: inherit; font-size: 13px; text-decoration: underline; cursor: pointer; padding: 4px; }
.report { margin-top: 10px; display: grid; gap: 8px; }
.report[hidden] { display: none; }
.report textarea { width: 100%; min-height: 80px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); font: inherit; font-size: 15px; resize: vertical; }

/* 버튼 */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 48px; padding: 0 20px; border-radius: 12px; border: 1.5px solid var(--brand); background: var(--brand); color: var(--surface); font: inherit; font-weight: 700; cursor: pointer; text-decoration: none; }
.btn.secondary { background: var(--surface); color: var(--brand); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.btn.small { min-height: 40px; padding: 0 14px; font-size: 14px; }

.submit-bar { position: sticky; bottom: 0; padding: 12px 0 16px; background: linear-gradient(to top, var(--bg) 70%, transparent); display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.submit-bar .hint { color: var(--muted); font-size: 14px; }

/* 결과 */
.score { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px; }
.score-top { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.score-big { font-size: 40px; font-weight: 800; color: var(--brand); letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.score-sub { color: var(--muted); }
.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 12px 0 16px; }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.mail { display: flex; gap: 8px; flex-wrap: wrap; }
.mail input { flex: 1 1 220px; min-height: 48px; padding: 0 14px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); font: inherit; }
.mail input:focus { outline: 2px solid var(--focus); outline-offset: 1px; }
.note { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }

/* 아카이브 */
.archive { display: grid; gap: 10px; }
.day { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.day-date { font-weight: 700; margin-bottom: 8px; }
.day-links { display: flex; flex-wrap: wrap; gap: 8px; }
.day-links a { padding: 6px 12px; border-radius: 999px; background: var(--surface-2); text-decoration: none; font-size: 14px; font-weight: 600; }
.day-links a:hover { background: var(--brand-soft); color: var(--brand); }

.empty { padding: 40px 0; text-align: center; color: var(--muted); }

.footer { border-top: 1px solid var(--line); padding: 20px 0 32px; color: var(--muted); font-size: 13px; }
.footer p { margin: 4px 0; }

@media (max-width: 520px) {
  h1 { font-size: 22px; }
  main { padding-top: 18px; }
  .q { padding: 16px; }
  .brand span:last-child { font-size: 15px; }
  .nav a { padding: 6px 8px; font-size: 13px; }
  .submit-bar .hint { font-size: 13px; }
}
