/* Scorched Rama — two switchable themes via body class. */

:root {
  --topbar-h: 44px;
  --controls-h: 96px;
}

/* ---------- Retro CRT theme ---------- */
body.theme-retro {
  --bg: #0a0a12;
  --panel: rgba(8, 18, 8, 0.92);
  --panel-border: #2dbf4e;
  --text: #9dffb0;
  --text-dim: #4e8f5d;
  --accent: #ffd24d;
  --danger: #ff5555;
  --btn-bg: #11331a;
  --btn-border: #2dbf4e;
  --font: "Courier New", ui-monospace, monospace;
  --radius: 0px;
  --glow: 0 0 6px rgba(45, 191, 78, 0.7);
}
body.theme-retro #scanlines {
  display: block;
  position: fixed; inset: 0; pointer-events: none; z-index: 90;
  background: repeating-linear-gradient(
    to bottom, rgba(0,0,0,0) 0 2px, rgba(0,0,0,0.18) 2px 4px);
}
body.theme-retro button, body.theme-retro .chip { text-transform: uppercase; letter-spacing: 1px; }

/* ---------- Modern theme ---------- */
body.theme-modern {
  --bg: #1c2330;
  --panel: rgba(28, 36, 50, 0.92);
  --panel-border: #3b4a63;
  --text: #e8eef7;
  --text-dim: #8b99af;
  --accent: #4da3ff;
  --danger: #ff6b6b;
  --btn-bg: #2a3448;
  --btn-border: #46587a;
  --font: system-ui, "Segoe UI", Roboto, sans-serif;
  --radius: 8px;
  --glow: none;
}
body.theme-modern #scanlines { display: none; }

/* ---------- Layout ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; max-width: 100vw; }
body { height: 100dvh; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  user-select: none;
}

#topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 16px;
  padding: 0 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-border);
  font-size: 14px;
  position: relative; z-index: 20;
}
#topbar .title { font-weight: bold; color: var(--accent); text-shadow: var(--glow); white-space: nowrap; }
#phaseInfo {
  flex: 0 0 auto; font-size: 17px; font-weight: bold;
  color: var(--accent); text-shadow: var(--glow); white-space: nowrap;
}
#windBox { flex: 1 1 0; min-width: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; gap: 8px; }
#windArrow { font-size: 22px; font-weight: bold; min-width: 140px; text-align: center; letter-spacing: -1px; white-space: nowrap; }
#windArrow.strong { color: var(--danger); }
#windArrow.pulse { animation: windpulse 0.4s ease-in-out 5; }
@keyframes windpulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.35); }
}
#timer { min-width: 56px; text-align: right; font-size: 18px; font-weight: bold; }
#timer.low { color: var(--danger); }
#youScore { white-space: nowrap; }
#themeBtn, #muteBtn, #scoreBtn { margin-left: 4px; }

#main {
  position: absolute; top: var(--topbar-h); bottom: var(--controls-h);
  left: 0; right: 0;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
#game { display: block; image-rendering: pixelated; touch-action: none; }
body.theme-modern #game { image-rendering: auto; }

/* ---------- Controls ---------- */
#controls {
  position: absolute; bottom: 0; left: 0; right: 0;
  height: var(--controls-h);
  background: var(--panel);
  border-top: 1px solid var(--panel-border);
  display: flex; align-items: center; gap: 14px;
  padding: 0 14px;
  z-index: 20;
}
#controls.disabled { opacity: 0.45; pointer-events: none; }
.ctl { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--text-dim); }
.ctl .val { color: var(--text); font-size: 15px; font-weight: bold; }
.ctl input[type="range"] {
  width: 150px; accent-color: var(--accent);
  margin-left: 10px; /* room to grab the thumb at the 180° end */
}
.sliderRow { display: flex; align-items: center; gap: 4px; }
.stepBtn {
  display: none; /* fine-tune buttons appear on touch / small screens */
  width: 34px; min-width: 34px; height: 34px;
  align-items: center; justify-content: center;
  font-size: 18px; font-weight: bold; padding: 0;
}
.totalCol { color: var(--text-dim); }

#loadoutBar { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; }
.itemBtn {
  background: var(--btn-bg); border: 1px solid var(--btn-border); color: var(--text);
  border-radius: var(--radius); padding: 6px 9px; cursor: pointer; font-family: inherit;
  font-size: 13px; display: flex; align-items: center; gap: 5px;
}
.itemBtn .ico { font-size: 16px; }
.itemBtn .key {
  color: var(--text-dim); font-size: 10px; border: 1px solid var(--btn-border);
  border-radius: 3px; padding: 0 4px; margin-right: 2px;
}
.itemBtn:focus { outline: none; border-color: var(--accent); box-shadow: var(--glow); }
.itemBtn.sel { border-color: var(--accent); color: var(--accent); box-shadow: var(--glow); }
.itemBtn .cnt { color: var(--text-dim); font-size: 11px; }

button {
  background: var(--btn-bg); border: 1px solid var(--btn-border); color: var(--text);
  border-radius: var(--radius); padding: 6px 12px; cursor: pointer;
  font-family: inherit; font-size: 13px;
}
button:hover { border-color: var(--accent); }
#fireBtn {
  font-size: 17px; font-weight: bold; padding: 12px 26px;
  border-color: var(--accent); color: var(--accent); box-shadow: var(--glow);
}
#fireBtn.committed { border-color: var(--text-dim); color: var(--text-dim); box-shadow: none; }

/* ---------- Join Game button ---------- */
#joinGameBtn {
  position: absolute; left: 50%; bottom: calc(var(--controls-h) + 18px);
  transform: translateX(-50%);
  font-size: 20px; font-weight: bold; padding: 14px 34px;
  border: 2px solid var(--accent); color: var(--accent);
  box-shadow: var(--glow); z-index: 28;
}
#joinGameBtn.hidden { display: none; }
#zzzBtn.on, #trajBtn.on { border-color: var(--accent); color: var(--accent); }

/* ---------- Scoreboard ---------- */
#scoreboard {
  position: absolute; top: calc(var(--topbar-h) + 8px); left: 8px;
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: var(--radius); padding: 8px 10px;
  font-size: 12px; min-width: 230px; max-height: 60vh; overflow-y: auto;
  z-index: 30;
}
#scoreboard h3 { margin: 0 0 6px; font-size: 12px; color: var(--text-dim); }
#scoreboard table { border-collapse: collapse; width: 100%; }
#scoreboard td { padding: 2px 6px 2px 0; white-space: nowrap; }
#scoreboard tr.dead td { opacity: 0.45; text-decoration: line-through; }
#scoreboard tr.spect td { opacity: 0.6; font-style: italic; }
#scoreboard tr.locked td:first-child { color: var(--accent); text-shadow: var(--glow); }
#scoreboard .idleTag { color: var(--text-dim); font-style: italic; }
#scoreboard .muteBtn {
  cursor: pointer; opacity: 0.5; background: none; border: none;
  color: var(--text); padding: 0 2px; font-size: 11px;
}
#scoreboard .muteBtn.on { opacity: 1; color: var(--danger); }
#scoreboard .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; }
#scoreboard .vend { color: var(--danger); }
#scoreboard.hidden { display: none; }

/* ---------- Minimap ---------- */
#minimap {
  position: absolute; left: 8px; bottom: calc(var(--controls-h) + 8px);
  touch-action: none;
  z-index: 30; display: none;
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  cursor: crosshair;
  opacity: 0.9;
}

/* ---------- Log & chat panel ---------- */
#logPanel {
  position: absolute; top: calc(var(--topbar-h) + 8px); right: 8px;
  width: 280px; z-index: 30;
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  display: flex; flex-direction: column;
}
#logPanel.hidden { display: none; }
#logEntries {
  max-height: 34vh; overflow-y: auto; padding: 6px 8px;
  display: flex; flex-direction: column; gap: 3px;
  font-size: 12px; line-height: 1.35; word-wrap: break-word;
}
#logEntries .entry { opacity: 0.92; }
#logEntries .entry.vendetta { color: var(--danger); font-weight: bold; }
#logEntries .entry.sys { color: var(--text-dim); }
#logEntries .entry .who { font-weight: bold; }
#chatInput {
  border: none; border-top: 1px solid var(--panel-border);
  background: var(--bg); color: var(--text);
  padding: 7px 9px; font-family: inherit; font-size: 13px; outline: none;
  border-radius: 0 0 var(--radius) var(--radius);
}

#banner {
  position: absolute; top: 30%; left: 50%; transform: translate(-50%, -50%);
  font-size: 26px; font-weight: bold; color: var(--accent);
  text-shadow: var(--glow); z-index: 25; text-align: center; pointer-events: none;
  background: var(--panel); padding: 14px 30px; border: 1px solid var(--panel-border);
  border-radius: var(--radius);
}
#banner.hidden { display: none; }
#banner .sub { font-size: 14px; color: var(--text-dim); margin-top: 6px; font-weight: normal; }

/* ---------- Modals ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal.hidden { display: none; }
.modal .box {
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: var(--radius); padding: 26px; min-width: 340px; max-width: 720px;
  max-height: 85vh; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--panel-border) transparent;
}
.modal .box::-webkit-scrollbar { width: 10px; }
.modal .box::-webkit-scrollbar-track { background: transparent; }
.modal .box::-webkit-scrollbar-thumb {
  background: var(--panel-border); border-radius: 6px;
  border: 2px solid var(--panel);
}
.modal .box::-webkit-scrollbar-thumb:hover { background: var(--accent); }
.modal h2 { margin: 0 0 12px; color: var(--accent); text-shadow: var(--glow); }
.modal input[type="text"] {
  width: 100%; padding: 10px; font-size: 16px; font-family: inherit;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--btn-border); border-radius: var(--radius);
}
.modal .row { margin: 12px 0; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* Loadout picker */
#catalogGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.catItem {
  background: var(--btn-bg); border: 1px solid var(--btn-border); border-radius: var(--radius);
  padding: 8px; cursor: pointer; font-size: 12px;
}
.catItem:hover { border-color: var(--accent); }
.catItem .name { font-weight: bold; font-size: 13px; }
.catItem .name .ico { margin-right: 4px; }
.catItem .desc { color: var(--text-dim); margin-top: 3px; line-height: 1.3; }
.catItem .tag { float: right; font-size: 10px; color: var(--accent); }
.catItem .pickCnt { color: var(--accent); font-weight: bold; margin-left: 4px; }
.catItem.picked { border-color: var(--accent); }
.catItem.maxed { opacity: 0.55; cursor: not-allowed; }
.catItem.free { opacity: 0.65; cursor: default; }
.catItem.free:hover { border-color: var(--btn-border); }
#pickChips { display: flex; gap: 6px; flex-wrap: wrap; min-height: 34px; margin: 10px 0; }
.chip {
  background: var(--btn-bg); border: 1px solid var(--accent); color: var(--accent);
  border-radius: var(--radius); padding: 5px 10px; cursor: pointer; font-size: 13px;
}
#confirmRow {
  position: sticky; top: -26px; z-index: 5;
  background: var(--panel);
  margin: 0 -4px 10px; padding: 10px 4px 8px;
  border-bottom: 1px solid var(--panel-border);
}
.confirmRowMain { display: flex; gap: 10px; align-items: center; }
#loadoutCount { color: var(--text-dim); font-size: 13px; }

#loadoutTimer {
  height: 6px; background: var(--accent); transition: width 1s linear;
  margin-top: 8px; border-radius: var(--radius);
  box-shadow: var(--glow);
}

/* ---------- Unlisted admin spectator ---------- */
body.spectator #controls,
body.spectator #joinGameBtn,
body.spectator #zzzBtn { display: none; }
body.spectator #main { bottom: 0; }

/* CRT scanlines scale down on small screens (finer, subtler) */
@media (max-width: 700px), (max-height: 460px) {
  body.theme-retro #scanlines {
    background: repeating-linear-gradient(
      to bottom, rgba(0,0,0,0) 0 2px, rgba(0,0,0,0.10) 2px 3px);
  }
}

/* ---------- Responsive: touch ---------- */
@media (pointer: coarse) {
  .stepBtn { display: flex; }
  .ctl input[type="range"] { height: 34px; }
  .itemBtn { padding: 10px 12px; font-size: 14px; }
  button { padding: 10px 14px; }
  #topbar button { padding: 6px 8px; } /* keep the topbar narrow */
  #chatInput { font-size: 16px; } /* prevents iOS focus zoom */
  #scoreboard .muteBtn { font-size: 14px; padding: 4px 6px; }
}

/* ---------- Responsive: narrow screens (portrait phones) ---------- */
@media (max-width: 700px) {
  #topbar { gap: 5px; padding: 0 5px; font-size: 12px; }
  #topbar .title { display: none; }
  #topbar button { margin-left: 0; padding: 5px 7px; font-size: 12px; }
  #phaseInfo { font-size: 13px; }
  #windArrow { font-size: 16px; min-width: 0; }
  #youScore { display: none; }
  #timer { min-width: 34px; font-size: 14px; }

  :root { --controls-h: 196px; }
  #controls {
    flex-direction: column; align-items: stretch;
    gap: 4px; padding: 6px 8px;
  }
  #loadoutBar {
    order: 0; flex: 0 0 auto;
    flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }
  #loadoutBar .itemBtn { flex-shrink: 0; }
  /* stacked, full-width aim rows with the label inline */
  #controls .ctl {
    order: 1; flex: 0 0 auto;
    flex-direction: row; align-items: center; gap: 6px;
  }
  #controls .ctl > span { width: 86px; min-width: 86px; font-size: 10px; }
  #controls .ctl .sliderRow { flex: 1; min-width: 0; }
  .ctl input[type="range"] { width: 100%; margin-left: 0; flex: 1; min-width: 0; }
  .stepBtn { display: flex; }
  #fireBtn { order: 2; font-size: 16px; padding: 10px; width: 100%; }

  #scoreboard { max-width: 86vw; max-height: 50vh; font-size: 11px; min-width: 0; }
  #logPanel { width: min(280px, 86vw); }
  #minimap { width: 150px; height: 38px; }
  #banner { font-size: 18px; max-width: 92vw; padding: 10px 16px; }
  #banner .sub { font-size: 12px; }
  .modal .box { min-width: 0; width: 94vw; padding: 14px; }
  #catalogGrid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
  .catItem { font-size: 11px; }
}

/* ---------- Responsive: short screens (landscape phones) ---------- */
@media (max-height: 460px) {
  :root { --topbar-h: 34px; --controls-h: 56px; }
  #topbar { font-size: 12px; gap: 5px; padding: 0 5px; }
  #topbar .title { display: none; }
  #topbar button { margin-left: 0; padding: 3px 7px; font-size: 12px; }
  #phaseInfo { font-size: 13px; }
  #windArrow { font-size: 15px; min-width: 0; }
  #controls { gap: 8px; padding: 0 8px; }
  .ctl { font-size: 10px; flex: 1 1 0; min-width: 0; }
  .ctl .sliderRow { width: 100%; }
  .ctl input[type="range"] { width: 100%; flex: 1; min-width: 0; height: 26px; margin-left: 0; }
  .stepBtn { display: flex; width: 30px; min-width: 30px; height: 30px; }
  #fireBtn { font-size: 14px; padding: 8px 14px; }
  /* weapons live in a vertical strip on the right edge */
  #loadoutBar {
    position: fixed; right: 0; top: var(--topbar-h); bottom: var(--controls-h);
    width: 138px; z-index: 24;
    display: flex; flex-direction: column; flex-wrap: nowrap;
    overflow-y: auto; overflow-x: hidden; gap: 4px;
    background: var(--panel); border-left: 1px solid var(--panel-border);
    padding: 6px; margin: 0;
  }
  #loadoutBar .itemBtn {
    flex-shrink: 0; width: 100%; font-size: 11px; padding: 7px 6px;
  }
  /* keep the log panel clear of the weapon strip */
  #logPanel { right: 142px; }
  #scoreboard { max-height: 60vh; font-size: 11px; }
  #logEntries { max-height: 24vh; }
  #minimap { width: 140px; height: 36px; }
  #banner { font-size: 16px; padding: 8px 14px; }
  #banner .sub { font-size: 11px; }
  .modal .box { max-height: 92vh; padding: 12px; }
}
