/* Tank Wars — UI styling.
   The canvas owns the whole viewport; everything else is a layer on top of it.
   Palette is deliberately desaturated olive/steel so the bright pickup and damage
   colours read instantly against it. */

:root {
  --bg: #10140f;
  --panel: rgba(18, 22, 17, 0.92);
  --panel-solid: #161a14;
  --edge: #2f3a2a;
  --ink: #e8ecdf;
  --ink-dim: #98a189;
  --accent: #c8d94f;
  --accent-dark: #8fa020;
  --danger: #e05b4a;
  --good: #6fbf5b;
  --warn: #e0a94a;
  --steel: #8a97a3;
  --radius: 4px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.55);
  --font: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

#viewport {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  /* Right-click is the secondary weapon, not a context menu. */
  cursor: crosshair;
  touch-action: none;
}

/* ---------------------------------------------------------------- screens */

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 20;
  overflow-y: auto;
}

.screen.overlay { background: rgba(6, 8, 6, 0.82); backdrop-filter: blur(3px); z-index: 30; }
[hidden] { display: none !important; }

#menu {
  background:
    radial-gradient(circle at 50% 30%, rgba(200, 217, 79, 0.09), transparent 55%),
    linear-gradient(160deg, #10140f 0%, #171d14 50%, #0d100c 100%);
}

.menu-card {
  width: min(460px, 100%);
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  text-align: center;
}

.menu-card.narrow { width: min(380px, 100%); }
.menu-card.wide { width: min(1000px, 100%); text-align: left; }

.logo {
  margin: 0;
  font-size: clamp(2.4rem, 8vw, 3.6rem);
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--ink);
  text-shadow: 0 3px 0 #0b0d0a, 0 0 26px rgba(200, 217, 79, 0.25);
}
.logo span { color: var(--accent); }

.tagline {
  margin: 0.15rem 0 1.4rem;
  color: var(--ink-dim);
  letter-spacing: 0.32em;
  font-size: 0.72rem;
  text-transform: uppercase;
}

.motd {
  margin-bottom: 1rem;
  padding: 0.6rem 0.8rem;
  background: rgba(200, 217, 79, 0.1);
  border-left: 3px solid var(--accent);
  color: var(--ink);
  font-size: 0.86rem;
  text-align: left;
}

/* ---------------------------------------------------------------- forms */

label {
  display: block;
  margin: 0.9rem 0 0.3rem;
  font-size: 0.74rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
  text-align: left;
}
label em { text-transform: none; letter-spacing: 0; font-style: normal; opacity: 0.7; }

input, select {
  width: 100%;
  padding: 0.65rem 0.7rem;
  background: #0c0f0b;
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1rem;
}
input:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

#callsign {
  font-family: var(--mono);
  font-size: 2rem;
  letter-spacing: 0.5rem;
  text-align: center;
  text-transform: uppercase;
  padding: 0.5rem;
}

.name-status { min-height: 1.2rem; margin-top: 0.35rem; font-size: 0.8rem; text-align: left; }
.name-status.ok { color: var(--good); }
.name-status.warn { color: var(--warn); }
.name-status.bad { color: var(--danger); }

.form-error { min-height: 1.2rem; margin-top: 0.5rem; color: var(--danger); font-size: 0.85rem; }

button {
  font-family: var(--font);
  font-size: 0.9rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

button.primary {
  width: 100%;
  margin-top: 1.2rem;
  padding: 0.85rem;
  background: var(--accent);
  color: #12160f;
  border: none;
  font-weight: 700;
  letter-spacing: 0.2em;
}
button.primary:hover:not(:disabled) { background: #d8e968; }
button.primary:disabled { background: #4a5340; color: #8d947f; cursor: not-allowed; }

button.danger {
  padding: 0.6rem 0.8rem;
  background: transparent;
  border: 1px solid #6d3029;
  color: var(--danger);
  font-weight: 600;
}
button.danger:hover { background: rgba(224, 91, 74, 0.12); border-color: var(--danger); }

button.ghost {
  padding: 0.5rem 0.8rem;
  background: transparent;
  border: 1px solid var(--edge);
  color: var(--ink-dim);
}
button.ghost:hover { border-color: var(--accent); color: var(--accent); }

.menu-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; margin-top: 1.2rem; }
.row { display: flex; gap: 0.6rem; align-items: center; margin-top: 1rem; }
.row button { flex: 1; }

.server-line { margin: 1.3rem 0 0; font-size: 0.75rem; color: var(--ink-dim); font-family: var(--mono); }
.hint { color: var(--ink-dim); font-size: 0.84rem; line-height: 1.5; }

/* ---------------------------------------------------------------- scoreboard */

.scores-controls { flex-wrap: wrap; }
.scores-controls label { margin: 0; }
.scores-controls select, .scores-controls input { width: auto; flex: 0 1 160px; }
.scores-controls button { flex: 0 0 auto; margin-left: auto; }

.table-wrap { max-height: 58vh; overflow-y: auto; margin-top: 1rem; border: 1px solid var(--edge); }

table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
thead th {
  position: sticky;
  top: 0;
  background: var(--panel-solid);
  padding: 0.55rem 0.5rem;
  text-align: left;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-dim);
  border-bottom: 1px solid var(--edge);
}
tbody td { padding: 0.45rem 0.5rem; border-bottom: 1px solid rgba(47, 58, 42, 0.5); }
tbody tr:hover { background: rgba(200, 217, 79, 0.06); }
td.name { font-family: var(--mono); font-weight: 700; color: var(--accent); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.locked-badge { margin-left: 0.3rem; font-size: 0.7rem; color: var(--steel); }

.help-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1.2rem; margin: 1rem 0; }
.help-grid h3 { margin: 0 0 0.5rem; font-size: 0.8rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); }
.help-grid ul { margin: 0; padding-left: 1.1rem; color: var(--ink-dim); font-size: 0.86rem; line-height: 1.75; }
/* Swatch colours live here rather than as style="" attributes: the CSP forbids inline
   styles (no 'unsafe-inline'), so markup-level colours are silently dropped. */
.swatch { display: inline-block; width: 0.7rem; height: 0.7rem; border-radius: 2px; margin-right: 0.35rem; }
.sw-weapon { background: #ffb347; }
.sw-armor { background: #90a4ae; }
.sw-parts { background: #4fc3f7; }
.sw-utility { background: #66bb6a; }
.sw-funny { background: #ab47bc; }

.noscript-note { color: #eee; padding: 2rem; }
.chip.debuff { border-color: #ab47bc; }

kbd {
  display: inline-block;
  min-width: 1.4rem;
  padding: 0.05rem 0.3rem;
  background: #0c0f0b;
  border: 1px solid var(--edge);
  border-bottom-width: 2px;
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 0.78rem;
  text-align: center;
  color: var(--ink);
}

/* ---------------------------------------------------------------- alerts */

.menu-banner {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin-bottom: 1rem;
  padding: 0.75rem 0.9rem;
  background: rgba(224, 91, 74, 0.14);
  border: 1px solid var(--danger);
  border-left-width: 4px;
  border-radius: var(--radius);
  text-align: left;
}
.menu-banner strong {
  font-size: 0.82rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--danger);
}
.menu-banner span { color: var(--ink); font-size: 0.88rem; line-height: 1.45; }
.menu-banner.info { background: rgba(200, 217, 79, 0.12); border-color: var(--accent); }
.menu-banner.info strong { color: var(--accent); }

/* Deliberately unmissable: it explains why the game just ended. */
.game-alert {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  background: rgba(8, 6, 6, 0.82);
  text-align: center;
  padding: 2rem;
  animation: alert-in 0.18s ease-out;
}
.game-alert h2 {
  margin: 0;
  font-size: clamp(2rem, 7vw, 4rem);
  letter-spacing: 0.16em;
  color: var(--danger);
  text-shadow: 0 4px 0 #1a0505, 0 0 40px rgba(224, 91, 74, 0.35);
}
.game-alert p { margin: 0; font-size: clamp(0.95rem, 2vw, 1.2rem); color: var(--ink); max-width: 36rem; }
.game-alert-footer { color: var(--ink-dim) !important; font-size: 0.85rem !important; margin-top: 0.8rem !important; }
@keyframes alert-in { from { opacity: 0; transform: scale(1.04); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------- pause menu */

.pause-title { margin: 0 0 0.4rem; letter-spacing: 0.22em; font-size: 1.5rem; }
.warn-hint { color: var(--warn); border-left: 3px solid var(--warn); padding-left: 0.6rem; text-align: left; }

.pause-actions { display: flex; flex-direction: column; gap: 0.45rem; margin-top: 1.2rem; }
.pause-actions button { width: 100%; margin-top: 0; }

.tank-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1rem 1.6rem;
  margin: 1rem 0;
}
.tank-grid h3 {
  margin: 0 0 0.4rem;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}

/* Definition lists rather than a table: these are label/value pairs, and a grid keeps the
   values aligned without inventing columns. */
.spec { display: grid; grid-template-columns: auto 1fr; gap: 0.15rem 0.7rem; margin: 0; font-size: 0.85rem; }
.spec dt { color: var(--ink-dim); }
.spec dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.spec dd.tier { color: var(--accent); font-weight: 600; }
.spec dd.none { color: var(--ink-dim); }
.spec dd.ready { color: var(--good); }
.spec dd.cooling { color: var(--warn); }

.count-badge { font-size: 0.8rem; color: var(--ink-dim); font-weight: 400; }
tbody td.dead { color: var(--ink-dim); }
td.flag-cell, tbody td.flag { width: 1.6rem; padding-right: 0.2rem; }
/* The roster rows are tight, so the flag sits closer to the name there. */
.live-board .flag { margin-right: 0.25rem; }
tbody tr.me td { color: var(--accent); }

/* ---------------------------------------------------------------- HUD */

#hud {
  position: fixed;
  inset: 0;
  z-index: 10;
  /* The HUD must never eat a click meant for the turret. */
  pointer-events: none;
  font-size: 0.85rem;
}

#hud-top-left { position: absolute; top: 1rem; left: 1rem; }
#hud-top-right { position: absolute; top: 1rem; right: 1rem; text-align: right; }
#hud-bottom { position: absolute; bottom: 1rem; left: 50%; transform: translateX(-50%); text-align: center; }

.hp-wrap { display: flex; align-items: center; gap: 0.5rem; }
.hp-bar {
  width: 220px;
  height: 16px;
  background: rgba(10, 12, 9, 0.8);
  border: 1px solid var(--edge);
  border-radius: 2px;
  overflow: hidden;
}
#hp-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--good), #9ad17f);
  transition: width 0.15s linear, background 0.3s ease;
}
#hp-fill.hurt { background: linear-gradient(90deg, var(--warn), #e8c169); }
#hp-fill.critical { background: linear-gradient(90deg, var(--danger), #ef8877); }
#hp-text { font-family: var(--mono); font-weight: 700; min-width: 3ch; }

.loadout { margin-top: 0.5rem; display: flex; flex-wrap: wrap; gap: 0.3rem; max-width: 340px; }
.chip {
  padding: 0.15rem 0.45rem;
  background: rgba(18, 22, 17, 0.85);
  border: 1px solid var(--edge);
  border-radius: 2px;
  font-size: 0.72rem;
  color: var(--ink-dim);
}
.chip b { color: var(--ink); font-weight: 600; }
.chip.hot { border-color: var(--accent-dark); color: var(--accent); }

.live-board { background: rgba(18, 22, 17, 0.8); border: 1px solid var(--edge); padding: 0.4rem 0.6rem; min-width: 190px; }
.live-board .lb-row { display: flex; justify-content: space-between; gap: 0.8rem; font-family: var(--mono); font-size: 0.78rem; padding: 0.08rem 0; }
.live-board .lb-row.me { color: var(--accent); }
.live-board .lb-row.dead { opacity: 0.45; }
.live-board h4 { margin: 0 0 0.3rem; font-size: 0.66rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-dim); }
.live-board .lb-more { color: var(--ink-dim); font-size: 0.68rem; padding-top: 0.2rem; }
.live-board .lb-row.visible span:first-child::before { content: '▸ '; color: var(--accent); }

.kill-feed { position: absolute; top: 1rem; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 0.2rem; align-items: center; }
.kill-feed div {
  padding: 0.2rem 0.6rem;
  background: rgba(18, 22, 17, 0.85);
  border-left: 2px solid var(--danger);
  font-size: 0.8rem;
  animation: fade-slide 0.25s ease;
}
.kill-feed .mine { border-left-color: var(--accent); color: var(--accent); }
@keyframes fade-slide { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

.abilities { display: flex; gap: 0.5rem; justify-content: center; }
.ability {
  position: relative;
  width: 56px;
  height: 56px;
  background: rgba(18, 22, 17, 0.9);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  overflow: hidden;
}
.ability .key { font-family: var(--mono); font-weight: 700; color: var(--accent); font-size: 0.8rem; }
.ability .lbl { font-size: 0.56rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-dim); }
.ability .cool {
  position: absolute;
  inset: 0;
  background: rgba(6, 8, 6, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 0.9rem;
  color: var(--ink-dim);
}
.ability.ready { border-color: var(--accent-dark); }

.secondary-info { margin-top: 0.4rem; font-family: var(--mono); font-size: 0.76rem; color: var(--ink-dim); }

#minimap {
  position: absolute;
  bottom: 1rem;
  right: 1rem;
  background: rgba(10, 12, 9, 0.75);
  border: 1px solid var(--edge);
  border-radius: 2px;
}

.respawn {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(30, 6, 6, 0.42);
  text-align: center;
}
.respawn h2 { margin: 0; font-size: 3rem; letter-spacing: 0.3em; color: var(--danger); text-shadow: 0 3px 0 #1a0505; }
.respawn p { margin: 0.4rem 0 0; color: var(--ink); font-size: 1rem; }

.notice {
  position: absolute;
  bottom: 6.5rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.5rem 1rem;
  background: rgba(18, 22, 17, 0.94);
  border: 1px solid var(--accent-dark);
  color: var(--accent);
  max-width: 80vw;
  text-align: center;
}
.notice.error { border-color: var(--danger); color: var(--danger); }

@media (max-width: 640px) {
  .menu-card { padding: 1.3rem; }
  .hp-bar { width: 140px; }
  .live-board { min-width: 0; font-size: 0.7rem; }
  #minimap { width: 110px; height: 110px; }
  .ability { width: 46px; height: 46px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
