:root {
  color-scheme: dark;
  --bg: #090e17;
  --panel: #0e1623;
  --line: #25354b;
  --muted: #9cacc1;
  --text: #e7f1ff;
  --cyan: #6ae6e1;
  --amber: #ffcd7a;
  --red: #ff7e80;
  --mono: ui-monospace, 'SFMono-Regular', Consolas, monospace;
  font: 16px/1.5 system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 290px; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .48; }
button:focus-visible, input:focus-visible, canvas:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }
h1, h2, p { margin: 0; }
.shell { width: min(1510px, calc(100% - 96px)); margin-inline: auto; }
.topbar { background: #0b121e; border-bottom: 1px solid var(--line); }
.topbar-inner { height: 66px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; color: var(--text); font: 800 17px var(--mono); letter-spacing: .11em; white-space: nowrap; }
.brand-icon { display: grid; place-items: center; width: 28px; height: 28px; border: 1px solid #337572; margin-right: 10px; color: var(--cyan); font-size: 24px; line-height: 1; }
.brand-end { color: var(--cyan); }
.top-controls, .connection { display: flex; align-items: center; gap: 12px; }
.connection { font: 12px var(--mono); color: var(--muted); gap: 8px; }
.connection i, .swatch { display: inline-block; width: 8px; height: 8px; background: #8799b0; }
.connection.is-online i { background: var(--cyan); box-shadow: 0 0 10px #6ae6e173; }

.heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin: 41px 0 25px; }
h1 { font: 800 clamp(31px, 4.5vw, 58px)/1.08 var(--mono); letter-spacing: -.075em; }
.heading p { color: var(--muted); margin-top: 9px; }
.map-size { text-align: right; white-space: nowrap; font-family: var(--mono); }
.map-size strong { color: var(--cyan); font-size: clamp(17px, 2.4vw, 27px); display: block; }
.map-size span { color: var(--muted); font-size: 10px; letter-spacing: .14em; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 316px; gap: 19px; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); }
.panel-header, .board-footer { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 13px 17px; }
.panel-header { border-bottom: 1px solid var(--line); }
.board-footer { border-top: 1px solid var(--line); }
h2 { font: 700 15px var(--mono); }
.phase { font: 11px var(--mono); color: var(--cyan); letter-spacing: .05em; text-transform: uppercase; }
.board-scroll { overflow: auto; background-color: #0a111d; background-image: radial-gradient(ellipse at 50% 40%, #1b344c, transparent 70%); }
#board { display: block; width: 100%; min-width: 545px; aspect-ratio: 1000 / 590; touch-action: pan-x pan-y; }
#board.interactive { cursor: crosshair; }
.legend { display: flex; flex-wrap: wrap; gap: 7px 17px; color: var(--muted); font: 11px var(--mono); }
.legend span { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.swatch.own { background: var(--cyan); }
.swatch.near { background: #ffcb62; }
.swatch.near-close { background: #ff544b; }
.swatch.hit { background: var(--red); }
.swatch.shield { background: #a1d9ff; }
.swatch.double { background: #d3a7ff; }
.swatch.reinforce { background: #b8e898; }
.loot { display: flex; flex-wrap: wrap; gap: 7px; list-style: none; margin: 0; padding: 8px 17px; border-bottom: 1px solid var(--line); }
.loot li { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); padding: 4px 7px; color: var(--text); font: 11px var(--mono); }
.loot canvas { width: 18px; height: 18px; image-rendering: pixelated; }
@media (prefers-reduced-motion: no-preference) {
  .loot li { animation: recover-bonus 220ms 150ms both; }
}
@keyframes recover-bonus {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
#coordinate { color: var(--cyan); font: 12px var(--mono); white-space: nowrap; }

.armory { display: grid; gap: 5px; padding: 8px 17px; border-bottom: 1px solid var(--line); }
.stock { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; color: var(--muted); font: 11px var(--mono); }
.stock > span { min-width: 103px; }
.stock-icons { display: flex; gap: 3px; flex-wrap: wrap; }
.stock-icons i { display: block; width: 10px; height: 12px; background: #39495b; }
.stock-icons .loaded { background: #8edddc; }
.stock-icons .missile-icon { clip-path: polygon(50% 0, 72% 21%, 72% 66%, 100% 96%, 68% 89%, 50% 100%, 32% 89%, 0 96%, 28% 66%, 28% 21%); }
.stock-icons .missile-icon.loaded { background: #faa58c; }
.stock-icons .torpedo-icon { clip-path: polygon(50% 0, 68% 15%, 68% 72%, 92% 100%, 8% 100%, 32% 72%, 32% 15%); }
.stock-icons .light-icon { clip-path: polygon(60% 0, 100% 0, 100% 100%, 60% 100%, 44% 64%, 0 64%, 0 36%, 44% 36%); }
.stock-icons .light-icon.loaded { background: #ffcd7a; }
.search-legend { padding: 8px 17px; border-bottom: 1px solid var(--line); color: var(--amber); font: 11px var(--mono); }
.sidebar { display: grid; gap: 14px; }
.side-panel { padding: 19px; }
.side-panel p, .rules { color: var(--muted); font-size: 14px; margin-top: 10px; }
.rules { padding-left: 19px; margin-bottom: 0; }
.rules li + li { margin-top: 8px; }
form { display: grid; gap: 9px; margin-top: 19px; }
label { font: 12px var(--mono); color: var(--muted); }
input, button { border: 1px solid #334964; background: #111d2d; color: var(--text); padding: 9px 11px; border-radius: 0; min-width: 0; }
input { width: 100%; background: #0b131f; }
input::placeholder { color: #8192aa; }
button { font: 700 12px var(--mono); min-height: 39px; }
button:hover:not(:disabled) { background: #21354b; }
button.quiet { color: var(--muted); padding: 5px 8px; font-size: 11px; min-height: 29px; white-space: nowrap; }
button.primary { background: var(--cyan); color: #081b21; border-color: var(--cyan); }
button.primary:hover:not(:disabled) { background: #a0fff9; }
.join-row { display: grid; grid-template-columns: 1fr auto; gap: 7px; margin-top: 5px; }
#code { text-transform: uppercase; font: 13px var(--mono); }
#code::placeholder { text-transform: none; }
.room-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#room-code { color: var(--cyan); }
.players, .shots { list-style: none; padding: 0; margin: 12px 0 0; }
.players li, .shots li { display: flex; gap: 9px; align-items: center; justify-content: space-between; padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px; overflow-wrap: anywhere; }
.players small { color: var(--muted); text-align: right; font: 11px var(--mono); min-width: 62px; }
.player-name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.player-name i { flex: 0 0 8px; height: 8px; }
.players .active small { color: var(--cyan); }
.fleet { display: grid; gap: 4px; list-style: none; padding: 0; margin: 12px 0 0; }
.fleet li { display: flex; align-items: center; justify-content: space-between; gap: 8px; border: 1px solid var(--line); padding: 4px 8px; color: var(--muted); font: 12px var(--mono); }
.fleet li span:last-child { white-space: nowrap; }
.fleet .placed { color: var(--cyan); }
.fleet [aria-current] { border-color: var(--cyan); color: var(--text); background: #193747; }
.segments { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 12px; }
.segments [aria-pressed="true"] { border-color: var(--cyan); color: var(--cyan); }
.battle-modes { grid-template-columns: repeat(3, 1fr); gap: 4px; }
.battle-modes button { padding-inline: 5px; }
#reload, #rescue-clock { color: var(--amber); }
#action, #randomize-fleet, #reload { width: 100%; margin-top: 12px; }
.flight { border-bottom: 1px solid #6f5332; padding: 9px 17px 10px; background: #252221; color: var(--amber); font: 12px var(--mono); }
.flight-status { display: flex; justify-content: space-between; gap: 8px; }
.flight-track { position: relative; margin-top: 8px; padding: 0 11px; }
.flight-track progress { display: block; appearance: none; width: 100%; height: 5px; border: 0; background: #46362d; }
.flight-track progress::-webkit-progress-bar { background: #46362d; }
.flight-track progress::-webkit-progress-value { background: #b57d49; }
.flight-track progress::-moz-progress-bar { background: #b57d49; }
.flight-icon { position: absolute; width: 20px; height: 10px; top: -3px; left: clamp(0px, calc(var(--flight-position, 0%) - 10px), calc(100% - 20px)); background: #ffe2af; clip-path: polygon(0 0, 25% 0, 25% 20%, 80% 20%, 100% 50%, 80% 80%, 25% 80%, 25% 100%, 0 100%, 10% 50%); }
.shots li { display: block; color: var(--muted); }
.shots strong { color: var(--text); }
.error { border: 1px solid #9a4a59; background: #381b28; color: #ffc9cf; padding: 10px 12px; font-size: 14px; }
.page-footer { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font: 11px var(--mono); margin: 23px 0; }

@media (max-width: 1050px) {
  .shell { width: calc(100% - 48px); }
  .layout { grid-template-columns: minmax(0, 1fr) 280px; gap: 13px; }
}
@media (max-width: 830px) {
  .layout { display: flex; flex-direction: column; }
  .sidebar { display: contents; }
  .sidebar > * { order: 1; }
  .board-panel { order: 2; }
  .sidebar #info, .sidebar #activity { order: 3; }
  .heading { margin-top: 25px; }
}
@media (max-width: 450px) {
  .shell { width: calc(100% - 24px); }
  .topbar-inner { height: 53px; }
  .top-controls { gap: 7px; }
  .connection { font-size: 10px; }
  .brand { font-size: 13px; }
  .brand-icon { display: none; }
  .heading p { font-size: 13px; }
  .panel-header, .board-footer { padding-inline: 10px; }
}
