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

html, body {
  width: 100%; height: 100%;
  background: #000;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: rgba(255,255,255,0.88);
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ── HUD ── */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 16px 20px;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(0,0,8,0.75) 0%, transparent 100%);
}

.hud-panel {
  backdrop-filter: blur(16px);
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 10px;
  padding: 14px 20px;
  min-width: 270px;
}

.hud-title {
  font-size: 1.02rem;
  font-weight: 600;
  letter-spacing: 0.45em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.45);
  margin-bottom: 12px;
}

.hud-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 7px;
}

.hud-label {
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.38);
  flex: 1;
}

.hud-value {
  font-size: 1.43rem;
  font-weight: 300;
  letter-spacing: 0.05em;
  color: rgba(255,255,255,0.9);
  font-variant-numeric: tabular-nums;
  min-width: 64px;
  text-align: right;
}

.hud-value.danger { color: rgba(255,80,80,0.95); }
.hud-value.caution { color: rgba(255,200,50,0.95); }
.hud-value.safe { color: rgba(50,210,100,0.95); }

.hud-unit {
  font-size: 0.87rem;
  color: rgba(255,255,255,0.28);
  letter-spacing: 0.1em;
  width: 32px;
}

/* Fuel bar */
.right-panel {
  min-width: 195px;
  text-align: right;
}

.right-panel .hud-label {
  display: block;
  text-align: right;
  flex: none;
  margin-bottom: 6px;
}

.fuel-bar-track {
  width: 100%;
  height: 6px;
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 4px;
}

.fuel-bar-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, rgba(80,130,255,0.7), rgba(140,200,255,0.9));
  border-radius: 3px;
  transition: width 0.1s, background 0.3s;
}

.fuel-bar-fill.low {
  background: linear-gradient(90deg, rgba(255,100,50,0.8), rgba(255,160,50,0.9));
}

.fuel-pct {
  font-size: 1.13rem;
  text-align: right;
  display: block;
}

/* Controls hint */
#controls-hint {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.65);
  display: flex;
  align-items: center;
  gap: 4px;
  pointer-events: none;
  white-space: nowrap;
}

.key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  background: rgba(255,255,255,0.10);
  border: 1px solid rgba(255,255,255,0.30);
  border-radius: 4px;
  font-size: 0.70rem;
  color: rgba(255,255,255,0.75);
}

/* ── Overlay ── */
#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,8,0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 1.1s cubic-bezier(0.4, 0, 0.2, 1);
}

#overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.overlay-box {
  backdrop-filter: blur(24px);
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(80,130,255,0.3);
  border-radius: 16px;
  padding: 40px 48px;
  text-align: center;
  box-shadow: 0 8px 60px rgba(0,0,0,0.8), 0 0 40px rgba(80,130,255,0.08);
  min-width: 320px;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.overlay-icon {
  font-size: 2.8rem;
  margin-bottom: 16px;
  filter: drop-shadow(0 0 16px rgba(140,200,255,0.5));
}

.overlay-title {
  font-size: 1.4rem;
  font-weight: 200;
  letter-spacing: 0.45em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.92);
  margin-bottom: 8px;
}

.overlay-subtitle {
  font-size: 0.78rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.45);
  margin-bottom: 20px;
  min-height: 1.2em;
}

.overlay-stats {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.55);
  letter-spacing: 0.1em;
  line-height: 1.8;
  margin-bottom: 24px;
  min-height: 2em;
}

.overlay-stats .stat-good { color: rgba(50,210,100,0.9); }
.overlay-stats .stat-bad  { color: rgba(255,80,80,0.9); }

.overlay-stats .ctrl-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 4px 0;
}

.overlay-stats .ctrl-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 4px;
  font-size: 0.68rem;
  color: rgba(255,255,255,0.6);
  letter-spacing: 0;
}

.overlay-stats .ctrl-label {
  color: rgba(255,255,255,0.4);
  font-size: 0.68rem;
  letter-spacing: 0.15em;
}

.overlay-btn {
  background: rgba(80,130,255,0.12);
  border: 1px solid rgba(80,130,255,0.45);
  border-radius: 8px;
  color: rgba(140,185,255,0.92);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  padding: 12px 32px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.overlay-btn:hover {
  background: rgba(80,130,255,0.22);
  border-color: rgba(80,130,255,0.7);
  box-shadow: 0 0 20px rgba(80,130,255,0.2);
}

.overlay-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

.overlay-btn.crash {
  background: rgba(255,80,50,0.1);
  border-color: rgba(255,80,50,0.4);
  color: rgba(255,140,120,0.92);
}
.overlay-btn.crash:hover {
  background: rgba(255,80,50,0.2);
  border-color: rgba(255,80,50,0.65);
  box-shadow: 0 0 20px rgba(255,80,50,0.2);
}

.overlay-btn.success {
  background: rgba(50,210,100,0.1);
  border-color: rgba(50,210,100,0.4);
  color: rgba(100,230,150,0.92);
}
.overlay-btn.success:hover {
  background: rgba(50,210,100,0.2);
  border-color: rgba(50,210,100,0.65);
  box-shadow: 0 0 20px rgba(50,210,100,0.2);
}

/* ── Touch controls ── */
#touch-controls {
  display: none;
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.touch-group {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 16px;
  pointer-events: none;
}

#touch-group-left  { left: 20px; }
#touch-group-right { right: 20px; }

.touch-btn {
  width: 90px;
  height: 90px;
  border-radius: 14px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.22);
  color: rgba(255,255,255,0.75);
  font-size: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
}

.touch-btn.pressed {
  background: rgba(80,130,255,0.22);
  border-color: rgba(80,130,255,0.55);
  color: rgba(140,185,255,0.95);
}

@media (pointer: coarse) {
  #touch-controls { display: block; }
  #controls-hint  { display: none; }
}

/* ── Demo scores panel ── */
#demo-scores {
  display: none;
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  backdrop-filter: blur(16px);
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 10px;
  padding: 14px 8px 14px 20px;
  min-width: 200px;
  pointer-events: none;
}

#demo-hs-table .hs-name {
  padding-right: 20px !important;
}

#demo-scores.visible { display: block; }

/* ── Lives dot display ── */
#hud-lives {
  letter-spacing: 0.18em;
  font-size: 1.1rem;
}

/* ── Initials entry ── */
#initials-section {
  margin: 4px 0 18px;
}

.initials-prompt {
  font-size: 0.65rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(50,210,100,0.85);
  margin-bottom: 12px;
}

.initials-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

#initials-input {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(80,130,255,0.45);
  border-radius: 6px;
  color: rgba(255,255,255,0.95);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 1.5rem;
  font-weight: 300;
  letter-spacing: 0.18em;
  text-align: center;
  text-transform: uppercase;
  width: 100px;
  padding: 8px 4px 8px 8px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#initials-input:focus {
  border-color: rgba(80,130,255,0.75);
  box-shadow: 0 0 14px rgba(80,130,255,0.18);
}

#initials-submit {
  background: rgba(50,210,100,0.1);
  border: 1px solid rgba(50,210,100,0.4);
  border-radius: 6px;
  color: rgba(100,230,150,0.9);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.22em;
  padding: 10px 16px;
  text-transform: uppercase;
  transition: background 0.2s, border-color 0.2s;
}

#initials-submit:hover {
  background: rgba(50,210,100,0.2);
  border-color: rgba(50,210,100,0.65);
}

/* ── High scores table ── */
#hs-section {
  margin: 4px 0 20px;
  width: 100%;
}

.hs-heading {
  font-size: 0.62rem;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.28);
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}

#hs-table {
  width: 100%;
  border-collapse: collapse;
}

#hs-table td {
  padding: 5px 4px;
  font-size: 0.8rem;
}

.hs-rank {
  color: rgba(255,255,255,0.25);
  text-align: right;
  width: 20px;
  font-size: 0.65rem;
  letter-spacing: 0.05em;
}

.hs-name {
  color: rgba(255,255,255,0.72);
  text-align: left;
  padding-left: 14px !important;
  letter-spacing: 0.28em;
  font-weight: 500;
}

.hs-pts {
  color: rgba(255,255,255,0.6);
  text-align: right;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.05em;
}

.hs-new td {
  color: rgba(50,210,100,0.92) !important;
}

.hs-empty {
  color: rgba(255,255,255,0.25);
  font-size: 0.68rem;
  letter-spacing: 0.2em;
  padding: 12px 0 !important;
  text-align: center;
}
