:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f1;
  --line: #dde4e2;
  --text: #17201f;
  --muted: #5d6b69;
  --primary: #0d6e6e;
  --primary-ink: #ffffff;
  --primary-soft: #dff0ee;
  --ok: #1d7a46;
  --ok-soft: #e1f3e8;
  --bad: #c2362f;
  --bad-soft: #fbe7e5;
  --warn: #a86a00;
  --warn-soft: #fff1d6;
  --star: #e0a100;
  --shadow: 0 1px 2px rgba(16, 33, 31, .06), 0 4px 14px rgba(16, 33, 31, .06);
  --radius: 16px;
  --fs: 17px;
  --bar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1716; --surface: #172221; --surface-2: #1e2c2a; --line: #2a3b39;
    --text: #e6eeec; --muted: #9aaba8; --primary: #3fb3a8; --primary-ink: #06201d; --primary-soft: #183936;
    --ok: #4cc27f; --ok-soft: #173326; --bad: #ff7a6e; --bad-soft: #3a1d1b; --warn: #f0b44c; --warn-soft: #36290f;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1716; --surface: #172221; --surface-2: #1e2c2a; --line: #2a3b39;
  --text: #e6eeec; --muted: #9aaba8; --primary: #3fb3a8; --primary-ink: #06201d; --primary-soft: #183936;
  --ok: #4cc27f; --ok-soft: #173326; --bad: #ff7a6e; --bad-soft: #3a1d1b; --warn: #f0b44c; --warn-soft: #36290f;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  font-size: var(--fs); line-height: 1.6; word-break: keep-all; overflow-wrap: anywhere;
  min-height: 100dvh;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: 8px; }

.wrap { max-width: 720px; margin: 0 auto; padding: calc(12px + var(--safe-t)) 16px calc(24px + var(--safe-b)); }
.wrap.has-bar { padding-bottom: calc(var(--bar-h) + 28px + var(--safe-b)); }

/* 상단 */
.top { display: flex; align-items: center; gap: 8px; min-height: 52px; }
.top h1 { font-size: 1.15rem; margin: 0; flex: 1; letter-spacing: -.01em; }
.top .sub { color: var(--muted); font-size: .85rem; font-weight: 500; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; display: inline-grid; place-items: center; color: var(--text); }
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn.on { color: var(--star); }

/* 카드 */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 18px; }
.stack > * + * { margin-top: 12px; }
.section-title { font-size: .9rem; color: var(--muted); font-weight: 600; margin: 24px 4px 8px; }

/* 홈 요약 */
.hero { display: flex; gap: 18px; align-items: center; }
.ring { --p: 0; width: 92px; height: 92px; border-radius: 50%; flex: none;
  background: conic-gradient(var(--primary) calc(var(--p) * 1%), var(--surface-2) 0); display: grid; place-items: center; }
.ring > div { width: 74px; height: 74px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; text-align: center; line-height: 1.1; }
.ring b { font-size: 1.35rem; }
.ring small { font-size: .72rem; color: var(--muted); }
.hero-text { flex: 1; min-width: 0; }
.hero-text .big { font-size: 1.05rem; font-weight: 700; }
.hero-text .meta { color: var(--muted); font-size: .88rem; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.kpi { background: var(--surface-2); border-radius: 12px; padding: 10px; text-align: center; }
.kpi b { display: block; font-size: 1.1rem; }
.kpi span { font-size: .78rem; color: var(--muted); }

/* 모드 */
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode { text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; min-height: 118px; display: flex; flex-direction: column; gap: 6px; }
.mode:active { transform: scale(.985); }
.mode .ic { width: 38px; height: 38px; border-radius: 10px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; }
.mode .ic svg { width: 22px; height: 22px; }
.mode b { font-size: 1rem; }
.mode span { font-size: .8rem; color: var(--muted); line-height: 1.4; }
.mode.wide { grid-column: span 2; flex-direction: row; align-items: center; min-height: 0; }
.mode.wide > div:not(.ic) { flex: 1; min-width: 0; }
.mode.wide .ic { flex: none; }
.pill { display: inline-block; font-size: .75rem; font-weight: 700; padding: 2px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.star { background: var(--warn-soft); color: var(--warn); }

/* 장별 진도 */
.chap { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.chap:first-child { border-top: 0; padding-top: 0; }
.chap .name { font-weight: 600; font-size: .95rem; }
.chap .num { font-size: .82rem; color: var(--muted); text-align: right; }
.bar { grid-column: span 2; height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; }
.bar .c { background: var(--ok); }
.bar .w { background: var(--bad); }

/* 설정 시트 */
.sheet-back { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 720px; border-radius: 22px 22px 0 0; max-height: 92dvh; overflow: auto;
  padding: 10px 18px calc(18px + var(--safe-b)); }
.sheet .grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 4px auto 10px; }
.sheet h2 { font-size: 1.15rem; margin: 4px 0 2px; }
.sheet .desc { color: var(--muted); font-size: .88rem; margin: 0 0 8px; }
.field { margin-top: 16px; }
.field > label { display: block; font-size: .85rem; font-weight: 700; color: var(--muted); margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 40px; padding: 7px 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); font-size: .9rem; font-weight: 600; }
.chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.chip small { font-weight: 500; opacity: .75; margin-left: 4px; }
.count-note { margin-top: 18px; font-size: .9rem; color: var(--muted); text-align: center; }

/* 버튼 */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 0 20px; border-radius: 14px; font-weight: 700; font-size: 1rem; }
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.primary:disabled { opacity: .45; }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.block { width: 100%; }
.row { display: flex; gap: 10px; }
.row > .btn { flex: 1; }

/* 문제 */
.qhead { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 10px; }
.tag { font-size: .76rem; font-weight: 700; padding: 3px 9px; border-radius: 8px; background: var(--surface-2); color: var(--muted); }
.tag.type { background: var(--primary-soft); color: var(--primary); }
.qno { font-weight: 800; color: var(--primary); }
.stem { font-weight: 700; font-size: 1.02em; margin: 0 0 12px; }
.items { list-style: none; margin: 0 0 4px; padding: 14px; background: var(--surface-2); border-radius: 12px; }
.items li { display: grid; grid-template-columns: 1.6em 1fr; gap: 2px; padding: 4px 0; }
.items li + li { border-top: 1px dashed var(--line); padding-top: 8px; margin-top: 4px; }
.items .k { font-weight: 800; }
.blank { display: inline-block; min-width: 2.2em; text-align: center; border-bottom: 2px solid var(--muted); margin: 0 2px; line-height: 1.2; }
.blank.fill { color: var(--primary); font-weight: 800; border-color: var(--primary); }

.opts { display: grid; gap: 8px; margin-top: 14px; }
.opt { display: flex; align-items: center; gap: 12px; min-height: 54px; padding: 10px 14px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface); text-align: left; font-weight: 600; }
.opt .n { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; border: 1.5px solid var(--line); font-size: .9rem; font-weight: 800; }
.opt.sel { border-color: var(--primary); background: var(--primary-soft); }
.opt.sel .n { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.right .n { background: var(--ok); border-color: var(--ok); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .n { background: var(--bad); border-color: var(--bad); color: #fff; }
.opt:disabled { cursor: default; }

.verdict { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.05rem; padding: 12px 14px; border-radius: 12px; margin-top: 14px; }
.verdict.ok { background: var(--ok-soft); color: var(--ok); }
.verdict.no { background: var(--bad-soft); color: var(--bad); }

.explain { margin-top: 12px; }
.explain h3 { font-size: .9rem; margin: 0 0 8px; color: var(--muted); }
.ex-item { display: grid; grid-template-columns: 30px 1fr; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); font-size: .95em; }
.ex-item:first-of-type { border-top: 0; }
.ox { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; font-weight: 900; font-size: .9rem; }
.ox.o { background: var(--ok-soft); color: var(--ok); }
.ox.x { background: var(--bad-soft); color: var(--bad); }
.ox.v { background: var(--primary-soft); color: var(--primary); font-size: .72rem; width: auto; min-width: 28px; padding: 0 4px; }
.ex-item .why { color: var(--bad); font-weight: 600; display: block; margin-top: 2px; }
.meta-box { margin-top: 10px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); font-size: .9em; }
.meta-box p { margin: 0; }
.meta-box p + p { margin-top: 6px; }
.meta-box b { color: var(--muted); margin-right: 6px; }
.reveal { margin-top: 14px; }

/* 하단 고정 바 */
.bottom-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-top: 1px solid var(--line); padding: 8px 16px calc(8px + var(--safe-b)); }
.bottom-bar .in { max-width: 720px; margin: 0 auto; display: flex; gap: 8px; align-items: center; }
.bottom-bar .btn { min-height: 48px; flex: 1; }
.bottom-bar .btn.sq { flex: none; width: 52px; padding: 0; }

.progress-line { height: 4px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 2px 0 12px; }
.progress-line i { display: block; height: 100%; background: var(--primary); transition: width .2s; }
.timer { font-variant-numeric: tabular-nums; font-weight: 800; padding: 4px 10px; border-radius: 10px; background: var(--surface-2); font-size: .95rem; }
.timer.low { background: var(--bad-soft); color: var(--bad); }

/* 답안지(OMR) */
.omr { display: grid; grid-template-columns: repeat(auto-fill, minmax(54px, 1fr)); gap: 6px; }
.omr button { min-height: 48px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-size: .82rem; font-weight: 700; line-height: 1.15; display: grid; place-items: center; }
.omr button small { display: block; font-weight: 800; font-size: .9rem; color: var(--primary); }
.omr button.done { background: var(--primary-soft); border-color: var(--primary); }
.omr button.cur { outline: 2px solid var(--text); }
.omr button.right { background: var(--ok-soft); border-color: var(--ok); }
.omr button.wrong { background: var(--bad-soft); border-color: var(--bad); }

/* OX 훈련 */
.ox-card { font-size: 1.05em; min-height: 160px; }
.ox-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.ox-btns button { min-height: 76px; border-radius: 16px; font-size: 2rem; font-weight: 900; border: 2px solid var(--line); background: var(--surface); }
.ox-btns .o { color: var(--ok); }
.ox-btns .x { color: var(--bad); }
.ox-btns .correct { background: var(--ok-soft); border-color: var(--ok); }
.ox-btns .miss { background: var(--bad-soft); border-color: var(--bad); }
.ox-btns button:disabled { cursor: default; }
.from { font-size: .82rem; color: var(--muted); margin-bottom: 8px; }

/* 결과 */
.score { text-align: center; padding: 22px 18px; }
.score .pt { font-size: 3rem; font-weight: 900; line-height: 1; color: var(--primary); }
.score .pt small { font-size: 1.1rem; color: var(--muted); font-weight: 700; }
.list-btn { display: flex; width: 100%; gap: 12px; align-items: center; text-align: left; padding: 12px 0; border-top: 1px solid var(--line); }
.list-btn:first-child { border-top: 0; }
.list-btn .no { flex: none; width: 44px; font-weight: 800; color: var(--bad); }
.list-btn .t { flex: 1; min-width: 0; font-size: .92rem; }
.list-btn .t small { display: block; color: var(--muted); }

/* 로그인 */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login .card { width: 100%; max-width: 400px; padding: 28px 22px; }
.login h1 { font-size: 1.4rem; margin: 10px 0 4px; }
.login p { color: var(--muted); margin: 0 0 20px; font-size: .92rem; }
.logo { width: 56px; height: 56px; border-radius: 16px; background: var(--primary); color: var(--primary-ink); display: grid; place-items: center; }
.logo svg { width: 32px; height: 32px; }
.input { width: 100%; min-height: 54px; padding: 0 16px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface); font-size: 1.05rem; }
.input:focus { border-color: var(--primary); outline: none; }
.err { color: var(--bad); font-size: .9rem; min-height: 1.4em; margin: 8px 2px; }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.mt { margin-top: 14px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.setting-row:first-child { border-top: 0; padding-top: 0; }

#toast { position: fixed; left: 50%; bottom: calc(var(--bar-h) + 24px + var(--safe-b)); transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; font-size: .9rem; font-weight: 600; z-index: 60; display: none; max-width: calc(100% - 32px); }
#toast.show { display: block; }

@media (min-width: 640px) {
  .modes { grid-template-columns: repeat(4, 1fr); }
  .mode.wide { grid-column: span 2; }
}
.sheet-actions { position: sticky; bottom: calc(-18px - var(--safe-b)); margin: 14px -18px 0; padding: 12px 18px calc(18px + var(--safe-b)); background: var(--surface); border-top: 1px solid var(--line); }
.count-note + .sheet-actions { margin-top: 10px; }
@media (max-width: 420px) {
  .wrap { padding-left: 12px; padding-right: 12px; }
  .card { padding: 15px; }
  .items { padding: 10px 12px; margin-left: -4px; margin-right: -4px; }
}
