/* How Broadside looks. Colours are in the :root list at the top. */
:root {
  --bg: #0f2e45;
  --bg2: #174a68;
  --card: #fbf3e0;
  --ink: #2b1d10;
  --muted: #7d6a52;
  --accent: #c8402d;
  --accent2: #2f78c8;
  --good: #3ddc84;
  --radius: 18px;
  font-family: "Baloo 2", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(circle at 20% 10%, #23638a 0, transparent 45%), radial-gradient(circle at 85% 90%, #145a5f 0, transparent 45%), var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
button, input, select { font: inherit; }

.screen { max-width: 920px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }

/* ---- Title */
.title { text-align: center; color: #fff; padding-top: 8px; }
.title h1 { font-family: "Pirata One", "Baloo 2", serif; font-weight: 400; font-size: clamp(56px, 15vw, 112px); margin: 0; line-height: 1; letter-spacing: 3px; color: #ffd76a; text-shadow: 0 5px 0 #7a3a10, 0 9px 18px rgba(0,0,0,.4); animation: rock 4s ease-in-out infinite; display: inline-block; }
.title p { margin: 4px 0 0; font-size: 18px; opacity: .9; }
@keyframes rock { 50% { transform: rotate(-2deg) translateY(-4px); } }

/* ---- Cards and buttons */
.card { background: var(--card); border-radius: var(--radius); padding: 16px 18px; box-shadow: 0 6px 0 rgba(0,0,0,.25); }
.card h2 { margin: 0 0 10px; font-size: 22px; }
.home-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
@media (max-width: 700px) { .home-grid { grid-template-columns: minmax(0, 1fr); } }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.center { justify-content: center; }
.hint { font-size: 14px; color: var(--muted); margin: 10px 0 0; }

.btn {
  border: 0; border-radius: 14px; padding: 10px 18px; cursor: pointer; font-weight: 700; font-size: 18px;
  background: var(--accent); color: #fff; box-shadow: 0 4px 0 #8a2414; transition: transform .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #8a2414; }
.btn.alt { background: var(--accent2); box-shadow: 0 4px 0 #1c4f8a; }
.btn.ghost { background: #efe3c8; color: var(--ink); box-shadow: 0 4px 0 #d4c29c; }
.btn.big { font-size: 22px; padding: 12px 22px; }
.btn.small { font-size: 16px; padding: 6px 14px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: #efe3c8; border-radius: 12px; font-size: 22px; padding: 4px 10px; cursor: pointer; }

.name-card { display: flex; align-items: center; gap: 10px; justify-content: center; font-size: 20px; flex-wrap: wrap; }
.name-card strong { font-size: 24px; }

.join-row { display: flex; gap: 10px; }
.join-row input {
  flex: 1; min-width: 0; font-size: 28px; font-weight: 800; letter-spacing: 8px; text-transform: uppercase; text-align: center;
  border: 3px solid #dccaa4; border-radius: 14px; padding: 4px 10px; background: #fff; color: var(--ink);
}
.join-row input:focus { outline: none; border-color: var(--accent2); }
.rooms-title { margin-top: 16px !important; display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--good); display: inline-block; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.room-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 280px; overflow-y: auto; }
.room-list li.room { display: flex; align-items: center; gap: 10px; background: #f3e8cf; border-radius: 12px; padding: 8px 10px; }
.room-list .code { font-weight: 800; letter-spacing: 2px; font-size: 18px; }
.room-list .info { flex: 1; font-size: 14px; color: var(--muted); line-height: 1.2; }

.how summary { font-weight: 700; font-size: 20px; cursor: pointer; }
.how li { margin: 6px 0; }
footer { text-align: center; padding-bottom: 12px; color: #dccaa4; }
footer a { color: #dccaa4; }

/* ---- Lobby */
.code-card { text-align: center; }
.room-code { font-size: clamp(56px, 16vw, 96px); font-weight: 800; letter-spacing: 12px; line-height: 1.1; color: var(--accent); }
.code-card .row { justify-content: center; }
.pill { background: #efe3c8; border-radius: 999px; padding: 3px 12px; font-weight: 700; }
.players { list-style: none; padding: 0; margin: 0 0 12px; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.players li { display: flex; align-items: center; gap: 8px; background: #f3e8cf; border-radius: 12px; padding: 6px 10px; font-weight: 700; }
.players .blob { width: 26px; height: 26px; border-radius: 50%; flex: none; box-shadow: inset 0 -3px 0 rgba(0,0,0,.2); }
.players .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players .x { border: 0; background: none; cursor: pointer; font-size: 18px; color: var(--muted); }
.settings { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }
.settings h2 { width: 100%; }
.settings label { display: flex; gap: 6px; align-items: center; font-weight: 700; }
.settings select { border: 2px solid #dccaa4; border-radius: 10px; padding: 4px 8px; background: #fff; }
body:not(.is-host) .host-only { display: none !important; }
body.is-host .guest-only { display: none !important; }
#waiting { color: #dccaa4; }

/* ---- Lobby teams */
.teams { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
@media (max-width: 640px) { .teams { grid-template-columns: minmax(0, 1fr); } }
.team { border-top: 8px solid var(--team, #ccc); }
.team .players { grid-template-columns: minmax(0, 1fr); margin: 0; }

/* ---- Game: the 3D view fills the screen and the HUD sits on top of it. */
#game { position: fixed; inset: 0; overflow: hidden; background: #0b2233; user-select: none; -webkit-user-select: none; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.touch-zone { position: absolute; inset: 0; display: none; touch-action: none; }
body.touch .touch-zone { display: block; }
.hud-top { position: absolute; top: max(8px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 12px; pointer-events: none; }
.hud-mid { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.timer { font-size: 30px; font-weight: 800; color: #fff; background: rgba(8,22,34,.55); border-radius: 12px; padding: 0 14px; line-height: 1.3; }
.timer.low { color: #ffd23f; animation: pulse .5s infinite; }
.target { font-size: 13px; font-weight: 700; color: #fff; text-shadow: 0 1px 0 rgba(0,0,0,.6); }
.score { font-weight: 800; font-size: 30px; color: #fff; min-width: 64px; text-align: center; border-radius: 14px; padding: 0 12px; background: var(--team, #888); box-shadow: 0 3px 0 rgba(0,0,0,.3); text-shadow: 0 2px 0 rgba(0,0,0,.35); }
.minimap { position: absolute; top: max(8px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right)); width: 192px; height: 120px; border-radius: 10px; border: 3px solid rgba(255,255,255,.8); background: #1f6f8f; box-shadow: 0 4px 0 rgba(0,0,0,.25); pointer-events: none; }
@media (max-width: 700px) { .minimap { width: 120px; height: 75px; } .hud-top { left: 8px; transform: none; gap: 6px; } .score { font-size: 20px; min-width: 40px; } .timer { font-size: 20px; } .target { font-size: 11px; } }
.hurt { position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 140px 40px #c0281a; opacity: 0; transition: opacity .2s; }
.hud-bottom { position: absolute; left: 50%; bottom: max(10px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 4px; pointer-events: none; }
.hp-row, .guns-row { display: flex; align-items: center; gap: 8px; }
.ship-icon, .gun-icon { font-size: 22px; filter: drop-shadow(0 2px 0 rgba(0,0,0,.4)); }
.hp-track { width: 220px; height: 16px; border-radius: 10px; background: rgba(8,22,34,.6); border: 2px solid rgba(255,255,255,.75); overflow: hidden; }
.hp-fill { height: 100%; width: 100%; background: linear-gradient(#5fe08a, #2fae5a); transition: width .15s; }
.hp-fill.low { background: linear-gradient(#ff8a6a, #d8382c); animation: pulse .5s infinite; }
.hp-text { color: #fff; font-weight: 800; text-shadow: 0 2px 0 rgba(0,0,0,.5); min-width: 34px; }
.side { display: flex; flex-direction: column; align-items: center; color: #fff; font-weight: 700; font-size: 13px; text-shadow: 0 1px 0 rgba(0,0,0,.6); opacity: .65; }
.side.on { opacity: 1; }
.side .reload { width: 92px; height: 10px; border-radius: 6px; background: rgba(8,22,34,.6); border: 2px solid rgba(255,255,255,.6); overflow: hidden; }
.side .reload-fill { height: 100%; width: 100%; background: #ffd76a; }
.side.ready .reload { border-color: #ffd76a; box-shadow: 0 0 8px #ffd76a; }
.sail-level { color: #fff; font-weight: 700; font-size: 14px; background: rgba(8,22,34,.5); border-radius: 10px; padding: 0 10px; }
.fort-warning { position: absolute; left: 50%; top: 22%; transform: translateX(-50%); background: rgba(160,30,20,.85); color: #fff; font-weight: 800; padding: 6px 16px; border-radius: 14px; pointer-events: none; text-align: center; animation: pulse 0.8s infinite; max-width: calc(100% - 32px); }
.feed { position: absolute; left: max(10px, env(safe-area-inset-left)); top: 150px; display: flex; flex-direction: column; gap: 4px; pointer-events: none; }
.feed div { background: rgba(8,22,34,.6); color: #fff; font-weight: 700; padding: 2px 10px; border-radius: 10px; font-size: 15px; animation: fade 4s forwards; }
@keyframes fade { 80% { opacity: 1; } 100% { opacity: 0; } }
.click-to-aim { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(8,22,34,.35); cursor: pointer; }
.click-to-aim .card { font-size: 24px; font-weight: 800; text-align: center; }
.sunk { position: absolute; left: 50%; top: 28%; transform: translateX(-50%); text-align: center; color: #fff; font-weight: 800; font-size: clamp(44px, 11vw, 88px); text-shadow: 0 5px 0 rgba(0,0,0,.4); pointer-events: none; line-height: 1.1; font-family: "Pirata One", "Baloo 2", serif; }
.sunk .by, .sunk .respawn { font-family: "Baloo 2", system-ui, sans-serif; }
.sunk .by { font-size: 24px; } .sunk .respawn { font-size: 26px; }
.stick { position: fixed; width: 130px; height: 64px; margin: -32px 0 0 -65px; border-radius: 32px; background: rgba(255,255,255,.15); border: 3px solid rgba(255,255,255,.4); pointer-events: none; }
.stick .knob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%; background: rgba(255,255,255,.75); }
.touch-buttons { display: none; }
body.touch .touch-buttons { display: block; }
.tbtn { position: absolute; border: 0; border-radius: 50%; color: #fff; font-weight: 800; font-family: inherit; touch-action: none; box-shadow: 0 5px 0 rgba(0,0,0,.3); opacity: .92; }
.tbtn.fire { right: max(18px, env(safe-area-inset-right)); bottom: max(22px, env(safe-area-inset-bottom)); width: 108px; height: 108px; font-size: 22px; background: #c8402d; }
.tbtn.sail { right: max(138px, calc(env(safe-area-inset-right) + 120px)); width: 58px; height: 58px; font-size: 22px; background: rgba(23,74,104,.9); }
.tbtn.sail.up { bottom: max(96px, calc(env(safe-area-inset-bottom) + 86px)); }
.tbtn.sail.down { bottom: max(26px, env(safe-area-inset-bottom)); }
body.touch .hud-bottom { left: max(10px, env(safe-area-inset-left)); transform: none; align-items: flex-start; }
body.touch .hp-track { width: 140px; }
body.touch .side .reload { width: 64px; }
.emote-bar { position: absolute; left: max(10px, env(safe-area-inset-left)); top: max(10px, env(safe-area-inset-top)); display: flex; gap: 6px; align-items: flex-start; }
.emote-toggle { border: 0; background: rgba(255,255,255,.2); border-radius: 12px; font-size: 22px; padding: 2px 8px; cursor: pointer; }
.emotes { display: flex; flex-wrap: wrap; gap: 4px; max-width: 280px; }
.emotes button { border: 0; background: var(--card); border-radius: 10px; font: inherit; font-weight: 700; padding: 2px 8px; cursor: pointer; }
@media (max-width: 700px) { .emote-bar { top: 64px; } }
.banner { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); font-size: clamp(48px, 13vw, 104px); color: #ffd76a; text-shadow: 0 6px 0 #7a3a10; pointer-events: none; animation: pop .9s ease-out forwards; white-space: nowrap; font-family: "Pirata One", "Baloo 2", serif; }
@keyframes pop { 0% { transform: translate(-50%, -50%) scale(.3); opacity: 0; } 25% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; } 80% { opacity: 1; } 100% { transform: translate(-50%, -50%) scale(1); opacity: 0; } }
.results { position: absolute; inset: 0; background: rgba(8,22,34,.55); display: flex; align-items: center; justify-content: center; padding: 16px; overflow-y: auto; }
.results .card { width: min(480px, 100%); text-align: center; max-height: 100%; overflow-y: auto; }
.results-teams { display: flex; height: 48px; border-radius: 14px; overflow: hidden; margin-bottom: 12px; font-weight: 800; font-size: 22px; color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.3); }
.results-teams div { display: flex; align-items: center; justify-content: center; flex: 1; }
.results ol { text-align: left; padding: 0; list-style: none; margin: 0 0 14px; display: flex; flex-direction: column; gap: 6px; }
.results li { display: flex; align-items: center; gap: 10px; background: #f3e8cf; border-radius: 12px; padding: 6px 12px; font-weight: 700; font-size: 17px; border-left: 8px solid var(--team, #ccc); }
.results li .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results li .stat { color: var(--muted); font-size: 15px; white-space: nowrap; }
.results li.me { outline: 3px solid var(--accent2); }

/* ---- Bits */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 14px; font-weight: 700; box-shadow: 0 6px 20px rgba(0,0,0,.4); max-width: calc(100% - 32px); text-align: center; z-index: 10; }
.mute { position: fixed; top: 10px; right: 10px; border: 0; background: rgba(255,255,255,.15); border-radius: 12px; font-size: 20px; padding: 4px 8px; cursor: pointer; z-index: 5; }
#game:not(.hidden) ~ .mute { top: auto; bottom: max(12px, env(safe-area-inset-bottom)); right: auto; left: 230px; }
body.touch #game:not(.hidden) ~ .mute { left: auto; right: max(10px, env(safe-area-inset-right)); bottom: auto; top: max(140px, calc(env(safe-area-inset-top) + 132px)); }
@media (max-width: 700px) { body.touch #game:not(.hidden) ~ .mute { top: max(92px, calc(env(safe-area-inset-top) + 86px)); } }

/* ---- Gold, the shop button, abilities and power-ups (bottom left) */
.hud-left { position: absolute; left: max(12px, env(safe-area-inset-left)); bottom: max(12px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.hud-row { display: flex; gap: 8px; align-items: center; }
.gold { font-weight: 800; font-size: 20px; color: #ffd76a; background: rgba(8,22,34,.6); border-radius: 12px; padding: 1px 12px; text-shadow: 0 2px 0 rgba(0,0,0,.4); }
.hud-btn { position: relative; border: 3px solid rgba(255,255,255,.8); border-radius: 14px; width: 52px; height: 48px; font-size: 24px; background: rgba(8,22,34,.6); color: #fff; cursor: pointer; font-family: inherit; padding: 0; touch-action: none; }
.hud-btn .key { position: absolute; right: 3px; bottom: 0; font-size: 11px; font-weight: 800; opacity: .8; }
body.touch .hud-btn .key { display: none; }
.shop-btn.open { border-color: #ffd76a; box-shadow: 0 0 12px #ffd76a; animation: pulse 1s infinite; }
.ability-btn.ready { border-color: #7fe3ff; box-shadow: 0 0 10px #7fe3ff; }
.ability-btn .cd { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; border-radius: 11px; background: rgba(8,22,34,.7); font-size: 18px; font-weight: 800; }
.ability-btn .cd:empty { display: none; }
.buffs { display: flex; gap: 6px; flex-wrap: wrap; pointer-events: none; }
.buff { font-weight: 800; color: #1d2a3a; border-radius: 12px; padding: 0 10px; font-size: 16px; box-shadow: 0 2px 0 rgba(0,0,0,.3); }
.buff.ending { animation: pulse .4s infinite; }
body.touch .hud-left { left: max(10px, env(safe-area-inset-left)); bottom: auto; top: max(110px, calc(env(safe-area-inset-top) + 100px)); }
@media (min-width: 701px) { body:not(.touch) .hud-left { bottom: max(12px, env(safe-area-inset-bottom)); } }
@media (max-width: 900px) { body:not(.touch) .hud-left { bottom: 110px; } }
body.touch .feed { top: max(70px, calc(env(safe-area-inset-top) + 64px)); left: 50%; transform: translateX(-50%); align-items: center; }

.shop { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(8,22,34,.5); padding: 12px; }
.shop .card { width: min(640px, 100%); max-height: 100%; overflow-y: auto; }
.shop-head { display: flex; align-items: center; gap: 12px; }
.shop-head h2 { margin: 0; flex: 1; }
.shop h3 { margin: 12px 0 6px; }
.shop-note { margin: 4px 0; font-size: 14px; }
.shop-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
.item { border: 3px solid #e6d6b3; border-radius: 14px; padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; background: #fffaf0; }
.item.on { border-color: #c8402d; background: #fff1dc; }
.item .top { display: flex; align-items: center; gap: 6px; font-weight: 800; font-size: 17px; }
.item .icon { font-size: 24px; }
.item .about { font-size: 13px; color: #6d5a40; flex: 1; }
.item .stats { font-size: 12px; color: #8a7658; }
.item button { margin-top: 4px; }
