:root {
  --ink: #f4f1ea;
  --dim: rgba(244, 241, 234, .62);
  --panel: rgba(10, 10, 12, .94);
  --line: rgba(232, 185, 35, .22);
  --gold: #e8b923;
  --gold-d: #a07c12;
  --red: #c41e1e;
  --red-d: #7a1010;
  --gothic: 'Pirata One', 'Old English Text MT', Georgia, serif;
  --tag: 'Permanent Marker', 'Marker Felt', cursive;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #0b0b0d; color: var(--ink);
  font-family: 'Rubik', system-ui, -apple-system, sans-serif;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; overscroll-behavior: none;
}
canvas#three { position: fixed; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
canvas#game { position: fixed; inset: 0; display: block; touch-action: none; cursor: crosshair; background: transparent; }
body.mode3d canvas#game { cursor: crosshair; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud button, #minimap-wrap, #vice-menu { pointer-events: auto; }
#hud-tl {
  position: absolute; top: calc(12px + var(--safe-t)); left: calc(12px + var(--safe-l));
  display: flex; flex-direction: column; gap: 5px; width: 220px;
}
.bar { position: relative; height: 14px; background: rgba(0,0,0,.6); border: 2px solid #000; border-radius: 3px; overflow: hidden; box-shadow: 0 0 0 1px rgba(232,185,35,.35); }
.bar > div { position: absolute; inset: 0 auto 0 0; width: 100%; transition: width .12s; }
.bar.hp > div { background: linear-gradient(#ff5a5a, var(--red)); }
.bar.hp span { position: absolute; right: 6px; top: -2px; font: 800 12px 'Rubik', sans-serif; text-shadow: 0 1px 2px #000; }
.bar.ar { height: 8px; }
.bar.ar > div { background: linear-gradient(#f6d77a, var(--gold)); }
#cash { font: 400 30px var(--tag); color: #7CFC8A; text-shadow: 2px 2px 0 #000, -1px -1px 0 #000; line-height: 1.05; }
#heat { font-size: 22px; letter-spacing: 2px; text-shadow: 0 2px 2px #000; line-height: 1; }
#homies { font: 400 14px var(--tag); color: #ff8080; text-shadow: 1px 1px 0 #000; min-height: 0; }
.bar.rs { height: 10px; margin-top: 2px; }
.bar.rs > div { background: linear-gradient(#ffd27a, #c98a12); }
.bar.rs span { position: absolute; left: 6px; top: -3px; font: 400 10px var(--tag); color: #fff; text-shadow: 1px 1px 0 #000; letter-spacing: .5px; }
#clock { font-weight: 600; font-size: 12px; color: var(--dim); text-shadow: 0 1px 2px #000; }
#buffs { font-weight: 800; font-size: 13px; text-shadow: 0 1px 2px #000; min-height: 0; }
#combo { opacity: 0; transition: opacity .2s; font: 400 14px var(--tag); color: var(--gold); text-shadow: 2px 2px 0 #000; }
#combo-n { font-size: 26px; color: #ff4d6d; }
#combo-mul { color: #7CFC8A; }
#combo-bar { height: 4px; background: rgba(0,0,0,.5); border-radius: 2px; margin-top: 2px; overflow: hidden; width: 150px; }
#combo-fill { height: 100%; background: var(--gold); }

#hud-top { position: absolute; top: calc(12px + var(--safe-t)); left: 50%; transform: translateX(-50%); width: min(46vw, 520px); text-align: center; }
#objective {
  display: inline-block; padding: 7px 14px; background: rgba(8,8,10,.78); border-left: 4px solid var(--gold);
  border-radius: 4px; font-weight: 600; font-size: 14px; line-height: 1.3; text-shadow: 0 1px 1px #000;
}
#bounty { display: none; margin-top: 6px; font: 400 15px var(--tag); color: #ffb000; text-shadow: 2px 2px 0 #000; }
#boss-wrap { display: none; margin-top: 8px; }
#boss-name { font: 400 22px var(--gothic); color: var(--gold); text-shadow: 2px 2px 0 #000; }
.bar.boss { height: 12px; margin-top: 3px; }
.bar.boss > div { background: linear-gradient(#ff7a7a, var(--red)); }

#hud-tr {
  position: absolute; top: calc(12px + var(--safe-t)); right: calc(12px + var(--safe-r));
  display: grid; grid-template-columns: auto auto; gap: 8px; justify-items: end; align-items: start;
}
#btn-pause { width: 40px; height: 40px; border-radius: 6px; border: 2px solid var(--gold-d); background: rgba(8,8,10,.75); font: 400 18px var(--gothic); color: var(--gold); }
#weapon { min-width: 130px; padding: 6px 12px; border-radius: 6px; border: 2px solid var(--gold-d); background: rgba(8,8,10,.75); text-align: right; }
#weapon-name { font: 400 20px var(--gothic); color: var(--gold); line-height: 1; }
#weapon-ammo { font-weight: 800; font-size: 18px; }
#weapon-nades { font-size: 10px; font-weight: 800; color: var(--dim); }
#minimap-wrap {
  grid-column: 1 / span 2; position: relative; width: 160px; height: 160px; border-radius: 50%; overflow: hidden;
  border: 3px solid var(--gold-d); box-shadow: 0 4px 14px rgba(0,0,0,.55), 0 0 0 2px #000; cursor: pointer;
}
#minimap-wrap span { position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%); font: 400 11px var(--tag); opacity: .8; text-shadow: 0 1px 2px #000; }
#minimap { width: 100%; height: 100%; display: block; }

#hint {
  position: absolute; bottom: calc(26px + var(--safe-b)); left: 50%; transform: translateX(-50%);
  padding: 8px 16px; background: rgba(8,8,10,.8); border: 1px solid var(--line); border-radius: 6px; font: 400 15px var(--tag); color: var(--gold);
  transition: opacity .2s; white-space: nowrap;
}

#tb-shop {
  position: absolute; left: 50%; bottom: calc(70px + var(--safe-b)); transform: translateX(-50%);
  padding: 12px 22px; border-radius: 30px; border: 3px solid var(--gold); background: rgba(40,10,10,.88); color: var(--gold);
  font: 400 20px var(--gothic); letter-spacing: .5px; animation: pulse 1.2s infinite; box-shadow: 0 0 20px rgba(232,185,35,.35);
}
#touch-buttons { display: none; position: absolute; right: calc(16px + var(--safe-r)); bottom: calc(150px + var(--safe-b)); grid-template-columns: repeat(3, auto); gap: 10px; }
body.touch #touch-buttons { display: grid; }
body.touch #hint { display: none; }
#touch-buttons button {
  width: 62px; height: 62px; border-radius: 50%; border: 3px solid rgba(232,185,35,.6); background: rgba(8,8,10,.6);
  font: 400 13px var(--tag); transition: transform .1s, background .2s, opacity .2s;
}
#touch-buttons button:active { transform: scale(.92); }
#tb-fire { background: rgba(196,30,30,.75) !important; border-color: #ff9a9a !important; font-size: 15px !important; }
body:not(.mode3d) #tb-fire { display: none; }
#tb-dash { border-color: #43e0ff !important; }
#tb-car.glow { background: rgba(232,185,35,.9); color: #111; border-color: #fff; animation: pulse 0.9s infinite; }
#tb-car.dim { opacity: .45; }
@keyframes pulse { 50% { transform: translateX(var(--tx, 0)) scale(1.06); } }
#tb-shop { --tx: -50%; }

#vice-menu {
  position: absolute; left: 50%; bottom: calc(130px + var(--safe-b)); transform: translateX(-50%);
  display: flex; gap: 10px; padding: 10px; background: rgba(8,8,10,.9); border: 2px solid var(--gold-d); border-radius: 14px;
}
#vice-menu button { width: 74px; padding: 8px 4px; border-radius: 10px; border: 2px solid rgba(255,255,255,.12); background: rgba(255,255,255,.05); font-size: 26px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
#vice-menu button:hover { background: rgba(232,185,35,.15); }
#vice-menu span { font: 400 12px var(--tag); }
#vice-menu b { font-size: 13px; color: var(--gold); }

#yt-wrap { position: absolute; left: calc(14px + var(--safe-l)); bottom: calc(14px + var(--safe-b)); width: 236px; background: rgba(8,8,10,.92); border: 2px solid var(--gold-d); border-radius: 10px; overflow: hidden; pointer-events: auto; z-index: 5; }
#yt-wrap iframe, #yt-wrap #yt { display: block; width: 236px; height: 200px; }
#yt-wrap.mini #yt, #yt-wrap.mini iframe { display: none; }
#yt-wrap .yt-bar { display: flex; align-items: center; gap: 6px; padding: 6px 8px; }
#yt-wrap .yt-bar span { flex: 1; font: 400 12px var(--tag); color: var(--gold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#yt-wrap .yt-bar button { width: 26px; height: 24px; border-radius: 6px; border: 1px solid rgba(255,255,255,.15); background: rgba(255,255,255,.06); font-size: 12px; }
body.touch #yt-wrap { bottom: calc(240px + var(--safe-b)); width: 200px; }
body.touch #yt-wrap iframe, body.touch #yt-wrap #yt { width: 200px; height: 200px; }
#banner { position: absolute; top: 28%; left: 0; right: 0; text-align: center; opacity: 0; pointer-events: none; }
#banner.show { animation: bannerIn 3.8s ease forwards; }
#banner-title { font: 400 clamp(40px, 8vw, 88px) var(--gothic); color: var(--gold); text-shadow: 4px 4px 0 #000, -2px -2px 0 #000, 0 0 30px rgba(196,30,30,.6); line-height: 1; }
#banner-sub { margin-top: 6px; font: 400 clamp(15px, 2.2vw, 22px) var(--tag); text-shadow: 0 2px 3px #000; }
@keyframes bannerIn { 0% { opacity: 0; transform: scale(1.3); } 8% { opacity: 1; transform: scale(1); } 85% { opacity: 1; } 100% { opacity: 0; } }
#announce { position: absolute; top: 17%; left: 0; right: 0; text-align: center; font: 400 clamp(30px, 6vw, 60px) var(--tag); text-shadow: 4px 4px 0 #000; opacity: 0; pointer-events: none; }
#announce.show { animation: announceIn 1.6s ease forwards; }
@keyframes announceIn { 0% { opacity: 0; transform: scale(.6) rotate(-4deg); } 12% { opacity: 1; transform: scale(1.1) rotate(-3deg); } 20% { transform: scale(1) rotate(-3deg); } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-20px) rotate(-3deg); } }

#toast {
  position: absolute; bottom: calc(120px + var(--safe-b)); left: 50%; transform: translate(-50%, 20px); opacity: 0;
  padding: 10px 18px; background: rgba(8,8,10,.9); border: 1px solid var(--line); border-radius: 8px; font-weight: 600; font-size: 14px;
  transition: opacity .25s, transform .25s; max-width: 86vw; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Screens ---------- */
.screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: calc(16px + var(--safe-t)) calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l));
  background: rgba(5, 5, 7, .6); z-index: 10;
}
#screen-title { background: radial-gradient(ellipse at center, rgba(40,5,5,.25), rgba(5,5,7,.88)); }
.title-wrap { text-align: center; }
.pub-logo { width: 64px; height: 64px; border-radius: 14px; margin: 0 auto 10px; display: block; box-shadow: 0 0 24px rgba(0,230,230,.35); }
.title-kicker { font: 400 18px var(--tag); letter-spacing: 1px; color: var(--gold); text-shadow: 0 2px 3px #000; }
.logo { margin: 4px 0 0; display: flex; flex-direction: column; line-height: .85; font: 400 clamp(64px, 14vw, 150px) var(--gothic); font-weight: 400; }
.logo span { color: var(--gold); text-shadow: 4px 4px 0 var(--red-d), 8px 8px 0 #000, 0 0 40px rgba(196,30,30,.45); }
.logo span:nth-child(2) { color: #f4f1ea; font-size: .72em; }
.starring { margin-top: 10px; font: 400 20px var(--tag); color: var(--ink); text-shadow: 0 2px 3px #000; }
.starring b { color: #ff4d4d; font-weight: 400; }
.tagline { margin: 10px auto 22px; max-width: 480px; font-size: 16px; color: var(--ink); text-shadow: 0 2px 4px #000; }
.menu { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
.menu.col { flex-direction: column; align-items: stretch; }
.btn {
  padding: 11px 26px; border-radius: 6px; border: 2px solid rgba(232,185,35,.35); background: rgba(20,20,24,.94);
  font: 400 22px var(--gothic); letter-spacing: .5px; transition: transform .1s, background .15s;
}
.btn:hover { background: rgba(50,30,30,.95); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--gold); color: #140c00; border-color: #fff0b8; box-shadow: 0 4px 0 var(--red-d); }
.btn.primary:hover { background: #f5cf52; }
.btn.danger { color: #ff8a9b; border-color: rgba(255,77,109,.4); }
.btn.small { padding: 6px 16px; font-size: 18px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-top: 4px solid var(--red); border-radius: 10px; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.7); }
.panel h2 { margin: 0 0 2px; font: 400 36px var(--gothic); color: var(--gold); line-height: 1; }
.small-panel { width: min(320px, 100%); text-align: center; }
.help-panel { width: min(760px, 100%); max-height: 100%; overflow: auto; font-size: 15px; line-height: 1.45; }
.help-panel h3 { margin: 14px 0 4px; font: 400 17px var(--tag); color: #ff6b6b; }
.help-panel ul { margin: 0; padding-left: 18px; }
.help-panel li { margin: 3px 0; }
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

.map-panel, .shop-panel { width: min(780px, 100%); max-height: 100%; display: flex; flex-direction: column; }
.map-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.map-sub { color: var(--dim); font-weight: 600; font-size: 14px; }
#zone-list { overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; padding-right: 4px; }
.state-head { margin: 14px 0 6px; font: 400 15px var(--tag); letter-spacing: 1px; color: var(--gold); }
.zone-card {
  --gc: #fff; width: 100%; display: grid; grid-template-columns: 48px 1fr auto; gap: 12px; align-items: center; text-align: left;
  padding: 12px 14px; margin-bottom: 8px; border-radius: 8px; border: 2px solid rgba(255,255,255,.06); background: rgba(255,255,255,.035);
  border-left: 6px solid var(--gc); transition: background .15s, transform .1s;
}
.zone-card:hover { background: rgba(232,185,35,.08); }
.zone-card:active { transform: scale(.99); }
.zone-card.current { outline: 2px solid var(--gold); }
.zone-card.locked { opacity: .45; cursor: not-allowed; border-left-color: #555; }
.zc-num { font: 400 34px var(--gothic); color: var(--gc); }
.zone-card.locked .zc-num { color: #777; }
.zc-name { font: 400 24px var(--gothic); line-height: 1; }
.zc-name span { font: 600 13px 'Rubik', sans-serif; color: var(--dim); margin-left: 6px; }
.zc-gang { font-weight: 600; font-size: 13px; margin-top: 3px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.zc-gang i { width: 10px; height: 10px; border-radius: 50%; background: var(--gc); display: inline-block; }
.zc-gang em { font-style: normal; color: #ffd700; font-weight: 600; }
.zc-blurb { color: var(--dim); font-size: 13px; margin-top: 3px; line-height: 1.35; }
.zc-status { font: 400 15px var(--tag); color: #ff6b6b; }
.zone-card.lib .zc-status { color: #7CFC8A; }

#shop-list { overflow-y: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; touch-action: pan-y; -webkit-overflow-scrolling: touch; padding-right: 4px; }
#shop-list .state-head { grid-column: 1 / -1; margin: 8px 0 0; }
.shop-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; text-align: left; padding: 10px 12px; border-radius: 8px; border: 2px solid rgba(255,255,255,.08); background: rgba(255,255,255,.045); }
.shop-item:hover { background: rgba(232,185,35,.1); border-color: rgba(232,185,35,.35); }
.shop-item.off { opacity: .4; }
.si-name { font-weight: 800; font-size: 15px; }
.si-desc { color: var(--dim); font-size: 12px; margin-top: 2px; }
.si-price { font: 400 18px var(--tag); color: #7CFC8A; white-space: nowrap; }

.screen.dead { flex-direction: column; background: radial-gradient(ellipse at center, rgba(120,0,0,.3), rgba(0,0,0,.8)); pointer-events: none; }
.dead-title { font: 400 clamp(80px, 18vw, 180px) var(--gothic); color: var(--red); text-shadow: 6px 6px 0 #000, 0 0 40px rgba(255,0,0,.4); animation: slam .5s cubic-bezier(.2,1.6,.4,1); line-height: 1; }
#dead-sub { font: 400 20px var(--tag); text-shadow: 0 2px 3px #000; margin-top: 6px; }
@keyframes slam { from { transform: scale(2.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

#rotate-hint { display: none; }

/* ---------- Mobile ---------- */
@media (max-width: 820px), (max-height: 500px) {
  #hud-tl { width: 150px; gap: 3px; }
  #cash { font-size: 21px; }
  #heat { font-size: 15px; }
  #clock, #buffs { font-size: 10px; }
  .bar { height: 12px; }
  .bar.hp span { font-size: 10px; top: -2px; }
  #hud-top { width: min(40vw, 360px); }
  #objective { font-size: 12px; padding: 5px 10px; }
  #weapon { min-width: 96px; padding: 4px 9px; }
  #weapon-name { font-size: 16px; }
  #weapon-ammo { font-size: 15px; }
  #btn-pause { width: 34px; height: 34px; }
  #minimap-wrap { width: 96px; height: 96px; }
  #touch-buttons button { width: 54px; height: 54px; font-size: 11px; }
  #touch-buttons { gap: 8px; bottom: calc(130px + var(--safe-b)); }
  #banner { top: 22%; }
  .help-cols { grid-template-columns: 1fr; gap: 0; }
  .panel { padding: 16px; }
  #shop-list { grid-template-columns: 1fr; }
  #combo-n { font-size: 20px; }
}
@media (max-height: 430px) {
  .logo { font-size: clamp(48px, 17vh, 90px); }
  .tagline { margin: 6px auto 8px; font-size: 13px; }
  .starring { font-size: 15px; margin-top: 4px; }
  .menu { margin-top: 6px; }
  #touch-buttons { bottom: calc(118px + var(--safe-b)); grid-template-columns: repeat(3, auto); }
  #touch-buttons button { width: 50px; height: 50px; }
  #tb-shop { bottom: calc(14px + var(--safe-b)); padding: 8px 16px; font-size: 16px; }
  #vice-menu { bottom: calc(60px + var(--safe-b)); }
  .zone-card { padding: 8px 12px; }
  .zc-blurb, #buffs { display: none; }
}
@media (orientation: portrait) and (pointer: coarse) {
  #rotate-hint {
    display: block; position: fixed; left: 50%; bottom: calc(16px + var(--safe-b)); transform: translateX(-50%); z-index: 20;
    padding: 6px 12px; border-radius: 20px; background: rgba(0,0,0,.6); font-size: 12px; pointer-events: none; opacity: .8;
  }
  #hud-top { top: calc(118px + var(--safe-t)); width: 80vw; }
  #touch-buttons { bottom: calc(190px + var(--safe-b)); }
}
