/* ============================================================
   SHARED BASE — Roblox-inspired: chunky borders, punchy plastic
   colors, bold rounded type, springy motion.
   ============================================================ */

:root {
  --bg-deep: #14162b;
  --bg-panel: #1f2242;
  --bg-panel-2: #262a4f;
  --ink: #ffffff;
  --ink-dim: #a9adcf;
  --accent-red: #ff5c5c;
  --accent-green: #4be38a;
  --accent-yellow: #ffcf4d;
  --accent-blue: #4d9bff;
  --accent-purple: #b57bff;
  --accent-orange: #ff9d4d;
  --border-dark: #0c0d1c;
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-chunk: 0 6px 0 var(--border-dark), 0 10px 24px rgba(0,0,0,0.35);
  --shadow-chunk-sm: 0 4px 0 var(--border-dark), 0 6px 14px rgba(0,0,0,0.3);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%; background: var(--bg-deep); color: var(--ink);
  font-family: "Nunito", sans-serif; overflow-x: hidden;
}
h1, h2, h3, .brand, .btn, .round-pill, .timer-pill, .winner-name {
  font-family: "Baloo 2", "Nunito", sans-serif;
}

#bg-blobs { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.blob { position: absolute; border-radius: 50%; filter: blur(60px); opacity: 0.35; }
.blob-a { width: 420px; height: 420px; background: var(--accent-purple); top: -120px; left: -100px; }
.blob-b { width: 380px; height: 380px; background: var(--accent-blue); bottom: -140px; right: -80px; }
.blob-c { width: 300px; height: 300px; background: var(--accent-green); bottom: 10%; left: 40%; opacity: 0.2; }

.screen {
  position: relative; z-index: 1; display: none; min-height: 100vh;
  padding: 24px 16px; align-items: center; justify-content: center; flex-direction: column;
}
.screen.active { display: flex; animation: screenIn 0.35s ease; }
@keyframes screenIn { from { opacity: 0; transform: translateY(14px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

.brand { text-align: center; margin-bottom: 20px; }
.brand-badge { font-size: 40px; display: inline-block; animation: wiggle 2.6s ease-in-out infinite; }
@keyframes wiggle { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(8deg); } }
.brand h1 {
  font-size: 44px; font-weight: 800; margin: 6px 0 0; color: var(--accent-yellow);
  text-shadow: 3px 3px 0 var(--border-dark); letter-spacing: 1px;
}
.tagline { color: var(--ink-dim); font-weight: 700; margin: 4px 0 0; }

.card {
  background: var(--bg-panel); border: 4px solid var(--border-dark);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-chunk); padding: 26px;
}
.panel { width: 100%; max-width: 380px; }
.panel-wide { max-width: 480px; }
.panel-narrow { max-width: 420px; text-align: center; }
.section-heading { font-size: 22px; font-weight: 700; margin: 0 0 14px; color: var(--ink); }

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block; font-weight: 800; font-size: 13px; color: var(--ink-dim);
  margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px;
}
input[type="text"], select {
  width: 100%; padding: 12px 14px; font-size: 16px; font-weight: 700;
  background: var(--bg-panel-2); color: var(--ink);
  border: 3px solid var(--border-dark); border-radius: var(--radius-sm);
  font-family: "Nunito", sans-serif; outline: none;
}
input[type="text"]:focus, select:focus { border-color: var(--accent-blue); }
input[type="text"]::placeholder { color: #6b7099; }

.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { width: 34px; height: 34px; border-radius: 10px; cursor: pointer; border: 3px solid var(--border-dark); transition: transform 0.15s ease; }
.swatch:hover { transform: translateY(-2px) scale(1.05); }
.swatch.selected { outline: 3px solid var(--ink); outline-offset: 2px; transform: translateY(-2px) scale(1.08); }

.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab-btn {
  flex: 1; padding: 10px; font-weight: 800; font-size: 14px;
  background: var(--bg-panel-2); color: var(--ink-dim);
  border: 3px solid var(--border-dark); border-radius: var(--radius-sm); cursor: pointer;
}
.tab-btn.active { background: var(--accent-blue); color: #fff; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

.btn {
  display: inline-block; text-align: center; cursor: pointer;
  font-weight: 800; font-size: 16px; letter-spacing: 0.3px;
  padding: 13px 20px; border-radius: var(--radius-md);
  border: 3px solid var(--border-dark); box-shadow: var(--shadow-chunk-sm);
  transition: transform 0.08s ease, box-shadow 0.08s ease; user-select: none;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--border-dark); }
.btn-block { display: block; width: 100%; margin-top: 10px; }
.btn-small { padding: 10px 16px; font-size: 14px; margin-top: 0; }
.btn-primary { background: var(--accent-green); color: #06331c; }
.btn-secondary { background: var(--accent-blue); color: #041a3d; }
.btn-ghost { background: var(--bg-panel-2); color: var(--ink-dim); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.error-text { color: var(--accent-red); font-weight: 700; font-size: 14px; min-height: 18px; margin-top: 10px; text-align: center; }
.hint-text { color: var(--ink-dim); font-weight: 700; font-size: 13px; text-align: center; margin: 10px 0; }

.room-code-header { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 18px; }
.room-code-header > span { font-weight: 800; color: var(--ink-dim); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }
.chip-code {
  display: flex; align-items: center; gap: 10px; background: var(--accent-yellow); color: #3a2a00;
  border: 3px solid var(--border-dark); border-radius: var(--radius-md); padding: 10px 18px;
  font-size: 26px; font-weight: 800; letter-spacing: 4px; cursor: pointer;
  box-shadow: var(--shadow-chunk-sm); font-family: "Baloo 2", sans-serif;
}
.chip-code:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--border-dark); }
.copy-icon { font-size: 18px; }

.player-list { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-direction: column; gap: 8px; }
.player-list li {
  display: flex; align-items: center; gap: 10px; background: var(--bg-panel-2);
  border: 3px solid var(--border-dark); border-radius: var(--radius-sm); padding: 10px 12px; font-weight: 700;
}
.player-avatar { width: 28px; height: 28px; border-radius: 8px; border: 2px solid var(--border-dark); flex-shrink: 0; }
.player-list .you-tag { margin-left: auto; font-size: 11px; background: var(--accent-purple); color: #fff; padding: 3px 8px; border-radius: 20px; font-weight: 800; }
.player-list .score-tag { margin-left: auto; font-weight: 800; color: var(--accent-yellow); }

.pulse-dot { width: 22px; height: 22px; border-radius: 50%; background: var(--accent-orange); margin: 0 auto 16px; animation: pulseDot 1.1s ease-in-out infinite; }
@keyframes pulseDot { 0%, 100% { transform: scale(0.8); opacity: 0.7; } 50% { transform: scale(1.25); opacity: 1; } }
.hidden { display: none !important; }

.trophy { font-size: 60px; animation: bounceLite 1s ease-in-out infinite; }
@keyframes bounceLite { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
.winner-name { font-size: 30px; font-weight: 800; color: var(--accent-yellow); text-shadow: 2px 2px 0 var(--border-dark); margin: 6px 0 18px; }
#confetti-layer { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 1; }
.confetti-piece { position: absolute; top: -20px; width: 10px; height: 16px; opacity: 0.9; animation: confettiFall linear forwards; }
@keyframes confettiFall { to { transform: translateY(110vh) rotate(540deg); opacity: 0.9; } }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-panel-2); border: 3px solid var(--border-dark); border-radius: var(--radius-md);
  padding: 10px 18px; font-weight: 700; box-shadow: var(--shadow-chunk-sm); z-index: 50;
}
.toast.hidden { display: none; }

/* ---------- loading screen (progress bar + skeleton) ---------- */
.loading-card { text-align: center; }
.progress-track {
  width: 100%; height: 10px; background: var(--bg-panel-2);
  border: 2px solid var(--border-dark); border-radius: 999px; overflow: hidden; margin-bottom: 16px;
}
.progress-fill { height: 100%; width: 0%; background: var(--accent-green); border-radius: 999px; transition: width 0.3s ease; }
@keyframes shimmer { 0% { background-position: -300px 0; } 100% { background-position: 300px 0; } }
.skeleton-block {
  height: 16px; border-radius: 8px; margin: 10px 0;
  background: linear-gradient(90deg, var(--bg-panel-2) 25%, #ffffff 37%, var(--bg-panel-2) 63%);
  background-size: 400px 100%; animation: shimmer 1.4s ease infinite;
}
.skeleton-chip { height: 34px; width: 60%; margin: 0 auto 16px; border-radius: 20px; }
.skeleton-line.short { width: 70%; }

/* ---------- top HUD chips (dark, matches reference mockup) ---------- */
.stat-chip {
  background: #1c2028; color: #fff; font-weight: 800; font-size: 14px;
  border-radius: 14px; padding: 8px 16px; display: inline-flex; align-items: center; gap: 6px;
}
.wave-chip {
  background: #1c2028; border-radius: 14px; padding: 6px 20px; text-align: center;
}
.wave-chip-title { color: #fff; font-weight: 800; font-size: 15px; letter-spacing: 0.5px; }
.wave-chip-timer { color: #4be38a; font-weight: 800; font-size: 13px; margin-top: 1px; }
.wave-chip-timer.urgent { color: var(--accent-red); animation: urgentPulse 0.5s ease-in-out infinite; }
@keyframes urgentPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.12); } }
.countdown-pill {
  background: var(--accent-red); color: #fff; font-weight: 800; font-size: 13px;
  border-radius: 20px; padding: 4px 12px; display: inline-block; margin-left: 6px;
}
.coin-pill {
  background: var(--bg-panel-2); border: 3px solid var(--border-dark);
  border-radius: 20px; padding: 8px 16px; font-weight: 800; font-size: 14px;
}

/* ---------- claiming screen ---------- */
.claiming-card { max-width: 620px; }

/* ---------- canvas scenes (hallway / room) ---------- */
.scene-wrap {
  width: 100%; aspect-ratio: 16/10; min-height: 200px; margin-top: 12px; position: relative;
  border: 4px solid var(--border-dark); border-radius: var(--radius-lg);
  overflow: hidden; box-shadow: var(--shadow-chunk);
}
.scene-wrap canvas { width: 100%; height: 100%; display: block; cursor: pointer; }

/* ---------- defense layout ---------- */
.defense-layout {
  width: 100%; max-width: 900px; display: grid;
  grid-template-columns: 220px 1fr; gap: 14px; align-items: start; margin: 0 auto;
}
.defense-sidebar { padding: 16px; }
.sidebar-title { margin: 0 0 10px; font-size: 15px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 1px; }
.dorm-scoreboard { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.dorm-entry { display: flex; flex-direction: column; gap: 4px; }
.dorm-entry .dot { width: 12px; height: 12px; border-radius: 4px; border: 2px solid var(--border-dark); display: inline-block; margin-right: 6px; }
.dorm-entry .name { font-weight: 700; font-size: 13px; }
.dorm-entry.eliminated { opacity: 0.5; }
.mini-hp-track { height: 6px; background: var(--bg-panel-2); border-radius: 4px; overflow: hidden; }
.mini-hp-fill { height: 100%; background: var(--accent-green); border-radius: 4px; transition: width 0.4s ease; }

.defense-main { display: flex; flex-direction: column; gap: 12px; }
.topbar { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; }

.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.panel-name { font-weight: 800; font-size: 14px; }

/* coin chip overlaid on the scene, top-right */
.coin-chip {
  position: absolute; top: 8px; right: 8px; z-index: 15;
  background: rgba(20,20,30,0.72); color: #fff; font-weight: 800; font-size: 12px;
  border-radius: 999px; padding: 5px 12px; display: flex; align-items: center; gap: 4px;
}

/* status rail - small icons showing door/bed progress, top-left */
.status-rail {
  position: absolute; top: 8px; left: 8px; z-index: 15;
  display: flex; flex-direction: column; gap: 6px;
}
.status-dot {
  width: 26px; height: 26px; border-radius: 50%; font-size: 13px;
  background: rgba(20,20,30,0.55); display: flex; align-items: center; justify-content: center;
  opacity: 0.6; transition: opacity 0.2s ease, background 0.2s ease;
}
.status-dot.done { opacity: 1; background: var(--accent-play, #22c55e); }

/* on-screen movement d-pad, overlaid bottom-right of the scene */
.dpad-holder { position: absolute; bottom: 8px; right: 8px; z-index: 15; opacity: 0.9; }
.dpad {
  display: grid; grid-template-columns: repeat(3, 34px); grid-template-rows: repeat(3, 34px); gap: 3px;
}
.dpad-btn {
  width: 34px; height: 34px; border-radius: 8px; border: none;
  background: rgba(20,20,30,0.55); color: #fff; font-size: 14px;
  display: flex; align-items: center; justify-content: center; cursor: pointer; touch-action: none;
}
.dpad-btn:active { background: rgba(20,20,30,0.8); }

.action-row { display: flex; align-items: center; gap: 8px; min-height: 20px; margin-top: 4px; }
.action-btn { padding: 9px 16px; font-size: 13px; margin: 0; }
.action-hint { font-size: 12px; font-weight: 700; color: var(--ink-dim); }

/* bottom action tiles (BUILD/UPGRADE style, matches the reference's dark rounded buttons) */
.upgrade-row { display: flex; gap: 10px; margin-top: 10px; }
.action-tile {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: #1c2028; border: none; border-radius: 14px; padding: 10px 8px; cursor: pointer;
  font-family: "Nunito", sans-serif;
}
.tile-icon { font-size: 20px; }
.tile-label { font-weight: 800; font-size: 12px; color: #fff; }
.tile-level { color: rgba(255,255,255,0.55); font-weight: 700; font-size: 10.5px; }
.tile-cost { font-weight: 800; font-size: 11px; color: #ffcf4d; display: flex; align-items: center; gap: 3px; }
.action-tile.affordable { background: #26623f; }
.action-tile:disabled { opacity: 0.55; cursor: not-allowed; }


@media (max-width: 700px) {
  #screen-defense.screen { padding: 10px 8px; min-height: 100vh; min-height: 100dvh; }
  .defense-layout { grid-template-columns: 1fr; max-width: 100%; gap: 8px; }

  /* room takes the phone screen seriously - tall portrait view, not a squished landscape strip */
  .scene-wrap { aspect-ratio: 3/4; min-height: 320px; }

  /* scoreboard becomes a slim horizontal strip instead of a boxed sidebar eating vertical space */
  .defense-sidebar {
    order: 2; padding: 8px 10px; max-height: none;
    display: flex; align-items: center; gap: 10px; overflow-x: auto;
  }
  .sidebar-title { display: none; }
  .dorm-scoreboard { flex-direction: row; gap: 10px; flex-wrap: nowrap; }
  .dorm-entry { flex-direction: row; align-items: center; gap: 6px; flex-shrink: 0; }
  .dorm-entry .mini-hp-track { width: 44px; }
  .dorm-entry .name { font-size: 11px; white-space: nowrap; }

  /* bigger touch targets for thumbs */
  .dpad { grid-template-columns: repeat(3, 42px); grid-template-rows: repeat(3, 42px); }
  .dpad-btn { width: 42px; height: 42px; font-size: 17px; }
  .action-btn { padding: 12px 20px; font-size: 14px; }
  .action-tile { padding: 10px 4px; }
  .tile-icon { font-size: 20px; }
  .tile-label { font-size: 10.5px; }
  .tile-cost { font-size: 10px; }
  .upgrade-row { gap: 6px; }

  .topbar { gap: 6px; }
  .stat-chip, .wave-chip, .countdown-pill { font-size: 12px; padding: 5px 10px; }

  /* two-player pass & play: keep both reachable without excess scrolling */
  .defense-panels.dual { grid-template-columns: 1fr; gap: 10px; }
  .defense-panels.dual .scene-wrap { aspect-ratio: 4/3; min-height: 220px; }
}


/* ---------- in-game chat (Roblox-style floating overlay) ---------- */
.chat-toggle-btn {
  position: fixed; bottom: 18px; left: 18px; z-index: 40;
  width: 46px; height: 46px; border-radius: 50%; padding: 0; margin: 0;
  background: rgba(20,20,30,0.75); color: #fff; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 20px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
}
.chat-toggle-btn:hover { background: rgba(20,20,30,0.9); }
.chat-toggle-btn:active { transform: scale(0.94); }
.chat-panel {
  position: fixed; bottom: 74px; left: 18px; z-index: 40;
  width: 300px; max-width: calc(100vw - 36px);
  background: rgba(15,15,20,0.72); border: none; border-radius: 10px; padding: 8px;
  display: flex; flex-direction: column; gap: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.chat-feed {
  max-height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px;
  padding-right: 2px; scrollbar-width: thin;
}
.chat-msg {
  font-family: Arial, Helvetica, sans-serif; font-size: 13px; font-weight: 400;
  padding: 3px 8px; border-radius: 4px; background: rgba(0,0,0,0.32); color: #f2f2f2;
  line-height: 1.4; word-break: break-word;
}
.chat-msg .c-name { font-weight: 700; margin-right: 3px; }
.chat-msg.own { background: rgba(0,0,0,0.48); }
.chat-form { display: flex; gap: 6px; }
.chat-form input {
  flex: 1; padding: 7px 10px; font-size: 13px; font-weight: 400;
  font-family: Arial, Helvetica, sans-serif;
  background: rgba(255,255,255,0.14); color: #fff; border: none;
  border-radius: 4px; outline: none; min-width: 0;
}
.chat-form input::placeholder { color: rgba(255,255,255,0.55); }
.chat-form .btn {
  padding: 7px 12px; font-size: 12px; font-weight: 700; border-radius: 4px;
  background: rgba(255,255,255,0.18); color: #fff; border: none; cursor: pointer;
  font-family: Arial, Helvetica, sans-serif;
}
.chat-form .btn:hover { background: rgba(255,255,255,0.28); }

@media (max-width: 480px) {
  .chat-panel { left: 10px; bottom: 68px; width: calc(100vw - 20px); }
  .chat-toggle-btn { left: 10px; }
}

/* ---------- winner / round-end shared bits ---------- */
.trophy { font-size: 60px; animation: bounceLite 1s ease-in-out infinite; }
@keyframes bounceLite { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
.winner-name { font-size: 26px; font-weight: 800; color: var(--accent-yellow); text-shadow: 2px 2px 0 var(--border-dark); margin: 6px 0 18px; }
#confetti-layer { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 1; }
.confetti-piece { position: absolute; top: -20px; width: 10px; height: 16px; opacity: 0.9; animation: confettiFall linear forwards; }
@keyframes confettiFall { to { transform: translateY(110vh) rotate(540deg); opacity: 0.9; } }

/* ---------- offline mode divider ---------- */
.offline-divider {
  display: flex; align-items: center; gap: 10px; margin: 18px 0 12px;
  color: var(--ink-dim); font-weight: 800; font-size: 12px; text-transform: uppercase; letter-spacing: 1px;
}
.offline-divider::before, .offline-divider::after {
  content: ""; flex: 1; height: 2px; background: var(--bg-panel-2);
}

/* ---------- acting-as toggle (pass & play claiming) ---------- */
.acting-as-toggle { display: flex; gap: 8px; justify-content: center; margin: 14px 0; flex-wrap: wrap; }
.acting-chip {
  padding: 8px 14px; border-radius: 20px; border: 3px solid var(--border-dark);
  background: var(--bg-panel-2); color: var(--ink); font-weight: 800; font-size: 12px;
  cursor: pointer; font-family: "Nunito", sans-serif;
}
.acting-chip.active { background: #f1e9fe; }
.acting-chip.done { opacity: 0.55; cursor: default; }

/* ---------- defense panels (single online/bot, dual pass & play) ---------- */
.defense-panels { display: flex; flex-direction: column; gap: 14px; }
.defense-panels.dual { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.defense-panel {
  background: var(--bg-panel); border: 4px solid var(--border-dark); border-radius: var(--radius-lg);
  padding: 14px; box-shadow: var(--shadow-chunk-sm); display: flex; flex-direction: column; gap: 10px;
}
