:root {
  --bg: #0b1020;
  --panel: rgba(12, 18, 36, 0.92);
  --text: #e9eefb;
  --muted: #8d98b8;
  --attack: #ff5a4a;
  --defend: #4aa8ff;
  --gold: #ffd45a;
  --font: "Press Start 2P", ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); overflow: hidden; }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
button { font-family: inherit; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
.muted { color: var(--muted); }

/* The one bar. Wraps to two rows on narrow screens; the arena is fitted
   above whatever height it ends up. */
.bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 8px 14px; min-height: 58px;
  background: rgba(8, 12, 26, 0.97); border-top: 2px solid #1f2b4d;
  pointer-events: auto;
}

.bar-you { display: flex; align-items: center; gap: 10px; font-size: 10px; min-width: 0; }
.you-meta { display: flex; flex-direction: column; gap: 5px; }
#you-score { font-size: 8px; }
.role-badge { padding: 5px 8px; border-radius: 6px; font-size: 9px; letter-spacing: 1px; color: #0b1020; }
.role-badge.attack { background: var(--attack); }
.role-badge.defend { background: var(--defend); }
.boost-badge {
  padding: 5px 8px; border-radius: 6px; color: #fff;
  font-family: system-ui, sans-serif; font-weight: 800; font-size: 11px;
}

.bar-score {
  display: flex; align-items: center; gap: 14px;
  padding: 0 14px; border-left: 1px solid #1f2b4d; border-right: 1px solid #1f2b4d;
}
.bs-team { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 52px; }
.bs-team small { font-size: 8px; letter-spacing: 1px; }
.bs-team b { font-size: 15px; font-weight: normal; }
.bs-team.attack small { color: var(--attack); }
.bs-team.defend small { color: var(--defend); }
.bs-mid { display: flex; flex-direction: column; align-items: center; gap: 5px; }
#timer { font-size: 16px; color: var(--gold); }
.bs-fort { display: flex; align-items: center; gap: 6px; font-size: 8px; color: var(--muted); }
.integrity-bar { width: 96px; height: 7px; background: #1a2340; border: 1px solid #2d3b66; border-radius: 4px; overflow: hidden; display: block; }
#integrity-fill { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #e9b93a, #ffd45a); transition: width .15s; }

/* Feed line / sponsor banner. */
.bar-ticker {
  flex: 1 1 220px; min-width: 0; height: 42px;
  display: flex; align-items: center; gap: 10px; padding: 0 12px;
  border-radius: 10px; background: rgba(255,255,255,0.035);
  font-size: 9px; color: var(--muted); white-space: nowrap; overflow: hidden;
}
.bar-ticker > span { overflow: hidden; text-overflow: ellipsis; }
.bar-ticker b.attack { color: var(--attack); }
.bar-ticker b.defend { color: var(--defend); }
.bar-ticker.new > span { animation: tick-in .35s ease-out; }
@keyframes tick-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.bar-ticker.brand {
  color: #fff; font-family: system-ui, sans-serif; box-shadow: inset 0 0 0 2px rgba(255,255,255,.85);
  animation: brand-in .5s cubic-bezier(.2,.9,.3,1.3);
}
.bar-ticker.brand img { width: 32px; height: 32px; border-radius: 8px; flex: none; }
.bar-ticker.brand .tk-boost { font-size: 18px; font-weight: 900; letter-spacing: .5px; flex: none; }
.bar-ticker.brand .tk-sub { font-size: 13px; font-weight: 700; opacity: .95; }
@keyframes brand-in { from { transform: scale(.92); } to { transform: none; } }

/* This round's sponsors. */
.bar-sponsors { display: flex; gap: 6px; }
.ss-chip {
  display: flex; align-items: center; gap: 6px;
  padding: 3px 9px 3px 3px; border-radius: 9px; color: #fff;
  font-family: system-ui, sans-serif; font-weight: 800; font-size: 11px; white-space: nowrap;
  transition: opacity .2s, box-shadow .2s;
}
.ss-chip img { width: 24px; height: 24px; border-radius: 6px; display: block; }
.ss-chip.respawning { opacity: .45; }
.ss-chip.carried { opacity: 1; box-shadow: 0 0 0 2px #fff, 0 0 14px rgba(255,255,255,.5); }

.bar-btns { display: flex; gap: 6px; margin-left: auto; }
.bar-btn {
  font-size: 15px; line-height: 1; padding: 7px 8px; cursor: pointer;
  background: #16214a; border: 2px solid #2d3b66; border-radius: 8px;
}
.bar-btn.on { border-color: var(--gold); }

/* Leaderboard pops up above the bar on demand. */
.lb-pop {
  position: absolute; right: 14px; width: 230px; pointer-events: auto;
  background: var(--panel); border: 2px solid #1f2b4d; border-radius: 10px;
  padding: 10px 12px; font-size: 9px;
}
.lb-title { color: var(--muted); letter-spacing: 1px; margin-bottom: 8px; }
#lb-list { list-style: none; margin: 0; padding: 0; }
#lb-list li { display: flex; justify-content: space-between; padding: 3px 0; gap: 6px; }
#lb-list li .lb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#lb-list li.attack .lb-name::before { content: "▲ "; color: var(--attack); }
#lb-list li.defend .lb-name::before { content: "■ "; color: var(--defend); }
#lb-list li.me { color: var(--gold); }

.sponsor-panel { width: min(820px, 96vw); text-align: left; }
.sp-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sp-head h2 { font-size: 14px; margin: 0; }
.sp-note { font-size: 8px; color: var(--muted); line-height: 1.7; margin: 0 0 12px; }
.sp-round { font-size: 9px; margin-bottom: 12px; line-height: 1.8; }
.sp-table { width: 100%; border-collapse: collapse; font-size: 9px; }
.sp-table th { color: var(--muted); font-weight: normal; text-align: left; padding: 6px 6px; border-bottom: 1px solid #26355f; }
.sp-table td { padding: 7px 6px; border-bottom: 1px solid #172142; }
.sp-table td.num { text-align: right; }
.sp-table th:nth-child(n+4) { text-align: right; }
.sp-swatch { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.sp-live { color: var(--gold); }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(5, 8, 18, 0.72); z-index: 10;
}
.overlay.light { background: rgba(5, 8, 18, 0.35); pointer-events: none; }

.panel {
  width: min(680px, 94vw); max-height: 94vh; overflow: auto;
  background: var(--panel); border: 2px solid #26355f; border-radius: 14px;
  padding: 28px 28px 22px; text-align: center;
}
.title { font-size: 26px; margin: 0 0 10px; letter-spacing: 1px; }
.title span { color: var(--gold); }
.subtitle { font-size: 10px; color: var(--muted); line-height: 1.7; margin: 0 0 16px; }

.live-pill {
  display: inline-flex; align-items: center; gap: 8px; font-size: 9px;
  border: 1px solid #2d3b66; border-radius: 999px; padding: 6px 12px; margin-bottom: 18px; color: var(--muted);
}
.live-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: #ff4a4a; box-shadow: 0 0 10px #ff4a4a; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .35; } }

.vs-hero { display: flex; align-items: center; justify-content: center; gap: 18px; margin-bottom: 18px; }
.vs-side { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 13px; line-height: 1.6; }
.vs-side canvas { display: block; }
.vs-side span { font-size: 8px; color: var(--muted); }
.vs-side.red { color: var(--attack); }
.vs-side.blue { color: var(--defend); }
.vs-mid { font-size: 22px; color: var(--gold); }

.name-row { margin-bottom: 14px; }
.name-row input {
  font-family: inherit; font-size: 10px; padding: 10px 12px; width: 100%;
  background: #0f1730; color: var(--text); border: 2px solid #26355f; border-radius: 8px; outline: none;
}
.name-row input:focus { border-color: var(--gold); }

.btn-row { display: flex; gap: 10px; justify-content: center; margin-bottom: 16px; }
.btn {
  font-size: 11px; padding: 12px 18px; border-radius: 8px; cursor: pointer;
  background: #16214a; color: var(--text); border: 2px solid #2d3b66;
}
.btn:hover { filter: brightness(1.15); }
.btn.primary { background: var(--gold); color: #0b1020; border-color: var(--gold); }
.btn.small { font-size: 9px; padding: 8px 12px; }

.controls-help { display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: center; font-size: 8px; color: var(--muted); }
.controls-help b { color: var(--text); }

.flash-card { text-align: center; }
.flash-label { font-size: 10px; color: var(--muted); letter-spacing: 2px; margin-bottom: 10px; }
.flash-label.small { margin-top: 18px; }
.flash-role { font-size: 34px; margin-bottom: 12px; }
.flash-role.small { font-size: 16px; }
.flash-role.attack { color: var(--attack); }
.flash-role.defend { color: var(--defend); }
.flash-goal { font-size: 10px; color: var(--text); line-height: 1.8; max-width: 520px; }

/* Scoreboard: your kills and deaths either side of the clock, and the
   fortress health bar. */
.bs-team.mine small { color: var(--muted); font-size: 7px; }
.bs-team.mine b { color: var(--text); }
.bs-fort-label { font-size: 7px; letter-spacing: 1px; color: var(--muted); }
.integrity-bar { width: 120px; height: 9px; }
#integrity-fill { transition: width .2s, background .4s; }
body.touch .bs-fort-label { display: none; }

/* Team table at the top of the 🏆 panel. */
.lb-teams { width: 100%; border-collapse: collapse; margin-bottom: 12px; font-size: 9px; }
.lb-teams th { font-weight: normal; padding: 3px 4px; text-align: right; }
.lb-teams th.attack { color: var(--attack); }
.lb-teams th.defend { color: var(--defend); }
.lb-teams td { padding: 4px; text-align: right; border-top: 1px solid #1f2b4d; }
.lb-teams td:first-child { text-align: left; color: var(--muted); }

/* ---------- Viewer follow mode ---------- */
.spec-mode {
  font-family: system-ui, sans-serif; font-size: 12px; font-weight: 700;
  padding: 7px 10px; border-radius: 8px; cursor: pointer;
  background: #16214a; color: var(--text); border: 2px solid #2d3b66; white-space: nowrap;
}
.bar-btn.on, .spec-mode.on { border-color: var(--gold); }
.spec-info { font-family: system-ui, sans-serif; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; min-width: 90px; }
body.touch .sm-label { display: none; }
body.touch #bar-spec { gap: 5px; flex-shrink: 0; }
body.touch #bar-spec .bar-btn, body.touch .spec-mode { padding: 4px 6px; }
body.touch .spec-info { font-size: 11px; min-width: 0; max-width: 104px; }
body.touch #btn-join-now { padding: 6px 8px; }
/* The sponsor report is a tool for you and sponsors, not players: desktop only. */
body.touch #btn-sponsors { display: none; }
.spec-info b { color: var(--text); }
.spec-info .attack { color: var(--attack); }
.spec-info .defend { color: var(--defend); }

/* ---------- Team quick-chat ---------- */
.chat-pop { width: 250px; }
.chat-list { display: flex; flex-direction: column; gap: 4px; }
.chat-line {
  display: flex; gap: 8px; align-items: center; text-align: left;
  font-family: system-ui, sans-serif; font-size: 13px; font-weight: 600;
  padding: 7px 9px; border-radius: 7px; cursor: pointer;
  background: #16214a; color: var(--text); border: 1px solid #2d3b66;
}
.chat-line:hover { border-color: var(--gold); }
.chat-line kbd { font-family: var(--font); font-size: 8px; color: var(--muted); min-width: 10px; }

/* ---------- Shells + Your Reef ---------- */
.btn-row { flex-wrap: wrap; }
#btn-reef-menu { flex-basis: 100%; background: #2a2412; color: #ffe08a; border-color: #6b5a24; }
.shells-chip {
  padding: 5px 8px; border-radius: 6px; background: #2a2412; color: #ffe08a;
  font-family: system-ui, sans-serif; font-weight: 800; font-size: 12px; white-space: nowrap;
}
.result-payout {
  margin-top: 14px; font-family: system-ui, sans-serif; font-size: 22px; font-weight: 900; color: #ffe08a;
}
.result-payout span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-top: 4px; }

#reef { z-index: 15; }
.reef-panel { width: min(1040px, 96vw); text-align: left; font-family: system-ui, sans-serif; padding: 18px 20px; }
.reef-head { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.reef-head h2 { font-family: var(--font); font-size: 15px; margin: 0; flex: 1; }
.reef-shells { font-size: 18px; font-weight: 900; color: #ffe08a; }
.reef-body { display: flex; gap: 16px; align-items: flex-start; }
.reef-left { flex: 1.25; min-width: 0; }
.reef-right { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
#reef-canvas { width: 100%; height: auto; display: block; border-radius: 12px; cursor: pointer; touch-action: manipulation; }
.reef-hint { min-height: 30px; margin: 8px 0 12px; font-size: 13px; color: var(--text); line-height: 30px; }
.reef-hint .btn { margin-left: 8px; }
.reef-box { background: #0f1730; border: 1px solid #26355f; border-radius: 10px; padding: 10px 12px; }
.reef-box-title { font-family: var(--font); font-size: 8px; color: var(--muted); letter-spacing: 1px; margin-bottom: 8px; }
.reef-shop { display: flex; flex-direction: column; gap: 6px; max-height: 300px; overflow: auto; }
.reef-card { display: flex; align-items: center; gap: 10px; padding: 4px 6px; border-radius: 8px; background: rgba(220,185,127,0.08); }
.reef-card canvas { flex: none; width: 84px; height: 64px; border-radius: 6px; background: #dcb97f; }
.rc-text { flex: 1; display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.rc-text span { font-size: 11px; color: var(--muted); }
.rc-buy { flex: none; background: #2a2412; color: #ffe08a; border-color: #6b5a24; font-family: system-ui, sans-serif; font-weight: 800; font-size: 12px; }
.rc-buy:disabled { opacity: .4; cursor: default; }
.reef-crab-row { display: flex; gap: 12px; align-items: center; }
.reef-crab-row canvas { flex: none; }
.reef-equip { display: flex; flex-direction: column; gap: 6px; }
.eq-row { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; font-size: 12px; }
.eq-label { width: 40px; color: var(--muted); }
.eq-chip { font-family: system-ui, sans-serif; font-size: 11px; padding: 4px 8px; border-radius: 999px; border: 1px solid #2d3b66; background: #16214a; color: var(--text); cursor: pointer; }
.eq-chip.on { background: var(--gold); color: #0b1020; border-color: var(--gold); }
.eq-locked { font-size: 11px; color: var(--muted); font-style: italic; }
.ch { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; font-size: 13px; padding: 5px 0; }
.ch.done { color: var(--muted); }
.ch-reward { color: #ffe08a; font-weight: 700; }
.ch-bar { grid-column: 1 / -1; height: 5px; background: #1a2340; border-radius: 3px; overflow: hidden; }
.ch-bar div { height: 100%; background: linear-gradient(90deg, #e9b93a, #ffd45a); }
.ch-streak { font-size: 12px; color: var(--muted); margin-top: 6px; }
.reef-note { font-size: 11px; color: var(--muted); margin: 12px 0 0; }

@media (max-width: 820px) {
  .reef-body { flex-direction: column; }
  .reef-left, .reef-right { width: 100%; }
  .reef-shop { max-height: none; }
}

/* ---------- Phones / touch ---------- */
canvas#game { touch-action: none; }
button { touch-action: manipulation; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input { -webkit-user-select: text; user-select: text; }

.touch-only { display: none; }
body.touch .touch-only { display: flex; }
body.touch .desktop-only { display: none; }

.touch-ui { position: fixed; inset: 0; pointer-events: none; z-index: 4; }
.stick {
  position: absolute; width: 112px; height: 112px; margin: -56px 0 0 -56px;
  border-radius: 50%; border: 2px solid rgba(255,255,255,.35); background: rgba(255,255,255,.07);
}
.stick .knob {
  position: absolute; left: 50%; top: 50%; width: 50px; height: 50px; margin: -25px 0 0 -25px;
  border-radius: 50%; background: rgba(255,255,255,.55);
}
.stick.aim { border-color: rgba(255,212,90,.5); }
.stick.aim .knob { background: rgba(255,212,90,.75); }
/* Ghost rings that show where the thumbs go until you touch. */
.stick-hint {
  position: absolute; bottom: 28px; width: 104px; height: 104px; border-radius: 50%;
  border: 2px dashed rgba(255,255,255,.18); display: flex; align-items: center; justify-content: center;
  font-size: 7px; color: rgba(255,255,255,.4); text-align: center;
}
.stick-hint.left { left: 28px; }
.stick-hint.right { right: 28px; }
.touch-ui.engaged .stick-hint { display: none; }
/* PATCH looks like the other ghost controls, and lights up while held. */
.patch-btn {
  position: absolute; right: 150px; bottom: 34px; pointer-events: auto;
  width: 74px; height: 74px; border-radius: 50%;
  background: transparent; color: rgba(255,255,255,.4);
  border: 2px dashed rgba(255,255,255,.18);
  font-family: var(--font); font-size: 7px;
}
.patch-btn.down { background: rgba(74,168,255,.2); border: 2px solid rgba(138,200,255,.6); color: rgba(255,255,255,.8); }

.team-edge { position: fixed; inset: 0; pointer-events: none; z-index: 3; border: 4px solid transparent; }
.team-edge.attack { border-color: rgba(255,90,74,.75); }
.team-edge.defend { border-color: rgba(74,168,255,.75); }

.rotate-icon { font-size: 44px; margin-bottom: 14px; }
#rotate { z-index: 20; background: #05080f; }
/* Let thumbs start moving while the team card is still showing. */
#role-flash { pointer-events: none; }

/* On phones the bar moves to a slim strip along the top, and the feed line
   becomes a short pop-up under it. */
body.touch .bar {
  top: 0; bottom: auto; min-height: 0; padding: 4px 10px; gap: 10px;
  border-top: none; border-bottom: 2px solid #1f2b4d;
}
body.touch #you-name { display: none; }
body.touch .you-meta { gap: 2px; }
body.touch .role-badge { padding: 4px 6px; font-size: 8px; }
body.touch .bar-score { padding: 0 8px; gap: 10px; }
body.touch .bs-team { min-width: 40px; gap: 2px; }
body.touch .bs-team b { font-size: 12px; }
body.touch .bs-team small { font-size: 7px; }
body.touch #timer { font-size: 12px; }
body.touch .bs-mid { gap: 3px; }
body.touch .integrity-bar { width: 64px; }
body.touch .ss-chip { padding: 2px; }
body.touch .ss-chip span { display: none; }
body.touch .ss-chip img { width: 20px; height: 20px; }
body.touch .bar-sponsors { gap: 4px; }
body.touch .bar-btn { padding: 4px 6px; font-size: 13px; }
body.touch .bar-ticker {
  position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  width: max-content; max-width: 80vw; height: 30px; opacity: 0; pointer-events: none;
  background: rgba(8,12,26,.9);
}
body.touch .bar-ticker.new, body.touch .bar-ticker.brand { animation: phone-toast 3s forwards; }
body.touch .bar-ticker.brand img { width: 22px; height: 22px; }
body.touch .bar-ticker.brand .tk-boost { font-size: 14px; }
body.touch .bar-ticker.brand .tk-sub { font-size: 11px; }
@keyframes phone-toast {
  0% { opacity: 0; transform: translate(-50%, -6px); }
  10%, 85% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, 0); }
}
@media (orientation: landscape) { body.touch .bar { flex-wrap: nowrap; } }

/* Narrow screens: the feed line drops to its own full-width row and the
   sponsor chips shrink to logos. */
@media (max-width: 1100px) {
  .bar { gap: 10px; padding: 8px 10px; }
  .bar-ticker { order: 10; flex-basis: 100%; height: 38px; }
  .ss-chip span { display: none; }
  .ss-chip { padding: 3px; }
}

/* Phones held sideways: squeeze the menu so Play is on screen without
   scrolling. */
@media (max-height: 500px) {
  .panel { padding: 12px 18px; }
  .title { font-size: 18px; margin-bottom: 4px; }
  .subtitle { font-size: 8px; margin-bottom: 8px; }
  .live-pill { margin-bottom: 8px; padding: 4px 10px; }
  .vs-hero { margin-bottom: 8px; gap: 12px; }
  .vs-side { flex-direction: row; gap: 8px; font-size: 10px; text-align: left; }
  .vs-side canvas { width: 60px; height: auto; }
  .vs-mid { font-size: 16px; }
  .name-row { margin-bottom: 8px; }
  .name-row input { padding: 8px 10px; }
  .btn-row { margin-bottom: 8px; }
  .btn { padding: 10px 16px; }
  .controls-help { gap: 4px 12px; font-size: 7px; }
}

@media (max-width: 640px) {
  .bar-score { padding: 0 8px; gap: 8px; border: none; }
  .integrity-bar { width: 60px; }
  .title { font-size: 18px; }
  .flash-role { font-size: 22px; }
}
