:root {
  --bg: #efe7d2; --panel: #fffaf0; --panel2: #f3ead6; --line: rgba(80, 60, 30, 0.16);
  --text: #2c2418; --dim: #7a6a50; --accent: #2563eb; --accent2: #1d4ed8; --bad: #dc2626; --gold: #d99a06; --ok: #16a34a;
  --r: 16px;
  /* 판 꾸미기 */
  --paper: #fffdf6; --rule: rgba(37, 99, 235, 0.13); --margin: rgba(220, 38, 38, 0.25); --dot: #3f3a33; --guide: rgba(63, 58, 51, 0.16);
  --me: #2563eb; --op: #e11d48; --meFill: rgba(37, 99, 235, 0.2); --opFill: rgba(225, 29, 72, 0.18); --pre: #8a7f6c; --warn: #f59e0b;
  --frame: rgba(60, 40, 10, 0.22);
}
body.t-chalk { --paper: #24463a; --rule: rgba(255, 255, 255, 0.04); --margin: transparent; --dot: #f1f5e9; --guide: rgba(255, 255, 255, 0.16); --me: #93c5fd; --op: #fda4af; --meFill: rgba(147, 197, 253, 0.22); --opFill: rgba(253, 164, 175, 0.2); --pre: #d6d3c4; --frame: #6b4f2a; }
body.t-hanji { --paper: #f3e6c8; --rule: transparent; --margin: transparent; --dot: #2b2118; --guide: rgba(60, 40, 20, 0.18); --me: #1e3a8a; --op: #b91c1c; --meFill: rgba(30, 58, 138, 0.18); --opFill: rgba(185, 28, 28, 0.17); --pre: #6b5a44; --frame: #8b5e34; }
body.t-neon { --paper: #0b1020; --rule: rgba(56, 189, 248, 0.05); --margin: transparent; --dot: #e0f2fe; --guide: rgba(148, 163, 184, 0.2); --me: #22d3ee; --op: #f472b6; --meFill: rgba(34, 211, 238, 0.22); --opFill: rgba(244, 114, 182, 0.2); --pre: #64748b; --frame: #312e81; }
body.t-night { --paper: #111733; --rule: transparent; --margin: transparent; --dot: #fde68a; --guide: rgba(253, 230, 138, 0.18); --me: #a5b4fc; --op: #fdba74; --meFill: rgba(165, 180, 252, 0.22); --opFill: rgba(253, 186, 116, 0.2); --pre: #6b7280; --frame: #1e1b4b; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(circle at 50% 0%, #fbf6e8 0%, var(--bg) 70%);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
  -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: 0.45; }
[hidden] { display: none !important; }

.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); }
.back-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px;
  background: rgba(37, 99, 235, 0.1); border: 1px solid rgba(37, 99, 235, 0.3); color: var(--accent2);
  text-decoration: none; font-size: 0.85rem; font-weight: 700;
}
.back-btn:hover { background: rgba(37, 99, 235, 0.18); }
.total { margin-left: auto; font-weight: 800; }
.tools { display: flex; gap: 6px; }
.mini { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); font-weight: 800; }

/* ── 메뉴 ── */
.screen { flex: 1; overflow-y: auto; padding: 4px 16px 32px; }
.screen > * { max-width: 680px; margin-left: auto; margin-right: auto; }
.logo { text-align: center; margin: 2px auto 12px; }
.logo-art { width: 120px; height: 60px; display: block; margin: 0 auto; }
.la-me { fill: rgba(37, 99, 235, 0.22); }
.la-line { fill: none; stroke: #2563eb; stroke-width: 5; stroke-linecap: round; }
.la-new { fill: none; stroke: #e11d48; stroke-width: 5; stroke-linecap: round; stroke-dasharray: 40; animation: laDraw 2.6s ease-in-out infinite; }
.la-dots circle { fill: #3f3a33; }
@keyframes laDraw { 0%, 20% { stroke-dashoffset: 40; } 55%, 100% { stroke-dashoffset: 0; } }
h1 { margin: 6px 0 2px; font-size: 1.6rem; letter-spacing: -0.02em; }
h1 span { color: var(--accent); }
.tagline { margin: 0; color: var(--dim); font-size: 0.9rem; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 12px; }
.tab { padding: 9px 2px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-weight: 700; font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tab.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.dim { color: var(--dim); }
.small { font-size: 0.82rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin-bottom: 12px; }
.card h3 { margin: 0 0 6px; font-size: 1.05rem; }
.btn { padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2); font-weight: 800; }
.btn.go { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.small { padding: 6px 10px; font-size: 0.85rem; }
.btn.wide { width: 100%; }
.continue {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px 14px; margin-bottom: 12px;
  border-radius: var(--r); border: 1px solid rgba(37, 99, 235, 0.45); background: linear-gradient(135deg, rgba(37, 99, 235, 0.14), rgba(37, 99, 235, 0.03));
}
.continue .ci { width: 34px; height: 34px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: #fff; }
.continue b { display: block; } .continue small { color: var(--dim); }
.reg-h { display: flex; align-items: baseline; gap: 8px; margin: 14px 2px 6px; }
.reg-h b { font-size: 1.02rem; } .reg-h small { color: var(--dim); }
.mission {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 10px 12px; margin-bottom: 8px;
  border-radius: 14px; border: 1px solid var(--line); background: var(--panel);
}
.mission .mi { font-size: 1.8rem; width: 40px; text-align: center; flex: none; }
.mission .mt { flex: 1; min-width: 0; }
.mission .mt b { display: block; } .mission .mt small { color: var(--dim); font-size: 0.75rem; }
.mission .ms { color: var(--gold); font-size: 0.95rem; letter-spacing: 1px; white-space: nowrap; }
.mission.lock { opacity: 0.45; }
.mission.next { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.chip { font-style: normal; font-size: 0.68rem; padding: 1px 6px; border-radius: 999px; background: var(--panel2); color: var(--dim); }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; margin: 8px 0; }
.kpis div { background: var(--panel2); border-radius: 12px; padding: 8px 2px; }
.kpis b { display: block; font-size: 1.2rem; } .kpis small { color: var(--dim); font-size: 0.72rem; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: 8px; }
.cal span, .cal button { aspect-ratio: 1; border-radius: 6px; background: var(--panel2); display: grid; place-items: center; font-size: 0.7rem; color: var(--dim); border: 0; padding: 0; font: inherit; font-size: 0.7rem; min-width: 0; }
.cal .w { background: var(--accent); color: #fff; font-weight: 800; } .cal .t { outline: 2px solid var(--accent); }
.cal button.past { cursor: pointer; box-shadow: inset 0 0 0 1.5px #a78bfa; color: var(--text); }
.cal button.past:hover, .cal button.past:focus-visible { box-shadow: inset 0 0 0 2.5px #8b5cf6; }
.cal .redo, .cal button.past.redo { background: #8b5cf6; color: #fff; font-weight: 800; }
.cal button.past.w { color: #fff; }
.seg { display: flex; gap: 4px; flex-wrap: wrap; margin: 4px 0 10px; }
.seg button { flex: 1; min-width: 56px; padding: 8px 4px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel2); font-weight: 700; font-size: 0.82rem; }
.seg button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.shapes { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 6px; margin: 4px 0 10px; }
.shapes button { padding: 6px 2px 4px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel2); font-size: 0.72rem; font-weight: 700; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.shapes button.on { background: rgba(37, 99, 235, 0.14); border-color: var(--accent); }
.shapes svg { width: 40px; height: 40px; }
.shapes svg rect { fill: var(--accent); opacity: 0.7; }
.lbl { font-size: 0.8rem; color: var(--dim); margin-top: 6px; }
.ach { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.ach div { background: var(--panel2); border-radius: 10px; padding: 8px; font-size: 0.78rem; opacity: 0.45; }
.ach div.got { opacity: 1; border: 1px solid rgba(217, 154, 6, 0.5); }
.ach b { display: block; font-size: 0.85rem; }
.themes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.themes button { padding: 8px 2px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel2); font-size: 0.75rem; font-weight: 700; }
.themes button.on { outline: 2px solid var(--accent); }
.themes i { display: block; height: 22px; border-radius: 6px; margin-bottom: 4px; border: 1px solid var(--line); }
.opt { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 0.9rem; }
.opt button { min-width: 64px; }
.lesson { font-size: 0.85rem; line-height: 1.55; margin: 0; padding-left: 18px; }

/* ── 대국 ── */
#game { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 0 10px calc(8px + env(safe-area-inset-bottom)); }
.g-head { display: flex; align-items: center; gap: 10px; max-width: 760px; width: 100%; margin: 0 auto 4px; }
.g-title { flex: 1; min-width: 0; }
.g-title b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-title small { color: var(--dim); font-size: 0.78rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.score { display: flex; align-items: center; gap: 8px; max-width: 760px; width: 100%; margin: 0 auto 6px; }
.pl { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 14px; background: var(--panel); border: 2px solid transparent; transition: border-color 0.2s, box-shadow 0.2s; }
.pl.op { justify-content: flex-end; }
.pl .av { font-size: 1.5rem; }
.pl .nm { flex: 1; min-width: 0; font-weight: 700; font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl.op .nm { text-align: right; }
.pl b { font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.pl.me b { color: var(--me); } .pl.op b { color: var(--op); }
body.t-chalk .pl.me b, body.t-neon .pl.me b, body.t-night .pl.me b { color: #2563eb; }
body.t-chalk .pl.op b, body.t-neon .pl.op b, body.t-night .pl.op b { color: #e11d48; }
.pl.turn.me { border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15); }
.pl.turn.op { border-color: #e11d48; box-shadow: 0 0 0 3px rgba(225, 29, 72, 0.15); }
.pl.bump b { animation: bump 0.35s; }
@keyframes bump { 50% { transform: scale(1.35); } }
.vs { text-align: center; font-weight: 800; color: var(--dim); min-width: 44px; }
.vs small { display: block; font-size: 0.7rem; font-weight: 700; }
.status { text-align: center; font-weight: 800; padding: 6px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); max-width: 760px; width: 100%; margin: 0 auto 6px; font-size: 0.9rem; min-height: 2.1em; }
.status.op { background: rgba(225, 29, 72, 0.08); border-color: rgba(225, 29, 72, 0.3); }
.status.me { background: rgba(37, 99, 235, 0.08); border-color: rgba(37, 99, 235, 0.3); }
.board-wrap { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
#board { width: 100%; height: 100%; max-width: 760px; touch-action: none; display: block; }
/* SVG 판 */
.paper { fill: var(--paper); stroke: var(--frame); stroke-width: 2; }
.rule { stroke: var(--rule); stroke-width: 1; }
.rule.m { stroke: var(--margin); }
.gd { stroke: var(--guide); stroke-width: 2; stroke-dasharray: 2 7; stroke-linecap: round; }
.ln { stroke-width: 7; stroke-linecap: round; }
.ln.p0 { stroke: var(--me); } .ln.p1 { stroke: var(--op); } .ln.p2 { stroke: var(--pre); stroke-width: 6; }
.ln.new { stroke-dasharray: 100; animation: lnDraw 0.28s ease-out; }
.ln.last { filter: drop-shadow(0 0 3px var(--warn)); }
@keyframes lnDraw { from { stroke-dashoffset: 100; } to { stroke-dashoffset: 0; } }
.bx.o0 { fill: var(--meFill); } .bx.o1 { fill: var(--opFill); }
.bx.pop { transform-box: fill-box; transform-origin: center; animation: bxPop 0.35s ease-out; }
@keyframes bxPop { 0% { transform: scale(0.2); opacity: 0; } 70% { transform: scale(1.08); } 100% { transform: scale(1); opacity: 1; } }
.bt { font-size: 28px; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.bt.pop { animation: bxPop 0.35s ease-out; transform-box: fill-box; transform-origin: center; }
.dt { fill: var(--dot); }
.pv { stroke-width: 9; stroke-linecap: round; stroke: var(--me); opacity: 0.45; }
.pv.p1 { stroke: var(--op); }
.pv.warn { stroke: var(--warn); opacity: 0.75; }
.pv.sel { opacity: 0.9; stroke-dasharray: 10 8; animation: march 0.6s linear infinite; }
@keyframes march { to { stroke-dashoffset: -18; } }
.hn { stroke: #facc15; stroke-width: 13; stroke-linecap: round; opacity: 0.8; animation: blink 0.8s ease-in-out infinite; }
@keyframes blink { 50% { opacity: 0.25; } }
.tri { fill: var(--warn); opacity: 0.16; }
#board.busy { cursor: wait; }

.toast { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); background: #1f2937; color: #fff; padding: 8px 14px; border-radius: 10px; font-weight: 800; font-size: 0.88rem; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25); z-index: 3; max-width: calc(100% - 24px); text-align: center; pointer-events: none; }
.toast.bad { background: #fee2e2; color: #7f1d1d; }
.toast.good { background: #fef9c3; color: #713f12; }
.ctrl { display: flex; gap: 8px; justify-content: center; margin-top: 6px; }
.cbtn { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 70px; padding: 8px 10px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel); font-size: 1.1rem; }
.cbtn span { font-size: 0.72rem; font-weight: 700; color: var(--dim); }
#okBtn:not(:disabled) { background: var(--accent); color: #fff; border-color: var(--accent); }
#okBtn:not(:disabled) span { color: #fff; }

/* ── 모달 ── */
.modal { position: fixed; inset: 0; background: rgba(30, 22, 10, 0.55); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal-box { width: min(440px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 18px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3); }
.modal-box h2 { margin: 0 0 8px; font-size: 1.25rem; }
.modal-box p { line-height: 1.5; }
.modal-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.modal-btns .btn { flex: 1; white-space: nowrap; padding: 10px 8px; }
.big-stars { color: var(--gold); text-align: center; font-size: 2.2rem; letter-spacing: 6px; margin: 4px 0; }
.big-stars .off { opacity: 0.2; }
.res-line { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 0.9rem; }
.quote { background: var(--panel2); border-radius: 12px; padding: 10px 12px; font-size: 0.9rem; }
.opp { text-align: center; font-size: 3rem; }
.final { display: flex; justify-content: center; align-items: center; gap: 14px; font-size: 2rem; font-weight: 900; margin: 6px 0; }
.final .a { color: #2563eb; } .final .b { color: #e11d48; } .final small { font-size: 0.9rem; color: var(--dim); }
.err { font-family: ui-monospace, monospace; font-size: 0.75rem; background: #1f1a12; padding: 8px; border-radius: 8px; white-space: pre-wrap; color: #fecaca; max-height: 140px; overflow: auto; user-select: text; -webkit-user-select: text; }
.ach-pop { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #fef9c3; color: #713f12; padding: 10px 16px; border-radius: 14px; font-weight: 800; box-shadow: 0 8px 22px rgba(0, 0, 0, 0.3); z-index: 20; animation: pop 0.3s ease-out; max-width: calc(100% - 32px); }
@keyframes pop { from { transform: translate(-50%, 20px); opacity: 0; } }
.help-fig { display: block; width: 100%; max-width: 300px; margin: 6px auto; }
.noscript { padding: 20px; text-align: center; }
@media (max-width: 420px) {
  .back-txt { display: none; }
  .cbtn { min-width: 60px; padding: 7px 6px; }
  .pl { padding: 5px 7px; gap: 5px; }
  .pl .av { font-size: 1.25rem; }
  .pl b { font-size: 1.35rem; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; } }
