* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --accent: #ffb703;
  --accent-dark: #fb8500;
  --good: #4ade80;
  --bad: #f87171;
  --ink: #1b263b;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #0d1b2a;
  user-select: none;
}

#game-container, #game-container canvas { position: absolute; inset: 0; }

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 14px 18px;
  pointer-events: none;
  z-index: 10;
}
.hud-left, .hud-right { display: flex; align-items: flex-start; gap: 12px; }
.hud-col { display: flex; flex-direction: column; gap: 8px; }

#health-wrap {
  display: flex; align-items: center; gap: 8px;
  background: rgba(13, 27, 42, .75);
  border: 2px solid rgba(255,255,255,.25);
  border-radius: 999px;
  padding: 6px 14px;
}
.hp-label { font-size: 11px; font-weight: 800; letter-spacing: 2px; color: rgba(255,255,255,.7); }
#health-bar {
  width: 130px; height: 12px;
  background: rgba(255,255,255,.15);
  border-radius: 999px;
  overflow: hidden;
}
#health-fill {
  width: 100%; height: 100%;
  background: linear-gradient(180deg, #6ee7a0, #22c55e);
  border-radius: 999px;
  transition: width .25s ease;
}
#health-fill.mid { background: linear-gradient(180deg, #fcd34d, #f59e0b); }
#health-fill.low { background: linear-gradient(180deg, #fca5a5, #ef4444); }

/* ---------- blast meter (Blast mode) ---------- */
#blast-wrap {
  display: flex; align-items: center; gap: 8px;
  background: rgba(13, 27, 42, .75);
  border: 2px solid rgba(255,255,255,.25);
  border-radius: 999px;
  padding: 6px 14px;
  transition: border-color .18s ease, box-shadow .18s ease;
}
#blast-wrap.hidden { display: none; }
#blast-bar {
  width: 130px; height: 12px;
  background: rgba(255,255,255,.15);
  border-radius: 999px;
  overflow: hidden;
}
#blast-fill {
  width: 0; height: 100%;
  background: linear-gradient(180deg, #a5f3fc, #22d3ee);
  border-radius: 999px;
  transition: width .12s linear;
}
#blast-ready {
  font-size: 11px; font-weight: 900; letter-spacing: 2px;
  color: #fde68a; opacity: 0; transition: opacity .18s ease;
}
#blast-wrap.full { border-color: #fbbf24; box-shadow: 0 0 16px rgba(251, 191, 36, .75); }
#blast-wrap.full #blast-fill { background: linear-gradient(180deg, #fef3c7, #fbbf24); }
#blast-wrap.full #blast-ready { opacity: 1; animation: blastPulse .7s ease-in-out infinite; }
@keyframes blastPulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* ---------- countdown clock (Time Attack) ---------- */
#time-pill.countdown span { color: #7dd3fc; }
#time-pill.low {
  border-color: #ef4444;
  animation: clockPulse .7s ease-in-out infinite;
}
#time-pill.low span { color: #fca5a5; }
@keyframes clockPulse {
  0%, 100% { box-shadow: 0 0 0 rgba(239, 68, 68, 0); }
  50%      { box-shadow: 0 0 18px rgba(239, 68, 68, .85); }
}

/* ---------- mode picker (title screen) ---------- */
#mode-select { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.mode-chip {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 132px;
  background: rgba(13, 27, 42, .7);
  border: 2px solid rgba(255,255,255,.22);
  border-radius: 14px;
  padding: 10px 18px;
  color: #fff;
  font-family: inherit;
  cursor: pointer;
  transition: transform .14s ease, border-color .14s ease, background .14s ease;
}
.mode-chip:hover { transform: translateY(-2px); border-color: rgba(255,255,255,.5); }
.mode-chip .m-icon { font-size: 22px; line-height: 1; }
.mode-chip b { font-size: 15px; font-weight: 800; }
.mode-chip i { font-size: 11px; font-style: normal; color: rgba(255,255,255,.55); letter-spacing: .5px; }
.mode-chip.on {
  border-color: var(--accent);
  background: rgba(255, 154, 61, .18);
  box-shadow: 0 0 18px rgba(255, 154, 61, .35);
}
.mode-chip.on i { color: var(--accent); }
#mode-desc {
  max-width: 560px; margin: 0; text-align: center;
  font-size: 14px; color: rgba(255,255,255,.7); min-height: 34px;
}

#banner .sub.mode { font-size: 16px; color: rgba(255,255,255,.8); margin-top: 2px; }

#vignette {
  position: absolute; inset: 0;
  pointer-events: none;
  z-index: 15;
  opacity: 0;
  box-shadow: inset 0 0 120px 40px rgba(220, 38, 38, .75);
}
#vignette.hit { animation: vigflash .6s ease-out; }
@keyframes vigflash {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

.failed-title {
  font-size: clamp(40px, 7vw, 72px); font-weight: 900; color: var(--bad);
  text-shadow: 0 5px 0 rgba(0,0,0,.4);
}
.failed-sub { color: rgba(255,255,255,.8); font-size: 18px; }
.hud-right { flex-direction: column; align-items: flex-end; gap: 8px; }

#target-badge {
  background: linear-gradient(180deg, var(--accent), var(--accent-dark));
  border: 4px solid #fff;
  border-radius: 18px;
  padding: 6px 18px 10px;
  text-align: center;
  box-shadow: 0 6px 18px rgba(0,0,0,.4);
}
.badge-label { font-size: 12px; font-weight: 800; letter-spacing: 3px; color: #7a3e00; }
#target-number { font-size: 44px; font-weight: 900; color: #fff; line-height: 1; text-shadow: 0 3px 0 rgba(0,0,0,.25); }

.hud-pill {
  background: rgba(13, 27, 42, .75);
  color: #fff;
  border: 2px solid rgba(255,255,255,.25);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 15px;
  font-weight: 600;
  backdrop-filter: blur(4px);
}
.hud-pill span { color: var(--accent); font-weight: 900; font-size: 17px; }

#controls-hint {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 22px;
  background: rgba(13, 27, 42, .6);
  color: rgba(255,255,255,.85);
  border-radius: 999px;
  padding: 8px 20px;
  font-size: 13px;
  z-index: 10;
  pointer-events: none;
}
#controls-hint b { color: var(--accent); }

#replay-panel {
  position: absolute; right: 18px; top: 148px;
  display: flex; gap: 6px; align-items: center;
  z-index: 10;
}
#replay-panel select {
  max-width: 190px;
  background: rgba(13, 27, 42, .85);
  color: #fff; border: 2px solid rgba(255,255,255,.25);
  border-radius: 8px; padding: 5px 8px;
  font-family: inherit; font-size: 12.5px;
}
#replay-panel button {
  background: rgba(13, 27, 42, .85);
  color: #fff; border: 2px solid rgba(255,255,255,.25);
  border-radius: 8px; padding: 5px 10px;
  cursor: pointer; font-size: 13px;
}
#replay-panel button:hover { border-color: var(--accent); }

#debug-line {
  position: absolute; left: 18px; bottom: 92px;
  font-family: Consolas, monospace; font-size: 13px;
  color: #9be8a8; text-shadow: 0 1px 0 rgba(0,0,0,.6);
  z-index: 10; pointer-events: none; white-space: pre;
}

/* ---------- speedometer ---------- */
#speedo {
  position: absolute; left: 18px; bottom: 60px;
  display: flex; align-items: center; gap: 10px;
  z-index: 10; pointer-events: none;
}
#speedo-bar {
  position: relative;
  width: 170px; height: 14px;
  background: rgba(13, 27, 42, .75);
  border: 2px solid rgba(255,255,255,.25);
  border-radius: 999px;
}
#speedo-fill {
  height: 100%; width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #4ade80, #ffb703 55%, #ff5a2b);
  background-size: 170px 100%;
  transition: width .08s linear;
}
#speedo-notch {
  position: absolute; top: -4px; bottom: -4px; width: 3px;
  background: #fff; opacity: .85; border-radius: 2px;
}
#speedo-num {
  color: #fff; font-weight: 900; font-size: 21px;
  text-shadow: 0 2px 0 rgba(0,0,0,.4);
  min-width: 62px;
}
#speedo-num span { font-size: 12px; color: rgba(255,255,255,.55); font-weight: 700; }
#speedo.hot #speedo-bar { box-shadow: 0 0 14px rgba(255, 123, 43, .8); border-color: #ff9a3d; }

/* ---------- floating labels ---------- */
#labels { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 12; }
.float-label {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: 900;
  font-size: 26px;
  white-space: nowrap;
  text-shadow: 0 2px 0 rgba(0,0,0,.35);
  animation: floatUp 1.4s ease-out forwards;
}
.float-label.good { color: var(--good); }
.float-label.bad  { color: var(--bad); }
.float-label.info { color: #fff; }
@keyframes floatUp {
  0%   { opacity: 0; margin-top: 10px; }
  12%  { opacity: 1; margin-top: 0; }
  75%  { opacity: 1; }
  100% { opacity: 0; margin-top: -70px; }
}

/* ---------- incoming-building equation previews ---------- */
#edge-previews { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 11; }
.edge-chip {
  position: absolute;
  bottom: 66px;
  transform: translateX(-50%);
  background: rgba(27, 38, 59, .92);
  border: 2.5px solid var(--accent);
  border-radius: 999px;
  padding: 7px 16px 8px;
  color: #fff;
  font-size: 19px;
  font-weight: 900;
  white-space: nowrap;
  text-align: center;
  animation: chipPop .22s cubic-bezier(.2,1.6,.4,1);
}
.edge-chip::after {
  content: '▼';
  display: block;
  font-size: 11px;
  color: var(--accent);
  line-height: .6;
  margin-top: 3px;
}
@keyframes chipPop {
  from { opacity: 0; transform: translateX(-50%) translateY(14px) scale(.6); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

/* ---------- center banner ---------- */
#banner {
  position: absolute; top: 26%; left: 50%; transform: translate(-50%, -50%);
  font-size: 40px; font-weight: 900; color: #fff;
  text-align: center;
  text-shadow: 0 4px 0 rgba(0,0,0,.35);
  z-index: 11;
  pointer-events: none;
  animation: bannerPop .45s cubic-bezier(.2,1.6,.4,1);
}
#banner .sub { display: block; font-size: 20px; font-weight: 700; color: var(--accent); margin-top: 6px; }
@keyframes bannerPop {
  from { transform: translate(-50%, -50%) scale(.5); opacity: 0; }
  to   { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* ---------- overlays ---------- */
.overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px;
  background: radial-gradient(ellipse at 50% 30%, rgba(27,59,95,.92), rgba(6,13,22,.96));
  z-index: 20;
}
/* the level menu can outgrow the screen — let it scroll */
#menu {
  justify-content: flex-start;
  overflow-y: auto;
  padding: 36px 14px 56px;
}

.game-title {
  font-size: clamp(48px, 9vw, 92px);
  font-weight: 900;
  color: #fff;
  letter-spacing: 4px;
  text-shadow: 0 6px 0 rgba(0,0,0,.4);
}
.game-title span { color: var(--accent); }
.tagline { color: rgba(255,255,255,.75); font-size: 18px; margin-top: -10px; }
.character-lab-link {
  display: inline-flex; align-items: center; gap: 8px;
  color: #bfefff; background: rgba(14, 35, 48, .72);
  border: 1px solid rgba(142, 202, 230, .55); border-radius: 999px;
  padding: 8px 15px; margin-top: -4px; text-decoration: none;
  font-size: 12px; font-weight: 800; letter-spacing: .04em;
  transition: background .15s, border-color .15s, transform .15s;
}
.character-lab-link span { color: var(--accent); }
.character-lab-link:hover { background: rgba(33, 158, 188, .25); border-color: #bfefff; transform: translateY(-2px); }

.visual-style-picker {
  display: inline-flex; align-items: center; gap: 10px;
  color: rgba(255,255,255,.72); font-size: 12px; font-weight: 800;
  letter-spacing: .09em; text-transform: uppercase;
}
.visual-style-picker select {
  min-width: 124px; color: #fff; background: rgba(13,27,42,.82);
  border: 1px solid rgba(255,255,255,.3); border-radius: 999px;
  padding: 7px 32px 7px 13px; font: 700 13px 'Segoe UI', system-ui, sans-serif;
  cursor: pointer; outline: none;
}
.visual-style-picker select:hover,
.visual-style-picker select:focus { border-color: var(--accent); }

#level-cards {
  display: flex; gap: 16px; margin: 14px 0 6px;
  flex-wrap: wrap; justify-content: center;
  max-width: 760px;
}
.vehicle-card {
  width: 170px;
  background: rgba(255,255,255,.06);
  border: 3px solid rgba(255,255,255,.18);
  border-radius: 16px;
  padding: 16px 14px;
  text-align: center;
  color: #fff;
  cursor: pointer;
  transition: transform .15s, border-color .15s, background .15s;
}
.vehicle-card .v-icon { font-size: 52px; line-height: 1.2; }
.vehicle-card h3 { font-size: 18px; margin: 8px 0 4px; }
.vehicle-card p { font-size: 12.5px; color: rgba(255,255,255,.65); line-height: 1.35; }
.vehicle-card:hover:not(.locked) { transform: translateY(-4px); background: rgba(255,255,255,.1); }
.vehicle-card.selected { border-color: var(--accent); background: rgba(255,183,3,.12); box-shadow: 0 0 24px rgba(255,183,3,.25); }
.vehicle-card.locked { opacity: .45; cursor: not-allowed; filter: grayscale(.6); }
.playground-card { border-style: dashed; border-color: rgba(255,255,255,.4); }
.playground-card:hover { border-color: var(--accent); }

.lv-title { font-size: 15px !important; color: #fff !important; font-weight: 700; margin-top: 2px; }
.lv-vehicle { margin-top: 8px; font-size: 11.5px !important; letter-spacing: 1px; text-transform: uppercase; }
.map-actions { display: flex; gap: 6px; justify-content: center; }
.map-btn {
  background: rgba(255,255,255,0.1); color: inherit; border: 1px solid rgba(255,255,255,0.25);
  border-radius: 6px; padding: 3px 8px; font-size: 11px; cursor: pointer;
}
.map-btn:hover { background: rgba(255,255,255,0.22); }
.target-chip {
  display: inline-block; margin-top: 8px;
  background: linear-gradient(180deg, var(--accent), var(--accent-dark));
  color: #7a3e00; font-size: 13px; font-weight: 700;
  border-radius: 999px; padding: 4px 14px;
}
.target-chip b { color: #fff; font-size: 15px; }
.lock-tag {
  display: inline-block; margin-top: 8px;
  font-size: 10.5px; font-weight: 800; letter-spacing: 1px;
  background: rgba(255,255,255,.15); border-radius: 999px; padding: 3px 10px;
}
.ready-tag { background: var(--good); color: #06290f; }

.big-btn {
  font-family: inherit;
  font-size: 20px; font-weight: 900; letter-spacing: 2px;
  color: #7a3e00;
  background: linear-gradient(180deg, var(--accent), var(--accent-dark));
  border: 4px solid #fff;
  border-radius: 999px;
  padding: 14px 44px;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(0,0,0,.45);
  transition: transform .12s;
}
.big-btn:hover { transform: scale(1.05); }
.big-btn.secondary { background: linear-gradient(180deg, #8ecae6, #219ebc); color: #06364a; }

.btn-row { display: flex; gap: 16px; }
.text-btn {
  background: none; border: none; cursor: pointer;
  color: rgba(255,255,255,.6); font-size: 14px; font-family: inherit;
  text-decoration: underline;
}
.text-btn:hover { color: #fff; }

.complete-title {
  font-size: clamp(40px, 7vw, 72px); font-weight: 900; color: var(--good);
  text-shadow: 0 5px 0 rgba(0,0,0,.4);
}
#stars { font-size: 52px; letter-spacing: 8px; }
#stars .dim { opacity: .25; }
#complete-stats { color: #fff; font-size: 18px; text-align: center; line-height: 1.7; }
#complete-stats b { color: var(--accent); }

/* ---------- touch controls ---------- */
#game-container { touch-action: none; }
body.touch { overscroll-behavior: none; -webkit-touch-callout: none; }
body.touch #controls-hint { display: none !important; }

#touch-ui { position: absolute; inset: 0; z-index: 14; pointer-events: none; touch-action: none; }
#touch-left {
  position: absolute; left: 0; top: 0; bottom: 0; width: 50%;
  pointer-events: auto; touch-action: none;
}
#stick {
  position: absolute; width: 0; height: 0; pointer-events: none;
}
#stick-base {
  position: absolute; left: -64px; top: -64px; width: 128px; height: 128px;
  border-radius: 50%;
  background: rgba(13, 27, 42, .35);
  border: 2px solid rgba(255,255,255,.45);
  box-shadow: 0 0 0 6px rgba(13, 27, 42, .18);
}
#stick-knob {
  position: absolute; left: -28px; top: -28px; width: 56px; height: 56px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, #ffb703 70%);
  border: 2px solid rgba(0,0,0,.25);
  box-shadow: 0 4px 10px rgba(0,0,0,.4);
}

#touch-buttons {
  position: absolute; right: 22px; bottom: 26px;
  display: flex; flex-direction: column; align-items: flex-end; gap: 14px;
  pointer-events: none;
}
.touch-btn {
  pointer-events: auto; touch-action: none;
  width: 96px; height: 96px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.55);
  background: rgba(255, 183, 3, .78);
  color: #1b263b;
  font: 900 18px/1 'Segoe UI', system-ui, sans-serif;
  letter-spacing: 2px;
  box-shadow: 0 6px 16px rgba(0,0,0,.45);
  transition: transform .06s ease, background .06s ease;
}
.touch-btn.down { transform: scale(.9); background: #fff; }
#btn-slam {
  width: 68px; height: 68px; font-size: 13px;
  background: rgba(239, 68, 68, .78); color: #fff;
  margin-right: 14px;
}
#btn-slam.down { background: #fff; color: #ef4444; }

#touch-hint {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  background: rgba(13, 27, 42, .6); color: rgba(255,255,255,.85);
  border-radius: 999px; padding: 6px 14px; font-size: 12px;
  white-space: nowrap; pointer-events: none;
}

#rotate-hint {
  position: absolute; inset: 0; z-index: 30;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: rgba(6, 13, 22, .92); color: #fff;
  font-size: 22px; font-weight: 800; text-align: center; padding: 24px;
}
#rotate-hint span { font-size: 56px; }

/* phones: tighter HUD so the pills and the stick zone don't fight for space */
@media (max-width: 820px) {
  #hud { padding: 8px 10px; }
  #target-badge { padding: 4px 12px 6px; }
  #target-number { font-size: 32px; }
  .hud-pill { padding: 5px 11px; font-size: 12px; }
  .hud-pill span { font-size: 14px; }
  #health-bar, #blast-bar { width: 90px; height: 10px; }
  #banner { font-size: 28px; }
  #banner .sub { font-size: 15px; }
  #speedo { display: none !important; }
}

/* touch: the ◀ Menu button lives top-center, clear of the right-hand pills and buttons */
body.touch #menu-back-btn {
  top: 8px !important; right: auto !important; left: 50% !important;
  transform: translateX(-50%);
}
/* touch: the editor's water-audit legend sits right where the GO button lives */
body.touch #ed-water-audit-legend { display: none !important; }
