:root {
  --bg: #f4eee4;
  --surface: #ffffff;
  --surface-2: #faf6f0;
  --ink: #2b2118;
  --ink-2: #5b4b3c;
  --muted: #968877;
  --border: #e7dccb;
  --accent: #6b4426;        /* 수바사 갈색 (호두나무) */
  --accent-hover: #54341b;
  --accent-soft: #f5ebdd;
  --ok: #18794e;
  --ok-soft: #eaf5ef;
  --ng: #b42318;
  --ng-soft: #fcefed;
  --gold: #b7791f;
  --gold-soft: #fbf3e4;
  --mark: #d92d20;
  --radius: 16px;
  /* 버튼 크기 기준: 모든 버튼 44px, 보기 버튼만 48px */
  --h-control: 44px;
  --h-choice: 48px;
  --r-control: 10px;
  --shadow: 0 1px 2px rgba(58, 38, 18, .06), 0 8px 24px rgba(58, 38, 18, .06);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
svg.board, select { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

/* ── 상단 바 ── */
.appbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.appbar-inner {
  max-width: 1040px; margin: 0 auto; padding: 14px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 34px; height: 34px; flex: none; object-fit: cover; border-radius: 8px; }
.brand-title { font-weight: 800; font-size: 17px; letter-spacing: -0.02em; }
.brand-sub { font-size: 13px; color: var(--muted); }
.meter { width: 180px; flex: none; }
.meter-label { font-size: 12.5px; color: var(--ink-2); text-align: right; margin-bottom: 6px; font-weight: 600; }
.meter-bar { height: 6px; border-radius: 99px; background: #ece2d3; overflow: hidden; }
.meter-bar span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .4s ease; }

.container { max-width: 1040px; margin: 0 auto; padding: 18px 20px 28px; }

/* ── 홈 ── 하바사 홈과 같은 틀 (머리 띠 · 주 버튼 · 2×2 타일 · 손글씨 문구) */
:root {
  --font-display: "Gowun Batang", "Nanum Myeongjo", "AppleMyungjo", serif;
  --font-hand: "Nanum Pen Script", cursive;
  --kaya: #e2b86c;          /* 비자나무 바둑판 */
  --kaya-soft: #f6ead2;
  --kaya-line: #e3cfa6;
  --slate: #17191c;         /* 흑돌 */
  --shell: #fbfaf7;         /* 백돌 */
}
.brand[role=button] { cursor: pointer; }
.home { max-width: 440px; margin: 0 auto; }
.home.show { display: block; }

.hh { margin: -18px -20px 0; padding: 24px 22px 18px; background: linear-gradient(160deg, var(--kaya-soft) 0%, #f1e2c4 100%);
  border-bottom: 1px solid var(--kaya-line); }
.hh-top { display: flex; align-items: center; gap: 18px; }
.hh-illust { width: 124px; flex: none; padding: 4px 4px 0; border: 0; border-radius: 10px; background: var(--kaya); cursor: pointer;
  box-shadow: 0 3px 10px rgba(61, 42, 18, .18); display: flex; flex-direction: column; align-items: stretch; }
.hh-illust:active { transform: scale(.97); }
.hh-illust-cap { padding: 4px 0 5px; font-size: 11px; font-weight: 700; color: #5c4210; text-align: center; }
.hh-greet { display: flex; flex-direction: column; line-height: 1.5; }
.hh-hello { font-size: 13.5px; font-weight: 500; color: #7a5b28; }
.hh-name { font-family: var(--font-display); font-size: 21px; font-weight: 700; letter-spacing: -0.01em; }
.hh-saying { margin-top: 14px; padding: 2px 0 0 12px; border-left: 3px solid #d2a95a; min-height: 3.6em; }
.hh-saying-text { display: block; font-size: 15px; line-height: 1.6; color: #3b3326; word-break: keep-all; }
.hh-saying-ref { display: block; margin-top: 4px; font-size: 12.5px; font-weight: 600; color: #9a6c1f; }

.home-body { display: flex; flex-direction: column; align-items: stretch; gap: 12px; padding: 22px 0 8px; }
.primary-tile { display: flex; align-items: center; gap: 18px; width: 100%; padding: 22px 20px; border: 0; border-radius: 20px;
  background: linear-gradient(135deg, #9c6b3e 0%, var(--accent) 100%); color: #fff; text-align: left; cursor: pointer;
  box-shadow: 0 4px 20px rgba(84, 52, 27, .25); transition: transform .13s, box-shadow .15s; }
.primary-tile:active { transform: scale(.98); }
.pt-icon svg { width: 42px; height: 42px; display: block; }
.pt-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pt-label { font-size: 17px; font-weight: 800; }
.pt-sub { margin-top: 2px; font-size: 13px; color: rgba(255, 255, 255, .78); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pt-chev svg { width: 22px; height: 22px; display: block; opacity: .7; stroke-width: 2.5; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.tile { position: relative; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 22px 8px 18px;
  border: 0; border-radius: 16px; background: var(--surface); cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 14px rgba(0, 0, 0, .07); transition: transform .13s, box-shadow .15s; }
.tile:active { transform: scale(.97); }
.tile-icon { color: var(--accent); display: flex; }
.tile-icon svg { width: 32px; height: 32px; }
.tile-label { font-size: 14px; font-weight: 700; }
.tile-sub { margin-top: -6px; font-size: 12px; color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.tile-sub.done { color: var(--ok); }
.tile-badge { position: absolute; top: 12px; right: 12px; width: 10px; height: 10px; border-radius: 50%; background: #e5484d; border: 2px solid var(--surface); }
@media (hover: hover) {
  .primary-tile:hover { transform: translateY(-2px); box-shadow: 0 8px 28px rgba(23, 25, 28, .32); }
  .tile:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0, 0, 0, .1); }
}
.primary-tile:focus-visible, .tile:focus-visible, .util-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.tagline { margin-top: 10px; text-align: center; font-family: var(--font-hand); font-size: 30px; color: #7a5b28; letter-spacing: .04em; }
.util-row { display: flex; justify-content: center; }
.util-btn { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); font-size: 13px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.util-btn svg { width: 15px; height: 15px; }
.font-sheet { padding: 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); }
.font-sheet-title { font-size: 13px; font-weight: 700; color: var(--ink-2); margin-bottom: 10px; text-align: center; }
.font-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.font-opt { display: flex; flex-direction: column; align-items: center; gap: 2px; height: 64px; justify-content: center;
  border-radius: 12px; border: 1.5px solid var(--border); background: var(--surface); font-size: 12.5px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.font-opt span { font-weight: 800; color: var(--ink); }
.font-opt.on { border-color: var(--slate); background: var(--surface-2); }

/* 문제집 목록 */
.lib { display: grid; gap: 12px; }
.lib-item { display: flex; align-items: center; gap: 16px; width: 100%; padding: 14px; border: 0; border-radius: 16px; text-align: left;
  background: var(--surface); box-shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 14px rgba(0, 0, 0, .07); cursor: pointer; }
.lib-item:active { transform: scale(.99); }
.lib-cover { width: 92px; flex: none; padding: 3px; border-radius: 8px; background: var(--kaya); }
.lib-body { flex: 1; min-width: 0; display: grid; gap: 4px; }
.lib-name { font-family: var(--font-display); font-weight: 700; font-size: 18px; }
.lib-meta { font-size: 13px; color: var(--muted); }
.lib-body .bar { margin-top: 4px; }

/* 하위 화면 공통: ‹ 홈 */
.subpage { max-width: 720px; margin: 0 auto; }
.sub-topbar { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; }
.sub-topbar .back { margin: 0; }
.sub-title { font-size: 15px; font-weight: 800; color: var(--ink-2); }
.sub-topbar::after { content: ""; flex: 1; }

/* 놓아보기 화면 */
.free-wrap { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.free-panel { display: grid; gap: 10px; padding: 16px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.free-size { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.free-size .seg.on { background: var(--slate); color: #fff; border-color: var(--slate); }
.free-turn { margin: 0; font-weight: 700; }
@media (max-width: 820px) { .free-wrap { grid-template-columns: minmax(0, 1fr); } }

/* 내 기록 화면 */
.rec-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.rec-stat { padding: 14px 8px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); text-align: center; }
.rec-stat b { display: block; font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.rec-stat span { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.rec-clear { width: 100%; margin-top: 16px; }

.thumb { display: block; width: 100%; height: auto; border-radius: 6px; pointer-events: none; }

@media (max-width: 560px) {
  .hh { margin: -12px -12px 0; padding: 20px 16px 16px; }
  .hh-illust { width: 112px; }
}

/* ── 문제집 안 (단원 목록) ── */
.book { max-width: 720px; margin: 0 auto; }
.back { height: 36px; padding: 0 12px 0 6px; margin: 0 0 10px; border: 0; background: none; cursor: pointer;
  font-size: 14.5px; font-weight: 700; color: var(--accent); }
.book-head { padding: 18px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); margin-bottom: 12px; }
.book-title { margin: 0 0 2px; font-size: 21px; font-weight: 800; }
.book-sub { margin: 0 0 12px; font-size: 13.5px; color: var(--muted); }
.units { display: grid; gap: 8px; }
.unit { display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 16px; border-radius: 14px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; text-align: left; }
.unit .uno { width: 30px; height: 30px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--border); font-size: 13px; font-weight: 800; color: var(--ink-2); }
.unit.done .uno { background: var(--ok); border-color: var(--ok); color: #fff; }
.unit .ubody { flex: 1; min-width: 0; }
.unit .uname { font-weight: 800; font-size: 15px; }
.unit .umeta { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.unit .bar { height: 5px; }
#study .setbar .back { margin: 0; }

/* ── 문제집·단원 ── */
.setbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs { display: inline-flex; padding: 4px; gap: 4px; border-radius: 12px; background: #e9e6df; }
.tab {
  height: 36px; padding: 0 16px; border: 0; border-radius: 9px; cursor: pointer;
  background: transparent; font-size: 14px; font-weight: 700; color: var(--ink-2);
}
.tab.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(58, 38, 18, .12); }
.unit-select {
  height: var(--h-control); min-width: 220px; padding: 0 12px; border-radius: var(--r-control);
  border: 1px solid var(--border); background: var(--surface); font: inherit; font-size: 14px; font-weight: 600; color: var(--ink);
}

/* ── 문제 번호: 한 줄 + 펼치는 번호판 ── */
.pnav { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.pn-arrow { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: var(--r-control);
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; color: var(--ink); }
.pn-arrow svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.pn-arrow:disabled { opacity: .35; cursor: default; }
.pn-cur { flex: 1; min-width: 0; height: 44px; display: flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: var(--r-control); border: 1px solid var(--border); background: var(--surface); cursor: pointer;
  font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--ink); }
.pn-cur small { font-weight: 600; color: var(--muted); }
.pn-caret { width: 16px; height: 16px; fill: none; stroke: var(--muted); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; transition: transform .15s; }
.pn-cur[aria-expanded="true"] .pn-caret { transform: rotate(180deg); }
.pn-st { width: 18px; height: 18px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 10.5px; color: #fff; }
.pn-st.todo { border: 1.5px solid #cdbfab; }
.pn-st.solved { background: var(--ok); }
.pn-st.perfect { background: var(--gold); }
.pgrid { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 6px; margin: -4px 0 14px; padding: 12px;
  border-radius: 14px; background: var(--surface); border: 1px solid var(--border); }
.pg { height: 34px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer;
  font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink-2); padding: 0; }
.pg.solved { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.pg.perfect { background: var(--gold-soft); border-color: transparent; color: var(--gold); }
.pg.now { background: var(--ink); border-color: var(--ink); color: #fff; }
.pg.reviewed { box-shadow: inset 0 -3px 0 var(--gold); }
@media (max-width: 560px) { .pgrid { gap: 5px; padding: 10px; } .pg { height: 32px; font-size: 12.5px; } }

/* ── (예전) 문제 번호 ── */
.pager { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 16px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: 13.5px; font-weight: 600; color: var(--ink-2); cursor: pointer;
  transition: border-color .15s, background .15s;
}
@media (hover: hover) { .pill:hover { border-color: #cdbfab; } }
.pill .st { width: 16px; height: 16px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 10px; color: #fff; }
.pill.perfect .st { background: var(--gold); }
.pill.solved .st { background: var(--ok); }
.pill.todo .st { border: 1.5px solid #cdbfab; }
.pill.now { background: var(--ink); border-color: var(--ink); color: #fff; }
.pill.now.todo .st { border-color: rgba(255, 255, 255, .5); }

/* ── 화면 ── */
.screen { display: none; }
.screen.show { display: block; }
.layout.show { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 820px) { .layout.show { grid-template-columns: minmax(0, 1fr); gap: 16px; } }

/* ── 바둑판 ── */
.board-frame {
  background: var(--surface); border-radius: var(--radius); padding: 10px; box-shadow: var(--shadow);
}
svg.board { display: block; width: 100%; height: auto; border-radius: 10px; user-select: none; }
.gb-grid line { stroke: #3d2a12; stroke-opacity: .85; }
.gb-star { fill: #3d2a12; }
.gb-num { font-size: 17px; font-weight: 700; text-anchor: middle; font-family: "Pretendard", system-ui, sans-serif; }
.gb-num.on-black { fill: #fff; }
.gb-num.on-white { fill: #1d2433; }
.gb-mark { fill: none; stroke: var(--mark); stroke-width: 3; stroke-linejoin: round; }
.gb-letter { cursor: pointer; }
.gb-letter circle { fill: rgba(255, 255, 255, .92); stroke: var(--accent); stroke-width: 2; transition: fill .15s; }
.gb-letter text { font-size: 16px; font-weight: 800; fill: var(--accent); text-anchor: middle; font-family: "Pretendard", system-ui, sans-serif; }
@media (hover: hover) { .gb-letter:hover circle { fill: var(--accent); } }
@media (hover: hover) { .gb-letter:hover text { fill: #fff; } }
.gb-letter.off { cursor: default; opacity: .3; }
.gb-letter.off:hover circle { fill: rgba(255, 255, 255, .92); }
.gb-letter.off:hover text { fill: var(--accent); }
.gb-ghost { opacity: .5; pointer-events: none; }
.gb-cross { stroke: var(--ng); stroke-width: 2.6; stroke-linecap: round; opacity: .8; pointer-events: none; }
.gb-hit rect { cursor: pointer; }
.gb-pop { animation: gb-pop .32s cubic-bezier(.2, .9, .3, 1.2); transform-box: fill-box; transform-origin: center; }
@keyframes gb-pop { from { opacity: 0; transform: scale(.5); } to { opacity: 1; transform: scale(1); } }

.board-caption { margin-top: 10px; font-size: 13px; color: var(--muted); text-align: center; }
.board-caption #qnum { color: var(--ink-2); font-weight: 700; }
.board-caption .dot { margin: 0 6px; }

/* ── 오른쪽 패널 ── */
.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px;
  display: flex; flex-direction: column; }
.panel > .eyebrow, .panel > .prompt { order: 0; }
#turn-panel, #waiting, #end-panel { order: 1; }
.panel > .timeline { order: 2; margin: 20px 0 0; padding-top: 16px; border-top: 1px solid var(--border); }
@media (max-width: 820px) { .panel { padding: 20px; } }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .08em; color: var(--accent); text-transform: uppercase; margin-bottom: 6px; }
.prompt { font-size: 21px; line-height: 1.4; font-weight: 800; letter-spacing: -0.025em; margin: 0 0 6px; }
.sub { margin: 0 0 18px; color: var(--muted); font-size: 14px; }

.choices { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.choices button {
  height: var(--h-choice); border-radius: var(--r-control); cursor: pointer;
  background: var(--surface); border: 1.5px solid var(--border);
  font-size: 18px; font-weight: 800; color: var(--ink);
  transition: border-color .15s, background .15s, transform .08s;
}
@media (hover: hover) { .choices button:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); } }
.choices button:active:not(:disabled) { transform: scale(.97); background: var(--accent-soft); }
.btn:active { transform: scale(.98); }
.choices button.tried { background: var(--surface-2); color: #c3c0b8; border-style: dashed; cursor: default; text-decoration: line-through; }
.notice { margin: 0 0 12px; padding: 10px 12px; border-radius: 10px; font-size: 14px; line-height: 1.6;
  background: var(--ng-soft); color: var(--ng); }
.notice.good { background: var(--ok-soft); color: var(--ok); }
.notice:empty { display: none; }
.confirm { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; padding: 10px 12px;
  border-radius: 12px; background: var(--accent-soft); }
.confirm span { flex: 1; font-weight: 700; font-size: 14.5px; }
.confirm .btn { flex: none; height: 40px; padding: 0 16px; }
.choices { margin-top: 12px; }

.hint-toggle {
  margin-top: 0; padding: 0; border: 0; background: none; cursor: pointer;
  color: var(--accent); font-size: 14px; font-weight: 600;
}
@media (hover: hover) { .hint-toggle:hover { text-decoration: underline; } }
.turn-tools { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.answer-toggle { color: var(--ink-2); }
.verdict.shown { background: var(--accent-soft); }
.verdict.shown .verdict-icon { background: var(--accent); }
.verdict.shown .verdict-title { color: var(--accent); }
.hint-box {
  margin-top: 10px; padding: 14px 16px; border-radius: 12px;
  background: var(--gold-soft); border: 1px solid #f0dfbd; color: #5c4210; line-height: 1.7;
}

/* 한 수씩 주고받기 */

.turn-label { margin: 0 0 12px; color: var(--ink-2); font-size: 14px; font-weight: 600; }
.waiting { margin: 0; padding: 14px 0; color: var(--muted); font-size: 14px; }

/* 놓아보기 */
#sandbox { order: 1; }
.sandbox { padding: 14px; border-radius: 12px; border: 1.5px solid var(--accent); background: var(--accent-soft); }
.sandbox-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.sandbox-head span { font-size: 13.5px; font-weight: 700; color: var(--ink-2); }
.sandbox-help { margin: 0 0 10px; font-size: 13.5px; color: var(--ink-2); }
.sandbox-tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.sandbox-tools .seg { font-size: 13px; padding: 0 4px; }
.sandbox-end { width: 100%; margin-top: 10px; }

/* 선생님 검토 모드 */
.review-badge { margin-left: 6px; padding: 2px 8px; border-radius: 99px; background: var(--gold); color: #fff; font-size: 11.5px; font-weight: 700; vertical-align: 2px; }
.review { margin-top: 16px; padding: 14px; border-radius: 12px; border: 1.5px dashed var(--gold); background: var(--gold-soft); }
.review-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.review-head span { font-size: 12.5px; color: var(--ink-2); }
.review-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 8px; }
.review-tools .seg.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.review-help { margin: 0 0 8px; font-size: 13px; color: #5c4210; }
.review-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.rv-chip { height: 34px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); font-size: 13.5px; font-weight: 700; cursor: pointer; }
.rv-chip.ans { border-color: var(--ok); color: var(--ok); }
.rv-chip.removed { text-decoration: line-through; color: var(--ng); border-color: var(--ng); background: var(--ng-soft); }
.rv-chip.added { border-color: var(--gold); color: var(--gold); }
.review-memo { width: 100%; padding: 10px; border-radius: 10px; border: 1px solid var(--border); font: inherit; font-size: 14px; resize: vertical; background: var(--surface); }
.review-actions { display: flex; gap: 8px; margin-top: 8px; }
.review-actions .btn { flex: 1 1 0; }
.gb-plus { stroke: var(--gold); stroke-width: 3.2; stroke-linecap: round; pointer-events: none; }
.pill.reviewed::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--gold); margin-left: 2px; }

/* 판정 */
.verdict { display: flex; gap: 12px; align-items: center; padding: 16px; border-radius: 12px; margin-bottom: 24px; }
.verdict.ok { background: var(--ok-soft); }
.verdict.ng { background: var(--ng-soft); }
.verdict-icon { width: 34px; height: 34px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; font-size: 17px; }
.verdict.ok .verdict-icon { background: var(--ok); }
.verdict.ng .verdict-icon { background: var(--ng); }
.verdict-title { font-weight: 800; font-size: 16.5px; }
.verdict.ok .verdict-title { color: var(--ok); }
.verdict.ng .verdict-title { color: var(--ng); }
.verdict-sub { font-size: 13.5px; color: var(--ink-2); }

/* 수순 타임라인 */
.section-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; font-size: 13px; font-weight: 700; color: var(--ink-2); }
.counter { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 600; }
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline li {
  position: relative; display: flex; gap: 12px; padding: 8px 10px; border-radius: 10px;
  transition: opacity .25s, background .25s;
}
.timeline li::before {
  content: ""; position: absolute; left: 22px; top: 34px; bottom: -8px; width: 1.5px; background: var(--border);
}
.timeline li:last-child::before { display: none; }
.timeline li.todo { opacity: .28; }
.timeline li.done { opacity: .65; }
.timeline li.now { background: var(--accent-soft); }
.stone-badge {
  position: relative; z-index: 1; flex: none; width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 12.5px; font-weight: 800;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
}
.stone-badge.black { background: radial-gradient(circle at 35% 30%, #666, #111 60%); color: #fff; }
.stone-badge.white { background: radial-gradient(circle at 35% 30%, #fff, #e3e0d8); color: var(--ink); border: 1px solid #cdbfab; }
.step-body { line-height: 1.65; padding-top: 1px; }
.step-who { font-weight: 800; margin-right: 6px; }
.tri { color: var(--mark); font-weight: 800; }

/* 수순 넘기기: 같은 크기 버튼 3개 */
.player { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.seg {
  height: var(--h-control); border-radius: var(--r-control); cursor: pointer;
  border: 1px solid var(--border); background: var(--surface);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 14px; font-weight: 600; color: var(--ink-2); transition: background .15s, border-color .15s;
}
.seg:hover:not(:disabled) { background: var(--surface-2); border-color: #cdbfab; }
.seg:disabled { opacity: .4; cursor: default; }
.seg svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

/* 정리 */
.lesson { margin-top: 16px; padding: 16px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.lesson-label { font-size: 12px; font-weight: 700; letter-spacing: .06em; color: var(--accent); margin-bottom: 4px; }
.lesson-title { font-weight: 800; font-size: 16px; margin-bottom: 4px; }
.lesson-title:empty { display: none; }
.lesson-text { margin: 0; color: var(--ink-2); line-height: 1.7; }

/* 버튼 */
/* 나란히 놓인 버튼은 같은 너비 */
.actions { display: flex; gap: 8px; margin-top: 24px; }
.actions .btn { flex: 1 1 0; }
.actions.center { max-width: 400px; margin-left: auto; margin-right: auto; }
.btn {
  height: var(--h-control); padding: 0 16px; border-radius: var(--r-control); cursor: pointer;
  font-size: 15px; font-weight: 700; border: 1.5px solid transparent; transition: background .15s, border-color .15s;
}
.btn.primary { background: var(--accent); color: #fff; }
@media (hover: hover) { .btn.primary:hover { background: var(--accent-hover); } }
.btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--border); }
@media (hover: hover) { .btn.secondary:hover { border-color: #cdbfab; } }

/* 결과 화면 */
.summary { max-width: 520px; margin: 24px auto; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 40px 28px; text-align: center; }
.summary-big { font-size: 52px; font-weight: 800; letter-spacing: -0.03em; margin: 4px 0 8px; font-variant-numeric: tabular-nums; }
.summary-detail { margin: 0 0 6px; color: var(--ink-2); }
.summary-msg { margin: 0; color: var(--muted); }

/* 아래 */
.foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 22px; }
.foot-note { font-size: 12px; color: var(--muted); text-align: center; }
.link { background: none; border: 0; padding: 6px 0; cursor: pointer; font-size: 14px; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.link:hover:not(:disabled) { color: var(--accent); }
.link:disabled { opacity: .35; cursor: default; }
@media (max-width: 820px) {
  .board-caption { margin-top: 6px; }
}
@media (max-width: 560px) {
  :root { --h-choice: 52px; --radius: 14px; }
  body { font-size: 15px; padding-bottom: env(safe-area-inset-bottom); }
  .appbar-inner { padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); }
  .container { padding: 12px 12px 24px; }
  .brand-mark { width: 28px; height: 28px; }
  .brand-title { font-size: 16px; }
  .brand-sub { display: none; }
  .meter { width: 104px; }
  .meter-label { font-size: 11.5px; margin-bottom: 4px; }

  /* 문제집 탭·단원: 화면 너비에 꽉 차게 */
  .setbar { gap: 8px; margin-bottom: 10px; }
  .tabs { display: flex; width: 100%; }
  .tab { flex: 1 1 0; padding: 0 8px; font-size: 13.5px; }
  .unit-select { width: 100%; min-width: 0; }

  /* 문제 번호: 한 줄로, 옆으로 밀어서 보기 */
  .pager { flex-wrap: nowrap; overflow-x: auto; margin: 0 -12px 12px; padding: 2px 12px 6px;
           scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .pager::-webkit-scrollbar { display: none; }
  .pill { flex: none; height: 34px; padding: 0 12px; }

  .layout.show { gap: 12px; }
  .board-frame { padding: 6px; }
  .board-caption { font-size: 12px; }
  .panel { padding: 16px; }
  .eyebrow { display: none; }
  .prompt { font-size: 17.5px; margin-bottom: 10px; }
  .turn-label { margin-bottom: 10px; font-size: 13.5px; }
  .verdict { margin-bottom: 12px; padding: 12px 14px; }
  .lesson { margin-top: 12px; padding: 14px; }
  .actions { margin-top: 16px; flex-wrap: wrap; }
  .actions .btn { flex: 1 1 40%; height: 48px; }
  .timeline li { padding: 6px 4px; }
  .timeline li::before { left: 16px; }
  .step-body { font-size: 14.5px; }

  /* 아래 이동 버튼 */
  .foot { margin-top: 14px; }
  .foot-note { display: none; }
  .link { height: 44px; padding: 0 14px; border-radius: var(--r-control); background: var(--surface); border: 1px solid var(--border); }
  .summary { margin: 8px auto; padding: 28px 18px; }
}

/* 홈·문제집 화면에서는 위쪽 진행 막대 대신 원형 그래프를 씀 */
body[data-screen="home"] .meter, body[data-screen="book"] .meter, body[data-screen="free"] .meter, body[data-screen="records"] .meter { visibility: hidden; }
.book-title { font-family: var(--font-display); font-weight: 700; font-size: 24px; }
.unit .uname { font-size: 15.5px; }

/* 급수 · 연속 학습일 · 오늘의 목표 */
.hh-top { position: relative; }
.hh-greet { flex: 1; min-width: 0; }
.hh-level { display: flex; align-items: center; gap: 8px; margin-top: 4px; font-size: 13px; color: #7a5b28; font-weight: 600; }
.hh-level b { padding: 1px 9px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 12.5px; font-weight: 800; }
.goal { width: 58px; height: 58px; flex: none; position: relative; }
.goal svg { width: 100%; height: 100%; display: block; transform: rotate(-90deg); }
.goal .track { fill: none; stroke: rgba(122, 91, 40, .18); stroke-width: 6; }
.goal .val { fill: none; stroke: var(--accent); stroke-width: 6; stroke-linecap: round; }
.goal .goal-text { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; line-height: 1.05;
  font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--ink); }
.goal .goal-text small { display: block; font-size: 9.5px; font-weight: 700; color: #7a5b28; }
.rec-level { display: grid; gap: 8px; padding: 18px; margin-bottom: 12px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.rec-level-top { display: flex; align-items: baseline; justify-content: space-between; }
.rec-level-top b { font-family: var(--font-display); font-size: 30px; }
.rec-level-top span { font-size: 13px; color: var(--muted); }
.rec-level .bar { height: 8px; }
.rec-level p { margin: 0; font-size: 13px; color: var(--ink-2); }
@media (max-width: 560px) { .goal { width: 52px; height: 52px; } }

/* 진행 막대 (단원·급수) */
.bar { display: block; height: 6px; border-radius: 99px; background: #ece2d3; overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; }

/* 문제집을 받는 동안 */
.loader { position: fixed; left: 50%; top: calc(72px + env(safe-area-inset-top, 0px)); transform: translateX(-50%); z-index: 20;
  padding: 10px 16px; border-radius: 999px; background: var(--ink); color: #fff; font-size: 14px; font-weight: 700;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .2); }

/* 놓아보기: 판이 화면 크기에 맞춰 저절로 커지고 작아짐 */
#free.subpage { max-width: 1240px; }
#free .free-wrap { grid-template-columns: auto minmax(220px, 300px); justify-content: center; align-items: start; }
#free .board-frame { width: min(calc(100vw - 380px), calc(100vh - 170px), 900px); min-width: 280px; }
#free .free-panel { position: sticky; top: 16px; user-select: none; -webkit-user-select: none; }
#free .sandbox-tools { grid-template-columns: 1fr; }
@supports (height: 100dvh) {
  #free .board-frame { width: min(calc(100vw - 380px), calc(100dvh - 170px), 900px); }
}
@media (max-width: 820px) {
  #free .free-wrap { grid-template-columns: minmax(0, 1fr); justify-items: center; }
  #free .board-frame { width: min(100%, calc(100vh - 300px)); min-width: 0; }
  #free .free-panel { position: static; width: 100%; }
  #free .sandbox-tools { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 820px) and (min-aspect-ratio: 1/1) {
  #free .board-frame { width: min(100%, calc(100vh - 200px)); }
}
@media (max-width: 560px) { #free .board-frame { width: 100%; } }

/* 결과 화면 버튼: 주 버튼은 넓게 한 줄, 나머지는 아래 한 줄에 같은 크기 */
#end-panel .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
#end-panel .btn { white-space: nowrap; }
#end-panel .btn.wide { order: -1; flex: 1 0 100%; height: 50px; font-size: 16px; }
#end-panel .btn.sub { flex: 1 1 0; min-width: 0; height: 46px; padding: 0 8px; display: inline-flex; align-items: center;
  justify-content: center; gap: 6px; font-size: 14px; font-weight: 700; color: var(--ink-2); }
#end-panel .btn.sub svg { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; }
#end-panel .btn.sub svg polygon { fill: currentColor; stroke: none; }
@media (hover: hover) { #end-panel .btn.sub:hover { color: var(--accent); border-color: var(--accent); } }

/* 점수 · 아이디 · 순위표 */
.hh-score { font-weight: 800; color: var(--ink); font-variant-numeric: tabular-nums; }
.login-card { padding: 16px; border-radius: 16px; background: var(--surface); box-shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 14px rgba(0, 0, 0, .07); }
.login-title { font-weight: 800; font-size: 15px; }
.login-sub { margin: 4px 0 10px; font-size: 13px; color: var(--muted); }
.login-row { display: flex; gap: 8px; }
.login-input { flex: 1; min-width: 0; height: 44px; padding: 0 12px; border-radius: var(--r-control); border: 1.5px solid var(--border);
  font: inherit; font-size: 15px; letter-spacing: .04em; background: var(--surface); color: var(--ink); }
.login-input:focus { outline: none; border-color: var(--accent); }
.login-row .btn { flex: none; }
.login-err { margin: 8px 0 0; font-size: 13px; color: var(--ng); }
.login-err:empty { display: none; }
.rec-level .rule { font-size: 12px; color: var(--muted); line-height: 1.6; }
.rank { margin-bottom: 12px; padding: 16px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); display: grid; gap: 6px; }
.rank:empty { display: none; }
.rank-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.rank-head b { font-size: 15px; }
.rank-head span { font-size: 12px; color: var(--ok); font-weight: 700; }
.rank-head span::before { content: "●"; margin-right: 4px; font-size: 9px; vertical-align: 1px; }
.rank-row { display: flex; align-items: center; gap: 12px; padding: 10px 10px; border-radius: 12px; }
.rank-row.me { background: var(--accent-soft); }
.rank-no { width: 28px; height: 28px; flex: none; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 13px;
  background: var(--surface-2); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.rank-row.top1 .rank-no { background: #e3b341; color: #fff; }
.rank-row.top2 .rank-no { background: #b4a594; color: #fff; }
.rank-row.top3 .rank-no { background: #c08457; color: #fff; }
.rank-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.rank-name { font-weight: 800; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-sub { font-size: 12px; color: var(--muted); }
.rank-score { font-variant-numeric: tabular-nums; font-size: 15px; }
.rank-empty { margin: 0; font-size: 13.5px; color: var(--muted); }
.rec-logout { display: block; margin: 10px auto 0; color: var(--muted); font-size: 13px; }
.toast { position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 30;
  padding: 10px 18px; border-radius: 999px; background: var(--accent); color: #fff; font-weight: 800; font-size: 15px;
  box-shadow: 0 8px 24px rgba(84, 52, 27, .3); pointer-events: none; }
.toast.show { animation: toast-in .25s ease-out; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }
@media (prefers-reduced-motion: reduce) { .toast.show { animation: none; } }

/* 오늘의 문제: 난이도 목록 */
.lv-date { margin: -4px 0 12px; font-size: 13px; color: var(--muted); }
.lv-list { display: grid; gap: 10px; }
.lv-item { display: flex; align-items: center; gap: 14px; width: 100%; padding: 14px 16px; border: 0; border-radius: 16px; text-align: left; cursor: pointer;
  background: var(--surface); box-shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 14px rgba(0, 0, 0, .07); }
.lv-item:active { transform: scale(.99); }
.lv-badge { width: 52px; height: 52px; flex: none; border-radius: 14px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: 15px; }
.lv-item.done .lv-badge { background: var(--ok-soft); color: var(--ok); }
.lv-body { flex: 1; min-width: 0; display: grid; gap: 8px; }
.lv-name { font-weight: 800; font-size: 15.5px; display: flex; align-items: center; gap: 8px; }
.lv-rec { padding: 1px 8px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 11.5px; font-weight: 800; }
.lv-dots { display: flex; gap: 6px; }
.lv-dots i { width: 14px; height: 14px; border-radius: 50%; background: var(--border); }
.lv-dots i.ok { background: var(--ok); }
.lv-dots i.star { background: var(--gold); }
.lv-count { flex: none; font-size: 13.5px; font-weight: 800; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.lv-item.done .lv-count { color: var(--ok); }
body[data-screen="dailies"] .meter { visibility: hidden; }

/* 휴대폰에서 화면이 흔들리거나 밀리지 않게 */
html, body { overflow-x: clip; max-width: 100%; }
@supports not (overflow-x: clip) { html, body { overflow-x: hidden; } }
body { overscroll-behavior: none; }                    /* 끝에서 튕기거나 당겨서 새로고침되는 움직임 막기 */
.login-input, .unit-select, .review-memo { font-size: 16px; }   /* 아이폰이 입력 칸을 누를 때 확대하지 않게 */
svg.board { touch-action: pan-y; }                    /* 판을 누를 때 좌우로 끌리지 않게 (위아래 스크롤은 됨) */
@media (max-width: 820px) {
  /* "이 자리에 둘까요?"는 화면 아래에 떠 있게 → 내용이 밀리지 않음 */
  .confirm { position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); z-index: 25;
    margin: 0; padding: 12px 14px; background: var(--surface); border: 1.5px solid var(--accent);
    box-shadow: 0 10px 30px rgba(84, 52, 27, .25); }
  .confirm .btn { height: 44px; }
  .toast { bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
}

html, body { touch-action: manipulation; }             /* 두 번 눌러 확대 막기 */
#end-panel .btn.wide { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
#end-panel .btn.wide svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* 홈 타일이 홀수면 마지막 타일은 넓게 */
.tiles .tile:last-child:nth-child(odd) { grid-column: span 2; }

/* 정석 외우기 */
.jstudy { max-width: 1040px; margin: 0 auto; }
.jstudy.show { display: block; }
.j-modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 14px; }
.j-modes .seg { font-size: 13.5px; padding: 0 4px; }
.j-modes .seg.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.j-why { margin: 0 0 12px; font-size: 14px; line-height: 1.7; color: var(--ink-2); }
.j-status { margin-bottom: 10px; padding: 12px 14px; border-radius: 12px; background: var(--accent-soft); font-weight: 700; font-size: 15px; }
.j-status.ok { background: var(--ok-soft); color: var(--ok); }
.j-status.ng { background: var(--ng-soft); color: var(--ng); }
.j-status:empty { display: none; }
.jstudy .timeline { margin-top: 12px; }
.jstudy .timeline li.hide .step-body span:last-child { filter: blur(4px); }
.lv-item .lv-badge.new { background: var(--surface-2); color: var(--ink-2); }
.lv-item .lv-badge.learn { background: var(--gold-soft); color: var(--gold); }
.lv-item .lv-badge.due { background: var(--ng-soft); color: var(--ng); }
.lv-item .lv-badge.done { background: var(--ok-soft); color: var(--ok); }
body[data-screen="jlist"] .meter, body[data-screen="jstudy"] .meter { visibility: hidden; }
