/* Star Hopper — iPhone-first layout with safe-area insets and dual
   orientation support. The stage fills the viewport box the page gives it. */

body.star-hopper {
  --dusk: #241a3a;
  --accent: #ffb35c;
  --accent2: #b47aff;
}

.star-hopper .stage {
  position: relative;
  width: 100%;
  height: min(78vh, 720px);
  min-height: 420px;
  border-radius: 18px;
  overflow: hidden;
  background: var(--dusk);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

@media (max-width: 760px), (pointer: coarse) {
  .star-hopper .stage {
    height: calc(100dvh - 170px);
    min-height: 320px;
    border-radius: 0;
    margin-inline: -12px;
    width: calc(100% + 24px);
  }
}

.star-hopper canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#gpu-canvas {
  z-index: 0;
}

#gpu-canvas.webgpu-on {
  display: block;
}

#game-canvas {
  z-index: 1;
  cursor: crosshair;
}

/* Speed/fall vignette. */
#speed-vignette {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(20, 8, 40, 0.85) 100%);
  opacity: 0;
  transition: opacity 120ms linear;
}

#crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 3;
  transform: translate(-50%, -50%);
  color: rgba(255, 255, 255, 0.8);
  font-size: 28px;
  font-weight: 700;
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

/* ---- HUD ---- */
#hud {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  transition: opacity 240ms ease;
}

#hud.visible {
  opacity: 1;
  pointer-events: none;
}

.hud-top {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  left: calc(10px + env(safe-area-inset-left));
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.hud-cell {
  background: rgba(20, 12, 40, 0.55);
  backdrop-filter: blur(6px);
  border-radius: 12px;
  padding: 6px 12px;
  color: #fff;
  display: flex;
  flex-direction: column;
  min-width: 64px;
}

.hud-k {
  font-size: 10px;
  letter-spacing: 0.08em;
  opacity: 0.75;
}

.hud-cell strong {
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.hud-time-cell.low strong {
  color: #ff6a5c;
  animation: pulse 0.9s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.5;
  }
}

[hidden] {
  display: none !important;
}

#combo-wrap {
  position: absolute;
  top: calc(76px + env(safe-area-inset-top));
  left: calc(10px + env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--accent);
  font-weight: 800;
  font-size: 20px;
  text-shadow: 0 0 8px rgba(255, 150, 60, 0.7);
}

#combo-wrap.hot #hud-combo {
  color: #ffe08a;
  animation: pulse 0.5s ease-in-out infinite;
}

.combo-track {
  width: 90px;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.2);
  overflow: hidden;
}

#combo-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #ffe08a);
  transform-origin: left center;
}

.hud-actions {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  right: calc(10px + env(safe-area-inset-right));
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(20, 12, 40, 0.55);
  backdrop-filter: blur(6px);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}

.icon-btn.off {
  opacity: 0.45;
}

/* ---- Center messages & toast ---- */
#center-msg {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%);
  z-index: 5;
  font-size: clamp(40px, 9vw, 84px);
  font-weight: 900;
  color: #fff;
  text-shadow:
    0 0 18px rgba(255, 180, 90, 0.9),
    0 4px 24px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  text-align: center;
  line-height: 1.05;
}

#center-msg.small {
  font-size: clamp(22px, 4.5vw, 40px);
}

#pop-layer {
  position: absolute;
  left: 50%;
  top: 46%;
  z-index: 5;
  pointer-events: none;
}

#pop-layer .pop {
  position: absolute;
  left: 0;
  font-size: clamp(18px, 3.4vw, 30px);
  font-weight: 800;
  color: #ffe08a;
  animation: popfloat 1.15s ease-out forwards;
  pointer-events: none;
  white-space: nowrap;
}

#center-msg .pop.bonus {
  color: #d6a8ff;
}

@keyframes popfloat {
  0% {
    transform: translate(-50%, 0) scale(0.6);
    opacity: 0;
  }
  15% {
    transform: translate(-50%, -14px) scale(1.15);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -72px) scale(1);
    opacity: 0;
  }
}

#toast {
  position: absolute;
  left: 50%;
  bottom: calc(110px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 5;
  background: rgba(20, 12, 40, 0.7);
  backdrop-filter: blur(8px);
  color: #fff;
  border-radius: 12px;
  padding: 8px 16px;
  text-align: center;
  opacity: 0;
  transition: opacity 200ms ease;
  pointer-events: none;
  max-width: 86%;
}

#toast.visible {
  opacity: 1;
}

.toast-main {
  font-weight: 700;
}

.toast-sub {
  font-size: 12px;
  opacity: 0.8;
}

#save-warning,
#boot-error {
  position: absolute;
  left: 50%;
  top: calc(10px + env(safe-area-inset-top));
  transform: translateX(-50%);
  z-index: 6;
  background: rgba(120, 30, 40, 0.9);
  color: #fff;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 13px;
  max-width: 90%;
}

/* ---- Touch controls ---- */
#touch-ui {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  display: none;
}

#touch-ui.on {
  display: block;
}

#jump-btn {
  position: absolute;
  right: calc(20px + env(safe-area-inset-right));
  bottom: calc(28px + env(safe-area-inset-bottom));
  width: 88px;
  height: 88px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 170, 70, 0.35);
  backdrop-filter: blur(4px);
  color: #fff;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.06em;
  pointer-events: auto;
  touch-action: none;
}

#jump-btn:active {
  background: rgba(255, 190, 90, 0.6);
  transform: scale(0.94);
}

.stick {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: none;
}

.stick.active {
  display: block;
}

.stick-base,
.stick-knob {
  position: absolute;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.stick-base {
  width: 120px;
  height: 120px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  background: rgba(20, 12, 40, 0.25);
}

.stick-knob {
  width: 56px;
  height: 56px;
  background: rgba(255, 255, 255, 0.55);
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.4);
}

/* ---- Screens ---- */
.screen {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(16, 8, 32, 0.55);
  backdrop-filter: blur(4px);
  padding: 16px;
}

.screen.visible {
  display: flex;
}

.panel {
  background: rgba(28, 16, 52, 0.85);
  border: 1px solid rgba(255, 200, 140, 0.25);
  border-radius: 20px;
  color: #fff;
  padding: 24px 28px;
  max-width: 460px;
  width: 100%;
  text-align: center;
  max-height: 90%;
  overflow-y: auto;
}

.panel-logo {
  font-size: 42px;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(255, 180, 90, 0.9);
}

.panel h2 {
  margin: 4px 0 8px;
  font-size: 26px;
}

.panel h2 span + span {
  color: var(--accent);
}

.panel .lead {
  font-size: 14px;
  line-height: 1.7;
  opacity: 0.9;
}

.panel button {
  font-size: 16px;
  padding: 12px 22px;
  border-radius: 14px;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  min-height: 44px;
}

.panel button.primary {
  background: linear-gradient(135deg, var(--accent), #ff7a59);
  color: #2a1408;
  font-weight: 800;
  font-size: 18px;
}

.panel .row {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 10px;
}

.panel > button {
  margin-top: 14px;
  width: 100%;
}

.vol-row {
  margin-top: 14px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
}

.vol-row input {
  accent-color: var(--accent);
  width: 140px;
}

.hint {
  margin-top: 12px;
  font-size: 11px;
  opacity: 0.7;
}

.engine-note {
  font-family: ui-monospace, monospace;
}

.result-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 18px;
  text-align: left;
  margin: 14px 0;
}

.result-grid dt {
  opacity: 0.75;
  font-size: 13px;
}

.result-grid dd {
  margin: 0;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.newbest {
  display: inline-block;
  background: linear-gradient(135deg, var(--accent), #ffe08a);
  color: #2a1408;
  font-weight: 800;
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 13px;
  animation: pulse 0.8s ease-in-out infinite;
}

.how-grid {
  text-align: left;
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 10px 12px;
  font-size: 13px;
  line-height: 1.6;
}

.how-grid dt {
  font-weight: 800;
  color: var(--accent);
}

.how-grid dd {
  margin: 0;
}

#oobe-dots {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-top: 10px;
}

#oobe-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
}

#oobe-dots span.on {
  background: var(--accent);
}

@media (max-height: 480px) {
  .panel {
    padding: 14px 18px;
  }
  .panel .lead {
    font-size: 12px;
  }
  #jump-btn {
    width: 72px;
    height: 72px;
    bottom: calc(18px + env(safe-area-inset-bottom));
  }
}
