:root {
  --bg: #05030c;
  --panel: rgba(12, 10, 28, 0.88);
  --line: #3a3366;
  --hi: #8f7dff;
  --text: #d8d4ff;
  --dim: #8a84b8;
  --metal: #b8c4d8;
  --ice: #7fdcff;
  --cr: #ffe066;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: 'VT323', monospace; font-size: 20px; user-select: none; }
canvas#game { position: fixed; inset: 0; image-rendering: pixelated; cursor: crosshair; }
.hidden { display: none !important; }

.panel { position: fixed; background: var(--panel); border: 2px solid var(--line);
  box-shadow: 0 0 0 2px #000, 4px 4px 0 0 rgba(0,0,0,.6); padding: 8px 10px; }
h1, h2, h3 { font-family: 'Press Start 2P', monospace; font-weight: normal; margin: 0 0 8px; letter-spacing: 1px; }
h1 { font-size: 28px; color: #fff; text-shadow: 3px 3px 0 #5a3aff; }
h2 { font-size: 16px; color: #fff; }
h3 { font-size: 10px; color: var(--hi); }

button { font-family: 'Press Start 2P', monospace; font-size: 10px; color: #fff; background: #4a36c8;
  border: 2px solid #000; box-shadow: inset -2px -2px 0 #2a1a80, inset 2px 2px 0 #8a76ff; padding: 6px 8px; cursor: pointer; }
button:hover { background: #5a46e0; }
button:active { box-shadow: inset 2px 2px 0 #2a1a80; }
button:disabled { background: #333; box-shadow: none; color: #777; cursor: default; }
button.ghost { background: transparent; box-shadow: none; border-color: var(--line); }
button.small { font-size: 8px; padding: 4px 5px; }
button.green { background: #1f8a4a; box-shadow: inset -2px -2px 0 #0d4a24, inset 2px 2px 0 #4ad88a; }
button.red { background: #a8323a; box-shadow: inset -2px -2px 0 #5a1018, inset 2px 2px 0 #ff6a72; }
input { font-family: 'VT323', monospace; font-size: 20px; background: #0a0818; color: #fff; border: 2px solid var(--line); padding: 4px 6px; }
input:focus { outline: none; border-color: var(--hi); }

#top { top: 10px; left: 50%; transform: translateX(-50%); display: flex; gap: 18px; align-items: center; white-space: nowrap; }
#top .res { display: flex; align-items: center; gap: 6px; }
#top .ico { width: 10px; height: 10px; display: inline-block; box-shadow: 0 0 0 2px #000; }
#top b { color: #fff; font-weight: normal; }
#fleet { top: 62px; left: 50%; transform: translateX(-50%); display: flex; gap: 6px; padding: 5px 6px; }
#fleet .fl { position: relative; display: flex; align-items: center; gap: 6px; min-width: 64px; height: 38px; padding: 4px 8px 4px 6px;
  font-family: 'VT323', monospace; font-size: 22px; background: #1a1540; box-shadow: inset -2px -2px 0 #0c0a24, inset 2px 2px 0 #3a3366; }
#fleet .fl:hover:not(:disabled) { background: #2a2260; }
#fleet .fl.on { background: #4a36c8; box-shadow: inset -2px -2px 0 #2a1a80, inset 2px 2px 0 #8a76ff; }
#fleet .fl:disabled { opacity: .4; }
#fleet .fl img { width: 33px; height: 33px; image-rendering: pixelated; }
#fleet .fl b { color: #fff; font-weight: normal; }
#fleet .fl .k { position: absolute; top: 1px; left: 3px; font-size: 13px; color: var(--dim); line-height: 1; }

#sel { left: 10px; bottom: 34px; width: 320px; min-height: 60px; max-height: 60vh; overflow-y: auto; }
#sel .row { color: var(--dim); }
#sel .btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
#sel .queue { margin-top: 6px; color: var(--dim); }
.bar { height: 6px; background: #222; border: 1px solid #000; margin: 4px 0; }
.bar > div { height: 100%; background: #6aff8a; }

#side { right: 10px; top: 10px; width: 290px; max-height: 45vh; overflow-y: auto; }
.prow { display: flex; align-items: center; gap: 6px; padding: 3px 0; border-bottom: 1px dashed #241f44; }
.prow .sw { width: 10px; height: 10px; flex: none; box-shadow: 0 0 0 1px #000; }
.prow .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow .st { color: var(--dim); font-size: 16px; }
.prow.me .nm { color: #fff; }
.tagb { color: var(--dim); font-size: 14px; }

#inbox { position: fixed; right: 10px; top: calc(45vh + 30px); width: 290px; display: flex; flex-direction: column; gap: 6px; }
#inbox .msg { background: var(--panel); border: 2px solid var(--hi); padding: 6px 8px; box-shadow: 0 0 0 2px #000; }
#inbox .msg .btns { display: flex; gap: 6px; margin-top: 4px; }

#log { position: fixed; left: 10px; top: 10px; width: 340px; pointer-events: none; text-shadow: 2px 2px 0 #000; }
#log div { transition: opacity 1s; }
#log .warn { color: #ff6a6a; font-size: 24px; }
/* enemy alert: a pulsing red frame around the whole screen */
#alert { position: fixed; inset: 0; pointer-events: none; z-index: 5; opacity: 0;
  box-shadow: inset 0 0 0 2px rgba(255,70,70,.75), inset 0 0 36px 6px rgba(255,40,40,.22); }
#alert.on { animation: alertGlow 1.6s ease-in-out 2; }   /* two slow, soft breaths */
@keyframes alertGlow { 0%, 100% { opacity: 0; } 50% { opacity: .8; } }

#minimap { position: fixed; right: 10px; bottom: 34px; border: 2px solid var(--line); box-shadow: 0 0 0 2px #000;
  image-rendering: pixelated; background: #000; cursor: pointer; }
#help { position: fixed; left: 0; right: 0; bottom: 0; padding: 4px 10px; font-size: 16px; color: var(--dim);
  background: rgba(0,0,0,.6); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(20,10,60,.55), rgba(0,0,0,.85)); z-index: 10; }
.card { background: var(--panel); border: 2px solid var(--hi); box-shadow: 0 0 0 4px #000, 8px 8px 0 #000;
  padding: 24px 28px; max-width: min(560px, calc(100vw - 32px)); text-align: center; }
.card .tag { color: var(--dim); margin: 0 0 16px; }
.card input { width: 240px; max-width: 100%; margin-right: 6px; }
.howto { text-align: left; color: var(--dim); margin: 18px 0 0; padding-left: 18px; font-size: 18px; }
.howto b { color: var(--text); font-weight: normal; }

@media (max-width: 760px) {
  #side { width: 200px; max-height: 30vh; }
  #inbox { width: 200px; top: calc(30vh + 30px); }
  #sel { width: calc(100vw - 220px); }
  #minimap { width: 120px; height: 120px; }
  #log { width: 60vw; top: 60px; }
  #top { left: 10px; transform: none; max-width: calc(100vw - 230px); flex-wrap: wrap; gap: 4px 10px; font-size: 16px; }
  #log { top: 140px; }
  #fleet { left: 10px; transform: none; top: 84px; }
  #fleet .fl { min-width: 0; padding: 2px 4px; }
  #fleet .fl img { width: 22px; height: 22px; }
}
.bi { display: inline-block; width: 6px; height: 6px; margin-right: 4px; box-shadow: 0 0 0 1px #000; vertical-align: 1px; }
.err { color: #ff6a6a; min-height: 22px; margin-top: 6px; }
.lobbyRow { margin-top: 10px; color: var(--dim); font-size: 16px; } .lobbyRow input { width: 120px; text-transform: uppercase; }

/* ---------- main menu ---------- */
.menu { width: min(860px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow-y: auto; text-align: center; }
.menu .tag { color: var(--dim); margin: 0 0 14px; }
.nameRow input { width: min(320px, 100%); text-align: center; font-size: 24px; }
.modes { display: grid; grid-template-columns: 1.4fr 1fr; gap: 12px; margin-top: 10px; }
.modes .side { display: grid; grid-template-rows: 1fr 1fr; gap: 12px; }
.mode { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; text-align: left; padding: 14px 16px;
  font-family: 'VT323', monospace; font-size: 18px; color: var(--text); background: var(--panel); border: 2px solid var(--line);
  box-shadow: 0 0 0 2px #000, 4px 4px 0 #000; cursor: pointer; }
.mode:hover { background: #1c1640; border-color: var(--hi); }
.mode.big { min-height: 230px; justify-content: flex-end; image-rendering: pixelated;
  /* in-game scene behind the card, darkened toward the bottom so the text stays readable */
  background: linear-gradient(to bottom, rgba(5,3,12,0) 22%, rgba(5,3,12,.86) 54%, rgba(5,3,12,.97) 100%),
              url(img/ffa.png) center 35% / cover no-repeat, #05030c; }
.mode.big:hover { background: linear-gradient(to bottom, rgba(5,3,12,0) 22%, rgba(5,3,12,.78) 54%, rgba(5,3,12,.94) 100%),
              url(img/ffa.png) center 35% / cover no-repeat, #05030c; }
.mode .mtitle { font-family: 'Press Start 2P', monospace; font-size: 14px; color: #fff; }
.mode.big .mtitle { font-size: 20px; text-shadow: 3px 3px 0 #5a3aff; }
.mode .msub { color: var(--dim); }
.mode .mstat { color: #ffe066; font-size: 20px; }
.mode .mjoin { margin-top: 4px; font-family: 'Press Start 2P', monospace; font-size: 10px; color: #fff; background: #4a36c8;
  padding: 6px 10px; box-shadow: inset -2px -2px 0 #2a1a80, inset 2px 2px 0 #8a76ff; }
.mode.custom { opacity: .75; }
.mode.custom .mstat { color: var(--dim); }
.menuFoot { display: flex; align-items: flex-start; gap: 14px; margin-top: 14px; text-align: left; }
.menuFoot details { color: var(--dim); flex: 1; }
.menuFoot summary { cursor: pointer; color: var(--text); }
.bigTimer { font-family: 'Press Start 2P', monospace; font-size: 34px; color: #ffe066; margin: 10px 0; }
.dim { color: var(--dim); }
.wPlayers { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 12px 0 16px; }
.wPlayers span { background: #1a1540; border: 1px solid var(--line); padding: 2px 8px; }
.wPlayers .meTag { border-color: #ffe066; color: #fff; }
.wip { font-family: 'Press Start 2P', monospace; font-size: 14px; color: #ffe066; }
.teamHead { font-family: 'Press Start 2P', monospace; font-size: 9px; margin: 6px 0 2px; }
@media (max-width: 640px) { .modes { grid-template-columns: 1fr; } .mode.big { min-height: 140px; } .menuFoot { flex-direction: column; } }
.mode.big .msub, .mode.big .mstat { text-shadow: 2px 2px 0 #000; }

/* ---------- tutorial ---------- */
#tut { left: 10px; top: 130px; width: 340px; max-width: calc(100vw - 20px); border-color: #ffe066; z-index: 6; }
#tut.ok { border-color: #6aff8a; }
#tut.ok #tutTitle::after { content: '  ✓'; color: #6aff8a; }
#tut .tutHead { display: flex; justify-content: space-between; align-items: center; color: var(--dim); font-size: 16px; margin-bottom: 6px; }
#tut h3 { color: #ffe066; font-size: 11px; }
#tutText { font-size: 18px; line-height: 1.25; }
#tutText b { color: #fff; font-weight: normal; }
#tut .btns { display: flex; gap: 6px; margin-top: 10px; }
.tutHi { outline: 2px solid #ffe066 !important; outline-offset: 2px; animation: tutPulse 1s ease-in-out infinite; }
@keyframes tutPulse { 50% { outline-color: rgba(255,224,102,.25); } }
#tutorialBtn { white-space: nowrap; }

/* ---------- custom games ---------- */
.customWrap { position: relative; display: grid; }
.customCount { position: absolute; top: -11px; right: 10px; z-index: 1; font-family: 'Press Start 2P', monospace; font-size: 8px;
  padding: 4px 6px; background: #1a1540; color: var(--dim); border: 2px solid var(--line); box-shadow: 0 0 0 2px #000; }
.customCount.live { background: #1f8a4a; color: #fff; border-color: #4ad88a; }
.mode.custom { opacity: 1; }
.card.wide { width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 40px); overflow-y: auto; text-align: left; }
.card.wide h2 { text-align: center; }
.tabs { display: flex; gap: 6px; margin: 6px 0 12px; }
.tab { background: transparent; box-shadow: none; border-color: var(--line); color: var(--dim); }
.tab.on { background: #4a36c8; color: #fff; box-shadow: inset -2px -2px 0 #2a1a80, inset 2px 2px 0 #8a76ff; }
#cList { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; max-height: 40vh; overflow-y: auto; }
.cRow { display: flex; align-items: center; gap: 10px; padding: 6px 8px; background: #120e2c; border: 1px solid var(--line); }
.cRow > div { flex: 1; }
.cRow b { color: #fff; font-weight: normal; }
.cN { color: #ffe066; }
.codeRow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.codeRow input { width: 90px; text-transform: uppercase; text-align: center; }
.cForm { display: grid; grid-template-columns: 170px 1fr; gap: 6px 12px; align-items: center; margin-bottom: 10px; }
.cForm label { color: var(--dim); }
.cIn { display: flex; align-items: center; gap: 8px; }
.cIn input[type=number], .cIn input:not([type]), .cIn select { width: 100%; max-width: 260px; }
.cIn input[type=range] { flex: 1; max-width: 220px; accent-color: #8f7dff; }
.cIn output { min-width: 36px; color: #ffe066; }
select { font-family: 'VT323', monospace; font-size: 20px; background: #0a0818; color: #fff; border: 2px solid var(--line); padding: 3px 6px; }
#customClose { margin-top: 10px; }
@media (max-width: 640px) { .cForm { grid-template-columns: 1fr; } }
.bigTimer .dim { display: block; font-size: 11px; margin-bottom: 6px; }

/* ---------- touch screens ---------- */
canvas#game, #minimap { touch-action: none; }
button, .mode { touch-action: manipulation; }
#touchBar { position: fixed; right: 10px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 4; }
#touchBar button { width: 54px; height: 46px; padding: 0; font-size: 12px; opacity: .92; }
#touchBar #tbZoomIn, #touchBar #tbZoomOut { font-size: 20px; }
#touchBar #tbPatrol { height: auto; min-height: 46px; padding: 6px 2px; font-size: 8px; line-height: 1.4; }
#touchBar #tbPatrol.on { background: #1f8a4a; box-shadow: inset -2px -2px 0 #0d4a24, inset 2px 2px 0 #4ad88a; }
body.touch #help { display: none; }
body.touch #minimap { bottom: 10px; }
body.touch #sel { bottom: 10px; }
@media (pointer: coarse) and (max-width: 900px) {
  #side { max-height: 22vh; width: 190px; font-size: 16px; }
  #side .prow .st { font-size: 13px; }
  #inbox { top: calc(22vh + 30px); width: 190px; }
  #top { font-size: 15px; gap: 2px 8px; padding: 5px 8px; }
  #fleet .fl { height: 32px; font-size: 18px; }
  #sel { width: min(300px, calc(100vw - 90px)); max-height: 36vh; }
  #tut { width: min(300px, calc(100vw - 90px)); top: 96px; max-height: 38vh; overflow-y: auto; }
  #tutText { font-size: 16px; }
}

/* touch layout: keep the right column free for the toolbar */
body.touch #sideHead { cursor: pointer; margin: 0; }
body.touch #sideHead::after { content: ' ▾'; }
body.touch.sideClosed #sideHead::after { content: ' ▸'; }
body.touch.sideClosed #players { display: none; }
body.touch #side { right: 74px; }
body.touch #inbox { right: 74px; top: 52px; }
body.touch:not(.sideClosed) #inbox { top: calc(22vh + 30px); }
body.touch #sel.idle { display: none; }
body.touch #log { top: 96px; width: min(46vw, 340px); font-size: 15px; }
body.touch #touchBar { top: 10px; transform: none; }
body.touch #touchBar button { width: 54px; height: 40px; }
@media (pointer: coarse) and (max-height: 480px) {
  body.touch #minimap { width: 96px; height: 96px; }
  body.touch #touchBar { gap: 5px; }
  body.touch #touchBar button { height: 36px; }
}
body.touch #top { left: 10px; transform: none; max-width: calc(100vw - 300px); flex-wrap: wrap; gap: 2px 10px; font-size: 15px; padding: 5px 8px; }
body.touch #fleet { left: 10px; transform: none; top: 76px; }
body.touch #log, body.touch #tut { top: 126px; }
@media (max-height: 480px) {
  body.touch #minimap { width: 96px; height: 96px; }
  body.touch #touchBar { gap: 5px; }
  body.touch #touchBar button { height: 36px; }
  body.touch #sel { max-height: calc(100vh - 140px); }
}
@media (max-width: 600px) { /* portrait phones: one column on the left, toolbar on the right */
  body.touch #top { max-width: calc(100vw - 84px); top: 8px; }
  body.touch #fleet { top: 66px; max-width: calc(100vw - 84px); overflow-x: auto; }
  body.touch #fleet .fl { min-width: 0; padding: 2px 5px; gap: 3px; }
  body.touch #fleet .fl img { width: 22px; height: 22px; }
  body.touch #side { top: 116px; left: 10px; right: auto; width: calc(100vw - 94px); }
  body.touch #inbox { top: 160px; left: 10px; right: auto; width: calc(100vw - 94px); }
  body.touch #log, body.touch #tut { top: 160px; }
  body.touch #minimap { width: 110px; height: 110px; }
  body.touch #sel { width: calc(100vw - 140px); }
}
