* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #111; color: #eee;
  font-family: "Arial Black", "Arial Bold", Impact, sans-serif;
  overscroll-behavior: none; -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; }
#game { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; touch-action: none; }
.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud-tl { position: absolute; top: 16px; left: 16px; display: flex; flex-direction: column; gap: 8px; }
.stat label { display: block; font-size: 12px; letter-spacing: 2px; text-shadow: 2px 2px 0 #000; color: #ffe14d; }
.meter { width: 220px; height: 16px; background: rgba(0,0,0,.6); border: 2px solid #000; }
.meter i { display: block; height: 100%; width: 100%; background: linear-gradient(#ff5b4d, #b81d12); transition: width .15s; }
.meter.car i { background: linear-gradient(#7fe3ff, #1f7fb0); }
.meter.car.burning i { background: linear-gradient(#ffb347, #e8590c); animation: blink .3s infinite; }
@keyframes blink { 50% { opacity: .4; } }
#hud-tr { position: absolute; top: 12px; right: 210px; text-align: right; text-shadow: 3px 3px 0 #000; }
#kills { font-size: 48px; line-height: 1; color: #ffe14d; transition: transform .1s; }
#kills.pop { transform: scale(1.35); color: #fff; }
#hud-tr .sub { font-size: 12px; letter-spacing: 3px; }
#info { text-shadow: 1px 1px 0 #000; margin-top: 8px; font-family: Arial, sans-serif; font-weight: bold; font-size: 12px; opacity: .85; }
#minimap { position: absolute; top: 12px; right: 12px; width: 180px; height: 180px; border: 3px solid #000;
  box-shadow: 0 0 0 2px #ffe14d; image-rendering: pixelated; transition: all .2s; }
#minimap.big { width: min(80vh, 80vw); height: min(80vh, 80vw); top: 50%; right: 50%; transform: translate(50%, -50%); }
#feed { position: absolute; left: 16px; bottom: 44px; display: flex; flex-direction: column; gap: 4px;
  font-family: Arial, sans-serif; font-weight: bold; font-size: 14px; }
#feed div { background: rgba(0,0,0,.55); padding: 4px 10px; border-left: 3px solid #ffe14d; animation: fade 6s forwards; }
@keyframes fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }
#toast { position: absolute; left: 50%; bottom: 90px; transform: translateX(-50%); font-size: 22px; color: #ffe14d;
  text-shadow: 3px 3px 0 #000; opacity: 0; transition: opacity .3s; white-space: nowrap; }
#toast.show { opacity: 1; }
#big { position: absolute; top: 38%; left: 0; right: 0; text-align: center; font-size: clamp(48px, 12vw, 140px);
  letter-spacing: 6px; text-shadow: 6px 6px 0 #000; opacity: 0; transition: opacity .4s; }
#big.show { opacity: 1; }
#big-sub { position: absolute; top: calc(38% + clamp(60px, 14vw, 160px)); left: 0; right: 0; text-align: center;
  font-size: clamp(18px, 3vw, 30px); color: #fff; text-shadow: 3px 3px 0 #000; opacity: 0; transition: opacity .4s; }
#big-sub.show { opacity: 1; }
#big-sub.record { color: #ffe14d; }
#hud-tr .sub.best { margin-top: 2px; font-size: 11px; color: #ffe14d; opacity: .85; }
#help { position: absolute; bottom: 12px; left: 0; right: 0; text-align: center; font-family: Arial, sans-serif;
  font-weight: bold; font-size: 12px; opacity: .7; text-shadow: 1px 1px 0 #000; }

/* ---------- shared panels (in-game leaderboard) ---------- */
.panel { background: rgba(20,20,20,.92); border: 3px solid #000; box-shadow: 0 0 0 3px #ffe14d, 10px 10px 0 #000; padding: 20px 24px; }
h2 { margin: 0 0 12px; color: #ffe14d; letter-spacing: 3px; }
h3 { margin: 0 0 8px; font-size: 14px; letter-spacing: 2px; color: #ffe14d; }
table { width: 100%; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; }
th { text-align: left; font-size: 11px; color: #888; letter-spacing: 1px; padding: 4px 6px; }
td { padding: 5px 6px; border-bottom: 1px solid #2a2a2a; }
td.n { text-align: right; font-weight: bold; color: #ffe14d; }
tr.me td { background: rgba(255,225,77,.12); }

#board { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.5); pointer-events: none; }
#board .panel { width: min(760px, 94vw); }
#board .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }

/* ---------- wanted level ---------- */
#wanted { margin-top: 6px; font-size: 26px; letter-spacing: 2px; line-height: 1; }
#wanted span { color: rgba(255,255,255,.18); text-shadow: 2px 2px 0 #000; transition: color .2s; }
#wanted span.on { color: #ffe14d; }
#wanted.cool span.on { animation: blink .6s infinite; }
#wanted.up span.on { color: #fff; transform: scale(1.2); }

/* ---------- touch controls ---------- */
#touch { position: fixed; inset: 0; pointer-events: none; z-index: 5;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#touch button { pointer-events: auto; touch-action: none; font-family: inherit; color: #fff;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#stick-zone { position: absolute; left: 0; bottom: 0; width: 46%; height: 72%; pointer-events: auto; touch-action: none; }
#stick-base { position: absolute; width: 132px; height: 132px; border-radius: 50%; transform: translate(-50%, -50%);
  border: 3px solid rgba(255,255,255,.22); background: rgba(0,0,0,.18); pointer-events: none; transition: opacity .15s; opacity: .55; }
#stick-base.active { opacity: 1; border-color: rgba(255,225,77,.7); background: rgba(0,0,0,.28); transition: none; }
#stick-knob { position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; border-radius: 50%;
  transform: translate(-50%, -50%); background: rgba(255,255,255,.35); border: 3px solid rgba(255,255,255,.6);
  box-shadow: 0 2px 8px rgba(0,0,0,.4); }
#stick-base.active #stick-knob { background: rgba(255,225,77,.55); border-color: #ffe14d; }
#action-pad { position: absolute; right: calc(14px + env(safe-area-inset-right)); bottom: calc(14px + env(safe-area-inset-bottom));
  width: 200px; height: 170px; pointer-events: none; }
.tbtn { position: absolute; border-radius: 50%; border: 3px solid rgba(255,255,255,.55); background: rgba(0,0,0,.35);
  font-size: 14px; letter-spacing: 1px; text-shadow: 1px 1px 0 #000; box-shadow: 0 3px 10px rgba(0,0,0,.4); }
.tbtn.down { background: rgba(255,225,77,.55); border-color: #ffe14d; transform: scale(.94); }
#t-fire { right: 0; bottom: 6px; width: 104px; height: 104px; font-size: 16px; border-color: rgba(255,120,100,.8); background: rgba(160,20,10,.35); }
#t-fire.brake { border-color: rgba(127,227,255,.8); background: rgba(20,90,130,.35); }
#t-car { left: 0; bottom: 70px; width: 72px; height: 72px; }
#util-pad { position: absolute; top: calc(8px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); display: flex; gap: 8px; }
#util-pad button { width: 46px; height: 34px; border-radius: 8px; border: 2px solid rgba(255,255,255,.35); background: rgba(0,0,0,.4);
  font-size: 11px; letter-spacing: 1px; }
#util-pad button.down { background: rgba(255,225,77,.5); }

#rotate { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; text-align: center;
  background: rgba(0,0,0,.88); font-size: 18px; padding: 24px; }
#rotate .phone { width: 44px; height: 76px; margin: 0 auto 18px; border: 4px solid #ffe14d; border-radius: 8px; animation: tilt 1.6s ease-in-out infinite; }
@keyframes tilt { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
#rotate p { margin: 0 0 14px; }

/* ---------- small screens & touch layout ---------- */
body.touch #help { display: none; }
body.touch #hud-tl { top: calc(10px + env(safe-area-inset-top)); left: calc(10px + env(safe-area-inset-left)); gap: 4px; }
body.touch .meter { width: 150px; height: 12px; }
body.touch .stat label { font-size: 10px; }
body.touch #minimap { width: 104px; height: 104px; top: calc(8px + env(safe-area-inset-top)); right: calc(8px + env(safe-area-inset-right)); border-width: 2px; }
body.touch #minimap.big { width: min(86vh, 86vw); height: min(86vh, 86vw); top: 50%; right: 50%; z-index: 6; }
body.touch #hud-tr { top: calc(6px + env(safe-area-inset-top)); right: calc(124px + env(safe-area-inset-right)); }
body.touch #kills { font-size: 30px; }
body.touch #hud-tr .sub { font-size: 9px; letter-spacing: 1px; }
body.touch #wanted { font-size: 17px; margin-top: 3px; }
body.touch #info { display: none; }
body.touch #feed { bottom: auto; top: calc(74px + env(safe-area-inset-top)); left: calc(10px + env(safe-area-inset-left)); font-size: 11px; max-width: 42vw; }
body.touch #feed div { padding: 3px 7px; }
body.touch #toast { bottom: auto; top: 24%; font-size: 16px; white-space: normal; text-align: center; width: 70vw; }
body.touch #big { top: 30%; }
body.touch #big-sub { top: calc(30% + clamp(60px, 14vw, 150px)); }
body.touch #board .panel { padding: 14px; max-height: 86vh; overflow: auto; }
@media (max-height: 420px) {  /* landscape phones: tighten vertical space */
  body.touch #feed { top: calc(64px + env(safe-area-inset-top)); }
  body.touch #feed div:nth-child(n+4) { display: none; }
  #stick-base { width: 116px; height: 116px; }
  #stick-knob { width: 50px; height: 50px; }
  #t-fire { width: 92px; height: 92px; }
  #t-car { width: 64px; height: 64px; bottom: 62px; }
}

/* menu and leaderboard on narrow screens */
@media (max-width: 760px) {
  .panel { padding: 16px; box-shadow: 0 0 0 3px #ffe14d, 6px 6px 0 #000; }
  #board .cols { grid-template-columns: 1fr; gap: 12px; }
  table { font-size: 13px; }
  th, td { padding: 4px 4px; }
}
input, button { font-size: 16px; }  /* 16px+ stops iOS zooming into the form */
/* thin shadows on small text: a 2-3px shadow looks like doubled text on phones */
body.touch .stat label, body.touch #hud-tr, body.touch #hud-tr .sub, body.touch #wanted span { text-shadow: 1px 1px 0 #000; }
/* upright phones: the top edge is too narrow for HUD + button row, so stack the buttons under the minimap */
@media (orientation: portrait) and (max-width: 700px) {
  body.touch #util-pad { left: auto; transform: none; right: calc(8px + env(safe-area-inset-right));
    top: calc(122px + env(safe-area-inset-top)); flex-direction: column; gap: 6px; }
  body.touch #util-pad button { width: 46px; height: 32px; }
  body.touch #hud-tr { right: calc(122px + env(safe-area-inset-right)); }
  body.touch #feed { top: calc(84px + env(safe-area-inset-top)); max-width: 58vw; }
}

/* ================= main menu ================= */
#menu { position: fixed; inset: 0; overflow: auto; -webkit-overflow-scrolling: touch;
  background: radial-gradient(circle at 25% 15%, #2a2a2a, #0b0b0b 70%);
  padding: calc(20px + env(safe-area-inset-top)) calc(20px + env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) calc(20px + env(safe-area-inset-left));
  display: flex; flex-direction: column; align-items: center; gap: 18px; }
#menu > * { width: 100%; max-width: 980px; }
#menu .label { font: bold 11px Arial, sans-serif; letter-spacing: 2px; color: #999; text-transform: uppercase; }

.brand { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.brand h1 { margin: 0; font-size: 34px; line-height: 1; color: #ffe14d; letter-spacing: 1px; text-shadow: 3px 3px 0 #b81d12; }
.brand h1 span { color: #fff; }
.brand p { margin: 0; font: bold 13px Arial, sans-serif; color: #888; letter-spacing: 1px; }

.menu-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 22px; align-items: stretch; }
.card { background: rgba(20,20,20,.94); border: 3px solid #000; box-shadow: 0 0 0 3px #ffe14d, 8px 8px 0 #000; padding: 20px; min-width: 0; }

/* play card: map on the left, everything you do on the right */
.play-card { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 22px; }
.pc-map { display: flex; flex-direction: column; gap: 8px; align-items: center; }
#preview { width: 264px; height: 264px; display: block; image-rendering: pixelated; border: 2px solid #000; background: #111; }
.hint { font: 12px Arial, sans-serif; color: #888; text-align: center; max-width: 264px; }
.pc-controls { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

#menu input { width: 100%; font: bold 16px Arial, sans-serif; padding: 10px 12px; background: #000; color: #fff;
  border: 2px solid #444; border-radius: 0; outline: none; }
#menu input::placeholder { color: #666; font-weight: normal; }
#menu input:focus { border-color: #ffe14d; }

#auth { display: flex; flex-direction: column; gap: 8px; }
.tabs { display: flex; }
.tabs button { flex: 1; font: bold 13px Arial, sans-serif; padding: 9px 8px; background: #000; color: #888;
  border: 2px solid #333; cursor: pointer; letter-spacing: 1px; }
.tabs button + button { border-left: 0; }
.tabs button.active { color: #000; background: #ffe14d; border-color: #ffe14d; }
.btn-secondary { font: inherit; font-size: 15px; padding: 10px; background: #7fe3ff; color: #000; border: 3px solid #000;
  box-shadow: 3px 3px 0 #1f7fb0; cursor: pointer; letter-spacing: 1px; }
.btn-secondary:hover { background: #fff; }

#account { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 12px;
  background: #000; border: 2px solid #333; padding: 12px 14px; font-family: Arial, sans-serif; }
#account .who { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
#account b { color: #ffe14d; font-size: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#acct-stats { grid-column: 1 / -1; color: #aaa; font-size: 13px; }
button.link { background: none; border: none; color: #7fe3ff; font: bold 13px Arial, sans-serif; cursor: pointer; text-decoration: underline; padding: 4px 0; }

.seed-block { display: flex; flex-direction: column; gap: 6px; }
.seedrow { display: flex; gap: 6px; }
.icon-btn { flex: none; width: 46px; font-size: 20px; background: #000; border: 2px solid #444; cursor: pointer; line-height: 1; }
.icon-btn:hover { border-color: #ffe14d; }
.icon-btn.ok { border-color: #58d68d; }

.play-bar { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
#err { color: #ff6b5b; font: bold 13px Arial, sans-serif; min-height: 0; }
#err:empty { display: none; }
.btn-play { font: inherit; font-size: 22px; padding: 14px; background: #ffe14d; color: #000; border: 3px solid #000;
  box-shadow: 5px 5px 0 #b81d12; cursor: pointer; letter-spacing: 1px; }
.btn-play:hover:not(:disabled) { background: #fff; }
.btn-play:disabled { background: #555; color: #ccc; box-shadow: 5px 5px 0 #222; cursor: default; }

/* live cities / top killers */
.info-card { display: flex; flex-direction: column; gap: 12px; padding: 16px; min-height: 0; }
.info-tabs button { font-size: 12px; }
#rooms-count:not(:empty)::before { content: '· '; }
.pane { overflow: auto; max-height: 360px; }
#rooms { list-style: none; margin: 0; padding: 0; font-family: Arial, sans-serif; font-size: 14px; }
#rooms li { padding: 10px 8px; border-bottom: 1px solid #2a2a2a; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
#rooms li span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#rooms li span:last-child { color: #58d68d; white-space: nowrap; }
#rooms li:hover, #rooms li.current { background: #222; color: #ffe14d; }
#rooms li.muted { cursor: default; color: #777; }
#rooms li.muted:hover { background: none; color: #777; }
#menu-board td.muted { color: #777; }

/* ---- medium: stack the two cards ---- */
@media (max-width: 900px) {
  .menu-grid { grid-template-columns: 1fr; max-width: 640px; margin: 0 auto; width: 100%; }
  .pane { max-height: none; }
}

/* ---- phones (portrait): one column; Play stays pinned to the bottom of the screen ---- */
@media (max-width: 600px) {
  #menu { padding: calc(12px + env(safe-area-inset-top)) 12px 0; gap: 14px; }
  .brand { justify-content: space-between; gap: 6px; }
  .brand h1 { font-size: 24px; }
  .brand p { display: none; }
  .card { padding: 14px; box-shadow: 0 0 0 3px #ffe14d, 5px 5px 0 #000; }
  .menu-grid { gap: 18px; }
  .play-card { grid-template-columns: 1fr; gap: 14px; }
  .pc-map { order: 2; }
  .pc-controls { display: contents; }          /* lets the map sit between seed and Play */
  #account-area { order: 0; }
  .seed-block { order: 1; }
  #preview { width: min(240px, 70vw); height: auto; aspect-ratio: 1; }
  .play-bar { order: 3; position: sticky; bottom: 0; z-index: 2; margin: 0 -14px -14px;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); background: rgba(20,20,20,.97); border-top: 2px solid #333; }
  .btn-play { font-size: 20px; padding: 12px; box-shadow: 4px 4px 0 #b81d12; }
  .info-card { margin-bottom: calc(20px + env(safe-area-inset-bottom)); }
}

/* ---- phones (landscape) and short windows: keep the play card side by side and compact ---- */
@media (max-height: 560px) and (orientation: landscape) {
  #menu { padding-top: calc(10px + env(safe-area-inset-top)); gap: 10px; }
  .brand h1 { font-size: 22px; }
  .brand p { font-size: 11px; }
  .menu-grid { grid-template-columns: minmax(0, 1fr) 260px; max-width: none; gap: 16px; }
  .card { padding: 12px; box-shadow: 0 0 0 3px #ffe14d, 5px 5px 0 #000; }
  .play-card { grid-template-columns: auto minmax(0, 1fr); gap: 14px; }
  .pc-controls { gap: 10px; }
  #preview { width: min(200px, calc(100vh - 150px)); height: auto; aspect-ratio: 1; }
  .hint { display: none; }
  #auth { gap: 6px; }
  #menu input { padding: 7px 10px; }
  .tabs button { padding: 6px; }
  .btn-secondary { padding: 7px; }
  #account { padding: 8px 10px; }
  #account b { font-size: 17px; }
  .btn-play { font-size: 18px; padding: 10px; }
  .pane { max-height: calc(100vh - 140px); }
}

/* centre the menu vertically when it fits (auto margins never clip when it doesn't) */
#menu > .brand { margin-top: auto; }
#menu > .menu-grid { margin-bottom: auto; }
.info-tabs button { padding: 8px 4px; font-size: 11px; letter-spacing: .5px; }
.howto { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 8px 12px; font: 13px Arial, sans-serif; }
.howto dt { color: #ffe14d; font-weight: bold; white-space: nowrap; }
.howto dd { margin: 0; color: #ccc; }
#help-pane p { font: 13px Arial, sans-serif; color: #999; margin: 14px 0 0; line-height: 1.4; }
.touch-only { display: none; }
body.touch .touch-only { display: grid; }
body.touch .keys-only { display: none; }
@media (max-width: 600px) { #menu > .brand { margin-top: 0; } }
th.n { text-align: right; }
td.n.dim { color: #ccc; font-weight: normal; }
.info-tabs button { white-space: nowrap; }
@media (max-height: 560px) and (orientation: landscape) { .info-tabs button { font-size: 10px; letter-spacing: 0; } }
