/* Solar Surfer 0.2.0 */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --cyan: #00f0ff;
  --pink: #ff2d95;
  --gold: #ffd166;
  --amber: #ffb347;
  --red: #ff5a5a;
  --bg: #030611;
  --panel: rgba(6, 11, 26, 0.86);
  --panel-border: rgba(0, 240, 255, 0.28);
  --text-dim: rgba(255, 255, 255, 0.62);
  --font: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;
  --mono: "Cascadia Mono", "SF Mono", Consolas, "Roboto Mono", monospace;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: #fff;
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
}
body { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
button { font: inherit; color: inherit; }
kbd {
  font-family: var(--mono); font-size: 0.85em;
  background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px; padding: 0 5px; margin: 0 1px;
}

#game-container { position: relative; width: 100%; height: 100%; overflow: hidden; }
canvas#viewport { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

#startup-warning, .startup-warning {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  max-width: 90%; padding: 10px 14px; border-radius: 8px; z-index: 90;
  background: rgba(120, 20, 40, 0.9); border: 1px solid var(--red); font-size: 13px;
}

/* ================= HUD ================= */
#hud {
  position: absolute; inset: 0;
  pointer-events: none;
  display: none;
  flex-direction: column;
  justify-content: space-between;
  padding: calc(10px + var(--sat)) calc(14px + var(--sar)) calc(12px + var(--sab)) calc(14px + var(--sal));
  z-index: 10;
}
#hud.visible { display: flex; }

.hud-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.hud-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }

.hud-pill {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: 0 4px 16px rgba(0,0,0,0.55), inset 0 0 10px rgba(0,240,255,0.08);
  border-radius: 10px;
  padding: 7px 12px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  pointer-events: auto;
  min-width: 0;
}
.stage-pill { max-width: 40vw; }
.stage-badge, .pill-label, .score-label, .stat-title {
  font-family: var(--mono); font-size: 10px; font-weight: 700; letter-spacing: 1.6px;
  color: var(--cyan); text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stage-title { font-size: 15px; font-weight: 800; letter-spacing: 0.6px; text-transform: uppercase; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.score-box { text-align: right; }
.score-label { color: var(--text-dim); }
.score-value { font-family: var(--mono); font-size: 22px; font-weight: 800; color: var(--gold); text-shadow: 0 0 12px rgba(255,209,102,0.45); line-height: 1.1; }

.hud-btn {
  background: var(--panel); border: 1px solid var(--panel-border); color: #fff;
  padding: 6px 11px; border-radius: 8px; font-size: 12px; font-weight: 700; cursor: pointer;
  pointer-events: auto; transition: background 0.15s, border-color 0.15s; white-space: nowrap;
}
.hud-btn:hover { background: rgba(0,240,255,0.18); border-color: var(--cyan); }
.hud-btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

/* Route progress: Sun to Saturn */
.route { display: flex; justify-content: center; margin-top: 8px; }
.route-bar {
  position: relative; width: min(520px, 70vw); height: 6px; border-radius: 3px;
  background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.12);
}
.route-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 3px; background: linear-gradient(90deg, var(--amber), var(--cyan)); box-shadow: 0 0 10px rgba(0,240,255,0.5); }
.route-dot {
  position: absolute; top: 50%; width: 10px; height: 10px; border-radius: 50%;
  transform: translate(-50%, -50%); background: var(--dot, #fff); box-shadow: 0 0 6px var(--dot, #fff);
}
.route-dot.route-end { width: 14px; height: 6px; border-radius: 3px; }
.route-marker {
  position: absolute; top: 50%; left: 0; width: 6px; height: 16px; border-radius: 3px;
  transform: translate(-50%, -50%); background: #fff; box-shadow: 0 0 8px #fff;
}

.hud-center { align-self: center; display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.announce-wrap { opacity: 0; transform: translateY(-8px) scale(0.96); transition: opacity 0.3s ease, transform 0.3s ease; }
.announce-wrap.show { opacity: 1; transform: none; }
.announcement { font-size: clamp(20px, 3.4vw, 32px); font-weight: 900; letter-spacing: 4px; text-transform: uppercase; text-shadow: 0 0 18px var(--cyan), 0 2px 6px rgba(0,0,0,0.8); }
.announcement-sub { font-size: 13px; letter-spacing: 1px; color: rgba(255,255,255,0.8); text-shadow: 0 1px 4px rgba(0,0,0,0.9); margin-top: 4px; }

.toast {
  font-family: var(--mono); font-size: 13px; font-weight: 800; letter-spacing: 1px;
  padding: 5px 12px; border-radius: 6px; background: rgba(6,11,26,0.75); border: 1px solid rgba(255,255,255,0.25);
  opacity: 0; transform: translateY(6px); transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: none; }
.toast.gold { color: var(--gold); border-color: var(--gold); }
.toast.cyan { color: var(--cyan); border-color: var(--cyan); }
.toast.pink { color: var(--pink); border-color: var(--pink); }
.toast.red { color: var(--red); border-color: var(--red); }
.toast.dim { color: var(--text-dim); }

.rim-graze-alert {
  display: flex; gap: 10px; align-items: baseline;
  font-family: var(--mono); font-weight: 900; letter-spacing: 2px;
  color: #fff3b0; background: rgba(255,170,0,0.22); border: 1px solid var(--gold);
  padding: 5px 14px; border-radius: 6px; text-shadow: 0 0 10px #ffaa00;
  opacity: 0; transform: translateY(-6px); transition: opacity 0.15s, transform 0.15s;
}
.rim-graze-alert .rim-title { font-size: 11px; text-transform: uppercase; }
.rim-graze-alert #rim-points { font-size: 16px; color: var(--gold); }
.rim-graze-alert.active { opacity: 1; transform: none; animation: pulse 0.6s ease-in-out infinite alternate; }
@keyframes pulse { from { box-shadow: 0 0 6px rgba(255,209,102,0.3); } to { box-shadow: 0 0 18px rgba(255,209,102,0.7); } }

.hud-bottom { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; }
.warp-container { width: 190px; max-width: 38vw; cursor: pointer; }
.warp-container:active { background: rgba(255, 45, 149, 0.18); }
.warp-label { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 5px; }
.warp-label kbd { font-size: 9px; padding: 0 4px; }
.warp-state { color: var(--text-dim); }
.warp-state.ready { color: var(--gold); }
.warp-state.engaged { color: var(--pink); }
.warp-track { height: 8px; background: rgba(255,255,255,0.12); border-radius: 4px; overflow: hidden; border: 1px solid rgba(0,240,255,0.3); }
.warp-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--cyan), var(--pink)); box-shadow: 0 0 8px var(--cyan); transition: width 0.15s ease; }

.shields { display: flex; gap: 6px; align-items: center; margin-top: 4px; }
.shield-cell { width: 20px; height: 14px; background: var(--cyan); border-radius: 3px; box-shadow: 0 0 8px var(--cyan); transition: opacity 0.25s, background 0.25s, box-shadow 0.25s; clip-path: polygon(0 0, 100% 0, 100% 60%, 50% 100%, 0 60%); }
.shield-cell.lost { opacity: 0.18; background: #fff; box-shadow: none; }

.dist-pill { text-align: right; }
.dist-display { font-family: var(--mono); font-size: 14px; font-weight: 700; display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; }
.dist-display .speed { font-size: 11px; color: var(--text-dim); font-weight: 600; }

/* ================= MODALS ================= */
.modal-layer {
  position: absolute; inset: 0; display: flex; justify-content: center; align-items: center;
  background: rgba(2, 4, 12, 0.72); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  z-index: 50; padding: calc(16px + var(--sat)) 16px calc(16px + var(--sab)); overflow-y: auto;
}
.modal-layer.hidden { display: none !important; }

.card-panel {
  background: var(--panel); border: 1px solid var(--panel-border);
  box-shadow: 0 10px 40px rgba(0,0,0,0.85), 0 0 30px rgba(0,240,255,0.15);
  border-radius: 16px; padding: 26px 24px; max-width: 560px; width: 100%; text-align: center;
  max-height: 100%; overflow-y: auto;
}
.card-panel.narrow { max-width: 380px; }
.eyebrow { font-family: var(--mono); font-size: 10px; letter-spacing: 2px; text-transform: uppercase; color: var(--text-dim); display: flex; justify-content: space-between; margin-bottom: 10px; }
.eyebrow .version { color: var(--cyan); }
.game-title {
  font-size: 38px; font-weight: 900; letter-spacing: 4px; text-transform: uppercase; line-height: 1;
  background: linear-gradient(135deg, #ffffff 25%, var(--cyan) 70%, var(--pink) 100%);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; margin-bottom: 8px;
}
.game-title.small { font-size: 26px; }
.game-tagline { font-size: 13px; font-weight: 500; color: var(--text-dim); line-height: 1.45; margin-bottom: 18px; }
.section-label { text-align: left; font-family: var(--mono); font-size: 10px; font-weight: 700; letter-spacing: 2px; color: var(--cyan); margin-bottom: 8px; text-transform: uppercase; }

.rig-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 18px; }
.rig-card {
  display: flex; flex-direction: column; gap: 5px;
  background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.14); border-radius: 12px;
  padding: 12px 12px 10px; cursor: pointer; text-align: left; transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.rig-card:hover { background: rgba(0,240,255,0.1); border-color: rgba(0,240,255,0.5); }
.rig-card:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.rig-card.selected { background: rgba(0,240,255,0.16); border-color: var(--cyan); box-shadow: 0 0 16px rgba(0,240,255,0.35); }
.rig-header { display: flex; justify-content: space-between; align-items: center; }
.rig-name { font-size: 14px; font-weight: 800; }
.rig-mult { font-family: var(--mono); font-size: 11px; font-weight: 800; color: var(--gold); background: rgba(255,209,102,0.15); padding: 2px 7px; border-radius: 4px; }
.rig-desc { font-size: 11.5px; color: var(--text-dim); line-height: 1.35; }
.rig-stats { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 10px; color: rgba(255,255,255,0.5); letter-spacing: 0.5px; }

.btn-launch {
  width: 100%; padding: 14px 20px; border: none; border-radius: 10px; cursor: pointer;
  background: linear-gradient(135deg, var(--cyan), #0088ff); color: #021020;
  font-size: 17px; font-weight: 900; letter-spacing: 2.5px; text-transform: uppercase;
  box-shadow: 0 4px 22px rgba(0,240,255,0.45); transition: transform 0.15s, box-shadow 0.15s;
}
.btn-launch:hover { transform: translateY(-2px); box-shadow: 0 6px 26px rgba(0,240,255,0.65); }
.btn-launch:active { transform: none; }
.btn-launch:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.btn-secondary {
  width: 100%; padding: 11px 16px; border-radius: 10px; cursor: pointer;
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.2); color: #fff;
  font-size: 13px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; transition: background 0.15s, border-color 0.15s;
}
.btn-secondary:hover { background: rgba(0,240,255,0.14); border-color: var(--cyan); }
.stack { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.stack.row { flex-direction: row; }
.stack.row .btn-secondary { width: auto; flex: 0 0 auto; }
.stack.row .btn-launch { flex: 1 1 auto; }

.menu-help { margin-top: 14px; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; font-size: 11.5px; color: var(--text-dim); }
.menu-best { margin-top: 12px; font-family: var(--mono); font-size: 11px; letter-spacing: 1px; color: var(--gold); }

.best-banner { display: inline-block; color: #021020; background: var(--gold); font-size: 11px; font-weight: 900; letter-spacing: 2px; text-transform: uppercase; padding: 4px 12px; border-radius: 999px; margin-bottom: 10px; }
.score-hero { display: flex; flex-direction: column; align-items: center; gap: 2px; margin-bottom: 14px; }
.score-hero strong { font-family: var(--mono); font-size: 40px; font-weight: 900; color: var(--gold); text-shadow: 0 0 18px rgba(255,209,102,0.5); line-height: 1.1; }
.res-best { font-family: var(--mono); font-size: 11px; letter-spacing: 1px; color: var(--text-dim); }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; text-align: left; }
.stat-item { background: rgba(255,255,255,0.05); border-radius: 8px; padding: 8px 12px; }
.stat-title { color: var(--text-dim); }
.stat-val { font-family: var(--mono); font-size: 17px; font-weight: 800; color: var(--cyan); margin-top: 2px; }
.breakdown { list-style: none; text-align: left; font-size: 12.5px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 18px; margin-bottom: 4px; }
.breakdown li { display: flex; justify-content: space-between; border-bottom: 1px dashed rgba(255,255,255,0.12); padding: 3px 0; color: var(--text-dim); }
.breakdown strong { font-family: var(--mono); color: #fff; }

/* When thumb buttons are showing (any size), lift the bottom HUD pills above them */
#hud.touch .hud-bottom { margin-bottom: 104px; }

/* ================= TOUCH CONTROLS ================= */
#touch-controls {
  position: absolute; left: 0; right: 0; bottom: 0; height: 170px;
  pointer-events: none; display: none; justify-content: space-between; align-items: flex-end;
  padding: 0 calc(18px + var(--sal)) calc(14px + var(--sab)) calc(18px + var(--sar)); z-index: 15;
}
#touch-controls.visible { display: flex; }
.touch-btn {
  width: 76px; height: 76px; border-radius: 50%;
  background: rgba(10,20,45,0.72); border: 2px solid rgba(0,240,255,0.45);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: flex; justify-content: center; align-items: center;
  pointer-events: auto; touch-action: none; color: var(--cyan); font-size: 26px; font-weight: 900;
  box-shadow: 0 4px 15px rgba(0,0,0,0.5); transition: transform 0.1s, background 0.1s, border-color 0.1s;
}
.touch-btn.pressed { background: rgba(0,240,255,0.3); border-color: var(--cyan); transform: scale(0.92); }
.touch-warp { width: 64px; height: 64px; border-color: rgba(255,45,149,0.55); color: var(--pink); margin-bottom: 6px; }

/* ================= RESPONSIVE ================= */
@media (max-width: 720px) {
  .hud-actions { order: 3; width: 100%; justify-content: flex-end; }
  .hud-top { flex-wrap: wrap; }
  .stage-pill { max-width: 52vw; }
  .score-value { font-size: 18px; }
  .warp-container { max-width: 34vw; }
  .rig-grid { grid-template-columns: 1fr; gap: 8px; }
  .card-panel { padding: 20px 16px; }
  .game-title { font-size: 28px; }
  .stats-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .stat-val { font-size: 14px; }
  .breakdown { grid-template-columns: 1fr; }
  .stack.row { flex-direction: column; }
  .stack.row .btn-secondary { width: 100%; }
}
@media (max-height: 480px) and (orientation: landscape) {
  .route { display: none; }
  #hud.touch .hud-bottom { margin-bottom: 0; padding: 0 86px; }
  #hud.touch .warp-container { cursor: pointer; }
  #touch-controls { padding-bottom: calc(10px + var(--sab)); height: 100px; }
  #touch-controls .touch-warp { visibility: hidden; } /* the warp meter itself is the button in short landscape */
  .touch-btn { width: 60px; height: 60px; font-size: 22px; }
  .card-panel { padding: 14px 16px; }
  .game-tagline { margin-bottom: 10px; }
  .rig-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
  .rig-desc { display: none; }
}
@media (hover: hover) and (pointer: fine) {
  .touch-help { display: none; }
}
/* Backdrop blur over a WebGL canvas costs real frame time on phone GPUs */
@media (pointer: coarse) {
  .hud-pill, .hud-btn, .touch-btn, .modal-layer { backdrop-filter: none; -webkit-backdrop-filter: none; }
  .hud-pill, .hud-btn { background: rgba(6, 11, 26, 0.92); }
}
.menu-settings { margin-top: 10px; display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.btn-secondary.off { color: var(--text-dim); border-style: dashed; }
.btn-secondary.small { width: auto; padding: 7px 14px; font-size: 11px; letter-spacing: 1px; }

@media (prefers-reduced-motion: reduce) {
  .announce-wrap, .toast, .rim-graze-alert, .rig-card, .btn-launch { transition: none; }
  .rim-graze-alert.active { animation: none; }
}

/* 0.3.0: HUD stays at the edges; messages sit in the upper third, clear of the rider and the road ahead. */
#hud { justify-content: flex-start; }
.hud-center { align-self: center; margin-top: clamp(14px, 7vh, 70px); max-width: min(560px, 92vw); }
.hud-bottom { margin-top: auto; }
.announcement { font-size: clamp(18px, 2.8vw, 28px); }
.announcement-sub { font-size: 12px; }
.warp-container { width: 170px; }
.warp-label { white-space: nowrap; }
.warp-state { overflow: visible; }
@media (pointer: coarse) { .warp-label kbd { display: none; } }
@media (max-width: 720px) { .hud-center { margin-top: 10px; } }
