:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #eeece6;
  --text: #1f2328;
  --muted: #5f6670;
  --line: #d9d6ce;
  --accent: #2f5d8a;
  --accent-text: #ffffff;
  --accent-soft: #e3ebf3;
  --ok: #1f7a4a;
  --ok-soft: #e3f2e9;
  --bad: #b3261e;
  --bad-soft: #fbe7e5;
  --warn: #8a5a00;
  --flag: #c2410c;
  --radius: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --surface: #1f2227;
    --surface-2: #2a2e35;
    --text: #e8e6e1;
    --muted: #a3a9b2;
    --line: #3a3f47;
    --accent: #8fb6dd;
    --accent-text: #10161d;
    --accent-soft: #24313f;
    --ok: #6fcf97;
    --ok-soft: #1c3127;
    --bad: #f28b82;
    --bad-soft: #3a2120;
    --warn: #e0b45c;
    --flag: #fb923c;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  font-size: 18px;
  line-height: 1.6;
  word-break: keep-all;
  overflow-wrap: anywhere;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
h1, h2, p, ul, ol { margin: 0; }

#app { max-width: 520px; margin: 0 auto; }
.screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding:
    calc(12px + env(safe-area-inset-top))
    calc(16px + env(safe-area-inset-right))
    calc(20px + env(safe-area-inset-bottom))
    calc(16px + env(safe-area-inset-left));
}
.screen.center { justify-content: center; text-align: center; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 15px; }
.warn { color: var(--warn); }
.strong { font-weight: 700; }

.topbar { display: flex; align-items: center; gap: 10px; min-height: 48px; }
.topbar .title { flex: 1; }
.title { font-size: 22px; line-height: 1.3; }
.label { font-size: 15px; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.block { display: flex; flex-direction: column; gap: 8px; }
.block > .label { margin-bottom: 0; }
.actions { gap: 10px; }
.foot { margin-top: auto; text-align: center; padding-top: 8px; }

/* 버튼 */
.btn {
  min-height: 52px;
  padding: 10px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active, .chip:active, .seg:active, .opt:active, .ox-btn:active, .word:active, .flag-btn:active { transform: scale(0.98); filter: brightness(0.95); }
.btn:disabled { opacity: 0.45; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.secondary { background: var(--surface); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn.big { min-height: 58px; font-size: 19px; }
.btn-small { min-height: 48px; padding: 6px 10px; font-size: 16px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* 칩·세그먼트 */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 48px; min-width: 48px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  touch-action: manipulation;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.chip[aria-pressed="true"]::before { content: '✓ '; }

.segment { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.seg { min-height: 50px; border: 0; border-left: 1px solid var(--line); background: transparent; cursor: pointer; touch-action: manipulation; }
.seg:first-child { border-left: 0; }
.seg[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); font-weight: 700; }

.stepper { display: grid; grid-template-columns: 64px 1fr 64px; gap: 8px; }
.step { font-size: 24px; padding: 0; }
.count-input, .answer-input, .memo-input {
  min-height: 52px;
  width: 100%;
  font-size: 18px; /* 16px 이상: iOS 자동 확대 방지 */
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
}
.count-input { text-align: center; font-weight: 700; }

.toggle { display: flex; align-items: center; gap: 12px; min-height: 48px; cursor: pointer; }
.toggle input { width: 24px; height: 24px; accent-color: var(--accent); }

/* 문제 화면 */
.quiz { gap: 14px; }
.quizbar { display: flex; align-items: center; gap: 8px; min-height: 48px; }
.progress { font-weight: 700; font-variant-numeric: tabular-nums; }
.tags { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; }
.tag { font-size: 13px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; line-height: 1.6; }
.flag-btn {
  width: 48px; height: 48px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 20px;
  filter: grayscale(1);
  opacity: 0.6;
  cursor: pointer;
  touch-action: manipulation;
}
.flag-btn[aria-pressed="true"] { filter: none; opacity: 1; border-color: var(--flag); box-shadow: inset 0 0 0 1px var(--flag); }

.q-body { display: flex; flex-direction: column; gap: 14px; }
.q-kind { font-size: 15px; color: var(--muted); font-weight: 600; }
.q-text { font-size: 19px; line-height: 1.7; }
.blank {
  display: inline-block;
  min-width: 4.5em;
  padding: 0 6px;
  border-bottom: 3px solid var(--accent);
  text-align: center;
  color: var(--muted);
  line-height: 1.4;
}
.blank.filled { color: var(--text); font-weight: 700; }
.hint { background: var(--accent-soft); padding: 8px 12px; border-radius: var(--radius); }
.hint strong { letter-spacing: 0.15em; }

.q-actions {
  margin-top: auto;
  position: sticky;
  bottom: 0;
  padding-top: 10px;
  padding-bottom: calc(4px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--bg) 14px);
}
.q-actions:empty { display: none; }
.q-actions > .btn { width: 100%; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ox-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ox-btn {
  min-height: 96px;
  font-size: 44px;
  font-weight: 800;
  border-radius: 16px;
  border: 2px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  touch-action: manipulation;
}
.ox-btn.o { color: var(--accent); }
.ox-btn.x { color: var(--bad); }

.opts { display: flex; flex-direction: column; gap: 8px; }
.opt {
  display: flex; align-items: flex-start; gap: 10px;
  min-height: 52px;
  padding: 12px 14px;
  text-align: left;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  touch-action: manipulation;
  line-height: 1.5;
}
div.opt { cursor: default; }
.opt-no { flex: none; color: var(--muted); font-weight: 700; }
.opt-text { flex: 1; }
.opt-mark { flex: none; font-weight: 700; font-size: 15px; }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.right .opt-mark { color: var(--ok); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .opt-mark { color: var(--bad); }
.opt.long .opt-text { font-size: 17px; line-height: 1.6; }
.opt-explain { display: block; margin-top: 6px; font-size: 15px; color: var(--muted); }
.ox-mark { font-weight: 700; }

.input-row { display: flex; flex-direction: column; gap: 10px; }
.row1 { display: grid; grid-template-columns: 1fr; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.typo { display: flex; flex-direction: column; gap: 8px; padding: 12px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--warn); }
.typo-msg { font-weight: 700; color: var(--warn); }

.fix-text { line-height: 2.3; }
.word {
  display: inline;
  padding: 4px 4px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  touch-action: manipulation;
  line-height: 1.6;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
.word.static { cursor: default; border-color: transparent; background: transparent; }
.word.hit { border-color: var(--ok); background: var(--ok-soft); font-weight: 700; text-decoration: underline wavy var(--ok); }
.word.miss { border-color: var(--bad); background: var(--bad-soft); text-decoration: line-through; }

.feedback { display: flex; flex-direction: column; gap: 10px; padding: 14px; border-radius: var(--radius); border: 2px solid; scroll-margin-top: 12px; }
.feedback.ok { border-color: var(--ok); background: var(--ok-soft); }
.feedback.bad { border-color: var(--bad); background: var(--bad-soft); }
.verdict { font-size: 20px; font-weight: 800; }
.feedback.ok .verdict { color: var(--ok); }
.feedback.bad .verdict { color: var(--bad); }
.explain { line-height: 1.7; }
.vs-box { padding: 10px 12px; border-radius: 10px; background: var(--surface); border-left: 4px solid var(--accent); }
.vs-box strong { color: var(--accent); }
.source summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; color: var(--accent); font-weight: 600; }
.source .orig-ans { margin-left: 10px; padding: 2px 8px; border-radius: 8px; background: var(--surface); color: var(--text); font-weight: 800; }
.source p { font-size: 16px; color: var(--muted); padding: 4px 0 0; }

/* 결과 */
.score { text-align: center; padding: 16px 0; }
.score-big { font-size: 44px; font-weight: 800; font-variant-numeric: tabular-nums; }
.wrong-list, .flag-list, .resolved-list, .plain { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.wrong-list li, .flag-card, .resolved-list li { padding: 12px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
.wrong-list .tag { align-self: flex-start; }
.answer { line-height: 1.5; }
.flag-text { white-space: pre-line; }
.plain.num { list-style: decimal; padding-left: 1.4em; }
.plain li { line-height: 1.6; }

/* 시트 */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.sheet {
  width: 100%; max-width: 520px;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  padding: 18px calc(16px + env(safe-area-inset-right)) calc(18px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: 12px;
}
.sheet-title { font-size: 19px; }

/* 토스트·배너 */
#toasts {
  position: fixed; left: 0; right: 0;
  top: calc(12px + env(safe-area-inset-top));
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none; z-index: 30; padding: 0 16px;
}
.toast { max-width: 488px; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 16px; line-height: 1.5; }
#banner {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(10px + env(safe-area-inset-bottom));
  width: calc(100% - 32px); max-width: 488px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 8px 8px 16px;
  background: var(--surface); border: 1px solid var(--accent); border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  z-index: 25; font-size: 16px;
}
#banner[hidden], body.in-quiz #banner { display: none; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* 사용법 */
.guide { gap: 26px; }
.g-sec { gap: 10px; }
.g-h { font-size: 19px; line-height: 1.35; }
.g-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.g-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.g-between { justify-content: space-between; }
.g-col { display: flex; flex-direction: column; gap: 6px; }
.g-center { align-items: center; }
.g-icon { display: inline-flex; flex: none; width: 22px; height: 22px; color: var(--muted); }
.g-icon svg { width: 100%; height: 100%; }
.g-ic-acc { color: var(--accent); }
.g-ic-big { width: 34px; height: 34px; }
.g-tip { font-size: 15px; padding: 10px 12px; border-radius: var(--radius); background: var(--accent-soft); }

/* 번호 배지 */
.g-badge {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  min-width: 22px; height: 22px; padding: 0 3px;
  border-radius: 999px; background: var(--flag); color: #fff;
  font-size: 14px; font-weight: 800; line-height: 1;
  box-shadow: 0 0 0 2px var(--bg);
}
.g-mark { position: relative; padding: 3px 26px 3px 3px; border-radius: 8px; outline: 1.5px dashed color-mix(in srgb, var(--flag) 70%, transparent); outline-offset: 1px; }
.g-mark + .g-mark { margin-top: 6px; }
.g-mark > .g-badge { position: absolute; top: 50%; right: 2px; transform: translateY(-50%); z-index: 1; }
.g-legend { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 8px; font-size: 16px; line-height: 1.5; }
.g-legend li { display: flex; align-items: flex-start; gap: 8px; }
.g-legend .g-badge { margin-top: 2px; box-shadow: none; }

/* 미니 '폰 화면' 목업: 실제 화면 클래스를 축소해서 재사용, 눌리지 않음 */
.g-phone {
  pointer-events: none; user-select: none; -webkit-user-select: none;
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px;
  border: 1px solid var(--line); border-radius: 16px;
  background: var(--bg);
  box-shadow: inset 0 0 0 4px var(--surface-2);
  font-size: 13.5px; line-height: 1.5;
  overflow: hidden;
}
.g-phone .g-label { font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.g-phone .g-link { color: var(--accent); font-weight: 600; font-size: 12.5px; }
.g-phone .btn { display: flex; align-items: center; justify-content: center; min-height: 32px; padding: 4px 10px; font-size: 13px; border-radius: 9px; text-align: center; }
.g-phone .chips { gap: 5px; }
.g-phone .chip { min-height: 26px; min-width: 0; padding: 2px 9px; font-size: 12.5px; display: inline-flex; align-items: center; }
.g-phone .segment { border-radius: 9px; }
.g-phone .seg { min-height: 30px; display: flex; align-items: center; justify-content: center; font-size: 12.5px; }
.g-phone .stepper { grid-template-columns: 40px 1fr 40px; gap: 6px; }
.g-phone .step { font-size: 16px; }
.g-phone .count-input, .g-phone .answer-input { min-height: 32px; font-size: 13.5px; padding: 4px 10px; border-radius: 9px; display: flex; align-items: center; justify-content: center; }
.g-phone .answer-input { justify-content: flex-start; }
.g-phone .g-ph { color: var(--muted); }
.g-phone .q-kind { font-size: 12px; }
.g-phone .q-text { font-size: 14px; line-height: 1.6; }
.g-phone .fix-text { line-height: 2; }
.g-phone .word { padding: 2px 3px; border-radius: 6px; }
.g-phone .blank { border-bottom-width: 2px; min-width: 3em; }
.g-phone .hint { padding: 4px 10px; border-radius: 9px; font-size: 13px; }
.g-phone .ox-row { gap: 8px; }
.g-phone .ox-btn { min-height: 44px; font-size: 22px; border-radius: 10px; display: flex; align-items: center; justify-content: center; border-width: 1.5px; }
.g-phone .opts { gap: 5px; }
.g-phone .opt { min-height: 0; padding: 5px 10px; gap: 6px; border-radius: 9px; }
.g-phone .opt.long .opt-text { font-size: 13px; line-height: 1.5; }
.g-phone .row2 { gap: 6px; }
.g-phone .feedback { gap: 8px; padding: 10px; border-width: 1.5px; border-radius: 10px; }
.g-phone .verdict { font-size: 15px; }
.g-phone .explain { line-height: 1.55; }
.g-phone .vs-box { padding: 6px 9px; border-left-width: 3px; }
.g-phone .g-summary { display: flex; align-items: center; color: var(--accent); font-weight: 600; min-height: 26px; }
.g-phone .source .orig-ans { margin-left: 8px; padding: 0 6px; }
.g-phone .typo { padding: 8px; gap: 4px; border-radius: 10px; }
.g-phone .quizbar { min-height: 0; gap: 8px; }
.g-phone .tag { font-size: 11.5px; }
.g-phone .flag-btn { width: 34px; height: 34px; font-size: 15px; display: inline-flex; align-items: center; justify-content: center; border-radius: 9px; }

/* 한눈에 보기 흐름 */
.g-flow { list-style: none; padding: 0; display: grid; grid-template-columns: 1fr 14px 1fr 14px 1fr; align-items: start; gap: 4px; }
.g-step { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; min-width: 0; }
.g-step-icon {
  position: relative; display: flex; align-items: center; justify-content: center;
  width: 54px; height: 54px; border-radius: 16px;
  background: var(--accent-soft); color: var(--accent);
}
.g-step-icon .g-icon { width: 28px; height: 28px; color: var(--accent); }
.g-step-no {
  position: absolute; top: -6px; left: -6px;
  width: 22px; height: 22px; border-radius: 999px;
  background: var(--accent); color: var(--accent-text);
  font-size: 13px; font-weight: 800; display: flex; align-items: center; justify-content: center;
}
.g-step strong { font-size: 16px; }
.g-step-desc { font-size: 13px; line-height: 1.45; color: var(--muted); }
.g-arrow { margin-top: 14px; text-align: center; font-size: 22px; color: var(--muted); line-height: 1; }

/* 문제 유형 카드 */
.g-cards { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.g-card { display: flex; flex-direction: column; gap: 8px; padding: 12px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.g-lv { display: inline-block; font-size: 12.5px; font-weight: 700; padding: 1px 8px; border-radius: 999px; line-height: 1.6; white-space: nowrap; }
.g-lv.easy { background: var(--ok-soft); color: var(--ok); }
.g-lv.normal { background: var(--accent-soft); color: var(--accent); }
.g-lv.hard { background: var(--bad-soft); color: var(--bad); }
.g-lv.mix { background: var(--surface-2); color: var(--text); }

/* 난이도 표 */
.g-table { width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; font-size: 14px; background: var(--surface); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.g-table th, .g-table td { padding: 7px 2px; border-top: 1px solid var(--line); text-align: center; line-height: 1.35; }
.g-table thead th { border-top: 0; background: var(--surface-2); }
.g-table thead th:first-child, .g-table tbody th { width: 38%; text-align: left; padding-left: 10px; font-weight: 600; }
.g-table thead .g-lv { font-size: 12px; padding: 1px 5px; }
.g-table td.g-on { color: var(--accent); font-size: 15px; }

/* 🚩 흐름 */
.g-fsteps { list-style: none; padding: 0; display: flex; flex-direction: column; }
.g-fstep { position: relative; display: flex; gap: 10px; padding-bottom: 16px; }
.g-fstep:last-child { padding-bottom: 0; }
.g-fstep:not(:last-child)::before { content: ''; position: absolute; left: 13px; top: 30px; bottom: 2px; width: 2px; background: var(--line); }
.g-fno {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 28px; height: 28px; border-radius: 999px;
  background: var(--accent); color: var(--accent-text); font-size: 14px; font-weight: 800;
}
.g-fbody { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; padding-top: 2px; }
.g-fbody > strong { line-height: 1.4; }
.g-file { font-size: 12px; color: var(--muted); }
.g-arrow-s { color: var(--muted); }
.g-share { display: flex; gap: 14px; }
.g-app { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 12px; }
.g-app .g-icon { width: 40px; height: 40px; padding: 8px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.g-app:first-child .g-icon { border: 2px solid var(--flag); }
.g-app.dim { opacity: 0.55; }

/* 홈 화면에 추가 */
.g-adds { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.g-add { display: grid; grid-template-columns: 128px 1fr; align-items: center; gap: 12px; }
.g-add .g-phone { min-height: 76px; justify-content: center; padding: 8px; }
.g-addr { font-size: 11.5px; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.g-toolbar { display: flex; justify-content: space-around; align-items: center; font-size: 18px; color: var(--muted); }
.g-hl { color: var(--accent); width: 30px; height: 30px; padding: 2px; border-radius: 8px; box-shadow: 0 0 0 2px var(--flag); }
.g-menu { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.g-menu > span { display: flex; align-items: center; justify-content: space-between; gap: 4px; padding: 3px 6px; border-radius: 6px; background: var(--surface); }
.g-dim { color: var(--muted); }
.g-hl-row { box-shadow: 0 0 0 2px var(--flag); font-weight: 700; }
.g-hl-row .g-icon { width: 16px; height: 16px; color: var(--text); }
.g-later { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 0 12px; }
.g-later > summary { min-height: 52px; display: flex; align-items: center; cursor: pointer; font-weight: 600; color: var(--accent); }
.g-later[open] { padding-bottom: 12px; }
.g-later[open] > summary { margin-bottom: 6px; }

@media (max-width: 380px) {
  .g-add { grid-template-columns: 108px 1fr; gap: 10px; }
  .g-table { font-size: 13px; }
  .g-table thead .g-lv { padding: 1px 3px; font-size: 11px; }
}

.g-chain { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.g-chip-step { padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: 16px; }
.g-chain .g-arrow-s { color: var(--muted); }
