:root {
  --bg: #0b1220; --panel: rgba(18, 24, 44, 0.92); --panel2: rgba(30, 38, 66, 0.95); --line: rgba(255, 255, 255, 0.14);
  --ink: #f4efe6; --dim: #b8b3c8; --gold: #ffd25a; --go: #3fbf6a; --red: #e8453c; --blue: #3d6ff0; --mole: #c0612f;
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px); --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: ui-rounded, 'SF Pro Rounded', 'Segoe UI Rounded', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
body { background: radial-gradient(ellipse at 50% 0%, #1d2a52 0%, var(--bg) 70%); }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
input { font: inherit; }

/* ------------------------------------------------------------------ menus */
#ui { position: fixed; inset: 0; overflow: auto; padding: calc(12px + var(--safe-t)) calc(12px + var(--safe-r)) calc(12px + var(--safe-b)) calc(12px + var(--safe-l)); }
.menu { max-width: 980px; margin: 0 auto; display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; align-items: flex-start; }
.brand { flex: 1 1 100%; text-align: center; }
.brand h1 { margin: 0; font-size: clamp(34px, 7vw, 64px); letter-spacing: 1px; color: var(--gold); text-shadow: 0 4px 0 #6b3d14, 0 8px 24px rgba(0, 0, 0, 0.6); }
.brand .tag { margin: 4px 0 0; color: var(--dim); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 14px; flex: 1 1 300px; max-width: 460px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35); }
.card label { display: block; margin: 10px 0 6px; font-weight: 700; color: var(--dim); font-size: 14px; }
.card h2 { margin: 2px 0 10px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
.namerow, .joinrow { display: flex; gap: 8px; align-items: center; }
.joinrow { margin: 10px 0; }
input.name, input.code, input.chatin { flex: 1; min-width: 0; padding: 12px; border-radius: 12px; border: 2px solid var(--line); background: #0d1428; color: var(--ink); font-size: 18px; }
input.code { text-transform: uppercase; letter-spacing: 3px; font-weight: 800; flex: 0 0 150px; width: 150px; }
.joinrow .btn.big { margin: 0; }
.tagshow { color: var(--dim); font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 2px; border-radius: 12px; border: 2px solid transparent; background: #1a2340; cursor: pointer; }
.chip.on { border-color: var(--gold); background: #2a3560; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(0, 0, 0, 0.4); cursor: pointer; }
.swatch.on { border-color: #fff; box-shadow: 0 0 0 3px var(--gold); }
.swatch.taken { opacity: 0.25; cursor: not-allowed; }
.btn { border: 0; border-radius: 14px; padding: 11px 16px; background: #2d3866; color: var(--ink); font-weight: 800; cursor: pointer; box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35); touch-action: manipulation; }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.big { padding: 15px 18px; font-size: 18px; width: 100%; margin: 6px 0; }
.btn.go { background: linear-gradient(#4fd27c, #2f9e55); color: #082010; }
.btn.danger { background: linear-gradient(#ff6a5a, #c23628); }
.btn.on { background: #5a4ab0; outline: 2px solid var(--gold); }
.btn.small { padding: 8px 12px; }
.btn.tiny { padding: 4px 8px; border-radius: 9px; font-size: 14px; box-shadow: none; }
.btn.icon { width: 46px; height: 46px; padding: 0; font-size: 22px; border-radius: 50%; }
.btn.ghostbtn { background: transparent; border: 2px solid var(--line); box-shadow: none; }
.small { font-size: 13px; color: var(--dim); }
.warn { color: #ffb0a0; }
.footer { flex: 1 1 100%; text-align: center; }
.howto p { line-height: 1.45; }
.busy { text-align: center; }
.spinner { width: 44px; height: 44px; margin: 10px auto; border-radius: 50%; border: 5px solid var(--line); border-top-color: var(--gold); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ play */
#play { position: fixed; inset: 0; touch-action: none; user-select: none; -webkit-user-select: none; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#stick { position: absolute; left: 0; bottom: 0; width: 48%; height: 72%; z-index: 2; }
#stick .base { position: fixed; width: 116px; height: 116px; margin: -58px 0 0 -58px; border-radius: 50%; background: rgba(255, 255, 255, 0.09); border: 2px solid rgba(255, 255, 255, 0.25); opacity: 0; transition: opacity 0.15s; pointer-events: none; }
#stick .knob { position: absolute; left: 31px; top: 31px; width: 50px; height: 50px; border-radius: 50%; background: rgba(255, 255, 255, 0.45); }
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
#hud button { pointer-events: auto; }
.hud-top { position: absolute; top: calc(6px + var(--safe-t)); left: calc(6px + var(--safe-l)); right: calc(6px + var(--safe-r)); display: flex; gap: 8px; align-items: flex-start; }
.hud-left { flex: 0 1 34%; min-width: 150px; }
.hud-mid { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.topbuttons { display: flex; gap: 6px; }
.topbuttons .btn.icon { width: 42px; height: 42px; font-size: 19px; background: rgba(30, 38, 66, 0.85); }
.topbuttons .btn.on { background: #2f9e55; outline: none; }
.topbuttons .btn.off { opacity: 0.45; }
.rolebadge { display: inline-block; padding: 4px 10px; border-radius: 10px; font-weight: 900; font-size: 13px; letter-spacing: 1px; background: var(--blue); }
.rolebadge.mole { background: var(--mole); }
.rolebadge.ghost { background: #6a7a9a; }
.tasks { margin-top: 4px; background: rgba(10, 14, 30, 0.72); border-radius: 12px; padding: 6px 8px; font-size: 12.5px; line-height: 1.35; max-height: 40vh; overflow: hidden; }
.tasks-title { font-weight: 900; color: var(--gold); margin-bottom: 2px; }
.task.done { color: #8fe0a0; text-decoration: line-through; opacity: 0.8; }
.task.static { color: #ffb0a0; }
.bar { position: relative; width: min(46vw, 380px); height: 20px; border-radius: 10px; background: rgba(0, 0, 0, 0.55); border: 2px solid rgba(255, 255, 255, 0.25); overflow: hidden; }
.bar .fill { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, #39b866, #8be36b); transition: width 0.5s; }
.bar .label { position: relative; display: block; text-align: center; font-size: 12px; font-weight: 800; line-height: 16px; text-shadow: 0 1px 2px #000; }
.bar.hidden .fill { background: repeating-linear-gradient(45deg, #555 0 6px, #333 6px 12px); width: 100% !important; }
.alert { max-width: min(60vw, 520px); padding: 6px 12px; border-radius: 12px; font-weight: 800; font-size: 13.5px; text-align: center; background: rgba(200, 60, 40, 0.9); animation: pulse 1s ease-in-out infinite alternate; }
.alert.flood { background: rgba(40, 110, 230, 0.92); }
.alert.gates { background: rgba(130, 90, 40, 0.92); animation: none; }
@keyframes pulse { from { filter: brightness(1); } to { filter: brightness(1.35); } }
.dawn { font-size: 12px; color: #ffd9a0; text-shadow: 0 1px 2px #000; }
.roomname { position: absolute; bottom: calc(10px + var(--safe-b)); left: 50%; transform: translateX(-50%); font-weight: 800; font-size: 13px; color: rgba(255, 255, 255, 0.75); text-shadow: 0 1px 3px #000; }
.actions { position: absolute; right: calc(10px + var(--safe-r)); bottom: calc(10px + var(--safe-b)); display: grid; grid-template-columns: repeat(3, auto); gap: 9px; direction: rtl; }
.act { direction: ltr; width: clamp(62px, 9.5vmin, 84px); height: clamp(62px, 9.5vmin, 84px); border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.55); background: rgba(40, 52, 96, 0.9); font-weight: 900; font-size: clamp(11px, 1.9vmin, 14px); position: relative; touch-action: none; box-shadow: 0 5px 0 rgba(0, 0, 0, 0.35); cursor: pointer; }
.act.use { background: radial-gradient(circle at 40% 30%, #ffe27a, #d79a1e); color: #2a1a00; }
.act.report { background: radial-gradient(circle at 40% 30%, #ff9a7a, #c23628); }
.act.kill { background: radial-gradient(circle at 40% 30%, #ffb070, #a8401a); }
.act.sab { background: radial-gradient(circle at 40% 30%, #c89aff, #6a2fb0); }
.act.tunnel { background: radial-gradient(circle at 40% 30%, #c8a070, #6b4a2e); }
.act.talk { background: radial-gradient(circle at 40% 30%, #8affb0, #2f9e55); color: #062010; }
.act.talk.on { box-shadow: 0 0 0 5px rgba(120, 255, 160, 0.6); }
.act.off { filter: grayscale(0.85) brightness(0.6); }
.act .cd { position: absolute; inset: 0; display: grid; place-items: center; font-size: 22px; text-shadow: 0 2px 3px #000; pointer-events: none; }
.act .cd:empty { display: none; }
.act .lbl { pointer-events: none; }

/* ------------------------------------------------------------------ overlays */
.overlay { position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: calc(10px + var(--safe-t)) calc(10px + var(--safe-r)) calc(10px + var(--safe-b)) calc(10px + var(--safe-l)); overflow: auto; text-align: center; }
.overlay h1 { margin: 6px 0; font-size: clamp(26px, 5vw, 48px); text-shadow: 0 4px 12px rgba(0, 0, 0, 0.7); }
.lobby { background: rgba(6, 10, 24, 0.72); flex-direction: row; flex-wrap: wrap; align-items: stretch; gap: 12px; justify-content: center; text-align: left; }
.lobby-col { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 12px; flex: 1 1 320px; max-width: 480px; overflow: auto; }
.lobby-col h2 { margin: 4px 0 8px; font-size: 18px; }
.roster { display: flex; flex-direction: column; gap: 4px; }
.rrow { display: flex; align-items: center; gap: 8px; padding: 3px 6px; border-radius: 10px; background: rgba(255, 255, 255, 0.04); }
.rrow.me { background: rgba(255, 210, 90, 0.15); }
.rname { font-weight: 800; }
.rtag { color: var(--dim); font-size: 12px; }
.crown { margin-left: auto; }
.invite { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0; }
.code { font-size: 30px; font-weight: 900; letter-spacing: 4px; color: var(--gold); display: flex; flex-direction: column; line-height: 1; margin-right: auto; }
.code small { font-size: 11px; letter-spacing: 1px; color: var(--dim); }
.wait { padding: 14px; text-align: center; color: var(--dim); }
.settings { display: grid; grid-template-columns: 1fr; gap: 3px; }
.setrow { display: flex; align-items: center; gap: 6px; padding: 3px 6px; background: rgba(255, 255, 255, 0.04); border-radius: 8px; }
.setrow .sk { flex: 1; font-size: 14px; }
.setrow .sv { min-width: 64px; text-align: center; font-weight: 800; }
.pick { margin-bottom: 8px; font-weight: 700; color: var(--dim); }
.intro { background: radial-gradient(circle, rgba(20, 40, 90, 0.92), rgba(4, 6, 16, 0.98)); animation: fadein 0.5s; }
.intro.mole { background: radial-gradient(circle, rgba(110, 40, 20, 0.92), rgba(16, 4, 4, 0.98)); }
.intro.mole h1 { color: #ff8a5a; }
.intro.crew h1 { color: #8ab4ff; }
.lineup { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin: 10px 0; }
.lu { display: flex; flex-direction: column; align-items: center; font-weight: 800; font-size: 13px; padding: 4px; border-radius: 12px; }
.lu.mole { background: rgba(200, 80, 40, 0.35); }
@keyframes fadein { from { opacity: 0; transform: scale(1.06); } }
.meeting { background: linear-gradient(rgba(30, 20, 50, 0.96), rgba(10, 8, 24, 0.98)); justify-content: flex-start; }
.chat-open .meeting, .chat-open .lobby { padding-right: calc(min(320px, 42vw) + 16px + var(--safe-r)); }
.mhead h1 { margin: 2px 0; font-size: clamp(22px, 4.2vw, 40px); }
.mhead.body h1 { color: #ff7a6a; }
.mhead.bell h1 { color: var(--gold); }
.mhead p { margin: 0; color: var(--dim); }
.mtimer { font-weight: 900; font-size: 18px; margin: 4px 0 8px; color: #ffe9b0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(138px, 1fr)); gap: 8px; width: min(100%, 860px); }
.dot { animation: pop 0.35s backwards; }
@keyframes pop { from { transform: scale(0); } 70% { transform: scale(1.4); } }
.cardwrap { position: relative; }
.card.dead, .card.dead:disabled { opacity: 0.5; }
button.card { width: 100%; display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 14px; border: 3px solid transparent; background: #2a2f52; cursor: pointer; text-align: left; max-width: none; flex: none; box-shadow: none; position: relative; min-height: 62px; }
button.card:disabled { cursor: default; opacity: 0.92; }
button.card.chosen { border-color: var(--gold); background: #4a3f20; }
button.card.speaking { box-shadow: 0 0 0 3px rgba(120, 255, 160, 0.8); }
button.card.me { background: #303a66; }
.cname { font-weight: 800; font-size: 13px; overflow: hidden; overflow-wrap: anywhere; line-height: 1.1; max-height: 2.3em; flex: 1; }
.badge { position: absolute; top: 2px; right: 6px; color: #8fe0a0; font-weight: 900; }
.votes { position: absolute; bottom: 3px; right: 6px; display: flex; flex-wrap: wrap; gap: 2px; max-width: 60%; justify-content: flex-end; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 1.5px solid rgba(0, 0, 0, 0.5); }
.mutebtn { position: absolute; top: -6px; left: -6px; }
.mfoot { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; margin-top: 10px; width: min(100%, 620px); }
.mfoot .btn.big { width: auto; flex: 1 1 200px; }
.skipres { display: flex; gap: 4px; align-items: center; font-weight: 800; }
.eject { background: #0b1030; padding: 0; }
.eject-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.eject-text { position: relative; margin-top: -10vh; max-width: 90vw; font-size: clamp(22px, 4.4vw, 42px) !important; }
.eject-sub { position: relative; font-size: 18px; font-weight: 800; color: #ffd9a0; }
.results { background: radial-gradient(circle, rgba(20, 60, 40, 0.94), rgba(4, 10, 6, 0.98)); }
.results.moles { background: radial-gradient(circle, rgba(110, 40, 20, 0.94), rgba(16, 4, 4, 0.98)); }
.results .row { justify-content: center; }
.results .btn.big { width: auto; }
.youres { font-size: 40px; margin: 0; }
.sab { background: rgba(10, 6, 24, 0.85); }
.sab .sabgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; width: min(100%, 560px); margin-bottom: 8px; }
.map { background: rgba(4, 6, 16, 0.92); }
.minimap { width: min(96vw, 160vh); height: min(60vw, 92vh); }
.task { background: rgba(4, 6, 16, 0.78); z-index: 8; }
.task-panel { background: var(--panel2); border: 3px solid #8a6a44; border-radius: 20px; padding: 8px; max-width: 100%; }
.task-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.task-head h2 { margin: 0 4px; font-size: 18px; }
.task-panel p { margin: 2px 6px 6px; color: var(--dim); font-size: 13px; text-align: left; }
.task-canvas { display: block; width: min(92vw, calc((100vh - 130px) * 4 / 3), 640px); aspect-ratio: 4 / 3; border-radius: 12px; touch-action: none; background: #111; }
.pause { background: rgba(4, 6, 16, 0.85); z-index: 9; }
.pause .card { max-width: 420px; width: 100%; text-align: left; }
.pause input[type=range] { width: 100%; }
.chat { position: absolute; z-index: 7; right: calc(6px + var(--safe-r)); top: calc(56px + var(--safe-t)); bottom: calc(6px + var(--safe-b)); width: min(320px, 42vw); display: flex; flex-direction: column; background: rgba(12, 16, 32, 0.92); border: 1px solid var(--line); border-radius: 14px; padding: 6px; }
.chathead { display: flex; justify-content: space-between; align-items: center; padding: 0 4px 4px; }
.chatlist { flex: 1; overflow-y: auto; font-size: 14px; line-height: 1.35; padding: 2px 4px; word-break: break-word; text-align: left; }
.cline.ghost { opacity: 0.8; font-style: italic; }
.chatform { display: flex; gap: 6px; }
.chatnote { margin: 2px 4px; }
.chatin { font-size: 15px !important; padding: 8px !important; }
.netnote { position: absolute; z-index: 10; top: calc(50px + var(--safe-t)); left: 50%; transform: translateX(-50%); background: rgba(200, 120, 20, 0.95); padding: 6px 14px; border-radius: 12px; font-weight: 800; }
#toast { position: fixed; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translate(-50%, 120px); background: rgba(20, 26, 50, 0.96); border: 1px solid var(--line); padding: 10px 16px; border-radius: 14px; font-weight: 700; z-index: 20; transition: transform 0.25s; max-width: 90vw; text-align: center; }
#toast.on { transform: translate(-50%, 0); }
canvas.portrait { display: block; flex: none; }
canvas.hero { display: block; margin: 0 auto; }

/* Phones in landscape: compact everything vertically. */
@media (max-height: 460px) {
  .tasks { font-size: 11.5px; max-height: 46vh; }
  .brand h1 { font-size: 34px; }
  .card { padding: 10px; }
  .btn.big { padding: 11px 14px; font-size: 16px; }
  .overlay h1 { font-size: 26px; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 5px; }
  button.card { min-height: 50px; padding: 3px; }
  .lobby-col { padding: 8px; }
  .meeting .mtimer { margin: 0 0 4px; }
}
/* Phones upright: the chat goes to the bottom, the buttons get a bit smaller. */
@media (max-width: 600px) and (orientation: portrait) {
  .chat { left: calc(6px + var(--safe-l)); width: auto; top: 52%; }
  .hud-left { flex-basis: 46%; }
  .bar { width: 40vw; }
  .act { width: 60px; height: 60px; font-size: 11px; }
  .topbuttons .btn.icon { width: 36px; height: 36px; font-size: 16px; }
}
