:root {
  --ink: #0d141d;
  --panel: rgba(17, 27, 40, 0.92);
  --panel2: #1c2b3d;
  --line: #2e4258;
  --brass: #d4ab52;
  --brass-d: #8f6c2a;
  --parch: #efe3c4;
  --text: #e9e3d2;
  --muted: #98a6b6;
  --red: #e0533f;
  --green: #66c25a;
  --blue: #5a9be0;
  --gold: #ffd25a;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #163a5a; color: var(--text); font: 15px/1.35 'Pixelify Sans', system-ui, sans-serif; -webkit-font-smoothing: none; user-select: none; -webkit-user-select: none; }
canvas#screen, canvas#overlay { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; image-rendering: pixelated; }
canvas#overlay { pointer-events: none; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
.hidden { display: none !important; }
h1, h2, h3, .px { font-family: 'Silkscreen', monospace; font-weight: 400; letter-spacing: 0.02em; }
h2 { font-size: 20px; margin: 0 0 8px; color: var(--brass); }
h3 { font-size: 14px; margin: 0 0 4px; color: var(--parch); }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* pixel panel: two-step border */
.panel {
  background: var(--panel);
  border: 2px solid var(--ink);
  box-shadow: inset 0 0 0 2px var(--line), 0 4px 0 rgba(0,0,0,0.35);
  padding: 10px 12px;
}
.panel.brass { box-shadow: inset 0 0 0 2px var(--brass-d), inset 0 0 0 4px var(--ink), 0 4px 0 rgba(0,0,0,0.35); }

button, .btn {
  font: 13px 'Silkscreen', monospace; color: var(--text); background: var(--panel2); cursor: pointer;
  border: 2px solid var(--ink); box-shadow: inset 0 -3px 0 rgba(0,0,0,0.35), inset 0 2px 0 rgba(255,255,255,0.08);
  padding: 8px 12px; min-height: 40px; min-width: 40px; text-transform: uppercase; touch-action: manipulation;
}
button:hover { background: #26394f; }
button:active { box-shadow: inset 0 3px 0 rgba(0,0,0,0.35); transform: translateY(1px); }
button.primary { background: var(--brass); color: #20160a; }
button.primary:hover { background: #e4bd66; }
button.on { background: #3d5c7e; box-shadow: inset 0 0 0 2px var(--brass); }
button.danger { background: #6a2a22; }
button:disabled { opacity: 0.45; cursor: default; }
select, input[type=text] { font: 14px 'Pixelify Sans', sans-serif; background: #0e1824; color: var(--text); border: 2px solid var(--line); padding: 7px 8px; min-height: 40px; }
input[type=range] { width: 100%; accent-color: var(--brass); }
label.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 6px 0; }

/* ---------------------------------------------------------------- menus */
.screen { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b)); background: linear-gradient(rgba(8,16,26,0.25), rgba(8,16,26,0.7)); overflow-y: auto; }
.title-card { width: min(520px, 100%); text-align: center; }
.logo { font-family: 'Silkscreen', monospace; font-size: clamp(42px, 10vw, 76px); line-height: 1; color: var(--parch); text-shadow: 0 4px 0 #0d141d, 4px 4px 0 var(--brass-d); margin: 0 0 6px; }
.tag { color: var(--muted); margin-bottom: 22px; }
.menu-buttons { display: grid; gap: 10px; }
.menu-buttons button { font-size: 16px; min-height: 52px; }
.eras { display: flex; justify-content: center; gap: 6px; margin-top: 18px; flex-wrap: wrap; }
.era-chip { font: 11px 'Silkscreen', monospace; padding: 3px 7px; background: #0e1824; border: 1px solid var(--line); color: var(--muted); }
.era0 { color: #e8c88a; } .era1 { color: #b0b8c0; } .era2 { color: #9ab8d8; } .era3 { color: #9ae0d0; }

.wide { width: min(1080px, 100%); max-height: 100%; display: flex; flex-direction: column; }
.wide-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.wide-head h2 { margin: 0; flex: 1; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; overflow-y: auto; padding: 2px; }
.card { text-align: left; background: var(--panel2); border: 2px solid var(--ink); box-shadow: inset 0 0 0 2px var(--line); padding: 10px; cursor: pointer; text-transform: none; font: inherit; min-height: 120px; display: flex; flex-direction: column; gap: 4px; }
.card:hover { box-shadow: inset 0 0 0 2px var(--brass); }
.card .date { font: 11px 'Silkscreen', monospace; color: var(--muted); }
.card .name { font: 17px 'Silkscreen', monospace; color: var(--parch); }
.card .won { margin-left: auto; color: var(--gold); font: 11px 'Silkscreen', monospace; }
.detail { display: grid; grid-template-columns: 1.1fr 1fr; gap: 14px; overflow-y: auto; }
.sides { display: grid; gap: 10px; }
.side { text-align: left; text-transform: none; font: inherit; padding: 10px; min-height: 0; display: block; }
.side .swatch { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--ink); vertical-align: -1px; margin-right: 6px; }
.side.on { box-shadow: inset 0 0 0 3px var(--brass); }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 13px; margin: 8px 0; }
.facts b { font-family: 'Silkscreen', monospace; font-weight: 400; color: var(--muted); font-size: 11px; }
.start-row { display: flex; gap: 10px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.start-row .grow { flex: 1; }
.form { width: min(440px, 100%); }

/* ---------------------------------------------------------------- HUD */
.hud-top { position: absolute; top: calc(8px + var(--safe-t)); left: calc(8px + var(--safe-l)); right: calc(8px + var(--safe-r)); display: flex; gap: 8px; align-items: flex-start; pointer-events: none; }
.hud-top > * { pointer-events: auto; }
.hud-top .grow { flex: 1; pointer-events: none; }
.stat { display: flex; gap: 14px; align-items: center; padding: 6px 10px; flex-wrap: wrap; }
.stat .k { font: 10px 'Silkscreen', monospace; color: var(--muted); display: block; }
.stat .v { font: 16px 'Silkscreen', monospace; color: var(--parch); }
.stat .v.gold { color: var(--gold); }
.wind { display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 6px; }
.wind canvas { width: 40px; height: 40px; image-rendering: auto; }
.ctrls { display: flex; gap: 4px; }
.ctrls button { min-width: 40px; padding: 6px 8px; }
.mode-chip { font: 11px 'Silkscreen', monospace; padding: 4px 8px; text-align: center; }

.objective { position: absolute; top: calc(66px + var(--safe-t)); left: 50%; transform: translateX(-50%); padding: 6px 12px; font-size: 13px; max-width: min(640px, 92vw); text-align: center; pointer-events: none; }

.feed { position: absolute; left: calc(8px + var(--safe-l)); top: calc(110px + var(--safe-t)); width: min(340px, 60vw); display: flex; flex-direction: column; gap: 3px; pointer-events: none; }
.feed div { background: rgba(10,18,28,0.78); padding: 3px 8px; font-size: 13px; border-left: 3px solid var(--brass-d); animation: fade 8s forwards; }
@keyframes fade { 0%, 80% { opacity: 1 } 100% { opacity: 0 } }

.side-list { position: absolute; right: calc(8px + var(--safe-r)); top: calc(64px + var(--safe-t)); width: 230px; max-height: calc(100% - 330px - var(--safe-t)); overflow-y: auto; padding: 8px; }
.side-list .row { display: flex; align-items: center; gap: 6px; padding: 3px 4px; font-size: 13px; cursor: pointer; }
.side-list .row:hover { background: rgba(255,255,255,0.06); }
.side-list .row.sel { background: rgba(212,171,82,0.2); }
.side-list .sw { width: 10px; height: 10px; border: 1px solid var(--ink); flex: none; }
.side-list .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-list .c { font: 11px 'Silkscreen', monospace; color: var(--muted); }
.side-list h3 { margin-top: 4px; }

.bottom { position: absolute; left: calc(232px + var(--safe-l)); right: calc(8px + var(--safe-r)); bottom: calc(8px + var(--safe-b)); display: flex; justify-content: center; align-items: flex-end; gap: 8px; pointer-events: none; }
.bottom > * { pointer-events: auto; }
.minimap { position: absolute; left: calc(8px + var(--safe-l)); bottom: calc(8px + var(--safe-b)); padding: 4px; }
.minimap canvas { display: block; image-rendering: pixelated; cursor: pointer; touch-action: none; }
.buildbar { display: flex; gap: 6px; padding: 6px; }
.bbtn { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; width: 76px; min-height: 76px; padding: 4px; gap: 2px; text-transform: none; }
.bbtn canvas { image-rendering: pixelated; }
.bbtn .l { font: 10px 'Silkscreen', monospace; }
.bbtn .c { font: 11px 'Silkscreen', monospace; color: var(--gold); }
.bbtn .key { position: absolute; }

.sel-panel { width: min(560px, 100%); max-height: 52vh; overflow-y: auto; flex: 0 1 auto; }
.sel-head { display: flex; gap: 10px; align-items: center; }
.sel-head .t { flex: 1; min-width: 0; }
.sel-head .t .n { font: 16px 'Silkscreen', monospace; color: var(--parch); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sel-head .t .s { font-size: 12px; color: var(--muted); }
.hp { height: 8px; background: #0b121a; border: 1px solid var(--ink); margin: 6px 0; position: relative; }
.hp i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--green); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.chip { font: 10px 'Silkscreen', monospace; padding: 2px 6px; background: #0e1824; border: 1px solid var(--line); }
.chip.bad { color: #ff9a80; border-color: #6a2a22; }
.chip.good { color: #a0e090; }
.weapons { display: grid; grid-template-columns: 1fr auto auto; gap: 2px 10px; font-size: 12px; margin: 6px 0; align-items: center; }
.reload { width: 50px; height: 5px; background: #0b121a; position: relative; }
.reload i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--brass); }
.btnrow { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.btnrow button { padding: 6px 9px; font-size: 12px; min-height: 36px; }
.helm { display: flex; gap: 10px; align-items: center; margin-top: 6px; }
.helm canvas { width: 92px; height: 92px; cursor: pointer; touch-action: none; image-rendering: auto; }
.throttle { display: flex; flex-direction: column; gap: 3px; }
.throttle button { min-height: 30px; padding: 3px 8px; font-size: 11px; }
.queue { display: flex; gap: 4px; flex-wrap: wrap; }
.shipbtns { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px; margin-top: 6px; }
.shipbtns button { text-transform: none; font: 12px 'Pixelify Sans', sans-serif; text-align: left; display: flex; justify-content: space-between; gap: 6px; padding: 6px 8px; }
.shipbtns button b { font: 11px 'Silkscreen', monospace; color: var(--gold); font-weight: 400; }
.fleet-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 2px 8px; font-size: 12px; margin-top: 6px; }
.fleet-list div { cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fleet-list div:hover { color: var(--parch); }

.hint { position: absolute; left: 50%; transform: translateX(-50%); top: calc(110px + var(--safe-t)); padding: 8px 14px; font: 13px 'Silkscreen', monospace; color: var(--parch); pointer-events: none; text-align: center; }
.tooltip { position: absolute; padding: 5px 8px; font-size: 12px; pointer-events: none; max-width: 260px; z-index: 5; }

.modal-bg { position: absolute; inset: 0; background: rgba(6,10,16,0.6); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { width: min(520px, 100%); max-height: 100%; overflow-y: auto; }
.result { font: 34px 'Silkscreen', monospace; text-align: center; margin: 4px 0 6px; }
.result.win { color: var(--gold); } .result.lose { color: var(--red); }
table.stats { width: 100%; border-collapse: collapse; font-size: 13px; margin: 8px 0; }
table.stats td, table.stats th { padding: 3px 6px; border-bottom: 1px solid var(--line); text-align: right; }
table.stats td:first-child, table.stats th:first-child { text-align: left; }
.help-grid { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.help-grid b { font: 11px 'Silkscreen', monospace; color: var(--brass); font-weight: 400; white-space: nowrap; }
.ring { position: absolute; right: calc(10px + var(--safe-r)); top: calc(10px + var(--safe-t)); display: flex; gap: 6px; align-items: center; font-size: 13px; }

@media (max-width: 760px) {
  .side-list { display: none; }
  .detail { grid-template-columns: 1fr; }
  .sel-panel { width: calc(100vw - 16px); max-height: 38vh; }
  .bottom { flex-direction: column; align-items: stretch; left: 8px; }
  .minimap { bottom: auto; top: calc(116px + var(--safe-t)); }
  .minimap canvas { width: 110px !important; height: auto !important; }
  .bbtn { width: 64px; min-height: 64px; }
  .stat { gap: 8px; } .stat .v { font-size: 13px; }
  .objective { top: calc(100px + var(--safe-t)); font-size: 12px; }
  .feed { top: calc(150px + var(--safe-t)); }
}
.wind .k { font: 10px 'Silkscreen', monospace; color: var(--muted); display: block; }
.wind .v { font: 14px 'Silkscreen', monospace; color: var(--parch); }
@media (max-width: 760px) {
  .hud-top { flex-wrap: wrap; gap: 4px; }
  .hud-top .grow, .mode-chip { display: none; }
  .stat { flex: 1 1 100%; padding: 4px 8px; gap: 4px 12px; }
  .stat .small { display: none; }
  .wind { padding: 2px 6px 2px 2px; }
  .wind canvas { width: 30px; height: 30px; }
  .ctrls { flex: 1; justify-content: flex-end; flex-wrap: wrap; }
  .ctrls button { min-width: 36px; min-height: 36px; padding: 4px 6px; }
  .minimap { display: none; }
  .objective { top: calc(120px + var(--safe-t)); }
  .feed { top: calc(170px + var(--safe-t)); }
  .hint { top: calc(120px + var(--safe-t)); width: calc(100vw - 24px); }
}
