:root {
  --ink: #1d1b4b;
  --go: #2fd27a;
  --stop: #ff9f2e;
  --reset: #4d8dff;
  --sun: #ffd23f;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", "Trebuchet MS", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0d1240;
  color: #fff;
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
}

#flash {
  position: fixed;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}
#flash.on { animation: flash 0.5s ease-out; }
@keyframes flash { from { opacity: 0.85; } to { opacity: 0; } }

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(92vw, 560px);
  pointer-events: none;
}

#clock {
  font-size: clamp(56px, 13vw, 112px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  color: #fff;
  text-shadow: 0 4px 0 var(--ink), 0 0 24px rgba(255, 210, 63, 0.55);
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
}

#banner {
  padding: 6px 18px;
  border-radius: 999px;
  background: rgba(29, 27, 75, 0.72);
  font-size: clamp(16px, 3.6vw, 22px);
  font-weight: 800;
  text-align: center;
}
#banner[hidden] { display: none; }

#journey {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  font-size: 26px;
}
#journey .track {
  position: relative;
  flex: 1;
  height: 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.25);
  border: 2px solid rgba(255, 255, 255, 0.6);
}
#fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #4dbbff, #9b6bff, #ff6fb5, var(--sun));
}
#ship {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translate(-50%, -50%) rotate(45deg);
  font-size: 28px;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.4));
}

/* ---------- rear view window ---------- */
#rearview {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: 120px;
  width: clamp(150px, 26vw, 300px);
  aspect-ratio: 16 / 10;
  border: 5px solid #fff;
  border-radius: 22px;
  box-shadow: 0 0 0 4px var(--ink), 0 8px 24px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}
#rearview[hidden] { display: none; }
#rearview span {
  position: absolute;
  left: 50%;
  bottom: -16px;
  transform: translateX(-50%);
  white-space: nowrap;
  padding: 3px 12px;
  border-radius: 999px;
  background: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

/* ---------- big countdown + party ---------- */
#bigcount {
  position: fixed;
  left: 5vw;
  top: 50%;
  margin-top: -0.55em;
  line-height: 1;
  font-size: clamp(100px, 22vw, 220px);
  font-weight: 900;
  color: var(--sun);
  -webkit-text-stroke: 8px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 10px 0 var(--ink);
  pointer-events: none;
}
#bigcount[hidden] { display: none; }
#bigcount.pop { animation: pop 1s ease-out forwards; }
@keyframes pop {
  0% { transform: scale(0.3); opacity: 0; }
  20% { transform: scale(1.15); opacity: 1; }
  40% { transform: scale(1); }
  80% { opacity: 1; }
  100% { transform: scale(0.95); opacity: 0; }
}

#celebrate {
  position: fixed;
  left: 50%;
  top: 24%;
  transform: translate(-50%, -50%);
  width: 96vw;
  text-align: center;
  pointer-events: none;
  animation: party-in 0.7s cubic-bezier(0.2, 1.6, 0.4, 1) 0.4s both;
}
#celebrate[hidden] { display: none; }
#celebrate .title {
  white-space: nowrap;
  font-size: clamp(34px, 8vw, 76px);
  font-weight: 900;
  color: var(--sun);
  -webkit-text-stroke: 5px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 6px 0 var(--ink);
}
#celebrate .sub {
  margin-top: 8px;
  display: inline-block;
  padding: 8px 20px;
  border-radius: 999px;
  background: rgba(29, 27, 75, 0.8);
  font-size: clamp(18px, 4vw, 28px);
  font-weight: 800;
}
@keyframes party-in { from { transform: translate(-50%, -50%) scale(0); } to { transform: translate(-50%, -50%) scale(1); } }

/* ---------- control panel ---------- */
#panel {
  position: fixed;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  width: min(96vw, 640px);
  border-radius: 28px;
  background: rgba(29, 27, 75, 0.78);
  backdrop-filter: blur(6px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

.setter {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px 14px;
}
body:not([data-state="idle"]) .setter { display: none; }
body[data-state="done"] #journey { display: none; }

.field {
  display: flex;
  align-items: center;
  gap: 6px;
}
.field label {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-weight: 800;
}
.field input {
  width: 2.6em;
  padding: 6px 4px;
  border: 3px solid #fff;
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  font: 900 26px var(--font);
  text-align: center;
  -moz-appearance: textfield;
}
.field input::-webkit-outer-spin-button,
.field input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.field button, .presets button {
  min-width: 44px;
  height: 44px;
  border: none;
  border-radius: 999px;
  background: var(--sun);
  color: var(--ink);
  font: 900 24px var(--font);
  cursor: pointer;
  box-shadow: 0 4px 0 #c99a00;
}
.presets { display: flex; gap: 6px; }
.presets button {
  padding: 0 12px;
  font-size: 16px;
  background: #fff;
  box-shadow: 0 4px 0 #b9bde0;
}

.controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}
.btn {
  min-width: 120px;
  height: 58px;
  padding: 0 20px;
  border: none;
  border-radius: 999px;
  color: #fff;
  font: 900 22px var(--font);
  white-space: nowrap;
  cursor: pointer;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  transition: transform 0.08s, filter 0.2s;
}
.btn:active:not(:disabled), .field button:active:not(:disabled), .presets button:active:not(:disabled) { transform: translateY(3px); }
.btn:disabled, .field button:disabled, .presets button:disabled { filter: grayscale(0.8) brightness(0.7); cursor: default; }
.go { background: var(--go); box-shadow: 0 5px 0 #1a9a55; }
.stop { background: var(--stop); box-shadow: 0 5px 0 #c26d00; }
.reset { background: var(--reset); box-shadow: 0 5px 0 #2a5fc2; }
.icon { min-width: 58px; padding: 0; background: #fff; box-shadow: 0 5px 0 #b9bde0; text-shadow: none; }

button:focus-visible, input:focus-visible { outline: 4px solid var(--sun); outline-offset: 3px; }

.nojs {
  position: fixed;
  inset: 40% 10% auto;
  text-align: center;
  font-size: 22px;
}

@media (max-width: 520px) {
  .btn { min-width: 0; flex: 1; font-size: 18px; height: 52px; padding: 0 12px; }
  .icon { flex: 0 0 52px; }
  #rearview { bottom: 96px; }
  body[data-state="idle"] #rearview { bottom: 200px; }
}

@media (prefers-reduced-motion: reduce) {
  #flash.on, #bigcount.pop, #celebrate { animation: none; }
}
