:root,
[data-theme="night"] {
  --bg: #0d0d0f;
  --bg-panel: #141417;
  --card: #1a1a1e;
  --line: #2b2b31;
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --ground: #1c1b20;
  --bench: #25232b;
  --sky-glow: rgba(255, 138, 31, 0.14);
  --brand: #ff8a1f;
  --brand-hi: #ffb454;
  --machine-dark: #27272e;
  --machine-mid: #3a3a44;
  --track: #17171b;
  --cab-glass: #38bdf8;
  --ore: #a16207;
  --ore-hi: #ca8a04;
  --phone-body: #18181c;
  --phone-bezel: #3a3a42;
  --phone-screen: #101014;
  --btn-bg: #1e1e24;
  --btn-text: #e4e4e7;
  --ph-dig: #4ade80;
  --ph-swing-loaded: #38bdf8;
  --ph-dump: #f87171;
  --ph-swing-empty: #2dd4bf;
  --active-text: #111113;
}

html[data-theme="day"],
[data-theme="day"] {
  --bg: #f4f5f7;
  --bg-panel: #ffffff;
  --card: #ffffff;
  --line: #d4d4d8;
  --text: #111827;
  --muted: #52525b;
  --ground: #e4ded3;
  --bench: #cfc6b6;
  --sky-glow: rgba(255, 138, 31, 0.16);
  --brand: #ea6c00;
  --brand-hi: #ff8a1f;
  --machine-dark: #27272a;
  --machine-mid: #52525b;
  --track: #18181b;
  --cab-glass: #0284c7;
  --ore: #92400e;
  --ore-hi: #b45309;
  --phone-body: #27272a;
  --phone-bezel: #52525b;
  --phone-screen: #fafafa;
  --btn-bg: #e2e8f0;
  --btn-text: #1e293b;
  --ph-dig: #16a34a;
  --ph-swing-loaded: #0284c7;
  --ph-dump: #dc2626;
  --ph-swing-empty: #0d9488;
  --active-text: #ffffff;
}

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

html,
body {
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

body {
  display: grid;
  place-items: center;
}

.stage {
  position: relative;
  width: 100%;
  max-width: 1280px;
  aspect-ratio: 16 / 9;
  max-height: 100vh;
  background: radial-gradient(75% 65% at 32% 38%, var(--sky-glow), transparent 72%), var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  display: grid;
  grid-template-columns: 1.48fr 0.82fr;
  gap: clamp(12px, 2vw, 28px);
  padding: clamp(12px, 2.2vw, 28px);
  align-items: center;
  overflow: hidden;
}

/* Left pit scene */
.pit-scene {
  position: relative;
  width: 100%;
  height: 100%;
  background: linear-gradient(to bottom, var(--bg) 0%, var(--bg) 86%, var(--ground) 86%, var(--ground) 100%);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.scene-hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: clamp(8px, 1.3vw, 14px) clamp(12px, 1.6vw, 18px);
  border-bottom: 1px solid var(--line);
  font-size: clamp(10px, 1.15vw, 14px);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.phase-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.phase-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ph-dig);
}

.stage[data-phase="dig"] .phase-dot { background: var(--ph-dig); }
.stage[data-phase="swing-loaded"] .phase-dot { background: var(--ph-swing-loaded); }
.stage[data-phase="dump"] .phase-dot { background: var(--ph-dump); }
.stage[data-phase="swing-empty"] .phase-dot { background: var(--ph-swing-empty); }

.pit-svg {
  width: 100%;
  height: 100%;
  flex: 1 1 auto;
  display: block;
}

.el-ground { fill: var(--ground); }
.el-bench { fill: var(--bench); }
.el-line { stroke: var(--line); stroke-width: 2; }
.el-track { fill: var(--track); stroke: var(--machine-mid); stroke-width: 2; }
.el-roller { fill: var(--machine-mid); }
.el-brand { fill: var(--brand); }
.el-brand-hi { fill: var(--brand-hi); }
.el-dark { fill: var(--machine-dark); }
.el-mid { fill: var(--machine-mid); }
.el-glass { fill: var(--cab-glass); opacity: 0.85; }
.el-ore { fill: var(--ore); }
.el-ore-hi { fill: var(--ore-hi); }
.el-piston { stroke: var(--muted); stroke-width: 4; stroke-linecap: round; }

.ore-stream {
  opacity: 0;
  transition: opacity 0.2s ease;
}

.stage[data-phase="dump"] .ore-stream {
  opacity: 1;
}

.ore-drop {
  animation: oreFall 0.65s linear infinite;
}

.ore-drop.d2 { animation-delay: -0.22s; }
.ore-drop.d3 { animation-delay: -0.44s; }

@keyframes oreFall {
  0% { transform: translateY(-6px); opacity: 0; }
  25% { opacity: 1; }
  90% { opacity: 1; }
  100% { transform: translateY(28px); opacity: 0; }
}

/* Right phone controller */
.phone-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.phone {
  width: min(100%, 300px);
  aspect-ratio: 9 / 17.5;
  max-height: 100%;
  background: var(--phone-body);
  border: 2px solid var(--phone-bezel);
  border-radius: clamp(18px, 2.4vw, 30px);
  padding: clamp(7px, 1vw, 11px);
  box-shadow: 0 22px 44px -18px rgba(0, 0, 0, 0.55);
  display: flex;
}

.phone-screen {
  flex: 1;
  background: var(--phone-screen);
  border-radius: clamp(12px, 1.8vw, 22px);
  padding: clamp(10px, 1.4vw, 16px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: clamp(6px, 0.9vw, 10px);
  overflow: hidden;
}

.phone-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: clamp(9px, 0.9vw, 11px);
  font-weight: 700;
  color: var(--muted);
}

.phone-timer-box {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: clamp(6px, 1vw, 12px) clamp(8px, 1vw, 12px);
  text-align: center;
}

.timer-phase {
  display: block;
  font-size: clamp(9px, 0.95vw, 11px);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brand);
}

.stage[data-phase="dig"] .timer-phase { color: var(--ph-dig); }
.stage[data-phase="swing-loaded"] .timer-phase { color: var(--ph-swing-loaded); }
.stage[data-phase="dump"] .timer-phase { color: var(--ph-dump); }
.stage[data-phase="swing-empty"] .timer-phase { color: var(--ph-swing-empty); }

.timer-value {
  display: block;
  font-size: clamp(18px, 2.5vw, 30px);
  font-weight: 800;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.timer-track {
  margin-top: 6px;
  height: 4px;
  width: 100%;
  border-radius: 99px;
  background: var(--line);
  overflow: hidden;
}

.timer-fill {
  height: 100%;
  width: 0%;
  background: var(--brand);
  border-radius: 99px;
}

.stage[data-phase="dig"] .timer-fill { background: var(--ph-dig); }
.stage[data-phase="swing-loaded"] .timer-fill { background: var(--ph-swing-loaded); }
.stage[data-phase="dump"] .timer-fill { background: var(--ph-dump); }
.stage[data-phase="swing-empty"] .timer-fill { background: var(--ph-swing-empty); }

.btn-list {
  display: grid;
  gap: clamp(5px, 0.7vw, 8px);
  flex: 1;
  align-content: center;
}

.phase-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: clamp(6px, 0.9vw, 10px) clamp(8px, 1.1vw, 12px);
  border-radius: 10px;
  background: var(--btn-bg);
  border: 1px solid var(--line);
  color: var(--btn-text);
  font-size: clamp(10px, 1.05vw, 13px);
  font-weight: 700;
}

.phase-btn small {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  opacity: 0.75;
}

.phase-btn[data-step="dig"].active {
  background: var(--ph-dig);
  border-color: var(--ph-dig);
  color: var(--active-text);
}

.phase-btn[data-step="swing-loaded"].active {
  background: var(--ph-swing-loaded);
  border-color: var(--ph-swing-loaded);
  color: var(--active-text);
}

.phase-btn[data-step="dump"].active {
  background: var(--ph-dump);
  border-color: var(--ph-dump);
  color: var(--active-text);
}

.phase-btn[data-step="swing-empty"].active {
  background: var(--ph-swing-empty);
  border-color: var(--ph-swing-empty);
  color: var(--active-text);
}

.tap-ring {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2.5px solid currentColor;
  transform: translate(-50%, -50%) scale(0.4);
  opacity: 0;
  pointer-events: none;
}

.phase-btn.tapped .tap-ring {
  animation: tapPulse 0.85s ease-out forwards;
}

@keyframes tapPulse {
  0% {
    transform: translate(-50%, -50%) scale(0.45);
    opacity: 0.95;
  }
  100% {
    transform: translate(-50%, -50%) scale(2.8);
    opacity: 0;
  }
}

.phone-foot {
  text-align: center;
  font-size: clamp(9px, 0.85vw, 11px);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

@media (prefers-reduced-motion: reduce) {
  .ore-drop,
  .phase-btn.tapped .tap-ring {
    animation: none !important;
  }
  .phase-btn {
    transition: none !important;
  }
  .ore-stream {
    transition: none !important;
  }
}
