/* ---------- themes ---------- */
:root, [data-theme="neon"] {
  --bg: #0b0f1a; --surface: #141a2a; --surface2: #1d2540; --border: #2a3456;
  --text: #eef2ff; --muted: #8b95b8; --accent: #00e5ff; --accent-text: #001a1f; --accent2: #ff2bd6;
  --danger: #ff4d6d; --warn: #ffc53d; --ok: #3ddc84; --hider: #3ddc84; --seeker: #ff4d6d;
  --shadow: 0 6px 24px rgba(0,0,0,.45); --mask: rgba(5,8,16,.62);
}
[data-theme="midnight"] {
  --bg: #000; --surface: #0e0e12; --surface2: #18181f; --border: #26262f;
  --text: #f4f4f5; --muted: #8a8a96; --accent: #a78bfa; --accent-text: #120a2a; --accent2: #f472b6;
  --danger: #f87171; --warn: #fbbf24; --ok: #4ade80; --hider: #4ade80; --seeker: #f87171; --mask: rgba(0,0,0,.65);
}
[data-theme="light"] {
  --bg: #f4f6fb; --surface: #ffffff; --surface2: #eef1f8; --border: #d8deea;
  --text: #121826; --muted: #5d6680; --accent: #2563eb; --accent-text: #fff; --accent2: #db2777;
  --danger: #dc2626; --warn: #d97706; --ok: #16a34a; --hider: #16a34a; --seeker: #dc2626;
  --shadow: 0 6px 20px rgba(20,30,60,.12); --mask: rgba(20,24,40,.45);
}
[data-theme="forest"] {
  --bg: #0f1a12; --surface: #17251a; --surface2: #203324; --border: #2e4733;
  --text: #ecf5e9; --muted: #93ab93; --accent: #9be15d; --accent-text: #102006; --accent2: #f6c453;
  --danger: #ff6b5b; --warn: #f6c453; --ok: #9be15d; --hider: #9be15d; --seeker: #ff6b5b; --mask: rgba(8,14,9,.6);
}
[data-theme="ocean"] {
  --bg: #061a2b; --surface: #0b2840; --surface2: #113553; --border: #1b4a70;
  --text: #e6f4ff; --muted: #86a9c7; --accent: #38bdf8; --accent-text: #021523; --accent2: #2dd4bf;
  --danger: #fb7185; --warn: #fcd34d; --ok: #2dd4bf; --hider: #2dd4bf; --seeker: #fb7185; --mask: rgba(3,14,24,.6);
}
[data-theme="sunset"] {
  --bg: #1d0f1f; --surface: #2a1630; --surface2: #3a1f40; --border: #553058;
  --text: #fff1ea; --muted: #c49aa8; --accent: #ff8a3d; --accent-text: #2a0f00; --accent2: #ff4f8b;
  --danger: #ff4f6b; --warn: #ffd166; --ok: #7ae582; --hider: #7ae582; --seeker: #ff4f6b; --mask: rgba(18,6,20,.6);
}
[data-theme="contrast"] {
  --bg: #000; --surface: #000; --surface2: #111; --border: #fff;
  --text: #fff; --muted: #ddd; --accent: #ffff00; --accent-text: #000; --accent2: #00ffff;
  --danger: #ff3030; --warn: #ffff00; --ok: #00ff66; --hider: #00ff66; --seeker: #ff3030; --mask: rgba(0,0,0,.7);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
body { overflow: hidden; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
h1, h2, h3 { margin: .3em 0; }
h3 { font-size: 15px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-top: 22px; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }

/* ---------- controls ---------- */
.btn { appearance: none; border: 1px solid var(--border); background: var(--surface2); color: var(--text); border-radius: 12px; padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer; position: relative; touch-action: manipulation; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.big { padding: 15px 20px; font-size: 18px; width: 100%; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.icon { width: 44px; height: 44px; padding: 0; font-size: 18px; }
.btn.round { width: 52px; height: 52px; border-radius: 50%; padding: 0; font-size: 22px; box-shadow: var(--shadow); }
input, select { font: inherit; color: var(--text); background: var(--surface2); border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; width: 100%; min-width: 0; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field { display: block; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.row { display: flex; gap: 10px; align-items: center; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px; }
.badge { position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px; border-radius: 10px; background: var(--accent2); color: #fff; font: 700 12px/20px system-ui; font-style: normal; padding: 0 5px; }
.tabs .badge { position: static; display: inline-block; margin-left: 6px; }

/* ---------- home ---------- */
.home-wrap { margin: auto; width: min(420px, 100%); padding: 24px 18px; display: flex; flex-direction: column; gap: 16px; overflow-y: auto; max-height: 100%; }
.logo { text-align: center; color: var(--accent); }
.logo h1 { color: var(--text); font-size: 34px; letter-spacing: .02em; }
.logo p { margin: 0; }
.or { text-align: center; color: var(--muted); font-size: 13px; position: relative; }
.or::before, .or::after { content: ""; position: absolute; top: 50%; width: 38%; height: 1px; background: var(--border); }
.or::before { left: 0; } .or::after { right: 0; }
.code-input { text-transform: uppercase; letter-spacing: .35em; font-size: 22px; font-weight: 700; text-align: center; flex: 1; }
.row .btn.big { width: auto; flex: 0 0 auto; }
.home-foot { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.rules-tools { padding: 0 0 10px; }
.saved-list .thumb { width: 44px; height: 44px; flex: none; display: grid; place-items: center; color: var(--accent); font-size: 22px; }
.saved-list .nm small { display: block; color: var(--muted); font-size: 12px; }
.saved-list .acts { display: flex; gap: 6px; }

/* ---------- lobby ---------- */
.lobby-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; gap: 8px; }
.code-pill { display: flex; align-items: center; gap: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 6px 16px; font: inherit; cursor: pointer; }
.code-pill small { color: var(--muted); font-size: 12px; }
.code-pill b { font-size: 24px; letter-spacing: .2em; color: var(--accent); }
.tabs { display: flex; border-bottom: 1px solid var(--border); padding: 0 6px; }
.tabs button { flex: 1; background: none; border: 0; color: var(--muted); font: 600 14px system-ui; padding: 12px 4px; border-bottom: 3px solid transparent; cursor: pointer; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.tab-body { flex: 1; min-height: 0; position: relative; }
.tab { display: none; position: absolute; inset: 0; overflow-y: auto; padding: 12px; }
.tab.on { display: block; }
#tab-area { padding: 0; display: none; flex-direction: column; overflow: hidden; }
#tab-area.on { display: flex; }
#tab-chat { padding: 0; }
#tab-chat.on { display: flex; }
.map { background: var(--surface2); }
#lobby-map { flex: 1; min-height: 200px; }
.area-tools { display: flex; gap: 8px; padding: 10px 12px 4px; }
.area-tools .btn { flex: 1; padding: 10px 6px; font-size: 14px; }
.area-info { padding: 4px 12px 10px; font-size: 13px; }
.lobby-foot { padding: 10px 12px 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
#start-hint { text-align: center; }

.plist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.plist li { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
.dot { width: 28px; height: 28px; border-radius: 50%; flex: 0 0 auto; display: grid; place-items: center; font-weight: 800; font-size: 13px; color: #111; }
.plist .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.plist .nm small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.tag { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: var(--surface2); color: var(--muted); white-space: nowrap; }
.tag.ok { color: var(--ok); } .tag.bad { color: var(--danger); } .tag.warn { color: var(--warn); }
.tag.hider { background: var(--hider); color: #06200f; } .tag.seeker { background: var(--seeker); color: #2a0008; }
.plist .acts { display: flex; gap: 4px; }
.team-btns { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.team-btns .btn { flex: 1; border-width: 2px; }

/* rules form */
#rules fieldset { border: 1px solid var(--border); border-radius: 14px; margin: 0 0 12px; padding: 10px 12px 12px; background: var(--surface); }
#rules legend { font-weight: 700; padding: 0 6px; }
.rule { display: grid; grid-template-columns: 1fr minmax(130px, 46%); gap: 10px; align-items: center; padding: 6px 0; }
.rule > span { font-size: 14px; }
.rule > span small { display: block; color: var(--muted); font-size: 12px; }
.rule input[type="checkbox"] { width: 26px; height: 26px; justify-self: end; accent-color: var(--accent); }
.rule.dim { opacity: .4; }
#rules:not(.host) input, #rules:not(.host) select { pointer-events: none; opacity: .85; }
.host-note { margin: 0 0 10px; text-align: center; }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; width: 100%; height: 100%; min-height: 0; }
.chips { display: flex; gap: 6px; padding: 8px 10px; overflow-x: auto; flex: 0 0 auto; scrollbar-width: none; }
.chip { flex: 0 0 auto; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 6px 12px; font: 600 13px system-ui; cursor: pointer; position: relative; }
.chip.on { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.chip .badge { top: -6px; right: -6px; }
.chat-log { flex: 1; overflow-y: auto; padding: 8px 12px; display: flex; flex-direction: column; gap: 6px; min-height: 120px; }
.msg { max-width: 85%; background: var(--surface); border: 1px solid var(--border); padding: 7px 11px; border-radius: 14px 14px 14px 4px; align-self: flex-start; word-wrap: break-word; }
.msg.mine { align-self: flex-end; background: var(--surface2); border-radius: 14px 14px 4px 14px; }
.msg b { font-size: 12px; display: block; }
.msg time { font-size: 10px; color: var(--muted); margin-left: 6px; }
.msg.sys { align-self: center; background: none; border: 0; color: var(--muted); font-size: 12px; padding: 2px; }
.chat-form { display: flex; gap: 8px; padding: 8px 10px; border-top: 1px solid var(--border); }
.chat-form .btn { flex: 0 0 auto; }

/* ---------- game ---------- */
.map.full { position: absolute; inset: 0; }
.hud { position: absolute; top: env(safe-area-inset-top); left: 0; right: 0; padding: 10px; pointer-events: none; z-index: 500; display: flex; flex-direction: column; gap: 8px; }
.hud > * { pointer-events: auto; }
.hud-top { display: flex; align-items: center; gap: 8px; }
.role-badge { padding: 8px 12px; border-radius: 12px; font-weight: 800; font-size: 14px; letter-spacing: .05em; box-shadow: var(--shadow); background: var(--surface); }
.role-badge.hider { background: var(--hider); color: #06200f; }
.role-badge.seeker { background: var(--seeker); color: #2a0008; }
.timer-box { flex: 1; text-align: center; background: var(--surface); border-radius: 12px; padding: 4px 8px; box-shadow: var(--shadow); }
.timer-box small { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.timer-box b { font-size: 26px; font-variant-numeric: tabular-nums; }
.timer-box.urgent b { color: var(--danger); }
.hud-stats { background: var(--surface); padding: 8px 10px; border-radius: 12px; font-weight: 700; font-size: 14px; box-shadow: var(--shadow); white-space: nowrap; }
.hud-info { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.hud-info { flex-wrap: nowrap; }
.hud-info .tile { position: relative; overflow: hidden; flex: 1 1 0; min-width: 0; max-width: 160px; background: var(--surface); border-radius: 12px; padding: 5px 8px 7px; box-shadow: var(--shadow); text-align: center; }
.hud-info .tile small { display: block; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-info .tile b { font-size: 18px; font-variant-numeric: tabular-nums; }
.hud-info .tile i { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); transition: width 1s linear; }
.hud-info .tile.urgent { animation: tile-pulse 1s ease-in-out infinite; }
.hud-info .tile.urgent b { color: var(--danger); }
.hud-info .tile.urgent i { background: var(--danger); }
@keyframes tile-pulse { 50% { box-shadow: 0 0 0 3px var(--danger); } }
.bo-info { margin: 0 auto 18px; max-width: 420px; }
.banner { padding: 10px 14px; border-radius: 12px; font-weight: 700; box-shadow: var(--shadow); text-align: center; animation: pulse 1.2s infinite; }
.banner.danger { background: var(--danger); color: #fff; }
.banner.warn { background: var(--warn); color: #221800; }
@keyframes pulse { 50% { opacity: .78; } }
.map-btns { position: absolute; right: 12px; bottom: calc(96px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; z-index: 500; }
.game-bar { position: absolute; left: 0; right: 0; bottom: 0; padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 12px; z-index: 500; }
.game-bar .action { flex: 1; padding: 16px; font-size: 18px; border-radius: 16px; box-shadow: var(--shadow); }
.game-bar .action.seek { background: var(--seeker); color: #fff; }
.game-bar .action.hide { background: var(--hider); color: #06200f; }

.blackout { position: absolute; inset: 0; z-index: 900; background: var(--bg); display: grid; place-items: center; text-align: center; padding: 24px; }
.bo-eye { font-size: 72px; }
.bo-timer { font-size: 72px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--accent); margin: 16px 0; }

/* map markers */
.pm { width: 30px; height: 30px; border-radius: 50%; border: 3px solid #fff; display: grid; place-items: center; font: 800 12px system-ui; color: #111; box-shadow: 0 2px 8px rgba(0,0,0,.5); }
.pm.me { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(255,255,255,.25), 0 0 18px var(--accent); }
.pm.seeker { border-color: var(--seeker); }
.pm.stale { opacity: .45; }
.pm-label { position: absolute; top: 30px; left: 50%; transform: translateX(-50%); white-space: nowrap; font: 700 11px system-ui; color: #fff; text-shadow: 0 1px 3px #000, 0 0 2px #000; }
.rv { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font: 900 16px system-ui; color: #fff; background: var(--danger); border: 3px solid #fff; animation: pulse 1s infinite; }
.rv-label { position: absolute; top: 34px; left: 50%; transform: translateX(-50%); white-space: nowrap; font: 700 11px system-ui; color: #fff; text-shadow: 0 1px 3px #000; }
.leaflet-container { background: var(--surface2); font: inherit; }
.leaflet-control-attribution { font-size: 9px; opacity: .7; }

/* ---------- sheets & modals ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1000; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; height: 72vh; background: var(--bg); border-radius: 18px 18px 0 0; z-index: 1001; display: flex; flex-direction: column; box-shadow: var(--shadow); padding-bottom: env(safe-area-inset-bottom); border-top: 1px solid var(--border); }
.sheet-grab { width: 44px; height: 5px; border-radius: 3px; background: var(--border); margin: 8px auto; flex: 0 0 auto; }
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; }
#sheet-players .sheet-body { padding: 0 12px 12px; gap: 12px; }
.modal { position: fixed; inset: 0; z-index: 2000; background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 16px; }
.modal-card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 20px; width: min(420px, 100%); max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal-card h2 { margin-top: 0; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions .btn { flex: 1; }
.share-qr { display: block; width: 220px; height: 220px; margin: 10px auto; background: #fff; border-radius: 12px; padding: 8px; }
.pref-grid { display: flex; flex-direction: column; gap: 14px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 44px; height: 44px; border-radius: 12px; border: 2px solid var(--border); cursor: pointer; display: grid; place-items: center; font-size: 10px; font-weight: 700; }
.swatch.on { outline: 3px solid var(--accent); outline-offset: 2px; }
.seg { display: flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; background: var(--surface2); color: var(--text); border: 0; padding: 10px 6px; font: 600 14px system-ui; cursor: pointer; }
.seg button.on { background: var(--accent); color: var(--accent-text); }
.checks { display: flex; flex-direction: column; gap: 6px; max-height: 40vh; overflow-y: auto; }
.checks label { display: flex; align-items: center; gap: 10px; padding: 8px; background: var(--surface2); border-radius: 10px; }
.checks input { width: 22px; height: 22px; }

.qr-view { position: fixed; inset: 0; z-index: 3000; background: #fff; color: #111; display: grid; place-items: center; text-align: center; padding: 20px; }
.qr-inner { width: min(420px, 100%); }
.qr-view img { width: min(80vw, 360px); height: min(80vw, 360px); image-rendering: pixelated; }
.qr-code { font: 800 34px ui-monospace, monospace; letter-spacing: .25em; margin: 8px 0; }
.qr-view .btn { background: #111; color: #fff; }

.scanner { position: fixed; inset: 0; z-index: 3000; background: #000; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-frame { position: absolute; left: 50%; top: 40%; width: 64vw; height: 64vw; max-width: 320px; max-height: 320px; transform: translate(-50%, -50%); border: 4px solid var(--accent); border-radius: 18px; box-shadow: 0 0 0 9999px rgba(0,0,0,.45); }
.scan-ui { position: absolute; left: 0; right: 0; bottom: 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; color: #fff; text-align: center; }
.scan-ui input { text-transform: uppercase; letter-spacing: .2em; text-align: center; font-weight: 700; }

#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(92px + env(safe-area-inset-bottom)); flex-direction: column-reverse; z-index: 4000; display: flex; flex-direction: column; gap: 8px; width: min(420px, 92vw); pointer-events: none; }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--accent); padding: 10px 14px; border-radius: 12px; box-shadow: var(--shadow); font-weight: 600; animation: tin .25s ease-out; }
.toast.danger { border-left-color: var(--danger); } .toast.warn { border-left-color: var(--warn); } .toast.ok { border-left-color: var(--ok); }
@keyframes tin { from { transform: translateY(-12px); opacity: 0; } }
.conn { position: fixed; top: calc(6px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 5000; background: var(--warn); color: #221800; padding: 4px 12px; border-radius: 999px; font: 700 12px system-ui; }

/* ---------- end ---------- */
.end-wrap { overflow-y: auto; padding: 16px 14px 40px; width: min(720px, 100%); margin: 0 auto; }
.winner { text-align: center; padding: 22px 12px; border-radius: 18px; background: var(--surface); border: 1px solid var(--border); }
.winner .big { font-size: 34px; font-weight: 900; }
.winner.hiders .big { color: var(--hider); } .winner.seekers .big { color: var(--seeker); }
.map.replay { height: 46vh; border-radius: 14px; overflow: hidden; }
.replay-ctl { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.replay-ctl input { flex: 1; padding: 0; accent-color: var(--accent); }
.replay-ctl .btn.round { width: 44px; height: 44px; font-size: 18px; }
.results { width: 100%; border-collapse: collapse; font-size: 14px; }
.results th, .results td { padding: 8px 6px; border-bottom: 1px solid var(--border); text-align: left; }
.results th { color: var(--muted); font-weight: 600; font-size: 12px; }
.timeline { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.timeline li { background: var(--surface); padding: 8px 12px; border-radius: 10px; border: 1px solid var(--border); }
.timeline time { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 8px; }
.end-actions { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; }
.end-actions .btn { flex: 1; }
.team-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--surface); border-radius: 10px; margin-top: 8px; border: 1px solid var(--border); }
.team-row .sw { width: 16px; height: 16px; border-radius: 4px; }

@media (min-width: 900px) {
  .sheet { left: auto; width: 420px; height: 100vh; border-radius: 0; top: 0; }
}
