:root {
  --bg: #1c1410; --panel: #2a1f18; --panel2: #36291f; --line: rgba(253, 230, 138, 0.16);
  --text: #fdf6e8; --dim: #c4b39c; --accent: #f59e0b; --accent2: #fcd34d; --bad: #f87171; --gold: #facc15; --ok: #4ade80;
  --r: 16px;
  /* 판 꾸미기 */
  --mat: #c89b5f; --mat2: #b48550; --ink: #4a2e16; --dotc: #f8ecd4; --corner: #9a3412; --frame: #5b3a1f;
}
body.t-paper { --mat: #f1e6cf; --mat2: #e5d6b6; --ink: #57534e; --dotc: #ffffff; --corner: #b91c1c; --frame: #a8a29e; }
body.t-night { --mat: #1e2448; --mat2: #171c3a; --ink: #a5b4fc; --dotc: #312e81; --corner: #fbbf24; --frame: #0f1330; }
body.t-silk { --mat: #7f1d1d; --mat2: #6b1717; --ink: #fcd34d; --dotc: #991b1b; --corner: #fde68a; --frame: #450a0a; }
body.t-gold { --mat: #fbbf24; --mat2: #f59e0b; --ink: #78350f; --dotc: #fef3c7; --corner: #7c2d12; --frame: #78350f; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(circle at 50% 0%, #3b2617 0%, var(--bg) 60%, #0d0907 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; }

/* ── 메뉴 ── */
.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: 6px; padding: 8px 12px; border-radius: 12px; background: #c89b5f; }
.logo-art i { width: 12px; height: 46px; border-radius: 7px; background: linear-gradient(90deg, #7c4a1e, #a36a33); display: block; animation: lroll 3.2s ease-in-out infinite; }
.logo-art i.f { background: linear-gradient(90deg, #fdf0d0, #e8cf9f); }
.logo-art i:nth-child(2) { animation-delay: 0.15s; } .logo-art i:nth-child(3) { animation-delay: 0.3s; } .logo-art i:nth-child(4) { animation-delay: 0.45s; }
@keyframes lroll { 0%, 70%, 100% { transform: none; } 80% { transform: translateY(-10px) rotate(25deg); } 90% { transform: translateY(0) rotate(-8deg); } }
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(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: #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%; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.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, 158, 11, 0.5); background: linear-gradient(135deg, rgba(245, 158, 11, 0.2), rgba(245, 158, 11, 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: #b45309; color: #fff; font-weight: 800; } .cal .l { background: #57534e; color: #fff; } .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; }
.rule-chip { display: inline-block; padding: 3px 8px; border-radius: 999px; background: rgba(245, 158, 11, 0.15); border: 1px solid rgba(245, 158, 11, 0.4); font-size: 0.75rem; margin: 2px 2px 0 0; color: var(--accent2); }

.vil { margin-bottom: 12px; }
.vil-h { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.vil-h .vi { font-size: 1.3rem; } .vil-h b { font-size: 1rem; } .vil-h small { color: var(--dim); }
.vil-h .zs { margin-left: auto; font-weight: 800; color: var(--accent2); font-size: 0.85rem; white-space: nowrap; }
.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, 158, 11, 0.25) inset; }
.opp.lock { 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; }
.seat { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.seat .dotp { width: 18px; height: 18px; border-radius: 50%; flex: none; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.3); }
.seat .seg { flex: 1; margin: 0; }
.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: #4a3b2f; 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: #d97706; } .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, 158, 11, 0.3) inset; }
.th-mat { background: #c89b5f; } .th-paper { background: #f1e6cf; } .th-night { background: #1e2448; } .th-silk { background: #7f1d1d; } .th-gold { background: #fbbf24; }
.lvwins { display: grid; grid-template-columns: repeat(5, 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; }
.players { display: flex; gap: 6px; padding: 2px 12px; max-width: 560px; width: 100%; margin: 0 auto; }
.pl { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); transition: box-shadow 0.2s, border-color 0.2s; }
.pl .pi { font-size: 1.15rem; flex: none; }
.pl .pm { min-width: 0; flex: 1; }
.pl small { display: block; font-size: 0.7rem; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl .pcs { display: flex; gap: 2px; margin-top: 2px; }
.pl .pcs i { width: 9px; height: 9px; border-radius: 50%; display: block; border: 1.5px solid var(--c); }
.pl .pcs i.b { background: color-mix(in srgb, var(--c) 45%, transparent); }
.pl .pcs i.o { background: var(--c); }
.pl.on { border-color: var(--c); box-shadow: 0 0 0 2px color-mix(in srgb, var(--c) 40%, transparent); }
.pl.think small::after { content: ' …'; }
.board-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; position: relative; padding: 6px 8px; }
.board { width: min(100%, 520px); height: 100%; max-height: 520px; overflow: visible; touch-action: manipulation; }
.b-bg { fill: var(--mat); stroke: var(--frame); stroke-width: 2.4; }
.b-weave { fill: url(#weave); }
.b-line { stroke: var(--ink); stroke-width: 0.8; opacity: 0.55; stroke-linecap: round; }
.b-path { stroke: #fde047; stroke-width: 2.2; stroke-linecap: round; stroke-dasharray: 0.1 3.4; fill: none; opacity: 0.9; }
.st { fill: var(--dotc); stroke: var(--ink); stroke-width: 0.7; }
.st.bigst { stroke-width: 1.1; }
.st.cor { stroke: var(--corner); stroke-width: 1.3; }
.st-lbl { font-size: 3.1px; fill: var(--ink); opacity: 0.8; font-weight: 800; text-anchor: middle; pointer-events: none; }
.spot { font-size: 5px; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.tok { cursor: pointer; transition: transform 0.12s; }
.tok circle.ring { fill: none; stroke: none; }
.tok circle.body { stroke: rgba(0, 0, 0, 0.45); stroke-width: 0.6; }
.tok text { font-size: 3.6px; font-weight: 900; fill: #fff; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.tok .cnt { font-size: 3px; }
.tok.can circle.ring { stroke: #fff; stroke-width: 0.8; fill: none; animation: pulse 1s ease-in-out infinite; }
.tok.sel circle.ring { stroke: #fde047; stroke-width: 1.3; fill: none; }
@keyframes pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }
.dest { cursor: pointer; }
.dest circle { fill: rgba(253, 224, 71, 0.35); stroke: #fde047; stroke-width: 1; animation: pulse 0.9s ease-in-out infinite; }
.dest text { font-size: 3px; font-weight: 900; fill: #422006; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.hitfx { fill: none; stroke: #fff; stroke-width: 1; animation: boom 0.6s ease-out forwards; pointer-events: none; }
@keyframes boom { from { r: 3; opacity: 1; } to { r: 14; opacity: 0; } }
.toast { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); background: #fef3c7; color: #422006; 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; }
.big { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); font-size: 3.2rem; font-weight: 900; color: #fff; text-shadow: 0 4px 0 rgba(0, 0, 0, 0.35), 0 0 22px rgba(245, 158, 11, 0.8); pointer-events: none; z-index: 4; animation: bigpop 0.7s ease-out forwards; white-space: nowrap; }
.big.r5, .big.r4 { color: #fde047; font-size: 4rem; }
.big.rb { color: #fca5a5; }
@keyframes bigpop { 0% { transform: translate(-50%, -50%) scale(0.4); opacity: 0; } 25% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; } 70% { opacity: 1; } 100% { transform: translate(-50%, -60%) scale(1); opacity: 0; } }
.tray { display: flex; gap: 8px; align-items: center; padding: 2px 12px; max-width: 560px; width: 100%; margin: 0 auto; min-height: 44px; }
.home { display: flex; gap: 4px; align-items: center; flex: none; min-width: 0; }
.home .hp { width: 34px; height: 34px; border-radius: 50%; border: 2px solid rgba(0, 0, 0, 0.35); background: var(--c); color: #fff; font-weight: 900; font-size: 0.8rem; padding: 0; position: relative; }
.home .hp.can { box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.7); animation: hpulse 1s ease-in-out infinite; }
.home .hp.sel { box-shadow: 0 0 0 3px #fde047; }
.home .hp:disabled { opacity: 0.55; }
.home .lab { font-size: 0.7rem; color: var(--dim); margin-right: 2px; }
@keyframes hpulse { 50% { box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.25); } }
.pool { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; flex: 1; }
.chip { min-width: 46px; padding: 7px 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2); font-weight: 900; font-size: 0.95rem; }
.chip.on { background: var(--accent); color: #2a1503; border-color: var(--accent); }
.chip.dead { opacity: 0.4; text-decoration: line-through; }
.chip.r5, .chip.r4 { border-color: rgba(253, 224, 71, 0.6); }
.chip.rb { border-color: rgba(248, 113, 113, 0.6); }
.act { display: flex; gap: 8px; align-items: center; justify-content: center; padding: 6px 12px 12px; max-width: 560px; width: 100%; margin: 0 auto; }
.sticks { display: flex; gap: 4px; padding: 6px 8px; border-radius: 12px; background: rgba(0, 0, 0, 0.25); flex: none; }
.sticks i { width: 10px; height: 40px; border-radius: 6px; display: block; background: linear-gradient(90deg, #7c4a1e, #a36a33); position: relative; transition: background 0.1s; }
.sticks i.f { background: linear-gradient(90deg, #fdf0d0, #e8cf9f); }
.sticks i.f::after { content: ''; position: absolute; left: 3px; right: 3px; top: 8px; bottom: 8px; border-left: 1px dashed rgba(124, 74, 30, 0.35); }
.sticks i.mark.f::before { content: '✕'; position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%); font-size: 8px; text-align: center; color: #b91c1c; font-weight: 900; }
.sticks.roll i { animation: sroll 0.55s ease-in-out; }
.sticks.roll i:nth-child(2) { animation-delay: 0.05s; } .sticks.roll i:nth-child(3) { animation-delay: 0.1s; } .sticks.roll i:nth-child(4) { animation-delay: 0.15s; }
@keyframes sroll { 0% { transform: none; } 30% { transform: translateY(-26px) rotate(160deg); } 60% { transform: translateY(-8px) rotate(330deg); } 100% { transform: none; } }
.sticks.nak i { transform: translateY(6px) rotate(70deg); opacity: 0.5; }
.throw { flex: 1; max-width: 260px; padding: 12px 10px; border-radius: 16px; border: 0; background: linear-gradient(180deg, #f59e0b, #d97706); color: #2a1503; font-weight: 900; font-size: 1.1rem; box-shadow: 0 4px 0 #92400e; display: flex; flex-direction: column; align-items: center; line-height: 1.15; touch-action: manipulation; }
.throw small { font-size: 0.65rem; opacity: 0.7; font-weight: 700; }
.throw:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 #92400e; }
.throw:disabled { background: var(--panel2); color: var(--dim); box-shadow: none; }
.throw.wait { background: var(--panel2); color: var(--text); box-shadow: none; }
.cbtn { flex: none; width: 58px; display: flex; flex-direction: column; align-items: center; padding: 6px 4px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel); font-size: 1.1rem; line-height: 1.15; }
.cbtn span { font-size: 0.66rem; color: var(--dim); }

/* ── 모달 ── */
.modal { position: fixed; inset: 0; background: rgba(10, 6, 3, 0.72); 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-box ul { padding-left: 20px; line-height: 1.55; font-size: 0.9rem; }
.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: #120b06; 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; } }
.ranks { display: grid; gap: 4px; margin: 8px 0; text-align: left; }
.ranks div { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 10px; background: var(--panel2); font-size: 0.88rem; }
.ranks i { width: 14px; height: 14px; border-radius: 50%; display: block; flex: none; }
.ranks span { margin-left: auto; color: var(--dim); font-size: 0.8rem; }
.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(253, 230, 138, 0.12); border: 1px solid rgba(253, 230, 138, 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); }
.res-tbl { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; font-size: 0.8rem; margin: 6px 0; }
.res-tbl div { background: var(--panel2); border-radius: 8px; padding: 5px; text-align: center; }
.res-tbl b { display: block; }
.noscript { padding: 20px; text-align: center; }

@media (max-width: 400px) { .back-txt { display: none; } .tab { font-size: 0.75rem; } .pl { padding: 4px 6px; gap: 4px; } .pl .pi { font-size: 1rem; } .home .hp { width: 30px; height: 30px; } .chip { min-width: 40px; padding: 6px 7px; font-size: 0.88rem; } }
@media (max-height: 640px) { .p-title small { display: none; } .sticks i { height: 30px; } .throw { padding: 8px; } .throw small { display: none; } }
