:root {
  --bg: #f6f2e4; --bg2: #eee8d4; --panel: #fffdf6; --panel2: #edf4e2; --line: #d5dcc2;
  --text: #33402c; --muted: #7d8970; --accent: #4f9f5b; --alert: #e9677a; --warn: #c98316; --danger: #d9566a;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background:
    radial-gradient(ellipse 60% 45% at 10% 0%, rgba(255, 214, 230, .55) 0%, transparent 70%),
    radial-gradient(ellipse 55% 40% at 95% 10%, rgba(214, 205, 250, .5) 0%, transparent 70%),
    radial-gradient(ellipse 70% 50% at 50% 100%, rgba(196, 236, 222, .55) 0%, transparent 70%),
    linear-gradient(170deg, #fdf6f2 0%, #f6f2e4 55%, #eef6ee 100%) fixed;
  background-attachment: fixed;
  color: var(--text); font-family: 'Noto Sans KR', system-ui, sans-serif; min-height: 100vh;
}
h1, h2, h3 { font-family: 'Do Hyeon', 'Noto Sans KR', sans-serif; font-weight: 400; margin: 0; }
h2 { font-size: 26px; margin-bottom: 10px; }
h3 { font-size: 19px; margin-bottom: 6px; }
small { font-size: 0.7em; color: var(--muted); font-family: 'Noto Sans KR', sans-serif; }
a { color: var(--accent); }
.muted { color: var(--muted); font-size: 14px; }
.hidden { display: none !important; }
.center { text-align: center; }

button {
  font: inherit; font-weight: 700; color: var(--text); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 12px; padding: 9px 14px; cursor: pointer; transition: transform .08s, background .15s; touch-action: manipulation;
}
button:active:not(:disabled) { transform: scale(0.96); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button small { display: block; font-size: 12px; color: inherit; opacity: .75; font-weight: 400; }
button.primary { background: linear-gradient(180deg, #9edc96, #5fae6a); color: #143a1b; border-color: #86c98a; }
button.danger { background: #fde6e8; border-color: #f0b4bc; color: #b23a4c; }
button.ghost { background: transparent; }
button.ghost.off { opacity: 0.4; text-decoration: line-through; }
button.sm { padding: 4px 9px; font-size: 13px; border-radius: 9px; }
button.big { padding: 14px 20px; font-size: 19px; width: 100%; }
select, input { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }

header {
  display: flex; align-items: center; gap: 8px; padding: 10px 16px; flex-wrap: wrap;
  background: rgba(255, 253, 246, 0.88); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; backdrop-filter: blur(6px);
}
header h1 { font-size: 26px; white-space: nowrap; }
.spacer { flex: 1; }
.net { font-size: 13px; color: var(--muted); white-space: nowrap; }
.speed { font-size: 14px; color: var(--muted); }
.host-badge { background: var(--warn); color: #2a1600; padding: 2px 7px; border-radius: 8px; font-weight: 900; font-size: 12px; }

.overlay { position: fixed; inset: 0; background: rgba(70, 82, 58, 0.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.overlay-box { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 24px; text-align: center; max-width: 560px; width: 100%; max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 60px rgba(70,82,58,.25); }
.qr svg { width: 100%; max-width: 320px; background: #fff; border-radius: 12px; }
.small-qr { text-align: center; }
.small-qr svg { max-width: 200px; }
.join-url { word-break: break-all; font-size: 14px; color: var(--accent); margin: 8px 0; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #e6f4dc; border: 1px solid var(--line); padding: 12px 18px; border-radius: 14px; z-index: 80; font-weight: 700; max-width: calc(100% - 32px); box-shadow: 0 10px 30px rgba(70,82,58,.2); animation: pop .25s; }
.toast.err { background: #fde6e8; border-color: #f0b4bc; color: #b23a4c; }
@keyframes pop { from { transform: translate(-50%, 20px); opacity: 0; } }
body.shake main { animation: shake .5s; }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }

/* ---------- 룰렛 ---------- */
.wheel-wrap { position: relative; width: min(340px, 80vw); margin: 0 auto; }
.wheel { width: 100%; display: block; }
.pointer { position: absolute; left: 50%; top: -14px; transform: translateX(-50%); font-size: 30px; color: var(--accent); z-index: 1; text-shadow: 0 2px 4px rgba(70,82,58,.3); }
.roulette-result { font-family: 'Do Hyeon'; font-size: 26px; color: var(--accent); margin: 10px 0 0; }

/* ---------- 첫 화면 ---------- */
.landing main { max-width: 640px; margin: 0 auto; padding: 32px 16px; text-align: center; }
.landing h1 { font-size: clamp(40px, 11vw, 60px); margin-bottom: 8px; color: var(--accent); text-shadow: 0 0 18px rgba(255,255,255,.9), 0 0 36px rgba(183,160,240,.45); }
.hero { position: relative; height: 110px; }
.sprout { position: absolute; top: 10px; font-size: 64px; filter: drop-shadow(0 6px 10px rgba(95,174,106,.35)); animation: float 3s ease-in-out infinite; }
.sprout.v1 { left: calc(50% - 110px); font-size: 44px; animation-delay: -1s; }
.sprout.v2 { left: calc(50% - 34px); font-size: 72px; top: 0; }
.sprout.v3 { left: calc(50% + 60px); font-size: 40px; animation-delay: -2s;  }
@keyframes float { 50% { transform: translateY(-8px) rotate(6deg); } }
.big-link { display: block; padding: 16px; margin: 10px 0; border-radius: 16px; background: var(--panel2); border: 1px solid var(--line); text-decoration: none; color: var(--text); font-weight: 900; font-size: 19px; }
.big-link small { display: block; font-weight: 400; font-size: 13px; margin-top: 4px; color: inherit; opacity: .8; }
.big-link.host { background: linear-gradient(180deg, #9edc96, #5fae6a); color: #143a1b; }
.big-link.host2 { border-color: var(--accent); }
.pick { margin-top: 22px; font-size: 22px; }
.note { color: var(--muted); font-size: 14px; }
.rules { text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; margin-top: 14px; }
.rules summary { cursor: pointer; font-weight: 900; }
.rules li { margin: 6px 0; font-size: 14px; }

/* ---------- 대기실 ---------- */
.lobby { display: grid; grid-template-columns: minmax(260px, 380px) minmax(300px, 560px); gap: 24px; justify-content: center; padding: 24px 16px; }
.join-box, .members, .card-box { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 20px; }
.join-box { text-align: center; }
.mlist { list-style: none; padding: 0; margin: 0 0 10px; }
.mlist li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 12px; background: var(--bg2); margin-bottom: 6px; }
.mlist .seat { width: 26px; height: 26px; border-radius: 50%; background: var(--panel2); display: inline-flex; align-items: center; justify-content: center; font-weight: 900; font-size: 13px; flex: none; }
.mlist .mname { flex: 1; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mlist .online { font-size: 12px; color: var(--danger); }
.mlist .online.on { color: var(--accent); }
.mlist li.me { outline: 2px solid var(--accent); }
.npc-add { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 12px 0; font-weight: 700; }
@media (max-width: 720px) { .lobby { grid-template-columns: 1fr; } }

/* ---------- 방장: 게임판 ---------- */
.host .table { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(280px, 1fr); gap: 18px; padding: 16px; min-height: calc(100vh - 60px); }
.host .board { display: flex; flex-direction: column; gap: 14px; }
.turn-banner { text-align: center; font-family: 'Do Hyeon'; font-size: clamp(26px, 3vw, 40px); }
.turn-banner b { font-weight: 400; color: var(--accent); }
.last { text-align: center; color: var(--warn); font-weight: 700; min-height: 1.4em; }
.host .last { font-size: clamp(16px, 1.6vw, 22px); }
.board-area { flex: 1; display: flex; align-items: center; justify-content: center; background: rgba(255,253,246,.6); border: 1px dashed var(--line); border-radius: 20px; min-height: 320px; }
.placeholder { text-align: center; font-size: 72px; }
.placeholder p { font-size: 20px; margin: 8px 0 0; font-family: 'Do Hyeon'; }
.host .side { display: flex; flex-direction: column; gap: 12px; }
.players { display: flex; flex-direction: column; gap: 10px; }
.pl { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 10px 12px; transition: box-shadow .2s, border-color .2s; }
.pl.turn { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(95,174,106,.3), 0 0 24px rgba(95,174,106,.18); }
.pl-name { font-weight: 900; }
.off { font-size: 12px; color: var(--danger); font-weight: 700; }
.log-box { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 10px 12px; }
.log { margin: 0; padding-left: 20px; font-size: 14px; max-height: 260px; overflow: auto; }
.log li { margin: 3px 0; }
.over h2 { margin-bottom: 16px; }
@media (max-width: 860px) { .host .table { grid-template-columns: 1fr; } }

/* ---------- 휴대폰 ---------- */
.player main { max-width: 560px; margin: 0 auto; padding: 14px 16px 40px; display: flex; flex-direction: column; gap: 12px; }
.player header h1 { font-size: 22px; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.join input { width: 100%; margin-bottom: 10px; font-size: 18px; }
.host-note { color: var(--warn); font-size: 14px; }
.p-banner { text-align: center; font-family: 'Do Hyeon'; font-size: 26px; padding: 10px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); }
.p-banner.mine { background: linear-gradient(180deg, #bfe8b4, #86c98a); border-color: var(--accent); animation: pulse 1.4s infinite alternate; }
@keyframes pulse { to { box-shadow: 0 0 24px rgba(95,174,106,.45); } }
.last.small { font-size: 14px; }
.actions { display: flex; gap: 8px; margin-top: 10px; }
.actions button { flex: 1; padding: 12px; }
.dbox { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; }
.dbox summary { cursor: pointer; font-weight: 900; }
.dbox .qr { text-align: center; margin: 10px 0; }

/* ---------- 이름 바꾸기 · 연결 진단 ---------- */
.rename-box { padding: 12px 16px; }
.rename-box label { font-weight: 900; font-size: 14px; color: var(--muted); }
.rename-row { display: flex; gap: 8px; margin-top: 6px; }
.rename-row input { flex: 1; min-width: 0; font-size: 16px; }
.net-diag { max-width: 560px; margin: 10px auto 0; position: relative; z-index: 18; padding: 10px 14px; background: #fff4df; border: 1px solid #f0d39a; border-radius: 14px; font-size: 14px; }
.net-diag .nd-head { font-weight: 900; margin-bottom: 4px; }
.net-diag ul { margin: 4px 0 8px; padding-left: 20px; }
.net-diag li { margin: 3px 0; }

/* ---------- 디자인 페이지 (design/*.html) ---------- */
.design main { max-width: 1200px; margin: 0 auto; padding: 16px 16px 48px; }
.design h2 { margin: 26px 0 12px; }
.design header a { white-space: nowrap; }
.tk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.tk-card { margin: 0; background: var(--panel); border: 1px solid var(--line); border-top: 6px solid var(--tk); border-radius: 18px; padding: 14px; text-align: center; }
.tk-card b { color: var(--tkd); font-family: 'Do Hyeon', sans-serif; font-weight: 400; font-size: 20px; }
.tk-pics { display: flex; align-items: center; justify-content: center; gap: 14px; margin-bottom: 8px; }
.tk-ex { display: flex; flex-wrap: wrap; gap: 12px; }
.tk-ex figure { margin: 0; text-align: center; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 10px 12px; min-width: 110px; }
.tk-ex figcaption { margin-top: 4px; font-size: 14px; }
svg.token, svg.stack { display: block; margin: 0 auto; max-width: 100%; height: auto; }
.tk-count { display: inline-block; background: var(--tk); color: var(--tkc, #fff); font-weight: 900; font-size: 13px; padding: 1px 8px; border-radius: 10px; margin-left: 4px; }
.bd-row { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-start; }
.bd-row figure { margin: 0; text-align: center; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 12px; max-width: 100%; }
.bd-row figcaption { margin-top: 6px; font-size: 14px; }
svg.board { display: block; margin: 0 auto; max-width: 100%; height: auto; }
.st-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.st-card { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 10px; text-align: center; font-size: 14px; }
.st-pics { display: flex; align-items: flex-end; justify-content: center; gap: 4px; height: 100px; }
.st-pics svg.stack { margin: 0; }
.st-pts { font-weight: 900; color: var(--accent); }
.st-next .dot, .dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin: 0 1px; vertical-align: -1px; border: 1px solid rgba(0,0,0,.25); }
.sandbox { display: flex; flex-direction: column; gap: 10px; }
.sb-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.sb-colors { display: flex; gap: 6px; flex-wrap: wrap; }
.sb-color { padding: 3px; border-radius: 50%; background: transparent; border: 3px solid transparent; }
.sb-color.on { border-color: var(--accent); background: var(--panel2); }
.sb-color svg { display: block; }
.sb-opts { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; font-size: 14px; }
.sb-board svg { display: block; margin: 0 auto; max-width: 100%; height: auto; }
.sb-msg { text-align: center; font-weight: 700; margin: 0; min-height: 1.4em; }
.sb-msg.err { color: var(--danger); }
.an-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.an-grid figure { margin: 0; text-align: center; }
.an-grid figcaption { font-size: 14px; font-weight: 700; margin-top: 4px; }
.an-grid figcaption small { font-weight: 400; display: block; line-height: 1.4; }
svg.animal-card { display: block; margin: 0 auto; max-width: 100%; height: auto; filter: drop-shadow(0 4px 8px rgba(42,31,79,.25)); }
/* 동물이 뾰로롱 나타나기: 아래에서 튀어 오르며 커졌다 제자리, 둘레로 반짝이 별이 퍼짐 */
.board-animal.pop { animation: animal-pop .9s cubic-bezier(.2, 1.6, .4, 1) both; }
@keyframes animal-pop { 0% { transform: translateY(6px) scale(0); opacity: 0; } 45% { opacity: 1; } 70% { transform: translateY(-2px) scale(1.18); } 100% { transform: translateY(0) scale(1); } }
.pop-star { animation: pop-star 1s ease-out both; transform-box: fill-box; }
@keyframes pop-star { 0% { opacity: 0; translate: 0 0; scale: .2; } 30% { opacity: 1; scale: 1.2; } 100% { opacity: 0; translate: var(--dx) var(--dy); scale: .4; } }
.sb-animal { font-size: 14px; font-weight: 700; display: flex; align-items: center; gap: 6px; }

/* ---------- 게임 (방장·휴대폰 공용) ---------- */
.opts { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin: 12px 0; padding: 10px 12px; background: var(--bg2); border-radius: 12px; font-size: 14px; }
.opts label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.opt-side { display: inline-flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.ending { text-align: center; font-weight: 900; color: #b23a4c; background: #fde6e8; border: 1px solid #f0b4bc; border-radius: 12px; padding: 6px 10px; }
.areas { display: flex; flex-direction: column; gap: 6px; }
.area-row { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--bg2); border-radius: 12px; }
.area-row.empty { opacity: .55; }
.area-name { font-weight: 700; font-size: 14px; width: 74px; flex: none; }
.area-tokens { flex: 1; display: flex; gap: 4px; align-items: center; }
.area-tokens svg { display: block; }
.cards-row { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 8px; align-items: flex-start; scrollbar-width: thin; }
.cards-row svg.animal-card, .cards-row svg.spirit-card { flex: none; margin: 0; filter: drop-shadow(0 3px 6px rgba(42,31,79,.22)); }
svg.spirit-card { display: block; height: auto; max-width: 100%; }
.pick-card { flex: none; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.pick-card button { width: 100%; }
.my-card { flex: none; position: relative; border-radius: 10px; padding: 3px; border: 3px solid transparent; cursor: pointer; }
.my-card.on { border-color: var(--accent); background: rgba(95,174,106,.15); }
.my-card.can::after { content: ''; position: absolute; inset: -3px; border-radius: 10px; box-shadow: 0 0 0 3px #ffd27a; animation: pulse 1.2s infinite alternate; pointer-events: none; }
.can-badge { position: absolute; left: 50%; bottom: 6px; transform: translateX(-50%); background: #ffd27a; color: #5a3a00; font-size: 11px; font-weight: 900; padding: 2px 7px; border-radius: 9px; white-space: nowrap; }
.pboard svg.board { display: block; margin: 0 auto; max-width: 100%; height: auto; }
.pboard polygon.hex { transition: fill .15s; }
.hint { text-align: center; font-weight: 700; color: var(--warn); margin: 6px 0; }
.score-chips { display: inline-flex; flex-wrap: wrap; gap: 4px; justify-content: center; }
.chip { background: var(--bg2); border-radius: 9px; padding: 1px 7px; font-size: 13px; }
.chip b { margin-left: 2px; }
.todo ul { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 4px; font-size: 15px; }
.todo li.ok { color: var(--muted); text-decoration: line-through; }
.todo li.opt { color: var(--muted); }
.hand { display: flex; gap: 10px; justify-content: center; }
.tok { padding: 4px; border-radius: 50%; background: transparent; border: 3px solid transparent; }
.tok.on { border-color: var(--accent); background: var(--panel2); box-shadow: 0 0 14px rgba(95,174,106,.45); }
.tok svg { display: block; }
.spirit-pick { border-color: #a490d8; background: #f8f4ff; }
.spirit-pick .cards-row { justify-content: center; }
.done-cards summary { cursor: pointer; font-size: 14px; font-weight: 700; color: var(--muted); }
.other .pboard { margin: 8px 0; }
.res-wrap { overflow-x: auto; }
table.result { border-collapse: collapse; width: 100%; font-size: 15px; margin: 6px 0; }
table.result th, table.result td { padding: 6px 6px; text-align: center; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.result td.nm { text-align: left; font-weight: 700; }
table.result td.tot { font-weight: 900; font-size: 18px; color: var(--accent); }
table.result tr.win { background: #fff6d8; }
table.result tr.me td.nm::after { content: ' (나)'; font-size: 12px; color: var(--muted); }
.overlay-box.wide { max-width: 760px; }

/* 방장 화면 게임판 */
.host .g-table { display: grid; grid-template-columns: minmax(260px, 0.75fr) minmax(0, 2fr); gap: 16px; padding: 14px; align-items: start; }
.host .g-center { display: flex; flex-direction: column; gap: 10px; background: rgba(255,253,246,.7); border: 1px solid var(--line); border-radius: 20px; padding: 14px; position: sticky; top: 70px; }
.host .turn-banner small { font-size: .5em; }
.central svg { display: block; margin: 0 auto; max-width: 100%; height: auto; }
.counts { text-align: center; font-size: 15px; }
.host .g-center .market { flex-wrap: wrap; justify-content: center; overflow: visible; }
.host .g-players { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.host .g-players.n1 { grid-template-columns: minmax(300px, 640px); }
.pl-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.pl-name { font-weight: 900; font-size: 18px; }
.pl-score { font-family: 'Do Hyeon'; font-size: 28px; color: var(--accent); }
.pl-hand { display: flex; align-items: center; gap: 4px; font-size: 14px; font-weight: 700; color: var(--warn); }
.pl .cards-row { overflow-x: auto; }
.done-n { align-self: center; font-size: 13px; color: var(--muted); white-space: nowrap; }
@media (max-width: 860px) { .host .g-table { grid-template-columns: 1fr; } .host .g-center { position: static; } }
@media (max-width: 520px) { table.result { font-size: 13px; } table.result th, table.result td { padding: 5px 3px; } table.result td.tot { font-size: 16px; } }
.view-toggle { display: inline-flex; gap: 4px; margin-left: auto; }
.view-toggle button { padding: 3px 9px; font-size: 13px; font-family: 'Noto Sans KR', sans-serif; }
.view-toggle button.on { background: linear-gradient(180deg, #9edc96, #5fae6a); color: #143a1b; border-color: #86c98a; }
h3.board-h { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
