* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0b0b14;
  --panel: #14142a;
  --panel2: #1c1c38;
  --line: #2e2e55;
  --text: #d8d8f0;
  --dim: #8585ad;
  --accent: #5dff7e;
  --accent2: #ffd24f;
  --danger: #ff5b5b;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Courier New", ui-monospace, Menlo, monospace;
}

.hidden { display: none !important; }

.screen { min-height: 100vh; padding: 18px; }
.screen.center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  text-align: center;
}

.logo {
  font-size: 64px;
  letter-spacing: 10px;
  color: var(--accent);
  text-shadow: 0 0 18px rgba(93, 255, 126, .5), 3px 3px 0 #1c5c2a;
}
.tagline { color: var(--dim); letter-spacing: 3px; }
.hint { color: var(--dim); font-size: 12px; }

h2 { letter-spacing: 4px; color: var(--accent2); }

.btn {
  font-family: inherit;
  font-size: 14px;
  letter-spacing: 2px;
  padding: 9px 18px;
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .35; cursor: default; }
.btn.big { font-size: 17px; padding: 12px 28px; }
.btn.dim { opacity: .7; }
.btn.fire {
  background: #5c1414;
  border-color: #a33;
  color: #ffd9d9;
  font-size: 18px;
  font-weight: bold;
  padding: 10px 30px;
}
.btn.fire:hover:not(:disabled) { background: #7a1a1a; border-color: var(--danger); color: #fff; }

input, select {
  font-family: inherit;
  font-size: 15px;
  padding: 9px 12px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  outline: none;
}
input:focus { border-color: var(--accent); }

.name-form { display: flex; gap: 10px; }

.lobby-actions { display: flex; gap: 10px; }
.party-row { display: flex; gap: 10px; }
#lobby-scope { color: var(--accent); }

#games-list { width: min(560px, 92vw); display: flex; flex-direction: column; gap: 8px; }
.game-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
}
.game-row .gid { color: var(--accent2); letter-spacing: 2px; }
.game-row .ghost { color: var(--dim); flex: 1; text-align: left; }
.empty { color: var(--dim); padding: 18px; }

/* ---- game screen ---- */
#screen-game {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 10px;
  /* Fill the window. The world is simulated at 2:1 (1200x600) but the canvas
     may stretch horizontally up to 20% (factor 2.4) so it spans the full
     width on typical desktop aspect ratios; ~175px of HUD sits around it.
     Beyond 20% (ultrawide) it letterboxes with side margins. */
  --avail-h: calc(100vh - 175px);
  --game-w: min(100%, calc(var(--avail-h) * 2.4));
  --game-h: min(var(--avail-h), calc((100vw - 20px) / 2));
}
@supports (height: 100dvh) {
  /* dvh tracks mobile browser chrome (URL bar) so the canvas never jumps */
  #screen-game { --avail-h: calc(100dvh - 175px); }
}

#topbar {
  width: var(--game-w);
  display: flex;
  align-items: center;
  gap: 12px;
}
#players-bar { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; }
.chip {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 12px;
}
.chip.turn { border-color: var(--accent); box-shadow: 0 0 8px rgba(93, 255, 126, .35); }
.chip.dead { opacity: .45; text-decoration: line-through; }
.chip .dot { width: 10px; height: 10px; border-radius: 50%; }
.chip .hpbar { width: 52px; height: 7px; background: #000; border: 1px solid var(--line); }
.chip .hpfill { height: 100%; background: var(--accent); }
.chip .wins { color: var(--accent2); }
.chip .cash { color: var(--accent); }

#round-box,
#wind-box, #timer-box {
  padding: 6px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 13px;
  letter-spacing: 1px;
  white-space: nowrap;
}
#wind-val { color: var(--accent2); }
#timer-val { color: var(--accent); min-width: 3ch; display: inline-block; text-align: center; }
#timer-box.urgent #timer-val { color: var(--danger); }

#game-wrap { position: relative; width: var(--game-w); }
#game-canvas {
  width: 100%;
  height: var(--game-h);
  display: block;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 4px;
}

#banner {
  position: absolute;
  top: 38%;
  left: 0; right: 0;
  text-align: center;
  font-size: 42px;
  font-weight: bold;
  letter-spacing: 8px;
  color: var(--accent);
  text-shadow: 0 0 22px rgba(93, 255, 126, .8), 2px 2px 0 #000;
  pointer-events: none;
  animation: bannerpop .35s ease-out;
}
@keyframes bannerpop {
  from { transform: scale(.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  gap: 14px;
  background: rgba(8, 8, 18, .92);
  border-radius: 4px;
  text-align: center;
  overflow-y: auto;
  padding: 14px;
}
#room-code { color: var(--accent); }
#wait-players, #end-scores { display: flex; flex-direction: column; gap: 6px; min-width: 240px; }
.wait-row, .score-row {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 7px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
}
.score-row .wins { color: var(--accent2); }

#shop-cash { font-size: 26px; color: var(--accent); letter-spacing: 2px; }
#shop-items { display: flex; flex-direction: column; gap: 6px; width: min(560px, 92%); }
.shop-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 13px;
}
.shop-row .sname { flex: 1; text-align: left; }
.shop-row .sdesc { color: var(--dim); font-size: 11px; }
.shop-row .sown { color: var(--accent2); min-width: 5ch; }
.shop-row .sprice { color: var(--accent); min-width: 7ch; text-align: right; }
.shop-footer { display: flex; align-items: center; gap: 14px; }
#ready-btn.armed { border-color: var(--accent); color: var(--accent); }

#controls {
  width: var(--game-w);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  flex-wrap: wrap;
}
.ctl { display: flex; align-items: center; gap: 8px; }
.ctl label { font-size: 12px; color: var(--dim); letter-spacing: 2px; }
.ctl .val { color: var(--accent2); min-width: 4ch; font-size: 14px; }
input[type=range] { width: 150px; height: 28px; accent-color: var(--accent); padding: 0; }
button, select, input[type=range] { touch-action: manipulation; } /* no double-tap zoom on controls */
#fire-btn { margin-left: auto; }

#chat {
  position: absolute;
  left: 10px;
  bottom: 10px;
  width: min(320px, 55%);
  background: rgba(11, 11, 20, .72);
  border: 1px solid var(--line);
  border-radius: 4px;
}
#chat-head {
  padding: 4px 10px;
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--dim);
  background: rgba(28, 28, 56, .8);
  border-bottom: 1px solid var(--line);
  border-radius: 4px 4px 0 0;
  cursor: grab;
  user-select: none;
  touch-action: none; /* lets pointer events drag on touchscreens */
}
#chat-head:active { cursor: grabbing; }
#chat-msgs {
  height: 84px;
  overflow-y: auto;
  padding: 8px 12px;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
#chat-msgs .sys { color: var(--dim); font-style: italic; }
#chat-form input {
  width: 100%;
  border: none;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel2);
  font-size: 13px;
}

#toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: #3a1020;
  border: 1px solid var(--danger);
  color: #ffd9d9;
  padding: 10px 22px;
  border-radius: 4px;
  z-index: 50;
}

/* ---- small screens / touch ---- */
@media (max-width: 760px) {
  .logo { font-size: 40px; letter-spacing: 6px; }
  .tagline { font-size: 12px; letter-spacing: 2px; }
  h2 { font-size: 17px; letter-spacing: 2px; }
  .screen { padding: 10px; }

  .name-form, .party-row { width: 100%; max-width: 380px; }
  .name-form input, .party-row input { flex: 1; min-width: 0; }
  .lobby-actions { flex-wrap: wrap; justify-content: center; }

  #screen-game { padding: 6px; gap: 6px; }
  #topbar { gap: 6px; }
  .chip { font-size: 10px; padding: 4px 7px; gap: 5px; }
  .chip .hpbar { width: 36px; }
  #round-box, #wind-box, #timer-box { padding: 4px 8px; font-size: 11px; }

  /* controls stack into full-width touch rows */
  #controls { gap: 8px; padding: 8px 10px; }
  .ctl { flex: 1 1 100%; }
  .ctl input[type=range] { flex: 1; width: auto; min-width: 0; }
  .ctl select { flex: 1; min-width: 0; }
  #fire-btn { margin-left: 0; flex: 1 1 100%; padding: 14px; }
  #keys-hint { display: none; } /* keyboard hints are noise on touch */

  /* the floating chat would cover the small canvas — dock it below instead
     (!important beats the inline left/top set by dragging on desktop) */
  #chat {
    position: static !important;
    width: 100% !important;
    margin-top: 6px;
  }
  #chat-head { cursor: default; }
  #chat-msgs { height: 60px; }

  #banner { font-size: 26px; letter-spacing: 4px; }
  .overlay { gap: 10px; padding: 10px; }
  #shop-cash { font-size: 20px; }
  #shop-items { width: 96%; }
  .shop-row { flex-wrap: wrap; gap: 6px 10px; font-size: 12px; padding: 7px 10px; }
  .shop-footer { flex-wrap: wrap; justify-content: center; }
}
