/* Fonts are self-hosted (SIL Open Font License, see fonts/OFL-*.txt). */
@font-face { font-family: 'Press Start 2P'; src: url('fonts/press-start-2p.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'VT323'; src: url('fonts/vt323.woff2') format('woff2'); font-display: swap; }

:root {
  --ink: #2e222f;
  --ink2: #3e3546;
  --slate: #625565;
  --lilac: #7f708a;
  --steel: #9babb2;
  --mist: #c7dcd0;
  --white: #ffffff;
  --hot: #f04f78;
  --magenta: #c32454;
  --magenta0: #831c5d;
  --sky: #4d9be6;
  --blue: #4d65b4;
  --navy: #323353;
  --green: #1ebc73;
  --forest: #239063;
  --gold: #f9c22b;
  --amber: #f79617;
  --pink: #ed8099;
  --grape0: #45293f;
  --cream: #fbff86;
  --head: 'Press Start 2P', monospace;
  --body: 'VT323', monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--ink); color: var(--white); font-family: var(--body); font-size: 20px; }
canvas#game { position: fixed; left: 0; top: 0; image-rendering: pixelated; image-rendering: crisp-edges; display: block; touch-action: none; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
.hidden { display: none !important; }

h1, h2, h3 { font-family: var(--head); font-weight: normal; margin: 0 0 12px; letter-spacing: 1px; }
h2 { font-size: 16px; color: var(--gold); text-shadow: 2px 2px 0 var(--ink); }
h3 { font-size: 11px; color: var(--mist); }
p { margin: 0 0 10px; }
b { color: var(--cream); font-weight: normal; }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; flex-direction: column; padding: 16px; overflow-y: auto; }
.screen.active { display: flex; }
.screen.dim { background: rgba(46, 34, 47, 0.72); }
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(46, 34, 47, 0.6); padding: 16px; }

/* ---------- logo ---------- */
.logo { display: flex; align-items: center; gap: 22px; margin-bottom: 34px; }
#logo-worm { width: 96px; height: 112px; image-rendering: pixelated; animation: bob 1.6s steps(2) infinite; filter: drop-shadow(4px 4px 0 var(--ink)); }
@keyframes bob { 50% { transform: translateY(-6px); } }
.title { font-size: clamp(30px, 7vw, 68px); margin: 0; line-height: 1; }
.title span:first-child { color: var(--pink); text-shadow: 4px 0 0 var(--grape0), -4px 0 0 var(--grape0), 0 4px 0 var(--grape0), 0 -4px 0 var(--grape0), 6px 8px 0 var(--ink); }
.title span:last-child { color: var(--gold); text-shadow: 4px 0 0 var(--magenta0), -4px 0 0 var(--magenta0), 0 4px 0 var(--magenta0), 0 -4px 0 var(--magenta0), 6px 8px 0 var(--ink); }
.tagline { font-size: 24px; color: var(--mist); text-shadow: 2px 2px 0 var(--ink); margin-top: 16px; }
.menu-buttons { display: flex; flex-direction: column; gap: 14px; width: min(340px, 90vw); }
.footnote { margin-top: 28px; color: var(--mist); text-shadow: 2px 2px 0 var(--ink); text-align: center; }

/* ---------- buttons ---------- */
.btn {
  font-family: var(--head); font-size: 11px; color: var(--white); cursor: pointer;
  background: var(--hot); border: 3px solid var(--ink); padding: 10px 14px;
  box-shadow: inset -3px -3px 0 var(--magenta), inset 3px 3px 0 #f68181, 0 4px 0 var(--ink);
  text-shadow: 1px 1px 0 var(--ink); transition: transform .05s; white-space: nowrap;
}
.btn:hover { transform: translateY(-2px); filter: brightness(1.08); }
.btn:active { transform: translateY(2px); box-shadow: inset -3px -3px 0 var(--magenta), inset 3px 3px 0 #f68181, 0 1px 0 var(--ink); }
.btn:disabled { filter: grayscale(1) brightness(.7); cursor: not-allowed; transform: none; }
.btn.big { font-size: 14px; padding: 16px 18px; }
.btn.small { font-size: 9px; padding: 7px 10px; }
.btn.blue { background: var(--sky); box-shadow: inset -3px -3px 0 var(--blue), inset 3px 3px 0 #8fd3ff, 0 4px 0 var(--ink); }
.btn.green { background: var(--green); box-shadow: inset -3px -3px 0 var(--forest), inset 3px 3px 0 #91db69, 0 4px 0 var(--ink); }
.btn.gold { background: var(--gold); color: var(--ink); text-shadow: none; box-shadow: inset -3px -3px 0 var(--amber), inset 3px 3px 0 var(--cream), 0 4px 0 var(--ink); }
.btn.gray { background: var(--slate); box-shadow: inset -3px -3px 0 var(--ink2), inset 3px 3px 0 var(--lilac), 0 4px 0 var(--ink); }
.btn.start { width: 100%; margin-top: 14px; }

/* ---------- windows ---------- */
.window {
  background: var(--ink2); border: 4px solid var(--ink); padding: 18px 20px;
  box-shadow: inset 0 0 0 3px var(--slate), 0 8px 0 var(--ink);
  max-height: calc(100vh - 32px); overflow-y: auto; width: min(1100px, 100%);
}
.window.narrow { width: min(560px, 100%); }
.window.center { text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.win-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; }
.win-head h2 { margin: 0; }
.code { color: var(--cream); background: var(--ink); padding: 4px 10px; letter-spacing: 4px; }
.hint { color: var(--steel); font-size: 18px; margin-top: 8px; }

.setup { display: grid; grid-template-columns: 1.15fr 1fr; gap: 20px; }
@media (max-width: 860px) { .setup { grid-template-columns: 1fr; } }
.col-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.col-head h3 { margin: 0; }
.team-list { display: flex; flex-direction: column; gap: 10px; }

.team {
  background: var(--ink); border: 3px solid var(--slate); border-left-width: 8px; padding: 10px 10px 8px;
  display: grid; grid-template-columns: 1fr auto; gap: 6px 10px;
}
.team .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.team .row.full { grid-column: 1 / -1; }
.team input.name { font-family: var(--head); font-size: 11px; flex: 1; min-width: 120px; }
.team .owner { color: var(--steel); font-size: 17px; }
.team.locked { opacity: .85; }
.swatches { display: flex; gap: 3px; }
.swatch { width: 18px; height: 18px; border: 2px solid var(--ink); cursor: pointer; box-shadow: 0 0 0 2px var(--slate); }
.swatch.sel { box-shadow: 0 0 0 2px var(--white); }
.team .worm-names { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.worm-names input { font-size: 17px; padding: 2px 5px; width: 100%; }
.ally { font-family: var(--head); font-size: 10px; }

input, select, textarea {
  font-family: var(--body); font-size: 20px; color: var(--white); background: var(--ink2);
  border: 2px solid var(--slate); padding: 4px 8px; outline: none;
}
input:focus, select:focus { border-color: var(--gold); }
input:disabled, select:disabled { color: var(--steel); }
select { cursor: pointer; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; color: var(--mist); }
.check { display: flex; gap: 10px; align-items: center; margin: 10px 0; cursor: pointer; }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--hot); }
input[type=range] { accent-color: var(--hot); }

.preview-wrap { background: var(--ink); border: 3px solid var(--slate); padding: 6px; margin-bottom: 12px; }
#map-preview { width: 100%; height: auto; image-rendering: pixelated; display: block; background: var(--navy); }
.preview-bar { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; color: var(--mist); }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.opt { display: flex; flex-direction: column; gap: 3px; color: var(--steel); font-size: 18px; }
.opt.inline { flex-direction: row; align-items: center; gap: 8px; color: var(--mist); }

.online-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .online-actions { grid-template-columns: 1fr; } }
.box { background: var(--ink); border: 3px solid var(--slate); padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.box p { color: var(--steel); font-size: 18px; }
.code-input { font-family: var(--head); font-size: 18px; text-transform: uppercase; letter-spacing: 6px; text-align: center; }

.players ul { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.players { margin-top: 14px; }
.players li { background: var(--ink); border: 2px solid var(--slate); padding: 2px 8px; }
.players li.host::after { content: ' (host)'; color: var(--gold); }
.chat-box { margin-top: 12px; background: var(--ink); border: 3px solid var(--slate); }
#chat-log { height: 110px; overflow-y: auto; padding: 6px 8px; font-size: 18px; }
#chat-log .who { color: var(--gold); }
#chat-input { width: 100%; border: none; border-top: 2px solid var(--slate); }

/* ---------- help ---------- */
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 16px; }
@media (max-width: 860px) { .help-grid { grid-template-columns: 1fr; } }
.keys { border-collapse: collapse; width: 100%; }
.keys td { padding: 4px 6px; border-bottom: 2px solid var(--ink); vertical-align: top; }
.keys td:first-child { white-space: nowrap; width: 1%; }
kbd { font-family: var(--head); font-size: 9px; background: var(--slate); border: 2px solid var(--ink); padding: 3px 5px; margin-right: 3px; box-shadow: 0 2px 0 var(--ink); display: inline-block; }
.rules { margin: 0; padding-left: 20px; line-height: 1.15; }
.rules li { margin-bottom: 6px; }
.arsenal { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px; }
.arsenal .wpn { display: flex; gap: 8px; align-items: center; background: var(--ink); padding: 4px 6px; border: 2px solid var(--ink2); }
.arsenal canvas { width: 36px; height: 36px; image-rendering: pixelated; flex: none; }
.arsenal .wpn b { display: block; font-size: 19px; }
.arsenal .wpn span { color: var(--steel); font-size: 16px; line-height: 1; display: block; }

/* ---------- in-game ---------- */
#hud-buttons { position: fixed; top: 80px; right: 12px; display: flex; gap: 8px; }
#weapons {
  position: fixed; right: 12px; bottom: 60px; background: var(--ink2); border: 4px solid var(--ink);
  box-shadow: inset 0 0 0 3px var(--slate), 0 6px 0 var(--ink); padding: 10px; width: 300px; max-height: calc(100vh - 80px); overflow-y: auto;
}
.wp-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
#wp-title { font-family: var(--head); font-size: 10px; color: var(--gold); }
.wp-hint { color: var(--steel); font-size: 15px; }
#wp-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 3px; }
.wcell { position: relative; background: var(--ink); border: 2px solid var(--ink); aspect-ratio: 1; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.wcell:hover { border-color: var(--gold); background: var(--grape0); }
.wcell.sel { border-color: var(--white); background: var(--magenta0); }
.wcell.empty { opacity: .28; }
.wcell.locked { opacity: .45; }
.wcell canvas { width: 100%; height: 100%; image-rendering: pixelated; }
.wcell .cnt { position: absolute; right: 1px; bottom: -2px; font-size: 15px; color: var(--cream); text-shadow: 1px 1px 0 var(--ink), -1px -1px 0 var(--ink); }
.wcell .lock { position: absolute; left: 2px; top: -2px; font-size: 15px; color: var(--hot); text-shadow: 1px 1px 0 var(--ink); }
.wcell.blank { background: transparent; border-color: transparent; cursor: default; }
#wp-info { margin-top: 8px; min-height: 52px; font-size: 17px; color: var(--steel); line-height: 1; }
#wp-info b { display: block; font-size: 20px; margin-bottom: 2px; }
#chat { position: fixed; left: 50%; bottom: 70px; transform: translateX(-50%); width: min(480px, 90vw); }
#chat input { width: 100%; }
#go-stats { display: flex; flex-direction: column; gap: 4px; margin: 6px 0 10px; }
#go-stats .st { display: flex; justify-content: space-between; background: var(--ink); padding: 4px 10px; border-left: 6px solid; }
#go-sub { color: var(--mist); }

#toast { position: fixed; left: 50%; top: 18%; transform: translateX(-50%); font-family: var(--head); font-size: 12px; background: var(--ink); border: 3px solid var(--hot); padding: 12px 16px; display: none; z-index: 10; text-align: center; max-width: 90vw; }
#toast.show { display: block; }

#netstatus {
  position: fixed; left: 50%; top: 14px; transform: translateX(-50%); z-index: 20;
  display: flex; align-items: center; gap: 14px; max-width: 92vw;
  background: var(--ink); border: 3px solid var(--gold); padding: 8px 10px 8px 16px;
  font-family: var(--head); font-size: 10px; line-height: 1.5; box-shadow: 0 4px 0 var(--ink);
}
#netstatus span::before { content: ''; display: inline-block; width: 8px; height: 8px; margin-right: 10px; background: var(--gold); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.players li.away { opacity: .55; }

/* ---------- touch controls ---------- */
#touch { position: fixed; inset: auto 0 0 0; height: 0; pointer-events: none; }
#touch .tpad { position: fixed; bottom: calc(64px + env(safe-area-inset-bottom)); pointer-events: auto; user-select: none; -webkit-user-select: none; }
#touch .tleft { left: 14px; display: grid; grid-template-columns: repeat(3, 56px); grid-template-rows: repeat(3, 56px); gap: 4px; }
#touch .tright { right: 14px; display: flex; flex-wrap: wrap-reverse; justify-content: flex-end; align-items: flex-end; gap: 8px; width: 240px; }
.tbtn {
  font-family: var(--head); font-size: 11px; color: var(--white); background: rgba(62, 53, 70, .78);
  border: 3px solid var(--ink); box-shadow: inset 0 0 0 2px var(--slate); min-width: 56px; height: 56px;
  touch-action: none; -webkit-tap-highlight-color: transparent; padding: 0 10px;
}
.tbtn.on { background: var(--hot); }
.tbtn.tsmall { height: 44px; min-width: 52px; font-size: 9px; }
.tbtn.tfire { width: 92px; height: 92px; border-radius: 50%; background: rgba(240, 79, 120, .85); font-size: 14px; }
.tbtn.tfire.on { background: var(--gold); color: var(--ink); }
#touch .tu { grid-column: 2; grid-row: 1; }
#touch .tl { grid-column: 1; grid-row: 2; }
#touch .tr { grid-column: 3; grid-row: 2; }
#touch .td { grid-column: 2; grid-row: 3; }
#touch.idle .tpad { opacity: .35; }
#touch .tleft .tbtn { font-family: system-ui, sans-serif; font-size: 22px; line-height: 1; }
.online-actions .box { min-width: 0; }
.box input, .box .btn { width: 100%; min-width: 0; }
.field input { width: 100%; }
#rotate-hint { display: none; position: fixed; left: 50%; top: 40%; transform: translateX(-50%); font-family: var(--head); font-size: 10px; background: rgba(46, 34, 47, .85); padding: 10px 14px; border: 3px solid var(--slate); text-align: center; pointer-events: none; animation: fadeHint 6s forwards; }
@keyframes fadeHint { 0%, 70% { opacity: 1; } 100% { opacity: 0; } }
@media (orientation: portrait) { #touch:not(.hidden) #rotate-hint { display: block; } }

#weapons { z-index: 15; }
#touch.menu-open .tpad { display: none; }
.players li .kick { margin-left: 8px; font-family: var(--head); font-size: 8px; color: var(--white); background: var(--magenta); border: 2px solid var(--ink); cursor: pointer; padding: 1px 4px; }
#loading {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 30;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  background: var(--ink2); border: 4px solid var(--ink); box-shadow: inset 0 0 0 3px var(--slate), 0 6px 0 var(--ink);
  padding: 18px 26px; font-family: var(--head); font-size: 11px;
}
#loading .dig { display: flex; gap: 6px; }
#loading .dig i { width: 10px; height: 10px; background: var(--hot); animation: dig .9s steps(2) infinite; }
#loading .dig i:nth-child(2) { animation-delay: .3s; background: var(--gold); }
#loading .dig i:nth-child(3) { animation-delay: .6s; background: var(--sky); }
@keyframes dig { 50% { transform: translateY(-6px); } }

/* title screen: keep the menu readable over the demo battle */
#menu { background: radial-gradient(ellipse 60% 55% at 50% 45%, rgba(46, 34, 47, .72), rgba(46, 34, 47, .35) 60%, rgba(46, 34, 47, 0) 100%); }
/* fixed-height description so the weapon menu doesn't jump around while hovering */
#wp-info { height: 4.8em; min-height: 0; overflow: hidden; }
#wp-info b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
