:root {
  --bg: #2a1a0e; --panel: #fff8ec; --panel2: #f4e8d2; --line: rgba(80, 50, 20, 0.18);
  --text: #2c1d10; --dim: #7a5f42; --accent: #c2410c; --accent2: #9a3412; --bad: #dc2626; --gold: #d99a06; --ok: #16a34a;
  --r: 16px;
  /* 판 꾸미기 */
  --board1: #a0612b; --board2: #7a4519; --rim: #4a2a0f; --pit: #5b3414; --pitIn: #3a2009; --pitHi: rgba(255, 220, 160, 0.18);
  --me: #2563eb; --op: #e11d48; --cnt: #fff7e6; --seedA: #f5deb3; --seedB: #d97706; --seedC: #65a30d; --seedD: #b91c1c; --seedE: #e2e8f0;
}
body.t-stone { --board1: #8a8f98; --board2: #5c6169; --rim: #33363b; --pit: #4b4f56; --pitIn: #2a2c30; --pitHi: rgba(255, 255, 255, 0.12); --seedA: #f8fafc; --seedB: #fbbf24; --seedC: #34d399; --seedD: #f472b6; --seedE: #93c5fd; }
body.t-sand { --board1: #e8c98a; --board2: #c9a061; --rim: #8a6a3a; --pit: #b88f55; --pitIn: #8f6a37; --pitHi: rgba(255, 255, 255, 0.2); --cnt: #fffbeb; --seedA: #7c2d12; --seedB: #1e3a8a; --seedC: #166534; --seedD: #fefce8; --seedE: #9d174d; }
body.t-sea { --board1: #1e6f8f; --board2: #13506a; --rim: #0b3346; --pit: #0f425a; --pitIn: #082636; --pitHi: rgba(186, 230, 253, 0.15); --seedA: #fde68a; --seedB: #fca5a5; --seedC: #f8fafc; --seedD: #a7f3d0; --seedE: #fdba74; }
body.t-night { --board1: #2a2f5a; --board2: #191c3d; --rim: #0c0e24; --pit: #14173a; --pitIn: #080a1f; --pitHi: rgba(253, 230, 138, 0.12); --seedA: #fde68a; --seedB: #c4b5fd; --seedC: #67e8f9; --seedD: #fda4af; --seedE: #f8fafc; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(circle at 50% 0%, #fbeed6 0%, #ead7b5 60%, #d9bf94 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(194, 65, 12, 0.1); border: 1px solid rgba(194, 65, 12, 0.3); color: var(--accent2);
  text-decoration: none; font-size: 0.85rem; font-weight: 700;
}
.back-btn:hover { background: rgba(194, 65, 12, 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: 160px; height: 56px; display: block; margin: 0 auto; }
.la-board { fill: #a0612b; stroke: #4a2a0f; stroke-width: 2; }
.la-pit, .la-pits circle { fill: #4a2a0f; }
.la-seeds circle { fill: #f5deb3; }
.la-hop { fill: #fbbf24; animation: laHop 2.4s ease-in-out infinite; }
@keyframes laHop { 0%, 15% { transform: translate(0, 0); } 35% { transform: translate(11px, -10px); } 50%, 100% { transform: translate(23px, 0); opacity: 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(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.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(194, 65, 12, 0.45); background: linear-gradient(135deg, rgba(194, 65, 12, 0.14), rgba(194, 65, 12, 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(194, 65, 12, 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); }
.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); }
.status.good { background: #fef9c3; border-color: #facc15; }
.board-wrap { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
/* 만칼라 판 (그리드: JS가 가로·세로 배치) */
.board {
  display: grid; gap: 2.2%; padding: 2.4%; border-radius: 40px; position: relative;
  background: linear-gradient(160deg, var(--board1), var(--board2)); border: 3px solid var(--rim);
  box-shadow: 0 10px 26px rgba(40, 20, 5, 0.35), inset 0 2px 0 rgba(255, 255, 255, 0.18);
  touch-action: manipulation;
}
.board.h { grid-template-columns: 1.25fr repeat(6, 1fr) 1.25fr; grid-template-rows: 1fr 1fr; }
.board.v { grid-template-columns: 1fr 1fr; grid-template-rows: 1.25fr repeat(6, 1fr) 1.25fr; border-radius: 34px; }
.pit, .store {
  position: relative; border-radius: 50%; border: 0; padding: 0; min-width: 0; min-height: 0;
  background: radial-gradient(circle at 50% 38%, var(--pitIn) 0%, var(--pit) 70%, var(--rim) 100%);
  box-shadow: inset 0 4px 10px rgba(0, 0, 0, 0.45), 0 1px 0 var(--pitHi);
}
.store { border-radius: 999px; }
.pit.p0 { box-shadow: inset 0 4px 10px rgba(0, 0, 0, 0.45), 0 0 0 2px rgba(37, 99, 235, 0.35); }
.pit.p1 { box-shadow: inset 0 4px 10px rgba(0, 0, 0, 0.45), 0 0 0 2px rgba(225, 29, 72, 0.3); }
.store.p0 { box-shadow: inset 0 4px 12px rgba(0, 0, 0, 0.5), 0 0 0 3px rgba(37, 99, 235, 0.45); }
.store.p1 { box-shadow: inset 0 4px 12px rgba(0, 0, 0, 0.5), 0 0 0 3px rgba(225, 29, 72, 0.4); }
.pit.can { cursor: pointer; }
.pit.can:hover, .pit.sel { filter: brightness(1.25); }
.pit.sel { outline: 3px dashed #fbbf24; outline-offset: 2px; }
.pit.no { opacity: 0.55; }
.pit.src { outline: 3px solid #fbbf24; outline-offset: 1px; }
.pit.tgt, .store.tgt { box-shadow: inset 0 0 0 3px #fbbf24, 0 0 14px #fbbf24; }
.pit.hint { animation: hintPulse 0.8s ease-in-out infinite; }
@keyframes hintPulse { 50% { box-shadow: inset 0 0 0 4px #facc15, 0 0 18px #facc15; } }
.pit.capt { animation: capt 0.45s ease-in-out 2; }
@keyframes capt { 50% { box-shadow: inset 0 0 0 4px #f87171, 0 0 18px #f87171; } }
.seeds { position: absolute; inset: 8%; pointer-events: none; }
.sd { position: absolute; width: var(--sz, 22%); aspect-ratio: 1; border-radius: 50%; transform: translate(-50%, -50%); box-shadow: inset -1px -2px 2px rgba(0, 0, 0, 0.35), inset 1px 1px 1px rgba(255, 255, 255, 0.5); }
.store .sd { --sz: 30%; }
.board.v .store .sd { --sz: 13%; }
.board.h .store .sd { --sz: 27%; }
.sd.new { animation: sdDrop 0.22s ease-out; }
@keyframes sdDrop { from { transform: translate(-50%, -150%) scale(1.4); opacity: 0.2; } }
.sd.c0 { background: var(--seedA); } .sd.c1 { background: var(--seedB); } .sd.c2 { background: var(--seedC); } .sd.c3 { background: var(--seedD); } .sd.c4 { background: var(--seedE); }
.cnt {
  position: absolute; right: -2px; bottom: -2px; min-width: 1.6em; padding: 1px 4px; border-radius: 999px; font-size: 0.78rem; font-weight: 900;
  background: rgba(20, 10, 2, 0.75); color: var(--cnt); text-align: center; pointer-events: none; font-variant-numeric: tabular-nums;
}
.store .cnt { right: 50%; transform: translateX(50%); bottom: 4px; font-size: 1rem; }
.cnt.z { opacity: 0.4; }
.cnt.bump { animation: bump 0.3s; }
.tag-fly { position: absolute; left: 50%; top: -6px; transform: translate(-50%, -100%); white-space: nowrap; font-size: 0.72rem; font-weight: 900; background: #fbbf24; color: #3b1d06; padding: 1px 6px; border-radius: 8px; pointer-events: none; z-index: 2; }
.tag-fly.cap { background: #f87171; color: #fff; }
.board.busy .pit { 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, 18, 6, 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; } }

.pz-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin: 6px 0 4px; }
.pz-grid button { padding: 8px 2px 6px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2); font-weight: 800; font-size: 0.9rem; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.pz-grid button small { color: var(--gold); font-size: 0.7rem; letter-spacing: 1px; min-height: 1em; }
.pz-grid button.next { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.pz-grid button:disabled { opacity: 0.4; }
