:root {
  --bg: #14202b;
  --panel: rgba(16, 26, 36, 0.78);
  --card: #1c2a38;
  --card-2: #233548;
  --text: #eaf2f8;
  --muted: #8ea3b5;
  --accent: #ffc83d;
  --accent-2: #ff8a3d;
  --good: #4fd88a;
  --blue: #4aa3ff;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: 'Nunito', system-ui, sans-serif; user-select: none; -webkit-user-select: none; overscroll-behavior: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
/* Only the game surface blocks browser gestures; menus must stay scrollable on touch screens.
   The canvas is sized in px from JS (100vh is taller than the visible area on iOS Safari). */
canvas#game { position: fixed; left: 0; top: 0; width: 100vw; height: 100vh; display: block; z-index: 1; touch-action: none; }
button, input { touch-action: manipulation; }
#ground { position: fixed; left: 0; top: 0; z-index: 0; background-repeat: repeat; will-change: transform; image-rendering: auto; }
#debug { position: fixed; left: 54px; top: 10px; z-index: 30; margin: 0; padding: 8px 10px; background: rgba(0,0,0,0.75); color: #9f9; font: 12px/1.4 ui-monospace, Menlo, monospace; border-radius: 8px; pointer-events: none; }
.hidden { display: none !important; }
.no-gems .gem, .no-gems .alt-price, .no-gems #shop-action-gems { display: none !important; } /* the gem currency is off (hello) */
kbd { font-family: inherit; font-size: 0.75em; padding: 1px 5px; border-radius: 4px; background: rgba(255,255,255,0.14); border: 1px solid rgba(255,255,255,0.2); }
button { font-family: inherit; cursor: pointer; }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); background: radial-gradient(ellipse at center, rgba(20,32,43,0.75), rgba(8,12,18,0.95)); overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; z-index: 10; }
/* Centered when it fits, scrollable from the top when it doesn't (plain centering cuts off the top). */
.overlay::before, .overlay::after { content: ''; flex: 1 0 0; }
.overlay.see-through { background: rgba(8,12,18,0.45); }
.card { background: var(--card); border-radius: var(--radius); padding: 20px; box-shadow: 0 12px 40px rgba(0,0,0,0.45); border: 1px solid rgba(255,255,255,0.06); }

.logo { font-family: 'Russo One', sans-serif; font-size: clamp(40px, 9vw, 78px); margin: 0 0 18px; letter-spacing: 2px; text-shadow: 0 5px 0 #0a1118, 0 8px 24px rgba(0,0,0,0.5); }
.logo span { color: var(--accent); }
.logo small { font-size: 0.4em; color: var(--muted); }

.menu-grid { display: grid; grid-template-columns: minmax(0, 320px) minmax(0, 340px); gap: 16px; width: 100%; max-width: 680px; }
.play-card { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
#menu-preview { align-self: center; width: 220px; height: 160px; }
input#name-input { font: inherit; font-size: 18px; padding: 12px 14px; border-radius: 10px; border: 2px solid #34495e; background: #0f1922; color: var(--text); text-align: center; outline: none; }
input#name-input:focus { border-color: var(--accent); }

.btn { border: none; border-radius: 12px; padding: 12px 18px; font-weight: 800; font-size: 16px; color: #1b1300; transition: transform 0.08s, filter 0.15s; }
.btn:active { transform: translateY(2px); }
.btn:hover { filter: brightness(1.08); }
.btn:disabled { filter: grayscale(0.8) brightness(0.7); cursor: not-allowed; }
.btn-play { background: linear-gradient(180deg, var(--accent), var(--accent-2)); font-family: 'Russo One', sans-serif; font-size: 22px; letter-spacing: 1px; box-shadow: 0 5px 0 #a8501a; }
.btn-secondary { background: var(--card-2); color: var(--text); box-shadow: 0 4px 0 #111b25; }
.btn-gem { background: linear-gradient(180deg, #7fdcff, #3a8fd6); color: #04203a; box-shadow: 0 4px 0 #1d5a8f; }
.icon-btn { background: transparent; border: none; color: var(--muted); font-size: 22px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.hint { color: var(--muted); font-size: 13px; text-align: center; margin: 4px 0 0; }
.touch .desktop-only, body:not(.touch) .touch-only, .touch kbd { display: none; }

.side-card h3 { margin: 16px 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.wallet { display: flex; gap: 14px; font-size: 18px; }
.wallet b { color: var(--accent); }
.wallet .gem b { color: #7fdcff; }
.streak { margin-top: 8px; font-size: 14px; color: var(--good); }
#missions, .mini-missions { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.mission { background: var(--card-2); border-radius: 10px; padding: 8px 10px; font-size: 14px; display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; }
.mission .bar { grid-column: 1 / -1; }
.mission button { padding: 4px 10px; font-size: 13px; border-radius: 8px; border: none; background: var(--good); color: #062; font-weight: 800; }
.mission .done { color: var(--muted); font-size: 12px; }
.mission .reward { color: var(--accent); font-size: 13px; }
.bar { position: relative; height: 8px; background: #0e1720; border-radius: 6px; overflow: hidden; }
.bar > div { height: 100%; background: linear-gradient(90deg, var(--good), #9cf0c0); border-radius: 6px; transition: width 0.25s; }
.career { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; font-size: 12px; color: var(--muted); }
.career b { display: block; font-size: 18px; color: var(--text); }
.name-error { margin: -4px 0 0; color: #ff8a8a; font-size: 13px; font-weight: 800; text-align: center; }
#name-input[aria-invalid="true"] { border-color: #ff6b6b; }
.boards-tabs { margin: 0 0 8px; }
.boards-tabs button { padding: 5px 10px; font-size: 12px; }
.boards { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.boards li { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 6px; }
.boards li:nth-child(odd) { background: var(--card-2); }
.boards .place { width: 20px; text-align: right; color: var(--muted); font-weight: 800; }
.boards .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.boards .region { font-size: 10px; color: var(--muted); }
.boards .score { font-weight: 800; color: var(--accent); }
.boards .empty { color: var(--muted); justify-content: center; background: none; }
.reward .board-places b { color: var(--accent); }
.sound-row { display: flex; align-items: center; gap: 8px; }
.sound-row .icon-btn { font-size: 20px; padding: 0 4px; }
#volume { flex: 1; accent-color: var(--accent); }
.hud-btn { position: absolute; left: 10px; top: 10px; width: 36px; height: 36px; border: none; border-radius: 50%; background: var(--panel); font-size: 17px; }
/* Account: sign-in buttons for guests, a profile row when signed in (in the play card, visible without scrolling). */
.account { font-size: 13px; text-align: left; min-width: 0; }
.account:empty { display: none; }
.account.guest { margin-top: 6px; }
.account.guest p { margin: 6px 0 10px; color: var(--muted); text-align: center; line-height: 1.4; }
.account-head { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.account-head::before, .account-head::after { content: ''; flex: 1; height: 1px; background: rgba(255,255,255,0.12); }
.signin-col { display: flex; flex-direction: column; gap: 8px; }
/* Google's dark-theme button and Discord's brand color, per their sign-in branding guidelines. */
.signin { width: 100%; height: 44px; border-radius: 12px; padding: 0 14px; display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 700; font-size: 15px; transition: filter 0.15s, background 0.15s; }
.signin .brand { width: 20px; height: 20px; flex: none; }
.signin.google { background: #131314; color: #e3e3e3; border: 1px solid #8e918f; }
.signin.google:hover:not(:disabled) { background: #202124; }
.signin.discord { background: #5865f2; color: #fff; border: 1px solid #5865f2; }
.signin.discord:hover:not(:disabled) { filter: brightness(1.08); }
.signin.facebook { background: #1877f2; color: #fff; border: 1px solid #1877f2; }
.signin.facebook:hover:not(:disabled) { filter: brightness(1.08); }
.signin:disabled { opacity: 0.5; cursor: default; }
.signin.busy { opacity: 1; cursor: progress; }
.signin.busy .brand { animation: signin-pulse 0.9s ease-in-out infinite alternate; }
@keyframes signin-pulse { to { opacity: 0.35; } }
.consent { margin: 8px 0 0; font-size: 11px; color: var(--muted); text-align: center; }
.account.signed-in { background: var(--card-2); border-radius: 12px; padding: 10px 12px 8px; margin-top: 2px; }
.profile-row { display: flex; align-items: center; gap: 10px; }
.avatar { width: 38px; height: 38px; border-radius: 50%; flex: none; display: grid; place-items: center; background: hsl(var(--hue) 55% 42%); color: #fff; font-weight: 800; font-size: 17px; box-shadow: 0 0 0 2px rgba(255,255,255,0.12); }
.who { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.who b { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who small { display: flex; align-items: center; gap: 5px; color: var(--good); font-size: 12px; font-weight: 700; white-space: nowrap; overflow: hidden; }
.who small .brand { width: 12px; height: 12px; flex: none; }
.signed-in .chip { flex: none; background: transparent; color: var(--text); border: 1px solid rgba(255,255,255,0.18); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 700; text-decoration: none; }
.signed-in .chip:hover { background: rgba(255,255,255,0.07); }
.account-foot { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.account-foot #delete-account { margin-left: auto; }
.linkbtn { white-space: nowrap; background: none; border: none; padding: 0; color: var(--muted); font-size: 11px; font-weight: 700; text-decoration: underline; }
.linkbtn.danger { color: #ff8a8a; }
.gem-signin { grid-column: 1 / -1; background: var(--card-2); border-radius: 12px; padding: 16px; text-align: center; }
.gem-signin p { margin: 0 0 12px; }
.gem-signin .signin-col { max-width: 340px; margin: 0 auto; }
.legal-links a, .consent a { color: inherit; }
.fair { font-size: 12px; color: var(--muted); margin: 16px 0 0; }

/* ---------- HUD ---------- */
/* Inset by the safe areas so the notch and home indicator never cover HUD elements. */
#hud { position: fixed; inset: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); pointer-events: none; z-index: 5; touch-action: none; }
#hud button, #upgrades { pointer-events: auto; }
.panel { background: var(--panel); border-radius: 10px; padding: 8px 10px; backdrop-filter: blur(4px); }
#leaderboard { position: absolute; top: 10px; right: 10px; width: 190px; font-size: 13px; }
#leaderboard h4 { margin: 0 0 4px; font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: 1px; }
#lb-list { margin: 0; padding: 0; list-style: none; }
#lb-list li { display: flex; justify-content: space-between; gap: 6px; white-space: nowrap; }
#lb-list li span:first-child { overflow: hidden; text-overflow: ellipsis; }
#lb-list li.me { color: var(--accent); font-weight: 800; }
#lb-me { margin-top: 4px; color: var(--muted); font-size: 12px; }
/* Arena-wide announcements (the Dreadnought). */
#banner { position: absolute; top: 18%; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 22px; border-radius: 14px; background: rgba(20,8,8,0.82); border: 2px solid #ff5d5d; box-shadow: 0 0 30px rgba(255,60,40,0.35); text-align: center; pointer-events: none; animation: banner-in 0.35s ease-out; max-width: calc(100vw - 32px); }
#banner b { font-family: 'Russo One', sans-serif; font-size: 22px; color: #ff6b5d; letter-spacing: 0.5px; }
#banner small { font-size: 14px; color: #ffd9a8; font-weight: 700; }
#banner small:empty { display: none; }
#banner.good { border-color: #ffcc33; box-shadow: 0 0 30px rgba(255,204,51,0.35); }
#banner.good b { color: #ffcc33; }
@keyframes banner-in { from { opacity: 0; transform: translate(-50%, -12px) scale(0.92); } }
#killfeed { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 4px; align-items: center; font-size: 13px; }
#killfeed div { background: var(--panel); padding: 3px 10px; border-radius: 8px; animation: fadeout 4s forwards; }
#killfeed b { color: var(--accent); }
@keyframes fadeout { 0%, 75% { opacity: 1; } 100% { opacity: 0; } }
#minimap { position: absolute; bottom: 12px; right: 12px; width: 140px; height: 140px; border-radius: 10px; background: var(--panel); }
#statusbar { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); width: min(420px, 60vw); text-align: center; }
#score-line { font-family: 'Russo One', sans-serif; font-size: 18px; text-shadow: 0 2px 4px #000; margin-bottom: 4px; }
.bar.xp { height: 20px; border-radius: 10px; border: 2px solid rgba(0,0,0,0.4); }
.bar.xp > div { background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 0; }
#level-label { position: absolute; inset: 0; font-size: 12px; font-weight: 800; line-height: 16px; text-shadow: 0 1px 2px #000; }
#upgrades { position: absolute; left: 10px; bottom: 12px; width: 210px; }
.upg-title { font-size: 13px; margin-bottom: 6px; color: var(--accent); }
.upg { display: grid; grid-template-columns: 18px 1fr; align-items: center; gap: 6px; width: 100%; background: transparent; border: none; padding: 3px 0; color: var(--text); text-align: left; font-size: 12px; }
.upg .key { color: var(--muted); font-weight: 800; }
.upg .pips { display: flex; gap: 2px; margin-top: 2px; }
.upg .pips i { flex: 1; height: 6px; background: #0e1720; border-radius: 2px; }
.upg .pips i.on { background: var(--c); }
.upg:not(:disabled):hover .name { color: var(--accent); }
.upg:disabled { opacity: 0.55; cursor: default; }

/* ---------- shop ---------- */
.shop-wrap { width: min(920px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; padding: 16px; }
.shop-head { display: flex; align-items: center; gap: 16px; }
.shop-head h2 { margin: 0; font-family: 'Russo One', sans-serif; flex: 1; }
.tabs { display: flex; gap: 6px; margin: 12px 0; flex-wrap: wrap; }
.tabs button { background: var(--card-2); color: var(--muted); border: none; padding: 8px 14px; border-radius: 10px; font-weight: 800; }
.tabs button.active { background: var(--accent); color: #1b1300; }
.shop-body { display: grid; grid-template-columns: 320px 1fr; gap: 16px; min-height: 0; flex: 1; }
.shop-preview { display: flex; flex-direction: column; gap: 10px; background: #0f1922; border-radius: 12px; padding: 12px; }
#shop-canvas { width: 100%; aspect-ratio: 32 / 26; border-radius: 8px; }
.selected-info { text-align: center; }
.selected-info .name { font-size: 20px; font-weight: 800; }
.selected-info .rarity { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; font-weight: 800; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; overflow-y: auto; align-content: start; padding: 2px; }
.item { background: var(--card-2); border-radius: 10px; border: 2px solid transparent; padding: 8px; display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--text); font-size: 13px; position: relative; }
.item.selected { border-color: var(--accent); }
.item canvas { width: 96px; height: 72px; }
.item .rar { position: absolute; top: 0; left: 0; right: 0; height: 4px; border-radius: 8px 8px 0 0; }
.item .price { font-weight: 800; color: var(--accent); }
.item .price.owned { color: var(--muted); }
.item .alt-price { font-size: 11px; color: #7fdcff; margin-top: -3px; }
.item .price.equipped { color: var(--good); }
.gem-packs { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.gem-pack { background: linear-gradient(160deg, #1e4560, #172a3d); border-radius: 12px; padding: 16px; text-align: center; color: var(--text); border: none; }
.gem-pack b { display: block; font-size: 26px; color: #7fdcff; }
.gem-note { grid-column: 1 / -1; color: var(--muted); font-size: 13px; margin: 0; }

/* ---------- death ---------- */
.death-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 12px; text-align: center; }
.death-card h2 { margin: 0; font-family: 'Russo One', sans-serif; font-size: 28px; }
.death-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; font-size: 12px; color: var(--muted); }
.death-stats b { display: block; font-size: 20px; color: var(--text); }
.reward { background: #0f1922; border-radius: 10px; padding: 10px; font-size: 14px; }
.reward .total { font-size: 24px; font-weight: 800; color: var(--accent); }
.reward .breakdown { color: var(--muted); font-size: 12px; }

/* ---------- toasts ---------- */
#toasts { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 50; pointer-events: none; }
.toast { background: #0f1922; border: 1px solid rgba(255,255,255,0.12); border-radius: 10px; padding: 10px 16px; font-weight: 800; animation: toast 3s forwards; }
.toast.err { border-color: #ff5d5d; color: #ffb3b3; }
@keyframes toast { 0% { opacity: 0; transform: translateY(-8px); } 10%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* ---------- small screens ---------- */
@media (max-width: 720px) {
  .menu-grid { grid-template-columns: minmax(0, 1fr); max-width: 360px; }
  .shop-body { grid-template-columns: 1fr; overflow-y: auto; }
  .shop-grid { overflow: visible; }
  #shop-canvas { max-height: 180px; }
}
/* Phones (portrait or landscape): keep the bottom corners free for the joysticks. */
@media (max-width: 720px), (max-height: 500px) {
  #leaderboard { width: 140px; font-size: 11px; padding: 6px 8px; }
  #lb-list li:nth-child(n+6) { display: none; }
  #minimap { display: none; }
  #upgrades { width: 160px; top: 54px; bottom: auto; padding: 6px 8px; }
  #statusbar { top: 8px; bottom: auto; width: 36vw; }
  #score-line { font-size: 13px; }
  #killfeed { top: 56px; font-size: 11px; }
  #banner b { font-size: 17px; } #banner small { font-size: 12px; }
}

/* ---------- touch layout (phones and tablets; desktop is unaffected) ---------- */
.upg .icon { display: none; }
body.touch #minimap { display: none; }
body.touch #leaderboard { width: 150px; font-size: 11px; padding: 6px 8px; }
body.touch #lb-list li:nth-child(n+6) { display: none; }
body.touch #statusbar { top: 8px; bottom: auto; width: min(36vw, 320px); }
body.touch #score-line { font-size: 13px; }
body.touch #killfeed { top: 56px; font-size: 11px; }
/* Upgrades: a row of big buttons along the bottom center, between the thumb sticks. */
body.touch #upgrades { top: auto; bottom: 10px; left: 50%; transform: translateX(-50%); width: auto; padding: 6px 8px 8px; text-align: center; }
body.touch .upg-title { font-size: 12px; margin-bottom: 4px; }
body.touch #upg-list { display: flex; gap: 6px; }
body.touch .upg { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; width: 52px; height: 56px; padding: 4px; border-radius: 12px; background: rgba(255,255,255,0.08); }
body.touch .upg:not(:disabled):active { background: rgba(255,200,61,0.35); }
body.touch .upg .icon { display: block; font-size: 22px; line-height: 1; }
body.touch .upg .key, body.touch .upg .name { display: none; }
body.touch .upg .pips { width: 40px; margin: 0; }
body.touch .upg .pips i { height: 4px; }
/* Portrait phones: the sticks fill the bottom, so lift the upgrades above them and stack the top bar. */
@media (orientation: portrait) and (max-width: 600px) {
  body.touch #statusbar { left: 54px; right: 120px; width: auto; transform: none; }
  body.touch #leaderboard { width: 110px; }
  body.touch #lb-list li:nth-child(n+4) { display: none; }
  body.touch #upgrades { bottom: 200px; }
  body.touch #upg-list { gap: 4px; }
  body.touch .upg { width: 46px; }
}
#rotate-hint { position: fixed; left: 50%; top: 45%; transform: translate(-50%, -50%); z-index: 6; padding: 10px 16px; border-radius: 12px; background: var(--panel); font-weight: 800; pointer-events: none; display: none; animation: fadeout 5s forwards; }
@media (orientation: portrait) and (max-width: 600px) { body.touch.playing #rotate-hint { display: block; } }

/* ---------- short screens (phones in landscape): compact menus ---------- */
@media (max-height: 500px) {
  .logo { font-size: 34px; margin-bottom: 8px; }
  .card { padding: 12px; }
  .play-card { gap: 7px; }
  #menu-preview { width: 150px; height: 96px; }
  input#name-input { padding: 8px 12px; font-size: 16px; }
  .btn { padding: 9px 14px; }
  .btn-play { font-size: 19px; }
  .side-card h3 { margin: 10px 0 6px; }
  .mission { padding: 6px 8px; font-size: 13px; }
  .shop-wrap { padding: 10px; max-height: none; }
  .tabs { margin: 8px 0; }
  .tabs button { padding: 6px 10px; font-size: 13px; }
  .shop-body { grid-template-columns: 220px 1fr; }
  #shop-canvas { max-height: 130px; }
  .shop-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); overflow: visible; }
  .item canvas { width: 80px; height: 60px; }
  .death-card { gap: 8px; padding: 12px; }
  .death-card h2 { font-size: 22px; }
}

/* Death dialog on short landscape screens (phones held sideways): two columns instead of one tall stack,
   so everything including Play Again fits without scrolling. */
@media (max-height: 500px) and (orientation: landscape) {
  .death-card {
    width: min(720px, 100%);
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "title title" "stats missions" "reward missions" "again row";
    column-gap: 14px;
    row-gap: 8px;
    align-items: start;
  }
  #death-title { grid-area: title; font-size: 20px; }
  .death-stats { grid-area: stats; }
  .death-stats b { font-size: 17px; }
  #death-reward { grid-area: reward; padding: 8px; }
  #death-reward .total { font-size: 20px; }
  #death-missions .mission > span:first-child { text-align: left; }
  #death-missions { grid-area: missions; gap: 6px; }
  #death-missions .mission { padding: 5px 8px; font-size: 12px; }
  #again-btn { grid-area: again; align-self: stretch; }
  .death-card .row { grid-area: row; }
}
