:root {
  --bg: #1c140d; --panel: #2a1f15; --panel2: #36291c; --line: rgba(253, 230, 190, 0.16);
  --text: #fbf3e6; --dim: #c2ad92; --accent: #f5b65b; --accent2: #fcd9a0; --bad: #f87171; --gold: #facc15;
  --r: 16px;
  /* 판 꾸미기 */
  --wood: #e2b877; --wood2: #d3a35e; --ink: rgba(60, 32, 10, 0.85); --frame: #5a3a1c;
  --pc: #fff7e6; --pc2: #ead7b5; --pcEdge: #8a6a40; --cho: #15803d; --han: #c81e1e;
  --dot: rgba(40, 20, 0, 0.32); --mark: #2563eb;
}
body.t-hanji { --wood: #f3ead7; --wood2: #e7dcc3; --ink: rgba(70, 55, 35, 0.75); --frame: #8b7350; --pc: #fffdf7; --pc2: #efe6d2; --pcEdge: #a08860; }
body.t-bamboo { --wood: #c8d49a; --wood2: #b5c283; --ink: rgba(40, 60, 20, 0.8); --frame: #4b5d2a; --pc: #fbfbef; --pc2: #e2e6c8; --pcEdge: #6c7a3d; --dot: rgba(30, 50, 10, 0.35); }
body.t-ink { --wood: #3a3532; --wood2: #322d2a; --ink: rgba(240, 225, 200, 0.6); --frame: #171412; --pc: #f4eee4; --pc2: #d6cdbf; --pcEdge: #4b433b; --dot: rgba(255, 240, 210, 0.35); --mark: #60a5fa; }
body.t-night { --wood: #24305e; --wood2: #1e2850; --ink: rgba(253, 230, 160, 0.55); --frame: #0f1533; --pc: #fef9e7; --pc2: #e8dcb8; --pcEdge: #6a5a30; --dot: rgba(253, 230, 160, 0.38); --mark: #fde68a; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(circle at 50% 0%, #3a2715 0%, var(--bg) 60%, #0d0905 100%);
  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(56, 189, 248, 0.12); border: 1px solid rgba(56, 189, 248, 0.3); color: #7dd3fc;
  text-decoration: none; font-size: 0.85rem; font-weight: 700;
}
.back-btn:hover { background: rgba(56, 189, 248, 0.22); }
.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; }

/* 말 (팔각형) */
.pc {
  --s: 30px; width: var(--s); height: var(--s); display: grid; place-items: center; flex: none;
  font-style: normal; font-weight: 900; font-size: calc(var(--s) * 0.5); line-height: 1;
  font-family: 'Noto Serif KR', 'Nanum Myeongjo', 'Batang', 'AppleMyungjo', serif;
  clip-path: polygon(29% 0, 71% 0, 100% 29%, 100% 71%, 71% 100%, 29% 100%, 0 71%, 0 29%);
  background: radial-gradient(circle at 40% 30%, var(--pc), var(--pc2) 80%);
  box-shadow: inset 0 0 0 calc(var(--s) * 0.05) var(--pcEdge);
}
.pc.cho { color: var(--cho); } .pc.han { color: var(--han); }
.pc.big { --s: 38px; }
.pc.kr { font-family: system-ui, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif; font-size: calc(var(--s) * 0.46); }

/* ── 메뉴 ── */
.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 { display: inline-flex; gap: 8px; align-items: center; padding: 8px 14px; border-radius: 12px; background: #e2b877; box-shadow: inset 0 0 0 2px #5a3a1c; }
.logo-art .pc { animation: bob 3s ease-in-out infinite; }
.logo-art .pc:nth-child(2) { animation-delay: 0.5s; } .logo-art .pc:nth-child(3) { animation-delay: 1s; }
@keyframes bob { 0%, 70%, 100% { transform: none; } 80% { transform: translateY(-5px); } }
h1 { margin: 10px 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(5, 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.82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tab.on { background: var(--accent); color: #2a1503; 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: #2a1503; 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(245, 182, 91, 0.5); background: linear-gradient(135deg, rgba(245, 182, 91, 0.2), rgba(245, 182, 91, 0.05));
}
.continue .ci { width: 34px; height: 34px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: #2a1503; }
.continue b { display: block; } .continue small { 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 { aspect-ratio: 1; border-radius: 6px; background: var(--panel2); display: grid; place-items: center; font-size: 0.7rem; color: var(--dim); }
.cal .w { background: #9a5b16; color: #fff; font-weight: 800; } .cal .t { outline: 2px solid var(--accent); }
.wk { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; font-size: 0.66rem; color: var(--dim); text-align: center; margin-top: 8px; }

.opps { display: grid; gap: 8px; }
.opp { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--r); border: 1px solid var(--line); background: var(--panel); text-align: left; width: 100%; }
.opp .oi { font-size: 1.9rem; width: 44px; text-align: center; flex: none; }
.opp .om { flex: 1; min-width: 0; }
.opp b { display: block; } .opp small { color: var(--dim); display: block; font-size: 0.76rem; }
.opp .os { color: var(--gold); font-size: 1rem; letter-spacing: 1px; white-space: nowrap; }
.opp.next { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(245, 182, 91, 0.25) inset; }
.opp.lock { opacity: 0.45; }
.chap { margin-bottom: 12px; }
.chap-h { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.chap-h b { font-size: 1rem; } .chap-h small { color: var(--dim); }
.chap-h .zs { margin-left: auto; font-weight: 800; color: var(--accent2); font-size: 0.85rem; white-space: nowrap; }
.pzs { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; }
.pz { aspect-ratio: 1.4; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 800; padding: 0; font-size: 0.85rem; }
.pz small { font-size: 0.55rem; color: var(--gold); letter-spacing: -1px; min-height: 0.8em; }
.pz.done { background: var(--panel2); border-color: rgba(245, 182, 91, 0.4); }
.pz.next { border-color: var(--accent); }
.locked { opacity: 0.45; }
.seg { display: flex; gap: 4px; flex-wrap: wrap; margin: 4px 0 10px; }
.seg button { flex: 1; min-width: 44px; padding: 8px 6px; 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: #2a1503; border-color: var(--accent); }
.lbl { font-weight: 800; font-size: 0.85rem; margin-top: 4px; }
.lbl small { color: var(--dim); font-weight: 400; }
.achs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.ach { display: flex; gap: 8px; align-items: center; padding: 8px; border-radius: 12px; background: var(--panel2); font-size: 0.8rem; }
.ach .ai { font-size: 1.3rem; } .ach b { display: block; font-size: 0.85rem; } .ach small { color: var(--dim); }
.ach.off { opacity: 0.45; filter: grayscale(1); }
.opt { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.opt:first-of-type { border-top: 0; }
.opt div { flex: 1; } .opt small { display: block; color: var(--dim); }
.sw { width: 50px; height: 28px; border-radius: 999px; border: 1px solid var(--line); background: #4a3b2c; position: relative; flex: none; }
.sw::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.sw.on { background: #c27b1c; } .sw.on::after { transform: translateX(22px); }
.themes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.th { padding: 6px 2px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2); font-size: 0.68rem; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.th i { width: 34px; height: 34px; border-radius: 8px; display: block; border: 2px solid rgba(0, 0, 0, 0.3); }
.th.on { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(245, 182, 91, 0.3) inset; }
.th-wood { background: #e2b877; } .th-hanji { background: #f3ead7; } .th-bamboo { background: #c8d49a; } .th-ink { background: #3a3532; } .th-night { background: #24305e; }
.lvwins { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; text-align: center; font-size: 0.72rem; }
.lvwins div { background: var(--panel2); border-radius: 8px; padding: 4px 0; } .lvwins b { display: block; font-size: 0.9rem; }

/* ── 대국 ── */
#play { flex: 1; display: flex; flex-direction: column; min-height: 0; padding-bottom: env(safe-area-inset-bottom); }
.p-head { display: flex; align-items: center; gap: 8px; padding: 2px 12px 4px; max-width: 560px; width: 100%; margin: 0 auto; }
.p-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.p-title b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .p-title small { color: var(--dim); font-size: 0.76rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.score { display: flex; align-items: center; gap: 6px; padding: 2px 12px; max-width: 560px; width: 100%; margin: 0 auto; }
.side { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); transition: box-shadow 0.2s, border-color 0.2s; }
.side.r { justify-content: flex-end; text-align: right; }
.side .pc { --s: 28px; }
.side > div { min-width: 0; } .side small { display: block; color: var(--dim); font-size: 0.72rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side b { font-size: 1.15rem; line-height: 1; }
.side.on { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(245, 182, 91, 0.3); }
.side.chk { border-color: var(--bad); box-shadow: 0 0 0 2px rgba(248, 113, 113, 0.45); }
.caps { display: flex; flex-wrap: wrap; gap: 1px; flex: 1; min-width: 0; max-height: 34px; overflow: hidden; }
.side.r .caps { justify-content: flex-start; }
.side:not(.r) .caps { justify-content: flex-end; }
.caps .pc { --s: 15px; opacity: 0.9; }
.vs { flex: none; width: 84px; text-align: center; font-size: 0.78rem; font-weight: 700; color: var(--accent2); line-height: 1.25; }
.vs small { display: block; color: var(--dim); font-weight: 400; font-size: 0.68rem; }
.vs.think b::after { content: ''; display: inline-block; width: 1.2em; text-align: left; animation: dots 1s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
.board-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; position: relative; padding: 6px 8px; }
.board {
  position: relative; border-radius: 10px; touch-action: manipulation; cursor: pointer;
  background: linear-gradient(135deg, var(--wood), var(--wood2));
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), inset 0 0 0 4px var(--frame);
}
.grid { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.grid line { stroke: var(--ink); stroke-width: 1.2; }
.grid .edge { stroke-width: 2.4; }
.grid text { fill: var(--ink); font-size: 10px; font-weight: 700; opacity: 0.55; }
.layer { position: absolute; inset: 0; pointer-events: none; }
.board .pc { position: absolute; left: 0; top: 0; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.45)); transition: transform 0.22s ease-out; will-change: transform; }
.board .pc.sel { filter: drop-shadow(0 0 6px var(--gold)) drop-shadow(0 2px 2px rgba(0, 0, 0, 0.45)); }
.board .pc.inchk { animation: chk 0.9s ease-in-out infinite; }
@keyframes chk { 0%, 100% { filter: drop-shadow(0 0 2px #ef4444); } 50% { filter: drop-shadow(0 0 10px #ef4444); } }
.board .pc.gone { animation: gone 0.3s ease-in forwards; }
@keyframes gone { to { opacity: 0; } }
.mk { position: absolute; left: 0; top: 0; border-radius: 50%; }
.mk.dot { background: var(--dot); }
.mk.cap { border: 3px solid var(--dot); background: transparent; }
.mk.from { border: 2px dashed var(--mark); opacity: 0.65; }
.mk.to { border: 2px solid var(--mark); opacity: 0.8; }
.mk.hint { border: 3px solid var(--gold); box-shadow: 0 0 12px rgba(250, 204, 21, 0.8); }
.mk.bad { border: 3px solid var(--bad); }
.toast { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); background: #fdf6e8; color: #2a1503; padding: 8px 14px; border-radius: 10px; font-weight: 800; font-size: 0.88rem; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4); z-index: 3; max-width: calc(100% - 24px); text-align: center; pointer-events: none; }
.toast.bad { background: #fee2e2; color: #7f1d1d; }
.toast.big { font-size: 1.4rem; padding: 10px 22px; top: 40%; color: #b91c1c; letter-spacing: 0.1em; }
.ctrl { display: flex; gap: 8px; justify-content: center; padding: 4px 12px 12px; max-width: 560px; width: 100%; margin: 0 auto; }
.cbtn { flex: 1; max-width: 140px; display: flex; flex-direction: column; align-items: center; padding: 6px 8px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel); font-size: 1.15rem; line-height: 1.15; }
.cbtn span { font-size: 0.7rem; color: var(--dim); }
.cbtn.used { border-color: rgba(250, 204, 21, 0.5); }

/* ── 모달 ── */
.modal { position: fixed; inset: 0; background: rgba(10, 6, 2, 0.7); 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.5); }
.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; }
.err { font-family: ui-monospace, monospace; font-size: 0.75rem; background: #120c06; padding: 8px; border-radius: 8px; white-space: pre-wrap; color: #fecaca; max-height: 140px; overflow: auto; user-select: text; -webkit-user-select: text; }
.win { text-align: center; }
.win-ico { font-size: 2.6rem; animation: rise 0.5s ease-out; }
@keyframes rise { from { transform: scale(0.6) rotate(-6deg); opacity: 0; } to { transform: none; opacity: 1; } }
.final { display: flex; justify-content: center; align-items: center; gap: 14px; font-size: 1.3rem; font-weight: 900; margin: 6px 0; }
.final span { display: flex; align-items: center; gap: 6px; }
.final .pc { --s: 30px; }
.stars { font-size: 2rem; color: var(--gold); letter-spacing: 4px; }
.win-line { margin: 4px 0; font-weight: 700; }
.ach-got { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 8px; }
.ach-got span { padding: 5px 10px; border-radius: 999px; background: rgba(252, 217, 160, 0.12); border: 1px solid rgba(252, 217, 160, 0.45); font-size: 0.82rem; font-weight: 700; }
.intro { text-align: center; }
.intro .oi { font-size: 3rem; }
.intro q { display: block; margin: 8px 0; font-style: italic; color: var(--accent2); }
.intro ul { text-align: left; margin: 8px 0; padding-left: 20px; font-size: 0.86rem; color: var(--dim); }
.help-pcs { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; align-items: center; font-size: 0.84rem; margin: 8px 0; }
.help-pcs .pc { --s: 30px; }
.noscript { padding: 20px; text-align: center; }

@media (max-width: 400px) { .back-txt { display: none; } .tab { font-size: 0.72rem; } .pzs { gap: 3px; } .vs { width: 70px; font-size: 0.72rem; } .side { padding: 4px 6px; } .side .pc { --s: 22px; } .side b { font-size: 1rem; } .caps .pc { --s: 12px; } }
@media (max-height: 620px) { .cbtn span { display: none; } .p-title small { display: none; } }
