/* ==========================================================================
   DEEP SIX - phosphor terminal styling.
   Palette is a green CRT with amber highlights and a red alarm channel.
   ========================================================================== */

:root {
  --bg:        #05100c;
  --bg-panel:  #071a12;
  --bg-deep:   #030a07;
  --green:     #58f7a6;
  --green-dim: #2c8a5c;
  --green-low: #17402c;
  --amber:     #ffc24b;
  --red:       #ff4d5e;
  --blue:      #6fd6ff;
  --white:     #d8ffe9;
  --line:      #1d5c3f;
  --glow:      0 0 6px rgba(88, 247, 166, 0.55);
  --glow-amber:0 0 8px rgba(255, 194, 75, 0.6);
  --font: "Courier New", "DejaVu Sans Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #000;
  color: var(--green);
  font-family: var(--font);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  overflow: hidden;
  -webkit-font-smoothing: none;
}

button, input { font-family: inherit; font-weight: inherit; letter-spacing: inherit; text-transform: inherit; }

/* ------------------------------------------------------------------ CRT ---- */
#crt {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 45%, #0a2318 0%, var(--bg) 55%, #010402 100%);
  overflow: hidden;
}

#screen {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: clamp(8px, 2vw, 22px);
  animation: flicker 6s infinite steps(1);
}

@keyframes flicker {
  0%, 97%, 100% { opacity: 1; }
  98%           { opacity: 0.93; }
  99%           { opacity: 0.97; }
}

#scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.28) 3px,
    rgba(0, 0, 0, 0.28) 4px
  );
  mix-blend-mode: multiply;
  z-index: 60;
}

#glare {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 61;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(120, 255, 200, 0.07), transparent 55%),
    radial-gradient(ellipse at 50% 50%, transparent 45%, rgba(0, 0, 0, 0.55) 100%);
}

@media (prefers-reduced-motion: reduce) {
  #screen { animation: none; }
  * { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}

/* --------------------------------------------------------------- screens --- */
.scr { display: none; max-width: 1180px; margin: 0 auto; padding-bottom: 40px; }
.scr.active { display: block; animation: screenOn 0.28s ease-out; }

/* Screens that are mostly a short panel sit centred rather than clinging
   to the top of a tall display. */
#menu.active, #queue.active, #room.active, #over.active {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: calc(100vh - 44px);
}
#deploy.active { min-height: calc(100vh - 44px); display: flex; flex-direction: column; justify-content: center; }
@keyframes screenOn {
  from { opacity: 0; transform: scaleY(0.86); filter: brightness(2.2); }
  to   { opacity: 1; transform: scaleY(1); filter: none; }
}

.scr-title {
  font-size: clamp(15px, 3vw, 24px);
  text-shadow: var(--glow);
  margin: 18px 0 10px;
  text-align: center;
}

h2, h3 { margin: 0 0 10px; font-size: 13px; color: var(--amber); text-shadow: var(--glow-amber); }
p { margin: 6px 0; font-size: 12px; line-height: 1.55; }
.dim { color: var(--green-dim); }
.small { font-size: 10px; }
.hidden { display: none !important; }
.blink { animation: blink 1.1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------------------------------------------------------------- panels --- */
.panel {
  position: relative;
  background: linear-gradient(180deg, var(--bg-panel), var(--bg-deep));
  border: 2px solid var(--line);
  padding: 14px;
  box-shadow: inset 0 0 22px rgba(88, 247, 166, 0.07), 0 0 0 1px #000;
}
.panel::before, .panel::after {
  content: "";
  position: absolute;
  width: 8px; height: 8px;
  border: 2px solid var(--green);
  opacity: 0.75;
}
.panel::before { top: -2px; left: -2px; border-right: 0; border-bottom: 0; }
.panel::after  { bottom: -2px; right: -2px; border-left: 0; border-top: 0; }

/* --------------------------------------------------------------- buttons --- */
.btn {
  display: block;
  width: 100%;
  margin: 6px 0;
  padding: 9px 12px;
  background: #0a2418;
  color: var(--green);
  border: 2px solid var(--green-dim);
  cursor: pointer;
  font-size: 12px;
  text-align: left;
  transition: background 0.08s, color 0.08s, transform 0.06s;
}
.btn em {
  display: block;
  font-style: normal;
  font-size: 9px;
  color: var(--green-dim);
  margin-top: 3px;
  letter-spacing: 0.04em;
}
.btn:hover:not(:disabled) { background: var(--green); color: #04140d; border-color: var(--green); }
.btn:hover:not(:disabled) em { color: #06301f; }
.btn:active:not(:disabled) { transform: translateY(2px); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn.big { font-size: 15px; padding: 14px 12px; border-color: var(--green); box-shadow: var(--glow); }
.btn.primary { border-color: var(--amber); color: var(--amber); }
.btn.primary:hover:not(:disabled) { background: var(--amber); color: #1a1000; }
.btn.ghost { border-color: #2b4d3c; color: var(--green-dim); }
.btn.small { font-size: 10px; padding: 6px 8px; }
.btn:focus-visible, input:focus-visible, .link:focus-visible { outline: 2px dashed var(--amber); outline-offset: 2px; }

.link {
  background: none; border: 0; color: var(--green-dim);
  cursor: pointer; font-size: 10px; padding: 4px 6px; text-decoration: underline;
}
.link:hover { color: var(--amber); }

.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin: 14px 0; }
.row .btn { width: auto; min-width: 150px; text-align: center; }
.col { display: flex; flex-direction: column; }

/* ----------------------------------------------------------------- input --- */
.field { display: block; margin: 8px 0; }
.field span { display: block; font-size: 9px; color: var(--green-dim); margin-bottom: 4px; }
input {
  width: 100%;
  padding: 8px 10px;
  background: #041209;
  border: 2px solid var(--line);
  color: var(--amber);
  font-size: 13px;
  outline: none;
}
input::placeholder { color: #1f4a35; }
input:focus { border-color: var(--green); box-shadow: var(--glow); }

/* ------------------------------------------------------------------ boot --- */
#boot { padding-top: 6vh; }
#bootLog {
  font-family: var(--font);
  font-size: clamp(10px, 1.7vw, 13px);
  line-height: 1.6;
  color: var(--green);
  text-shadow: var(--glow);
  white-space: pre-wrap;
  margin: 0 auto;
  max-width: 720px;
  min-height: 55vh;
}
.boot-skip { text-align: center; color: var(--green-dim); font-size: 11px; }

/* ------------------------------------------------------------------ menu --- */
#titleCanvas {
  display: block;
  margin: 10px auto 0;
  width: min(480px, 96%);
  height: auto;
  image-rendering: pixelated;
  filter: drop-shadow(0 0 8px rgba(88, 247, 166, 0.6));
}
.tagline { text-align: center; color: var(--amber); font-size: 11px; margin-bottom: 18px; text-shadow: var(--glow-amber); }
.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  align-items: start;
}
.menu-links { display: flex; gap: 6px; justify-content: space-between; margin-top: 10px; flex-wrap: wrap; }
.join-row { display: flex; gap: 8px; align-items: stretch; }
.join-row input { flex: 1; text-align: center; letter-spacing: 0.4em; }
.join-row .btn { width: auto; margin: 0; }

.seg { display: flex; gap: 4px; margin: 8px 0 2px; }
.seg-btn {
  flex: 1; padding: 7px 2px; font-size: 10px;
  background: #071a12; color: var(--green-dim);
  border: 2px solid var(--line); cursor: pointer;
}
.seg-btn.active { background: var(--green-dim); color: #041209; border-color: var(--green); }
.seg-btn:hover { color: var(--green); }

/* ----------------------------------------------------------------- queue --- */
#queue { text-align: center; padding-top: 6vh; }
.sonar {
  position: relative; width: 190px; height: 190px; margin: 22px auto;
  border: 2px solid var(--line); border-radius: 50%;
  background: radial-gradient(circle, #06231a 0%, #030d09 70%);
  overflow: hidden;
}
.sonar-sweep {
  position: absolute; inset: 0;
  background: conic-gradient(from 0deg, rgba(88, 247, 166, 0.55), transparent 28%);
  animation: sweep 2.4s linear infinite;
}
.sonar-ring {
  position: absolute; inset: 22%;
  border: 2px solid var(--green-dim); border-radius: 50%; opacity: 0.5;
}
@keyframes sweep { to { transform: rotate(360deg); } }

.bar { height: 8px; background: #041209; border: 2px solid var(--line); margin: 8px 0; overflow: hidden; }
.bar.wide { width: min(420px, 100%); margin: 12px auto; }
.bar-fill { height: 100%; width: 0%; background: var(--green); box-shadow: var(--glow); transition: width 0.25s linear; }
.bar-fill.warn { background: var(--amber); }
.bar-fill.crit { background: var(--red); }

.code-big {
  font-size: clamp(40px, 12vw, 76px);
  color: var(--amber);
  text-shadow: var(--glow-amber);
  letter-spacing: 0.22em;
  margin: 14px 0;
  text-align: center;
}
#room { text-align: center; padding-top: 6vh; }
#room .btn { width: min(300px, 100%); margin: 8px auto; text-align: center; }

/* ---------------------------------------------------------------- deploy --- */
.deploy-wrap { display: flex; gap: 16px; align-items: flex-start; justify-content: center; flex-wrap: wrap; padding-top: 10px; }
.deploy-side { width: 290px; flex: 0 0 auto; }
.deploy-board { flex: 0 0 auto; }
canvas { image-rendering: pixelated; image-rendering: crisp-edges; display: block; max-width: 100%; touch-action: manipulation; }
#deployCanvas, #targetCanvas {
  border: 2px solid var(--line);
  background: var(--bg-deep);
  cursor: crosshair;
  box-shadow: 0 0 24px rgba(88, 247, 166, 0.12);
}
/* While an ultimate is armed the whole board reads as dangerous. */
#targetCanvas.ultimate-armed {
  border-color: var(--red);
  box-shadow: 0 0 30px rgba(255, 77, 94, 0.45), inset 0 0 20px rgba(255, 77, 94, 0.2);
}

.ship-list { list-style: none; margin: 8px 0; padding: 0; }
.ship-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; margin: 4px 0;
  border: 2px solid var(--line); background: #061a11;
  cursor: pointer; font-size: 11px;
}
.ship-item:hover { border-color: var(--green); }
.ship-item.selected { background: var(--green-dim); color: #041209; border-color: var(--green); }
.ship-item.placed { opacity: 0.5; }
.ship-item .pips { margin-left: auto; letter-spacing: 2px; color: var(--amber); }
.ship-item.selected .pips { color: #041209; }

/* ---------------------------------------------------------------- battle --- */
.hud-top {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 6px 4px; border-bottom: 2px solid var(--line); margin-bottom: 10px;
}
.hud-side { display: flex; flex-direction: column; min-width: 110px; }
.hud-side.foe { text-align: right; }
.hud-side .tag { font-size: 8px; color: var(--green-dim); }
.hud-side .name { font-size: 13px; color: var(--white); }
.hud-side .score { font-size: 16px; color: var(--amber); text-shadow: var(--glow-amber); }
.hud-side.disconnected .name { color: var(--red); animation: blink 1s steps(2) infinite; }
.hud-center { flex: 1; text-align: center; max-width: 340px; }
.turn-banner { font-size: 13px; color: var(--amber); text-shadow: var(--glow-amber); min-height: 18px; }
.turn-banner.yours { color: var(--green); text-shadow: var(--glow); }
.clock { font-size: 11px; color: var(--green-dim); }
.clock.crit { color: var(--red); animation: blink 0.5s steps(2) infinite; }

.battle-wrap { display: flex; gap: 14px; align-items: flex-start; justify-content: center; flex-wrap: wrap; }
.col-left, .col-right { width: 210px; flex: 0 0 auto; }
.board-main { flex: 0 1 auto; min-width: 0; max-width: 100%; text-align: center; }
.board-label { display: flex; justify-content: space-between; font-size: 10px; color: var(--green-dim); margin-bottom: 4px; }

.core { position: relative; height: 22px; border: 2px solid var(--line); background: #041209; margin-bottom: 10px; }
.core-fill {
  height: 100%; width: 0%;
  background: repeating-linear-gradient(90deg, var(--blue) 0 6px, #2b8fb8 6px 8px);
  box-shadow: 0 0 10px rgba(111, 214, 255, 0.7);
  transition: width 0.3s ease-out;
}
.core span, .core #coreValue {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 10px; color: var(--white); text-shadow: 0 0 3px #000;
}

/* The overdrive meter reads as danger, not as a resource like the core. */
.od-head { margin-top: 14px; color: var(--red); text-shadow: 0 0 8px rgba(255, 77, 94, 0.55); }
.core.od { border-color: #5c1f26; }
.od-fill {
  background: repeating-linear-gradient(90deg, var(--red) 0 6px, #a8202f 6px 8px);
  box-shadow: 0 0 10px rgba(255, 77, 94, 0.7);
}
.core.od.ready { border-color: var(--red); animation: odReady 0.7s infinite; }
.core.od.ready .od-fill {
  background: repeating-linear-gradient(90deg, #ffb3ba 0 4px, var(--red) 4px 8px);
}
.core.od.ready #odValue {
  color: #fff;
  text-shadow: 0 0 4px #000, 0 0 2px #000, 1px 1px 0 #5c1f26;
}
@keyframes odReady {
  50% { box-shadow: 0 0 18px var(--red), inset 0 0 12px rgba(255, 77, 94, 0.5); }
}
.od-hint { margin: 4px 0 8px; font-size: 9px; line-height: 1.4; }
.od-hint b { color: var(--red); }

.ability.ult { border-color: #5c1f26; color: #8a4048; }
.ability.ult .cost { color: var(--red); font-size: 9px; }
.ability.ult.ready {
  color: var(--red); border-color: var(--red);
  text-shadow: 0 0 6px rgba(255, 77, 94, 0.6);
  animation: odReady 0.9s infinite;
}
.ability.ult.ready:hover { background: var(--red); color: #1a0206; text-shadow: none; }
.ability.ult.armed { background: var(--red); color: #1a0206; border-color: #fff; text-shadow: none; }
.ability.ult.armed .cost, .ability.ult.armed .key { color: #1a0206; }

.abilities { display: flex; flex-direction: column; gap: 6px; }
.ability {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 8px; font-size: 10px; text-align: left;
  background: #071a12; border: 2px solid var(--line); color: var(--green-dim); cursor: pointer;
}
.ability .key { color: var(--amber); }
.ability .cost { margin-left: auto; color: var(--blue); }
.ability.ready { color: var(--green); border-color: var(--green-dim); }
.ability.ready:hover { background: var(--green-dim); color: #041209; }
.ability.armed { background: var(--amber); color: #1a1000; border-color: var(--amber); animation: pulse 0.9s infinite; }
.ability.armed .cost, .ability.armed .key { color: #1a1000; }
.ability:disabled { opacity: 0.4; cursor: not-allowed; }
@keyframes pulse { 50% { box-shadow: 0 0 14px var(--amber); } }

.chain {
  margin-top: 10px; padding: 6px; text-align: center;
  border: 2px solid var(--amber); color: var(--amber);
  font-size: 14px; text-shadow: var(--glow-amber);
  animation: chainPop 0.3s ease-out;
}
@keyframes chainPop { from { transform: scale(1.5); } to { transform: scale(1); } }

.fleet-status { list-style: none; margin: 0 0 12px; padding: 0; }
.fleet-status li { display: flex; align-items: center; gap: 6px; font-size: 10px; padding: 3px 0; }
.fleet-status .hull { margin-left: auto; letter-spacing: 1px; }
.fleet-status .hull i { font-style: normal; color: var(--green); }
.fleet-status .hull i.dmg { color: var(--red); }
.fleet-status li.sunk { color: #4a4a4a; text-decoration: line-through; }
.fleet-status li.sunk .hull i { color: #4a4a4a; }

#ownCanvas, #revealYou, #revealFoe {
  width: 196px; height: 196px;
  border: 2px solid var(--line); background: var(--bg-deep); margin-bottom: 10px;
}

.emotes { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; margin-top: 8px; }
.emote-btn {
  padding: 4px 7px; font-size: 9px;
  background: #071a12; border: 2px solid var(--line); color: var(--green-dim); cursor: pointer;
}
.emote-btn:hover { border-color: var(--amber); color: var(--amber); }

.log {
  max-width: 1180px; margin: 12px auto 0; height: 92px; overflow-y: auto;
  border: 2px solid var(--line); background: var(--bg-deep); padding: 6px 10px;
  font-size: 10px; line-height: 1.6;
}
.log div { color: var(--green-dim); }
.log .hit  { color: var(--amber); }
.log .sunk { color: var(--red); }
.log .you  { color: var(--green); }
.log .sys  { color: var(--blue); }

/* ------------------------------------------------------------------ over --- */
#over { text-align: center; padding-top: 3vh; }
.over-title { font-size: clamp(26px, 7vw, 46px); margin: 8px 0; text-shadow: var(--glow); }
.over-title.win  { color: var(--green); }
.over-title.lose { color: var(--red); text-shadow: 0 0 8px rgba(255, 77, 94, 0.6); }
.over-wrap { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin: 14px 0; text-align: left; }
.over-wrap .panel { min-width: 300px; }
.stats { width: 100%; border-collapse: collapse; font-size: 11px; }
.stats td { padding: 3px 6px; border-bottom: 1px solid #10382a; }
.stats td:first-child { color: var(--green-dim); }
.stats td:last-child { text-align: right; color: var(--white); }
.stats tr.hl td:last-child { color: var(--amber); }
.xp { color: var(--amber); font-size: 12px; margin-top: 10px; }
.reveal-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.reveal-row figure { margin: 0; }
.reveal-row figcaption { font-size: 9px; color: var(--green-dim); margin-bottom: 4px; text-align: center; }

/* -------------------------------------------------------------- overlays --- */
.overlay {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(2, 8, 5, 0.88);
  display: none; align-items: center; justify-content: center; padding: 16px;
}
.overlay.open { display: flex; }
.overlay-box { max-width: 560px; width: 100%; max-height: 84vh; overflow-y: auto; }
.help-body p { font-size: 11px; }
.help-body ul { padding-left: 16px; font-size: 11px; }
.help-body li { margin: 4px 0; line-height: 1.5; }
.help-body b { color: var(--amber); }
.close-overlay { margin-top: 12px; text-align: center; }

/* ---------------------------------------------------------------- toasts --- */
.toasts { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 80; pointer-events: none; }
.toast {
  margin: 4px 0; padding: 7px 14px; font-size: 11px;
  background: #04140d; border: 2px solid var(--amber); color: var(--amber);
  box-shadow: var(--glow-amber); animation: toastIn 0.2s ease-out;
}
.toast.bad { border-color: var(--red); color: var(--red); box-shadow: 0 0 8px rgba(255, 77, 94, 0.5); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }

.conn {
  position: fixed; bottom: 6px; right: 10px; z-index: 80;
  font-size: 9px; color: var(--green-dim);
}
.conn.bad { color: var(--red); }

/* ------------------------------------------------------------ responsive --- */
@media (max-width: 900px) {
  /* Stack the columns and put the board first - it is the thing you came for.
     min-width:0 lets the board column shrink instead of pushing the page wide. */
  .battle-wrap { flex-direction: column; align-items: center; }
  .board-main { order: -1; width: 100%; min-width: 0; }
  .col-right { order: 0; width: 100%; max-width: 460px; min-width: 0; }
  .col-left { order: 1; width: 100%; max-width: 460px; min-width: 0; }
  .emotes { max-width: 100%; }
  .abilities { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .chain { margin-top: 8px; }
  #ownCanvas, #deployCanvas, #targetCanvas { margin-left: auto; margin-right: auto; }
  /* The HUD owns the top of a phone screen, so notices go near the bottom. */
  .toasts { top: auto; bottom: 96px; }
  .deploy-wrap { flex-direction: column-reverse; align-items: center; }
  .deploy-side { width: 100%; max-width: 460px; }
}
@media (max-width: 560px) {
  .hud-side { min-width: 64px; }
  .hud-side .name { font-size: 10px; }
  .hud-side .score { font-size: 13px; }
  .log { height: 64px; }
  .menu-grid { gap: 10px; }
}
