:root {
  --ink: #0d2238;
  --ice: #e8f3ff;
  --blue: #2f7bff;
  --red: #ff4a3d;
  --glass: rgba(14, 34, 58, 0.62);
  --edge: rgba(190, 222, 255, 0.35);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #dbe8f5; color: var(--ice); user-select: none; -webkit-user-select: none; }
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: flex-start; padding: 0 6vw; background: linear-gradient(90deg, rgba(9, 24, 44, 0.78) 0%, rgba(9, 24, 44, 0.35) 55%, rgba(9, 24, 44, 0) 100%); z-index: 20; }
/* The menu is the game's collage key art (the title is in the picture); phones in portrait get the tall version. */
/* The art is drawn whole (never cropped, so the logo is always there) above a compact bar of choices; the art's own navy border is the page colour. */
#menu { flex-direction: column; justify-content: center; align-items: center; gap: 12px; padding: 1.2vh 2vw calc(2.6vh + env(safe-area-inset-bottom)); height: 100vh; height: 100dvh; background: #0b1e36; }
/* The picture takes what the bar leaves (flex), capped so the bar always has room and is never pushed off the bottom. */
#menu::before { content: ""; flex: 1 1 0; width: 100%; min-height: 0; max-height: 60vh; max-height: 60dvh; background: url("art/key_title.jpg") center / contain no-repeat; }
#menu > * { position: relative; z-index: 1; flex: 0 0 auto; }
.tagline { margin: 0; font-size: 13px; letter-spacing: 0.1em; text-transform: uppercase; color: #cfe6ff; text-shadow: 0 2px 6px rgba(0, 10, 30, 0.8); text-align: center; }
.menubar { position: relative; display: flex; align-items: flex-end; gap: 14px; width: min(1100px, 96vw); padding: 16px 18px; border-radius: 18px; background: rgba(10, 28, 52, 0.97); border: 2px solid rgba(150, 205, 255, 0.55); box-shadow: 0 0 0 4px rgba(10, 28, 52, 0.6), 0 16px 50px rgba(0, 10, 30, 0.6), 0 0 36px rgba(80, 160, 255, 0.28); }
.fields { display: flex; flex: 1 1 auto; gap: 10px; flex-wrap: wrap; }
.fields label { display: flex; flex-direction: column; gap: 5px; flex: 1 1 150px; min-width: 120px; font-size: 12px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: #bfe0ff; }
.fields select { font: inherit; font-size: 17px; font-weight: 600; letter-spacing: 0; text-transform: none; color: #fff; background: rgba(255, 255, 255, 0.16); border: 1px solid rgba(190, 222, 255, 0.55); border-radius: 9px; padding: 10px 11px; }
.fields select option { color: #0d2238; }
.menubar .big-btn { flex: 0 0 auto; width: 250px; padding: 17px 10px; font-size: 20px; }
.gear { flex: 0 0 auto; width: 56px; height: 56px; border-radius: 12px; border: 1px solid var(--edge); background: rgba(255, 255, 255, 0.1); color: #fff; font-size: 22px; cursor: pointer; padding: 0; }
.gear:hover, .gear[aria-expanded="true"] { background: rgba(255, 255, 255, 0.22); }
.pop { display: none; position: absolute; right: 0; bottom: calc(100% + 10px); width: min(480px, 94vw); padding: 16px 18px 12px; border-radius: 14px; background: rgba(12, 30, 54, 0.94); border: 1px solid var(--edge); backdrop-filter: blur(10px); box-shadow: 0 14px 44px rgba(0, 10, 30, 0.5); }
.pop.open { display: block; }
.pop-title { margin-bottom: 10px; font-size: 12px; letter-spacing: 0.2em; text-transform: uppercase; color: #9fd0ff; }
@media (max-aspect-ratio: 1/1) {
  #menu::before { background-image: url("art/key_portrait.jpg"); max-height: 56vh; max-height: 56dvh; }
  .menubar { flex-wrap: wrap; }
  .fields { flex: 1 1 100%; }
  .menubar .big-btn { flex: 1 1 auto; width: auto; }
}
@media (max-height: 470px) and (min-aspect-ratio: 1/1) {
  #menu { padding-bottom: calc(1.5vh + env(safe-area-inset-bottom)); }
  #menu::before { max-height: 54vh; max-height: 54dvh; }
  .tagline { display: none; }
  .menubar { padding: 8px 10px; gap: 8px; }
  .fields label { font-size: 9px; flex-basis: 100px; min-width: 90px; }
  .fields select { font-size: 13px; padding: 5px 7px; }
  .menubar .big-btn { width: 180px; padding: 10px 6px; font-size: 15px; }
  .gear { width: 42px; height: 42px; }
}
.sr { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
#pause, #over { justify-content: center; background: rgba(9, 24, 44, 0.55); backdrop-filter: blur(3px); }
.panel { width: min(470px, 100%); padding: 20px 26px 18px; border-radius: 18px; background: var(--glass); border: 1px solid var(--edge); backdrop-filter: blur(10px); box-shadow: 0 18px 60px rgba(0, 10, 30, 0.45); max-height: 94vh; overflow: auto; }
.panel.small { width: min(380px, 100%); text-align: center; }
.kicker { font-size: 12px; letter-spacing: 0.3em; text-transform: uppercase; color: #9fd0ff; margin-bottom: 8px; }
h1 { margin: 0 0 8px; font-size: clamp(36px, 6vw, 56px); line-height: 0.92; font-weight: 900; font-style: italic; letter-spacing: 0.01em; color: #fff; text-shadow: 0 3px 0 #2f7bff, 0 6px 18px rgba(0, 0, 0, 0.35); }
h2 { margin: 0 0 14px; font-size: 34px; font-weight: 900; font-style: italic; color: #fff; }
.lead { margin: 0 0 12px; line-height: 1.4; color: #d6e8fb; font-size: 14px; }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 7px 14px; margin-bottom: 14px; }
.opts label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: #9fd0ff; }
.opts input, .opts select { font: inherit; font-size: 15px; letter-spacing: 0; text-transform: none; color: #fff; background: rgba(255, 255, 255, 0.1); border: 1px solid var(--edge); border-radius: 8px; padding: 7px 9px; }
.opts select option { color: #0d2238; }
.opts input[type=range] { padding: 0; accent-color: #6fb4ff; height: 24px; }
.opts input, .opts select { padding: 5px 8px; }
.big-btn, .ghost-btn { display: block; width: 100%; font: inherit; font-weight: 800; font-size: 18px; letter-spacing: 0.06em; text-transform: uppercase; border-radius: 12px; padding: 14px 18px; cursor: pointer; border: 0; transition: transform 0.12s, filter 0.12s; }
.big-btn { color: #fff; background: linear-gradient(180deg, #4b95ff, #2762d8); box-shadow: 0 5px 0 #17408f, 0 10px 24px rgba(0, 20, 60, 0.4); }
.big-btn:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.08); }
.big-btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 #17408f; }
.big-btn:disabled { filter: grayscale(0.6) brightness(0.8); cursor: default; }
.ghost-btn { margin-top: 12px; color: #cfe6ff; background: transparent; border: 1px solid var(--edge); font-size: 14px; }
.ghost-btn:hover { background: rgba(255, 255, 255, 0.08); }
.note { margin-top: 12px; font-size: 13px; color: #ffd9a6; }
.controls { list-style: none; margin: 12px 0 0; padding: 0; font-size: 12px; line-height: 1.75; color: #cfe3f8; }
kbd { display: inline-block; min-width: 22px; padding: 1px 7px; border-radius: 6px; background: rgba(255, 255, 255, 0.14); border: 1px solid var(--edge); color: #fff; font: 700 12px "Trebuchet MS", sans-serif; text-align: center; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; text-shadow: 0 2px 6px rgba(0, 10, 30, 0.7); }
#scorebar { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 16px; padding: 7px 18px; border-radius: 40px; background: var(--glass); border: 1px solid var(--edge); backdrop-filter: blur(6px); font-weight: 800; }
#scorebar .team { display: flex; align-items: center; gap: 10px; font-size: 26px; }
#scorebar .team.blue b { color: #7db3ff; } #scorebar .team.red b { color: #ff8d83; }
#roundLbl { font-size: 12px; letter-spacing: 0.22em; color: #cfe6ff; min-width: 92px; text-align: center; }
.pips { display: inline-flex; gap: 5px; }
.pips i { width: 12px; height: 12px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5); transition: opacity 0.2s, transform 0.2s; }
.pips i.off { opacity: 0.18; transform: scale(0.7); }
.team.blue .pips { color: var(--blue); } .team.red .pips { color: var(--red); }
#feed { position: absolute; top: 14px; right: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 15px; font-weight: 700; }
#feed div { padding: 3px 10px; border-radius: 6px; background: var(--glass); animation: feedIn 0.25s ease-out; }
@keyframes feedIn { from { transform: translateX(30px); opacity: 0; } }
.b { color: #7db3ff; } .r { color: #ff8d83; }
#big { position: absolute; top: 24%; left: 0; right: 0; text-align: center; font-size: clamp(44px, 8vw, 96px); font-weight: 900; font-style: italic; color: #fff; text-shadow: 0 4px 0 rgba(47, 123, 255, 0.9), 0 8px 28px rgba(0, 0, 0, 0.45); }
#big.pop { animation: pop 0.35s ease-out; }
@keyframes pop { from { transform: scale(1.6); opacity: 0; } }
#sub { position: absolute; top: calc(24% + clamp(52px, 9vw, 108px)); left: 0; right: 0; text-align: center; font-size: 20px; letter-spacing: 0.1em; color: #dcecff; }
#cross { position: absolute; left: 50%; top: 50%; width: 22px; height: 22px; margin: -11px 0 0 -11px; border: 2px solid rgba(255, 255, 255, 0.85); border-radius: 50%; box-shadow: 0 0 0 1px rgba(0, 20, 50, 0.4); }
#cross i { position: absolute; left: 50%; top: 50%; width: 4px; height: 4px; margin: -2px 0 0 -2px; border-radius: 50%; background: #fff; }
#chargeWrap { position: absolute; left: 50%; top: calc(50% + 28px); width: 120px; height: 7px; margin-left: -60px; border-radius: 4px; background: rgba(0, 20, 50, 0.45); border: 1px solid var(--edge); opacity: 0; transition: opacity 0.1s; overflow: hidden; }
#chargeWrap.on { opacity: 1; }
#chargeFill { height: 100%; width: 0; background: linear-gradient(90deg, #8cc8ff, #fff); }
#ammoBox { position: absolute; left: 22px; bottom: 22px; }
#ammo { display: flex; gap: 6px; }
#ammo i { width: 18px; height: 18px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff, #bcd6f0); box-shadow: 0 2px 4px rgba(0, 20, 50, 0.5); transition: opacity 0.15s, transform 0.15s; }
#ammo i.off { opacity: 0.18; transform: scale(0.7); }
#ammoHint { margin-top: 8px; font-size: 13px; letter-spacing: 0.1em; text-transform: uppercase; color: #ffe2a8; min-height: 18px; }
#packWrap { margin-top: 6px; width: 150px; height: 6px; border-radius: 3px; background: rgba(0, 20, 50, 0.45); overflow: hidden; opacity: 0; }
#packWrap.on { opacity: 1; } #packFill { height: 100%; width: 0; background: #fff; }
#keys { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); font-size: 12px; letter-spacing: 0.04em; color: rgba(236, 246, 255, 0.78); white-space: nowrap; transition: opacity 1s; }
#outBanner { position: absolute; top: 9%; left: 0; right: 0; text-align: center; }
#outBanner b { display: block; font-size: clamp(32px, 5vw, 58px); font-weight: 900; font-style: italic; color: #fff; text-shadow: 0 4px 0 rgba(255, 74, 61, 0.9), 0 8px 28px rgba(0, 0, 0, 0.45); }
#outBanner span { font-size: 17px; letter-spacing: 0.1em; color: #dcecff; }
#flash { position: absolute; inset: 0; background: #fff; opacity: 0; }
#flash.on { animation: flash 0.7s ease-out; }
@keyframes flash { from { opacity: 0.85; } to { opacity: 0; } }
#splats { position: absolute; inset: 0; overflow: hidden; }
#splats i { position: absolute; border-radius: 50%; background: radial-gradient(circle, #fff 55%, rgba(255, 255, 255, 0) 72%); opacity: 0.95; animation: melt 3.2s ease-in forwards; }
@keyframes melt { 0%, 55% { opacity: 0.95; transform: translateY(0) scale(1); } 100% { opacity: 0; transform: translateY(46px) scale(1.12); } }
#slowNote { position: absolute; right: 16px; bottom: 14px; font-size: 12px; color: #ffe2a8; opacity: 0.85; }

/* ---------- touch ---------- */
body.touch { touch-action: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
body.touch #menu, body.touch #pause, body.touch #over { touch-action: pan-y; }
body.touch .controls.kb, body.touch #keys { display: none; }
#touchUI { display: none; position: fixed; inset: 0; z-index: 12; pointer-events: none; }
body.touch.playing #touchUI { display: block; }
#touchUI > * { pointer-events: auto; }
#stickBase { display: none; position: fixed; width: 124px; height: 124px; margin: -62px 0 0 -62px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.55); background: rgba(255, 255, 255, 0.12); pointer-events: none; }
#stickKnob { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%; background: rgba(255, 255, 255, 0.7); box-shadow: 0 2px 8px rgba(0, 20, 50, 0.4); }
.tb { position: fixed; display: flex; align-items: center; justify-content: center; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.7); background: rgba(20, 60, 130, 0.5); color: #fff; font: 800 12px "Trebuchet MS", sans-serif; letter-spacing: 0.06em; backdrop-filter: blur(2px); text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); touch-action: none; -webkit-user-select: none; user-select: none; padding: 0; }
.tb.on { background: rgba(255, 255, 255, 0.55); color: #0d2238; text-shadow: none; transform: scale(0.95); }
.tb.big { width: 104px; height: 104px; right: calc(18px + env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom)); font-size: 15px; background: rgba(214, 60, 50, 0.55); }
#tbRoll { width: 70px; height: 70px; right: calc(136px + env(safe-area-inset-right)); bottom: calc(86px + env(safe-area-inset-bottom)); }
#tbPack { width: 70px; height: 70px; right: calc(136px + env(safe-area-inset-right)); bottom: calc(14px + env(safe-area-inset-bottom)); }
#tbCrouch { width: 64px; height: 64px; right: calc(26px + env(safe-area-inset-right)); bottom: calc(138px + env(safe-area-inset-bottom)); }
#tbBuild { width: 52px; height: 52px; right: calc(26px + env(safe-area-inset-right)); bottom: calc(212px + env(safe-area-inset-bottom)); font-size: 10px; }
#tbPause { position: fixed; top: calc(10px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right)); width: 40px; height: 40px; border-radius: 10px; border: 1px solid rgba(255, 255, 255, 0.6); background: rgba(14, 34, 58, 0.55); color: #fff; font-size: 13px; padding: 0; }
body.touch #feed { top: 60px; }
body.touch #ammoBox { left: calc(14px + env(safe-area-inset-left)); top: 12px; bottom: auto; }
body.touch #scorebar { transform: translateX(-50%) scale(0.85); transform-origin: top center; }
body.touch #cross { margin-top: -11px; }
#rotate { position: fixed; inset: 0; z-index: 40; display: none; align-items: center; justify-content: center; text-align: center; background: rgba(9, 24, 44, 0.94); color: #fff; font: 800 22px "Trebuchet MS", sans-serif; }
#rotate small { display: block; margin-top: 8px; font-weight: 400; font-size: 14px; color: #cfe3f8; }
@media (orientation: portrait) { body.touch.playing #rotate { display: flex; } }
@media (max-width: 760px) { .opts { grid-template-columns: 1fr; } #keys { display: none; } }
