:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #101827;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #2563eb;
  --primary-soft: #dbeafe;
  --primary-ink: #ffffff;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --success: #15803d;
  --success-soft: #dcfce7;
  --warning: #b45309;
  --warning-soft: #fef3c7;
  --chip: #eef2ff;
  --shadow: 0 18px 50px rgba(15, 23, 42, .08);
  --radius: 20px;
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #111827;
  --surface-2: #0f172a;
  --ink: #e5e7eb;
  --muted: #94a3b8;
  --line: #263244;
  --primary: #60a5fa;
  --primary-soft: #172554;
  --primary-ink: #07111f;
  --danger: #f87171;
  --danger-soft: #3f1d22;
  --success: #4ade80;
  --success-soft: #12301d;
  --warning: #fbbf24;
  --warning-soft: #3b2b0d;
  --chip: #18233a;
  --shadow: 0 18px 50px rgba(0, 0, 0, .28);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", sans-serif;
}

body { padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
button, input, select, textarea { font: inherit; }
button { border: 0; cursor: pointer; }
button:disabled { opacity: .5; cursor: not-allowed; }

#app-shell {
  width: min(100%, 540px);
  min-height: 100vh;
  margin: 0 auto;
  position: relative;
  background: radial-gradient(circle at top right, color-mix(in srgb, var(--primary) 18%, transparent), transparent 32rem), var(--bg);
  padding-bottom: 88px;
}

.app-header {
  padding: 22px 18px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.header-actions { display:flex; gap: 8px; align-items:center; }
.eyebrow { margin: 0 0 4px; color: var(--primary); font-weight: 900; font-size: 12px; letter-spacing: .04em; line-height: 1.35; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 22px; line-height: 1.2; }
h2 { margin-bottom: 12px; font-size: 22px; }
h3 { margin-bottom: 8px; font-size: 17px; }
.view { padding: 0 14px 28px; }

.card {
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
}
.card.flat { box-shadow: none; background: var(--surface-2); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.metric { background: var(--surface-2); border: 1px solid var(--line); border-radius: 16px; padding: 12px; }
.metric .label { color: var(--muted); font-size: 12px; margin: 0 0 6px; }
.metric .value { font-size: 20px; font-weight: 900; margin: 0; }
.metric .sub { color: var(--muted); font-size: 12px; margin: 5px 0 0; }
.progress { height: 10px; background: color-mix(in srgb, var(--line) 70%, transparent); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; width: var(--w, 0%); background: var(--primary); border-radius: inherit; transition: width .25s ease; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.actions { display: grid; grid-template-columns: 1fr; gap: 10px; }
.actions.two { grid-template-columns: 1fr 1fr; }
.actions.three { grid-template-columns: repeat(3, 1fr); }
.primary, .secondary, .ghost, .danger { min-height: 46px; border-radius: 15px; padding: 11px 14px; font-weight: 900; }
.primary { background: var(--primary); color: var(--primary-ink); }
.secondary { background: var(--primary-soft); color: var(--primary); }
.ghost { background: var(--surface-2); border: 1px solid var(--line); color: var(--ink); }
.danger { background: var(--danger-soft); color: var(--danger); }
.small { min-height: 34px; border-radius: 11px; padding: 7px 10px; font-size: 13px; }
.hidden { display:none !important; }
.note { color: var(--muted); font-size: 14px; line-height: 1.55; margin-bottom: 0; }
.muted { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; justify-content: center; min-height: 28px; border-radius: 999px; padding: 5px 10px; background: var(--chip); color: var(--primary); font-size: 12px; font-weight: 900; border: 1px solid color-mix(in srgb, var(--primary) 18%, transparent); }
.chip.gray { color: var(--muted); background: var(--surface-2); border-color: var(--line); }
.chip.red { color: var(--danger); background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.chip.green { color: var(--success); background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 30%, transparent); }
.chip.yellow { color: var(--warning); background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 30%, transparent); }
.list { display:flex; flex-direction:column; gap:10px; }
.item { border: 1px solid var(--line); background: var(--surface-2); border-radius: 16px; padding: 12px; }
.item-title { font-weight: 900; line-height: 1.35; }
.item-meta { margin-top: 5px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.question-stem { font-size: 18px; line-height: 1.55; font-weight: 800; margin: 18px 0; white-space: pre-wrap; }
.choice { width:100%; text-align:left; min-height: 52px; border-radius: 16px; padding: 13px 14px; background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); line-height:1.45; }
.choice.selected { border-color: var(--primary); background: var(--primary-soft); font-weight: 900; }
.choice.correct { border-color: var(--success); background: var(--success-soft); color: var(--success); }
.choice.wrong { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.explanation { margin-top: 8px; padding: 8px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); white-space: normal; line-height:1.48; }
.explanation-detailed { display: grid; gap: 7px; padding: 8px; }
.explain-section { border: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 75%, var(--surface-2)); border-radius: 11px; padding: 8px 10px; }
.explain-section p { margin: 4px 0 0; color: var(--ink); line-height: 1.5; font-size: 13.5px; }
.explain-title { font-weight: 950; color: var(--primary); font-size: 13px; letter-spacing: .01em; }
.explain-section strong { color: var(--primary); }

.form { display:grid; gap: 12px; }
.field { display:grid; gap: 6px; }
.field label { color: var(--muted); font-size: 13px; font-weight: 800; }
input, select, textarea { width:100%; border: 1px solid var(--line); border-radius: 14px; padding: 12px; background: var(--surface-2); color: var(--ink); }
.table { width:100%; border-collapse: collapse; font-size: 13px; overflow:hidden; border-radius: 14px; }
.table th, .table td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align:left; vertical-align:top; }
.table th { color: var(--muted); font-weight: 900; }
.law-exempt { opacity:.45; }
.timer-box { position: sticky; top: 0; z-index: 3; margin-top: 0; }
.timer-text { font-size: 20px; font-weight: 950; font-variant-numeric: tabular-nums; }
.answer-grid { display:grid; grid-template-columns: repeat(10, 1fr); gap: 5px; }
.answer-dot { min-height: 28px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); font-size: 11px; font-weight: 800; }
.answer-dot.current { border-color: var(--primary); color: var(--primary); }
.answer-dot.answered { background: var(--primary-soft); color: var(--primary); }
.bank-card { text-align:left; display:block; width:100%; min-height: auto; }
.bank-title { font-weight: 950; margin-bottom: 4px; }
.bank-desc { color: var(--muted); font-size: 12px; line-height: 1.45; }
.tabbar { position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); width: min(100%, 540px); display:grid; grid-template-columns: repeat(5, 1fr); gap: 6px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--surface) 94%, transparent); border-top: 1px solid var(--line); backdrop-filter: blur(14px); }
.tab { min-height: 48px; border-radius: 15px; background: transparent; color: var(--muted); font-weight: 900; }
.tab.active { background: var(--primary); color: var(--primary-ink); }
.toast { position: fixed; left: 50%; bottom: 86px; transform: translateX(-50%); width: min(92%, 500px); background: color-mix(in srgb, var(--ink) 92%, transparent); color: var(--bg); padding: 12px 14px; border-radius: 14px; text-align: center; font-weight: 800; z-index: 20; box-shadow: var(--shadow); }
@media (max-width: 380px) {
  .actions.two, .actions.three, .grid2, .grid3 { grid-template-columns: 1fr; }
  .answer-grid { grid-template-columns: repeat(5, 1fr); }
  h1 { font-size: 19px; }
}


.explain-section.emphasis { border-color: var(--primary); background: var(--primary-soft); }
.explain-list { margin: 5px 0 0; padding-left: 18px; line-height: 1.5; font-size: 13.5px; }
.choice-analysis { display: grid; gap: 5px; margin: 5px 0 0; padding-left: 0 !important; list-style: none; white-space: normal; }
.choice-analysis li { display: grid; gap: 4px; padding: 7px 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font-size: 13.5px; line-height: 1.48; }
.choice-analysis .chip { width: fit-content; }


.timer-toggle {
  min-width: 94px;
  font-variant-numeric: tabular-nums;
  letter-spacing: .01em;
}
.timer-reset {
  min-width: 58px;
  padding-left: 9px;
  padding-right: 9px;
}
.timer-toggle.timer-running {
  background: var(--primary);
  color: var(--primary-ink);
  border-color: var(--primary);
}
.timer-toggle.timer-paused {
  color: var(--warning);
  background: var(--warning-soft);
  border-color: color-mix(in srgb, var(--warning) 30%, transparent);
}
.timer-note { margin-top: 4px; font-size: 12px; }
.hint-actions { display: flex; justify-content: flex-end; margin: -6px 0 10px; }
.hint-box {
  border: 1px solid color-mix(in srgb, var(--primary) 34%, var(--line));
  background: color-mix(in srgb, var(--primary-soft) 55%, var(--surface));
  border-radius: 16px;
  padding: 12px;
  margin: 0 0 12px;
  line-height: 1.58;
}
.hint-title {
  font-weight: 950;
  color: var(--primary);
  margin-bottom: 6px;
}
.hint-box p { margin: 6px 0 0; color: var(--ink); font-size: 14px; }
@media (max-width: 430px) {
  .app-header { align-items: flex-start; }
  .header-actions { flex-wrap: wrap; justify-content: flex-end; max-width: 190px; }
  .timer-toggle { min-width: 100px; }
  .timer-reset { min-width: 58px; }
}


.review-list { display: grid; gap: 8px; }
.review-item {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  overflow: hidden;
}
.review-item.correct { border-color: color-mix(in srgb, var(--success) 26%, var(--line)); }
.review-item.wrong { border-color: color-mix(in srgb, var(--danger) 28%, var(--line)); }
.review-item summary {
  cursor: pointer;
  list-style: none;
  padding: 10px 11px;
}
.review-item summary::-webkit-details-marker { display: none; }
.review-summary-main { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; line-height: 1.35; }
.review-summary-meta { margin-top: 4px; color: var(--muted); font-size: 12px; line-height: 1.35; }
.review-body { padding: 0 10px 10px; cursor: pointer; }
.review-choice-summary { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; }
.review-choices .choice { cursor: default; }

.review-body .question-stem { margin: 10px 0; font-size: 16px; line-height: 1.45; }
.review-body .stack { gap: 6px; }
.review-body .choice { min-height: auto; padding: 9px 10px; border-radius: 11px; line-height: 1.38; }
.review-body .explanation { margin-top: 8px; }
.review-body .explain-title { font-size: 12.5px; }
.review-body .chip { min-height: 24px; padding: 3px 8px; }
