:root {
  --font: "Baloo 2", "Trebuchet MS", "Segoe UI", Arial, sans-serif;
  --ink: #244353;
  --muted: #65808a;
  --ocean: #285f73;
  --paper: #fffaf0;
  --line: #cbdcd8;
  --mint: #34bd8e;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; background: var(--ocean); font-family: var(--font); user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none; }
canvas#game { display: block; position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; touch-action: none; outline: none; }
.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; color: #fff; font-weight: 800; }
#me-bar { position: absolute; left: 0; top: max(12px, env(safe-area-inset-top)); height: 38px; min-width: 180px; padding: 0 18px; border-radius: 0 14px 14px 0; display: flex; align-items: center; font-size: 24px; transition: width .4s cubic-bezier(.2,.9,.3,1.2); }
#best { position: absolute; left: 10px; top: calc(max(12px, env(safe-area-inset-top)) + 48px); color: #fffaf0; text-shadow: 0 2px 5px #173949; font-size: 18px; }
#kills { position: absolute; left: 0; top: calc(max(12px, env(safe-area-inset-top)) + 78px); background: #244353; padding: 1px 14px 1px 10px; border-radius: 0 14px 14px 0; font-size: 18px; box-shadow: 0 3px 0 #173949; }
#kills.bump { animation: bump .35s ease-out; }
#kills .skull { font-size: 20px; }
#leaderboard { position: absolute; right: 0; top: max(12px, env(safe-area-inset-top)); display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
#leaderboard .row { height: 34px; padding: 0 14px; border-radius: 14px 0 0 14px; display: flex; align-items: center; font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: width .4s ease; }
#leaderboard .row.me { outline: 3px solid rgba(255,255,255,.85); outline-offset: -3px; }
#leaderboard .gap { height: 8px; }
#minimap { position: absolute; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); width: 180px; height: 180px; padding: 5px; border: 2px solid rgba(255,250,240,.7); border-radius: 18px; background: rgba(29,66,80,.68); box-shadow: 0 6px 20px rgba(10,39,53,.22); }
#toast { position: absolute; left: 50%; top: 22%; transform: translate(-50%, 0) scale(.6); padding: 6px 22px; border-radius: 999px; background: rgba(40,50,48,.78); color: #fff; font-size: 24px; white-space: nowrap; opacity: 0; transition: opacity .2s, transform .25s cubic-bezier(.2,.9,.3,1.4); }
#toast.on { opacity: 1; transform: translate(-50%, 0) scale(1); }


/* ---------- menus ---------- */
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle at 50% 35%, rgba(29,79,97,.28), rgba(10,39,53,.76)); padding: 16px; animation: fade .25s ease-out; touch-action: manipulation; }
.card { max-height: 100%; overflow-y: auto; touch-action: pan-y; background: var(--paper); border: 2px solid #fff; border-radius: 26px; padding: 24px 26px 20px; width: min(410px, 100%); text-align: center; box-shadow: 0 9px 0 #c8d8d5, 0 24px 50px rgba(8,34,46,.28); animation: pop .35s cubic-bezier(.2,.9,.3,1.3); }
.logo { margin: 0 0 16px; font-size: 56px; line-height: 1; letter-spacing: .5px; font-weight: 800; }
.logo span { display: inline-block; animation: float 3s ease-in-out infinite; }
.logo .l1 { color: #ef6a5c; text-shadow: 0 6px 0 #b3463b; }
.logo .l2 { color: #5fb7e6; text-shadow: 0 6px 0 #3a82aa; animation-delay: -1.5s; }
#nick { width: 100%; font: inherit; font-size: 22px; font-weight: 700; color: var(--ink); background: #fff; padding: 10px 14px; border: 3px solid var(--line); border-radius: 14px; outline: none; text-align: center; transition: border-color .15s; -webkit-user-select: text; user-select: text; touch-action: manipulation; }
#nick:focus { border-color: #55b9bd; }
#swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 8px; margin: 14px 0 2px; }
#swatches button { aspect-ratio: 1; border: 0; border-radius: 9px; cursor: pointer; box-shadow: inset 0 -5px 0 rgba(0,0,0,.2); transition: transform .12s; touch-action: manipulation; padding: 0; }
#swatches button:hover { transform: translateY(-2px); }
#swatches button.sel { transform: scale(1.12); outline: 3px solid var(--ink); outline-offset: 2px; }
#swatches .random { background: conic-gradient(#ef6a5c, #fbe06b, #9be38a, #5fb7e6, #c39bff, #ef6a5c); }
#skins { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin: 12px 0 2px; }
#skins button { aspect-ratio: 1; padding: 0; border: 3px solid var(--line); border-radius: 10px; background: #fff; font-size: 22px; line-height: 1; cursor: pointer; touch-action: manipulation; font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif; transition: transform .12s; }
#skins button:hover { transform: translateY(-2px); }
#skins button.sel { border-color: var(--ink); background: #fff; transform: scale(1.08); }
#skins .none { font-size: 13px; font-weight: 800; color: var(--muted); font-family: var(--font); }
#map-row { margin-top: 12px; }
#map-label { color: var(--ink); font-size: 15px; font-weight: 700; margin-bottom: 6px; }
#maps { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
#maps button { padding: 4px 11px; font: inherit; font-size: 15px; font-weight: 700; color: var(--ink); background: #fff; border: 3px solid var(--line); border-radius: 999px; cursor: pointer; touch-action: manipulation; }
#maps button.sel { background: #43afb4; border-color: #27838d; color: #fff; }
.set-row.wide { grid-template-columns: 1fr 150px; }
.set-row input[type=range] { padding: 0; border: 0; accent-color: #34bd8e; height: 28px; }
.toggle { justify-self: end; min-width: 84px; padding: 4px 12px; font: inherit; font-size: 17px; font-weight: 800; color: #fff; background: var(--mint); border: 0; border-radius: 999px; box-shadow: 0 3px 0 #218e6a; cursor: pointer; touch-action: manipulation; }
.toggle.off { background: #b9c4c0; box-shadow: 0 3px 0 #8f9894; }
.mute.gear { left: 62px; }
.btn-play { width: 100%; margin-top: 14px; padding: 10px 14px 12px; font: inherit; font-size: 28px; font-weight: 800; letter-spacing: 1px; color: #fff; background: var(--mint); border: 0; border-radius: 14px; box-shadow: 0 6px 0 #218e6a; cursor: pointer; touch-action: manipulation; transition: transform .08s, box-shadow .08s, background .15s; }
.btn-play:hover { background: #46cca0; }
.btn-play:active { transform: translateY(5px); box-shadow: 0 1px 0 #218e6a; }
.btn-play:disabled { background: #b9c4c0; box-shadow: 0 6px 0 #8f9894; cursor: default; }
.btn-plain { margin-top: 10px; padding: 6px 18px; font: inherit; font-size: 17px; font-weight: 700; color: var(--muted); background: none; border: 0; cursor: pointer; touch-action: manipulation; }
.btn-plain:hover { color: var(--ink); }
.controls { margin-top: 14px; color: var(--ink); font-size: 15px; font-weight: 600; }
.tip { color: var(--muted); font-size: 14px; line-height: 1.35; margin: 8px 0 0; font-weight: 600; }
.status { color: var(--muted); font-size: 14px; margin: 6px 0 0; min-height: 1em; }
#death h2 { margin: 0 0 14px; color: var(--ink); font-size: 28px; line-height: 1.15; font-weight: 800; }
.stats { display: flex; justify-content: space-around; margin-bottom: 4px; }
.stats div { display: flex; flex-direction: column; }
.stats b { font-size: 32px; line-height: 1.1; color: #27838d; font-weight: 800; }
.stats span { color: var(--muted); font-size: 13px; text-transform: uppercase; font-weight: 700; letter-spacing: .5px; }

.menu-tools { display: flex; justify-content: center; flex-wrap: wrap; gap: 4px 16px; margin-top: 4px; }
.mute { position: absolute; left: 10px; bottom: max(12px, env(safe-area-inset-bottom)); width: 44px; height: 44px; border: 1px solid rgba(255,250,240,.5); border-radius: 14px; background: rgba(29,66,80,.72); color: #fff; font-size: 20px; line-height: 1; cursor: pointer; pointer-events: auto; touch-action: manipulation; }
.mute:active { transform: scale(.92); }
#perf { position: fixed; left: 8px; top: 140px; z-index: 5; padding: 6px 9px; border-radius: 8px; background: rgba(0,0,0,.6); color: #9fffb4; font: 12px/1.35 Consolas, monospace; white-space: pre; pointer-events: none; }
.settings-card { width: min(460px, 100%); max-height: 100%; overflow-y: auto; text-align: left; }
.settings-card h2 { margin: 0 0 4px; color: var(--ink); text-align: center; font-size: 28px; font-weight: 800; }
.settings-card .tip { text-align: center; margin-bottom: 10px; }
.set-row { display: grid; grid-template-columns: 1fr 96px; gap: 2px 12px; align-items: center; padding: 6px 0; border-bottom: 1px solid #edf2f0; }
.set-row label { color: var(--ink); font-weight: 700; font-size: 17px; line-height: 1.1; }
.set-row small { display: block; color: var(--muted); font-weight: 600; font-size: 12px; }
.set-row input { width: 100%; font: inherit; font-size: 18px; font-weight: 700; color: var(--ink); padding: 4px 8px; border: 3px solid var(--line); border-radius: 10px; outline: none; text-align: center; -webkit-user-select: text; user-select: text; }
.set-row input:focus { border-color: #55b9bd; }
.settings-actions { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.settings-actions .btn-play { margin-top: 0; flex: 1; font-size: 22px; }
.settings-actions .btn-plain { margin-top: 0; }

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

@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } }
@keyframes float { 50% { transform: translateY(-4px); } }
@keyframes bump { 40% { transform: scale(1.25); } }

@media (prefers-reduced-motion: reduce) {
  .overlay, .card, .logo span, #kills.bump { animation: none; }
  #me-bar, #leaderboard .row, #toast, .btn-play { transition: none; }
}

/* small screens: shrink the HUD so it doesn't cover the play field */
@media (max-width: 700px), (max-height: 500px) {
  #me-bar { height: 30px; font-size: 18px; min-width: 100px; padding: 0 12px; }
  #best { font-size: 15px; top: calc(max(10px, env(safe-area-inset-top)) + 36px); }
  #kills { font-size: 15px; top: calc(max(10px, env(safe-area-inset-top)) + 58px); }
  #me-bar, #leaderboard { top: max(10px, env(safe-area-inset-top)); }
  #leaderboard { gap: 5px; }
  #leaderboard .row { height: 25px; font-size: 14px; padding: 0 9px; }
  #minimap { width: 104px; height: 104px; right: max(10px, env(safe-area-inset-right)); bottom: max(10px, env(safe-area-inset-bottom)); border-radius: 12px; padding: 3px; }
  #toast { font-size: 18px; top: 18%; }
  .logo { font-size: 48px; }
  .card { padding: 20px 18px 16px; }
}
