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

:root {
  --bg-black: #030306;
  --surface-dark: #0a0c12;
  --surface-card: rgba(10, 14, 23, 0.94);
  --border-subtle: rgba(255, 255, 255, 0.1);
  --border-cyan: rgba(0, 240, 255, 0.4);
  --cyan: #00f0ff;
  --emerald: #10b981;
  --amber: #f59e0b;
  --rose: #ff1133;
  --purple: #a855f7;
  --text-primary: #f8fafc;
  --text-muted: #94a3b8;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-black);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* App Shell */
.app-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  background: #000000;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Minimalist Top Bar */
.top-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  pointer-events: none;
}

.top-bar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 12px var(--cyan);
}

.brand-title {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #ffffff;
}

.top-bar-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

.sensor-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border-subtle);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  color: var(--text-muted);
}

.sensor-pill.active {
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.35);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.85);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.icon-btn:hover {
  color: #ffffff;
  border-color: var(--border-cyan);
}

.icon-btn.active {
  color: var(--cyan);
  background: rgba(0, 240, 255, 0.14);
  border-color: var(--border-cyan);
}

/* Screens */
.screen {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000000;
}

/* Calibration Card */
.card {
  position: relative;
  z-index: 10;
  width: min(560px, 92vw);
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: 24px;
  padding: 28px 30px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.85), 0 0 40px rgba(0, 240, 255, 0.06);
  backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.card-title {
  font-size: 28px;
  font-weight: 900;
  letter-spacing: -0.02em;
  color: #ffffff;
  margin-bottom: 6px;
}

.card-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 420px;
  line-height: 1.5;
  margin-bottom: 20px;
}

/* Silhouette Frame */
.silhouette-box {
  position: relative;
  width: 170px;
  height: 220px;
  border: 2px dashed rgba(0, 240, 255, 0.4);
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  overflow: hidden;
}

.silhouette-svg {
  width: 120px;
  height: 180px;
  stroke: #475569;
  fill: transparent;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: all 0.25s ease;
}

.silhouette-svg.ready {
  stroke: var(--cyan);
  fill: rgba(0, 240, 255, 0.15);
  filter: drop-shadow(0 0 12px rgba(0, 240, 255, 0.7));
}

.scan-beam {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--cyan), transparent);
  box-shadow: 0 0 10px var(--cyan);
  animation: scanPulse 2s ease-in-out infinite;
}

@keyframes scanPulse {
  0%,
  100% {
    transform: translateY(-60px);
    opacity: 0.35;
  }
  50% {
    transform: translateY(60px);
    opacity: 0.95;
  }
}

.countdown-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.countdown-number {
  font-size: 68px;
  font-weight: 900;
  color: var(--cyan);
  text-shadow: 0 0 24px var(--cyan);
}

/* Body Parts Checklist */
.parts-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}

@media (max-width: 540px) {
  .parts-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.part-chip {
  padding: 8px 6px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(15, 23, 42, 0.65);
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: all 0.2s ease;
}

.part-chip.detected {
  background: rgba(0, 240, 255, 0.12);
  border-color: rgba(0, 240, 255, 0.45);
  color: #67e8f9;
}

/* Progress Bar */
.progress-wrap {
  width: 100%;
  margin-bottom: 20px;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-family: ui-monospace, monospace;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.progress-track {
  width: 100%;
  height: 10px;
  background: #1e293b;
  border-radius: 999px;
  overflow: hidden;
  padding: 2px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--cyan), var(--emerald));
  box-shadow: 0 0 10px var(--cyan);
  transition: width 0.12s linear;
}

/* Action Buttons */
.btn-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  width: 100%;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.16s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: linear-gradient(135deg, #00f0ff, #0284c7);
  color: #020617;
  box-shadow: 0 8px 24px rgba(0, 240, 255, 0.25);
}

.btn-primary:hover {
  filter: brightness(1.1);
}

.btn-emerald {
  background: linear-gradient(135deg, #10b981, #0d9488);
  color: #020617;
}

.btn-emerald:hover {
  filter: brightness(1.1);
}

.btn-amber {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #020617;
}

.btn-amber:hover {
  filter: brightness(1.1);
}

.btn-secondary {
  background: rgba(30, 41, 59, 0.8);
  border-color: rgba(255, 255, 255, 0.12);
  color: #e2e8f0;
}

.btn-secondary:hover {
  background: rgba(51, 65, 85, 0.9);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 7px 13px;
  font-size: 12px;
  border-radius: 9px;
}

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

/* Game Screen & HUD */
#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.game-hud {
  position: absolute;
  top: 58px;
  left: 24px;
  right: 24px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  pointer-events: none;
  z-index: 15;
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hud-box {
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(10, 14, 23, 0.85);
  border: 1px solid var(--border-subtle);
  backdrop-filter: blur(8px);
}

.hud-label {
  font-size: 10px;
  font-family: ui-monospace, monospace;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.hud-value {
  font-size: 26px;
  font-weight: 900;
  font-family: ui-monospace, monospace;
  color: var(--cyan);
  text-shadow: 0 0 12px rgba(0, 240, 255, 0.4);
}

.hud-value.amber {
  font-size: 20px;
  color: #fbbf24;
  text-shadow: none;
}

.hud-value.speed {
  font-size: 18px;
  color: #e2e8f0;
  text-shadow: none;
}

.hud-value.speed.boosted {
  color: #fbbf24;
}

.speed-banner {
  position: absolute;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  padding: 10px 22px;
  border-radius: 14px;
  background: linear-gradient(90deg, #f59e0b, #ef4444);
  color: #020617;
  font-weight: 900;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-shadow: 0 0 25px rgba(245, 158, 11, 0.8);
  pointer-events: none;
}

/* Modals (Game Over & Highscores) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.86);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.gameover-title {
  font-size: 42px;
  font-weight: 900;
  letter-spacing: 0.04em;
  background: linear-gradient(90deg, #ff1133, #fb923c);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 6px;
}

.stats-grid {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 18px 0;
}

.stat-card {
  padding: 14px;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border-subtle);
  text-align: center;
}

.stat-value {
  font-size: 24px;
  font-weight: 900;
  font-family: ui-monospace, monospace;
  color: var(--cyan);
  margin-top: 4px;
}

.stat-value.amber {
  color: #fbbf24;
}

/* Save Highscore Form */
.save-box {
  width: 100%;
  padding: 16px;
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(0, 240, 255, 0.25);
  margin-bottom: 16px;
}

.save-prompt {
  font-size: 13px;
  font-weight: 700;
  color: #e2e8f0;
  margin-bottom: 10px;
}

.name-input {
  width: 100%;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: #020617;
  color: #ffffff;
  font-size: 14px;
  outline: none;
  margin-bottom: 12px;
}

.name-input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 2px rgba(0, 240, 255, 0.2);
}

/* Leaderboard Table */
.leaderboard-wrap {
  width: 100%;
  max-height: min(440px, 48vh);
  overflow-y: auto;
  margin: 14px 0 12px;
  border-radius: 14px;
  border: 1px solid var(--border-subtle);
  background: rgba(2, 6, 23, 0.8);
}

.pagination-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}

.pagination-info {
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: var(--text-muted);
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}

.leaderboard-table th {
  position: sticky;
  top: 0;
  background: #0f172a;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.leaderboard-table td {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  color: #e2e8f0;
}

.leaderboard-table tr.highlight td {
  background: rgba(0, 240, 255, 0.12);
  color: #67e8f9;
  font-weight: 700;
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  font-family: ui-monospace, monospace;
  font-weight: 800;
  font-size: 12px;
  background: #1e293b;
  color: #94a3b8;
}

.rank-1 {
  background: rgba(251, 191, 36, 0.2);
  color: #fbbf24;
}

.rank-2 {
  background: rgba(203, 213, 225, 0.2);
  color: #e2e8f0;
}

.rank-3 {
  background: rgba(217, 119, 6, 0.2);
  color: #fb923c;
}

.time-cell {
  font-family: ui-monospace, monospace;
  font-weight: 700;
  color: var(--cyan);
}

/* Camera Peek PiP */
.camera-peek {
  position: absolute;
  bottom: 18px;
  right: 18px;
  z-index: 40;
  width: 176px;
  aspect-ratio: 4 / 3;
  border-radius: 14px;
  border: 2px solid rgba(0, 240, 255, 0.6);
  overflow: hidden;
  background: #020617;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.8);
}

.camera-peek video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}
