:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --text: #17202b;
  --muted: #5d6877;
  --border: #d8dee8;
  --primary: #1d4f91;
  --primary-text: #ffffff;
  --ok: #167a3e;
  --ok-bg: #e3f4e9;
  --no: #b3261e;
  --no-bg: #fbe6e4;
  --warn: #8a5a00;
  --warn-bg: #fff3d6;
  --draft-bg: #efe6ff;
  --draft-text: #54309b;
  --shadow: 0 1px 2px rgba(20, 30, 50, 0.08);
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1b212a;
    --surface-2: #252d38;
    --text: #e8edf4;
    --muted: #9aa6b6;
    --border: #2f3948;
    --primary: #6aa5f0;
    --primary-text: #0b1522;
    --ok: #62d08b;
    --ok-bg: #16301f;
    --no: #ff8a80;
    --no-bg: #3a1c1a;
    --warn: #f1c05c;
    --warn-bg: #3a2e10;
    --draft-bg: #2d2548;
    --draft-text: #c5b0ff;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', system-ui, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) calc(72px + env(safe-area-inset-bottom)) env(safe-area-inset-left);
}
main { max-width: 640px; margin: 0 auto; padding: 12px 16px 24px; outline: none; }
h1 { font-size: 1.45rem; margin: 8px 0 12px; }
h2 { font-size: 1.1rem; margin: 0 0 8px; }
h3 { font-size: 1rem; margin: 12px 0 4px; }
p { margin: 0 0 8px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }
ul, ol { margin: 4px 0 8px; padding-left: 1.3em; }
.plain-list { list-style: none; padding: 0; }
.plain-list > li { padding: 6px 0; border-top: 1px solid var(--border); }
.plain-list > li:first-child { border-top: 0; }
.loading { text-align: center; color: var(--muted); padding: 40px 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 0 0 12px;
  box-shadow: var(--shadow);
}
.card.warn { background: var(--warn-bg); border-color: var(--warn); }
.card.center { text-align: center; }
.text { white-space: pre-wrap; overflow-wrap: anywhere; }
.small { font-size: 0.86rem; color: var(--muted); overflow-wrap: anywhere; }
.big { font-size: 1.35rem; font-weight: 700; }
.pad { padding: 0 4px; }
.grow { flex: 1 1 auto; min-width: 0; }
.right { text-align: right; }
.row { display: flex; gap: 8px; align-items: center; }
.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.dday { font-size: 2rem; font-weight: 800; margin: 0; line-height: 1.1; }
.error { color: var(--no); margin: 6px 0 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* 버튼: 터치 영역 44px 이상 */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; min-width: 44px; padding: 8px 16px;
  font: inherit; font-weight: 600; color: var(--text); text-decoration: none; text-align: center;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.btn:active { filter: brightness(0.92); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.danger { color: var(--no); }
.btn.big-btn { min-height: 52px; font-size: 1.05rem; }
.btn.small-btn { padding: 6px 12px; font-size: 0.9rem; }
.btn.sign { font-size: 1.2rem; }
.btn.next { width: 100%; margin-top: 12px; min-height: 52px; }
.file-btn { position: relative; }

button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

/* 입력 */
.text-input, .text-area {
  width: 100%; min-height: 44px; padding: 8px 12px;
  font: inherit; font-size: 16px; /* 16px 미만이면 iOS 가 확대함 */
  color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
}
.text-input.narrow { width: 7em; display: block; margin-top: 4px; }
.field { margin: 0 0 14px; }
.field > label:not(.check-row) { display: block; font-weight: 600; }
.check-row { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 4px 0; }
.check-row input[type='checkbox'] { width: 22px; height: 22px; flex: none; }
.input-row { display: flex; gap: 8px; }
.answer-form { display: flex; flex-direction: column; gap: 8px; }

/* 배지·칩 */
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.badges:empty { display: none; }
.badge, .chip { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.badge.draft { background: var(--draft-bg); color: var(--draft-text); }
.badge.home { background: var(--warn-bg); color: var(--warn); }
.badge.retry { background: var(--no-bg); color: var(--no); }
.badge-gap { margin-left: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip.trap { background: var(--warn-bg); color: var(--warn); }

/* 문제 */
.stem { font-size: 1.08rem; white-space: pre-wrap; overflow-wrap: anywhere; margin: 4px 0 8px; }
.stem-sm { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0 0 2px; }
.hint { font-size: 0.82rem; color: var(--muted); }
.choice-wrap { margin-bottom: 8px; }
.choice {
  display: flex; align-items: flex-start; gap: 10px; width: 100%; min-height: 48px; padding: 10px 12px;
  font: inherit; text-align: left; color: var(--text);
  background: var(--surface-2); border: 2px solid var(--border); border-radius: 12px; cursor: pointer;
}
.choice:disabled { opacity: 1; cursor: default; }
.choice-no { flex: none; width: 1.6em; height: 1.6em; line-height: 1.6em; text-align: center; border-radius: 50%; background: var(--surface); font-weight: 700; font-size: 0.9rem; }
.choice-text { overflow-wrap: anywhere; }
.choice.correct { border-color: var(--ok); background: var(--ok-bg); }
.choice.wrong { border-color: var(--no); background: var(--no-bg); }
.choice-note { font-size: 0.85rem; color: var(--muted); padding: 4px 8px 0 12px; }
.ox-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice.ox { justify-content: center; align-items: center; font-size: 2rem; font-weight: 800; min-height: 72px; }

.feedback { margin-top: 12px; }
.result { padding: 10px 14px; border-radius: 12px; font-weight: 700; margin-bottom: 8px; }
.result.ok { background: var(--ok-bg); color: var(--ok); }
.result.no { background: var(--no-bg); color: var(--no); }
.expected { font-weight: 700; }
.steps ol { padding-left: 1.5em; }
.steps li { margin-bottom: 4px; overflow-wrap: anywhere; }
.report-box { margin-top: 8px; }
.report-box .row { margin-top: 8px; }

/* 진행 바 */
.run-head { display: flex; align-items: center; gap: 12px; margin: 4px 0 12px; }
.run-count { font-weight: 700; flex: none; }
.bar { display: block; flex: 1 1 auto; height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar .fill { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.fill.good { background: var(--ok); }
.fill.mid { background: var(--warn); }
.fill.low { background: var(--no); }
.stats li { padding: 8px 0; }
.stats .label { overflow-wrap: anywhere; }
.stats .bar { margin-top: 4px; }

details.detail { border-top: 1px solid var(--border); padding: 4px 0; }
details > summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; flex-wrap: wrap; }
.detail-body { padding: 4px 0 8px; }

.notice { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; margin: 0 0 12px; }
.notice.warn { background: var(--warn-bg); border-color: var(--warn); color: var(--text); }

/* 하단 탭 */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.tab {
  flex: 1; display: flex; align-items: center; justify-content: center;
  min-height: 56px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 0.95rem;
}
.tab[aria-current='page'] { color: var(--primary); box-shadow: inset 0 3px 0 var(--primary); }

/* 업데이트 배너 · 토스트 */
.banner {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 8px 16px; padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--primary); color: var(--primary-text); font-weight: 600;
}
.banner .btn { background: var(--surface); color: var(--text); }
#toast {
  position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 30;
  transform: translateX(-50%); max-width: 90vw; padding: 10px 16px; border-radius: 999px;
  background: var(--text); color: var(--bg); font-size: 0.9rem; opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
#toast.show { opacity: 0.95; }

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
