:root {
  --bg: #faf7f2; --panel: #ffffff; --ink: #1c1a18; --muted: #77706a; --line: #e8e1d8;
  --accent: #ff5a3c; --accent-ink: #fff; --mint: #2fbf8f; --gold: #ffc23c; --chip: #ffffff;
  --board: #f4efe7; --dot: #e2d9cc; --r: 14px; --fs: 16px; --chipfs: 17px;
  --font: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: var(--fs); color: var(--ink); background: var(--bg); display: flex; flex-direction: column; overflow: hidden; -webkit-tap-highlight-color: transparent; }
button { font: inherit; cursor: pointer; border: 0; border-radius: 999px; padding: .5em 1em; background: none; color: inherit; }
.primary { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.ghost { background: var(--panel); border: 1.5px solid var(--line); }
.ghost:hover { border-color: var(--ink); }
.small { font-size: .85em; padding: .35em .8em; }
.big { font-size: 1.15em; padding: .7em 1.6em; }
kbd { font-family: inherit; background: var(--panel); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; padding: 0 .35em; }
input { font: inherit; border: 1.5px solid var(--line); border-radius: 12px; padding: .55em .8em; background: var(--panel); color: var(--ink); min-width: 0; }
input:focus { outline: none; border-color: var(--accent); }
[hidden] { display: none !important; }

/* header */
.top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { display: flex; align-items: center; gap: 8px; font-size: 1.15em; white-space: nowrap; }
.logo { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; background: var(--ink); color: var(--bg); font-weight: 800; font-size: 20px; }
.mockTag { font-size: .7em; color: var(--muted); border: 1px dashed var(--muted); border-radius: 999px; padding: .1em .6em; }
.mission-chip { margin-left: auto; display: flex; align-items: center; gap: 8px; background: #fff1ec; border: 1.5px solid #ffd2c6; }
.mc-label { font-size: .8em; color: var(--accent); font-weight: 700; }
.mc-target { font-weight: 800; }
.actions { display: flex; gap: 6px; }

/* mission bar */
.mission-bar { display: flex; align-items: center; gap: 18px; padding: 8px 16px; background: var(--ink); color: var(--bg); }
.mission-bar .ghost { background: transparent; color: var(--bg); border-color: #555; }
.mb-goal { font-size: 1.1em; margin-right: auto; }
.mb-stat { display: flex; align-items: baseline; gap: 6px; font-variant-numeric: tabular-nums; }
.mb-stat b { font-size: 1.3em; }
.mb-stat .k { font-size: .8em; opacity: .7; }

/* play */
.play { flex: 1; display: flex; min-height: 0; }
.board { position: relative; flex: 1; min-width: 0; overflow: hidden; background-color: var(--board); background-image: radial-gradient(var(--dot) 1.2px, transparent 1.2px); background-size: 22px 22px; touch-action: none; }
.board-empty { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; color: var(--muted); pointer-events: none; padding: 20px; }
.be-1 { font-size: 1.35em; font-weight: 700; color: var(--ink); margin: 0 0 8px; }
.be-2 { margin: 0; font-size: .95em; }
.board-clear { position: absolute; right: 12px; bottom: 12px; }
.selected-hint { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); background: var(--ink); color: var(--bg); border-radius: 999px; padding: .4em 1em; font-size: .9em; pointer-events: none; white-space: nowrap; }

.chip { display: inline-flex; align-items: center; gap: .35em; padding: .45em .8em; border-radius: 12px; background: var(--chip); border: 1.5px solid var(--line); font-size: var(--chipfs); font-weight: 600; white-space: nowrap; user-select: none; -webkit-user-select: none; touch-action: none; box-shadow: 0 1px 0 rgba(0,0,0,.04); }
.chip .e { font-size: 1.1em; line-height: 1; }
.chip.sel { border-color: var(--accent); box-shadow: 0 0 0 3px #ffd2c6; }
.chip.new::after { content: "NEW"; font-size: .6em; font-weight: 800; color: var(--accent); margin-left: .2em; }
.chip.first { border-color: var(--gold); background: #fff8e3; }
.chip.target { outline: 2px dashed var(--accent); outline-offset: 2px; }
.board .chip { position: absolute; cursor: grab; transition: box-shadow .1s; }
.board .chip.dragging { cursor: grabbing; box-shadow: 0 8px 20px rgba(0,0,0,.15); z-index: 5; }
.board .chip.over { border-color: var(--mint); box-shadow: 0 0 0 3px #bdf0de; }
.board .chip.pop { animation: pop .35s ease-out; }
.board .chip.busy { opacity: .55; }
@keyframes pop { 0% { transform: scale(.6); } 70% { transform: scale(1.12); } 100% { transform: scale(1); } }
.drag-ghost { position: fixed; z-index: 50; pointer-events: none; transform: translate(-50%, -50%); }

.inv { width: 360px; display: flex; flex-direction: column; border-left: 1px solid var(--line); background: var(--panel); min-height: 0; }
.inv-head { display: flex; align-items: center; gap: 8px; padding: 10px; border-bottom: 1px solid var(--line); }
.inv-head input { flex: 1; }
.inv-count { color: var(--muted); font-size: .85em; white-space: nowrap; }
.inv-list { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-wrap: wrap; align-content: flex-start; gap: 7px; }
.inv-list .chip { cursor: pointer; }

/* chat bar */
.chatbar { display: flex; align-items: center; gap: 8px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--panel); }
.cb-label { font-weight: 700; font-size: .9em; white-space: nowrap; }
.chatbar input { flex: 0 1 380px; }
.cb-msg { color: var(--muted); font-size: .9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cb-msg.err { color: #c8321b; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--panel); border: 1.5px solid var(--line); border-radius: 18px; padding: 12px 16px; box-shadow: 0 10px 30px rgba(0,0,0,.12); z-index: 30; text-align: center; min-width: 260px; }
.t-eq { font-size: 1.15em; font-weight: 700; }
.t-eq .res { color: var(--accent); }
.t-meta { color: var(--muted); font-size: .85em; margin: 4px 0 8px; }
.t-why { color: var(--muted); font-size: .88em; font-weight: 600; margin-top: 3px; }
.f-why { font-size: 1.05em; font-weight: 600; opacity: .8; margin-top: 2px; }
.t-actions { display: flex; gap: 6px; justify-content: center; }

/* first discovery */
.fd-banner { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; pointer-events: none; background: rgba(28,26,24,.35); animation: fadein .2s; }
.f-inner { background: var(--gold); color: #1c1a18; border-radius: 28px; padding: 28px 48px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.3); animation: slam .5s cubic-bezier(.2,1.6,.4,1); border: 4px solid var(--ink); }
.f-kicker { font-size: 2.2em; font-weight: 900; letter-spacing: -.02em; }
.f-emoji { font-size: 4em; line-height: 1.1; margin-top: 6px; }
.f-name { font-size: 2.6em; font-weight: 900; }
.f-by { font-size: 1.1em; font-weight: 700; margin-top: 4px; }
@keyframes slam { 0% { transform: scale(2.2) rotate(-6deg); opacity: 0; } 100% { transform: scale(1) rotate(0); opacity: 1; } }
@keyframes fadein { from { opacity: 0; } }
.confetti { position: absolute; inset: 0; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 2px; animation: fall 1.8s linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* modals */
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(28,26,24,.45); display: grid; place-items: center; padding: 16px; }
.sheet { position: relative; background: var(--panel); border-radius: 22px; padding: 24px; width: min(520px, 100%); max-height: 90vh; overflow: auto; }
.sheet.wide { width: min(760px, 100%); }
.sheet.center { text-align: center; }
.sheet h2 { margin: .2em 0 .4em; font-size: 1.6em; }
.x { position: absolute; right: 12px; top: 12px; font-size: .85em; color: var(--muted); }
.kicker { color: var(--accent); font-weight: 800; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.row.wrap { flex-wrap: wrap; justify-content: center; }
.row input { flex: 1; }
.check { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
#castBg .on { border-color: var(--accent); background: #fff1ec; }
.qr { display: grid; place-items: center; margin: 12px auto; }
.qr img, .qr canvas { width: 220px; height: 220px; image-rendering: pixelated; }
.link { font-weight: 700; word-break: break-all; }
#donePreview { width: 270px; height: auto; border-radius: 14px; border: 1px solid var(--line); margin: 8px auto; display: block; }
.tabs { display: flex; gap: 6px; align-items: center; margin: 10px 0; flex-wrap: wrap; }
.tab { border: 1.5px solid var(--line); }
.tab.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.seedtoggle { margin-left: auto; font-size: .85em; color: var(--muted); display: flex; gap: 4px; align-items: center; }
.dex { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.dex li { display: grid; grid-template-columns: 2.2em 1fr auto; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 12px; }
.dex .rank { color: var(--muted); font-weight: 700; text-align: right; }
.dex .nm { font-weight: 700; }
.dex .sub { color: var(--muted); font-size: .85em; }
.dex .seed { font-size: .7em; color: var(--muted); border: 1px dashed var(--muted); border-radius: 999px; padding: 0 .5em; margin-left: .4em; }
.dex .right { text-align: right; font-size: .9em; color: var(--muted); white-space: nowrap; }
.dex .empty { display: block; text-align: center; color: var(--muted); border: 0; }

/* broadcast mode */
body.cast { --fs: 21px; --chipfs: 24px; --line: #cfc6ba; --muted: #4f4943; }
body.cast .nick, body.cast #mNick { display: none !important; }
body.cast .chip { border-width: 2.5px; border-color: #1c1a18; padding: .5em .9em; }
body.cast .top { padding: 14px 22px; }
body.cast .inv { width: 430px; }
body.cast .be-1 { font-size: 1.6em; }
body.cast .f-inner { transform-origin: center; padding: 40px 72px; }
body.cast .f-kicker { font-size: 3.2em; }
body.cast .f-name { font-size: 3.6em; }
body.cast.bg-dark { --bg: #121110; --panel: #1d1b19; --ink: #fbf7f1; --muted: #c9c1b6; --line: #3a3632; --board: #17110d; --dot: #2c2622; --chip: #262320; }
body.cast.bg-dark .chip { border-color: #fbf7f1; }
body.cast.bg-dark .chip.first { background: #4a3a10; border-color: var(--gold); }
body.cast.bg-dark .mission-chip { background: #3a1d15; border-color: #7a3424; }
body.cast.bg-dark .mission-bar { background: #fbf7f1; color: #121110; }
body.cast.bg-dark .mission-bar .ghost { color: #121110; border-color: #aaa; }
body.cast.bg-dark .logo { background: var(--accent); color: #fff; }
body.cast.bg-chroma .board { background: #00b140; background-image: none; }
body.cast.bg-chroma .board-empty, body.cast.bg-chroma .board-clear { display: none; }
body.cast.bg-clean .board { background: #ffffff; background-image: none; }

/* phone */
@media (max-width: 760px) {
  .top { flex-wrap: wrap; gap: 8px; padding: 8px 10px; }
  .brand { font-size: 1em; }
  .mission-chip { order: 3; margin-left: 0; width: 100%; justify-content: center; }
  .actions { margin-left: auto; }
  .actions button { padding: .4em .7em; font-size: .85em; }
  .play { flex-direction: column; }
  .board { flex: 0 0 38%; }
  .be-1 { font-size: 1.1em; }
  .be-2 { font-size: .85em; }
  .inv { width: auto; flex: 1; border-left: 0; border-top: 1px solid var(--line); }
  .inv-list { gap: 6px; padding: 8px; }
  .chip { font-size: 16px; padding: .45em .7em; }
  .chatbar { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
  .cb-label { display: none; }
  .chatbar input { flex: 1; }
  .cb-msg { display: none; }
  .mission-bar { gap: 10px; padding: 6px 10px; font-size: .9em; flex-wrap: wrap; }
  .toast { top: 118px; bottom: auto; width: calc(100% - 24px); padding: 8px 12px; min-width: 0; }
  .t-meta { margin: 2px 0 6px; }
  .f-inner { padding: 22px 26px; }
  .f-kicker { font-size: 1.7em; }
  .f-name { font-size: 2em; }
  body.cast { --fs: 17px; --chipfs: 18px; }
  body.cast .inv { width: auto; }
  body.cast .chip { border-width: 2px; padding: .4em .65em; }
  body.cast .top { padding: 8px 10px; }
  body.cast .f-kicker { font-size: 2em; }
  body.cast .f-name { font-size: 2.3em; }
  body.cast .f-inner { padding: 24px 28px; }
}
body.cast .f-why { font-size: 1.5em; }

/* consent notice (nickname dialog + first-discovery banner) */
.consent { color: var(--muted); font-size: .78em; margin: 8px 0 0; }
.f-consent { font-size: .72em; font-weight: 600; opacity: .7; margin-top: 8px; }
body.cast .f-consent { font-size: .9em; }

/* ?replay= capture mode: deterministic, JS-driven frames (no CSS animations) */
.replay .fd-banner, .replay .f-inner, .replay .confetti i, .replay .board .chip { animation: none !important; transition: none !important; }
.replay #btnNick, .replay .board-clear { visibility: hidden; }
.replay .toast { transform: translateX(-50%); }
.replay .confetti i { top: -20px; }
.replay-finger { position: absolute; left: 0; top: 0; width: 34px; height: 34px; border-radius: 50%; background: rgba(28,26,24,.28); border: 3px solid rgba(255,255,255,.9); box-shadow: 0 2px 10px rgba(0,0,0,.25); pointer-events: none; z-index: 8; opacity: 0; }
.replay .f-inner { position: relative; z-index: 2; }
.replay .confetti { z-index: 1; }
