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

html, body {
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  background: #000;
  color: #fff;
  font-family: "Impact", "Arial Black", "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  user-select: none;
}

/* Top arcade bar — hub + $HFO swap */
.arcade-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0 0.65rem;
  background: rgba(0, 0, 0, 0.88);
  border-bottom: 1px solid rgba(255, 229, 102, 0.35);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
}

.arcade-bar a {
  color: #ffe566;
  text-decoration: none;
}

.arcade-bar a:hover {
  color: #fff;
  text-decoration: underline;
}

.arcade-bar-title {
  letter-spacing: 0.12em;
  color: #fff;
  font-size: 0.72rem;
}

.arcade-bar-right .buy-link {
  color: #111;
  background: linear-gradient(180deg, #ffe566, #f5a623);
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  border: 1px solid #fff;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.arcade-bar-right .buy-link:hover {
  color: #111;
  filter: brightness(1.1);
  text-decoration: none;
}

.buy-cta {
  display: inline-block;
  margin-top: 0.35rem;
  padding: 0.55rem 1.1rem;
  font-size: clamp(0.8rem, 2vw, 0.95rem);
  font-weight: 900;
  letter-spacing: 0.1em;
  font-family: inherit;
  color: #111;
  text-decoration: none;
  background: linear-gradient(180deg, #8cff9a, #2db84a);
  border: 3px solid #fff;
  border-radius: 6px;
  box-shadow: 0 0 0 2px #146, 0 5px 0 #0a4, 0 0 18px rgba(80, 255, 120, 0.35);
  cursor: pointer;
}

.buy-cta:hover {
  filter: brightness(1.08);
  transform: scale(1.04);
}

.buy-cta.small {
  margin-top: 0.75rem;
  font-size: 0.78rem;
  padding: 0.4rem 0.85rem;
}

#game-wrap {
  width: 100%;
  height: 100%;
  height: calc(100dvh - 36px);
  max-height: calc(100dvh - 36px);
  margin-top: 36px;
  position: relative;
  overflow: hidden;
}

.screen {
  display: none;
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.screen.active {
  display: block;
}

/* Full-bleed concept art — letterbox so nothing is cropped off */
.bg-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center center;
  z-index: 0;
  pointer-events: none;
  background: #050510;
}

/* Dual-buffer dance frames */
#dance-stage {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: #050510;
}

#dance-stage .dance-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center 40%;
  opacity: 0;
  transition: opacity 0.07s linear;
  will-change: opacity, transform;
  background: #050510;
}

#dance-stage .dance-frame.active {
  opacity: 1;
  z-index: 1;
}

/* Screen shake ONLY on miss / fail */
#dance-stage.shake {
  animation: bg-shake 0.32s ease-out;
}

@keyframes bg-shake {
  0%, 100% { transform: translate(0, 0); filter: none; }
  20% { transform: translate(-6px, 2px); filter: grayscale(0.5) brightness(0.8); }
  40% { transform: translate(5px, -2px); }
  60% { transform: translate(-4px, 1px); }
  80% { transform: translate(3px, -1px); }
}

.scrim {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.2) 0%,
    rgba(0, 0, 0, 0.05) 40%,
    rgba(0, 0, 0, 0.55) 100%
  );
  pointer-events: none;
}

.scrim.dark {
  background: rgba(0, 0, 0, 0.45);
}

.play-scrim {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: linear-gradient(
    90deg,
    transparent 0%,
    transparent 52%,
    rgba(0, 0, 0, 0.2) 68%,
    rgba(0, 0, 0, 0.5) 100%
  );
}

/* ===== TITLE UI ===== */
.title-ui {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(4%, 12px);
  z-index: 2;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  padding: 0 12px;
}

.tag {
  letter-spacing: 0.3em;
  font-size: clamp(0.7rem, 1.6vw, 0.85rem);
  color: #ffe566;
  text-shadow: 0 2px 0 #000, 0 0 12px #f80;
}

#btn-start,
#btn-retry,
.btn-secondary {
  padding: 0.7rem 1.6rem;
  font-size: clamp(0.95rem, 2.5vw, 1.2rem);
  font-weight: 900;
  letter-spacing: 0.14em;
  font-family: inherit;
  color: #111;
  background: linear-gradient(180deg, #ffe566, #f5a623);
  border: 3px solid #fff;
  border-radius: 6px;
  cursor: pointer;
  text-shadow: none;
  box-shadow: 0 0 0 2px #c40, 0 6px 0 #a60, 0 0 24px rgba(255, 200, 50, 0.55);
  animation: pulse 1.15s ease-in-out infinite;
}

#btn-start:hover,
#btn-retry:hover,
.btn-secondary:hover {
  transform: scale(1.05);
}

.btn-secondary {
  display: block;
  margin: 0.55rem auto 0;
  font-size: 0.9rem;
  padding: 0.55rem 1.2rem;
  background: linear-gradient(180deg, #8cf, #48a);
  box-shadow: 0 0 0 2px #246, 0 5px 0 #135, 0 0 16px rgba(80, 180, 255, 0.4);
  animation: none;
}

@keyframes pulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.15); }
}

.hint {
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: clamp(0.75rem, 1.8vw, 0.9rem);
  color: #fff;
  text-shadow: 0 2px 6px #000;
  letter-spacing: 0.03em;
}

.tiny {
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.7);
  text-shadow: 0 1px 3px #000;
}

/* ===== HUD — compact top bar, game name always visible ===== */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 8;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.35rem 0.5rem;
  padding: 0.4rem 0.65rem;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.78) 0%, rgba(0, 0, 0, 0.35) 70%, transparent 100%);
}

.hud-left,
.hud-right {
  min-width: 0;
}

.hud-left {
  justify-self: start;
}

.hud-right {
  justify-self: end;
  text-align: right;
}

.hud-title {
  justify-self: center;
  text-align: center;
  font-size: clamp(0.95rem, 3.2vw, 1.55rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  line-height: 1.1;
  white-space: nowrap;
  background: linear-gradient(180deg, #fff 0%, #5cf 45%, #f55 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 1px 0 #000) drop-shadow(0 0 8px rgba(255, 80, 80, 0.45));
}

.hud-line {
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: clamp(0.65rem, 1.5vw, 0.85rem);
  font-weight: 800;
  color: #ffe566;
  text-shadow: 0 1px 0 #000, 0 0 8px rgba(0, 0, 0, 0.8);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-line strong {
  color: #fff;
  font-size: 1.05em;
}

/* ===== JUDGMENT ===== */
#judgment {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  z-index: 6;
  font-size: clamp(1.4rem, 4vw, 2.4rem);
  font-weight: 900;
  letter-spacing: 0.04em;
  text-shadow:
    0 2px 0 #000,
    0 0 14px currentColor,
    0 0 4px #000;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}

#judgment.show {
  animation: judge-pop 0.55s ease-out forwards;
}

#judgment.perfect { color: #ffe566; }
#judgment.great { color: #5cf; }
#judgment.good { color: #6f6; }
#judgment.miss { color: #f55; }

@keyframes judge-pop {
  0% { opacity: 0; transform: translateX(-50%) scale(0.5) translateY(10px); }
  18% { opacity: 1; transform: translateX(-50%) scale(1.15) translateY(0); }
  70% { opacity: 1; transform: translateX(-50%) scale(1) translateY(-8px); }
  100% { opacity: 0; transform: translateX(-50%) scale(0.9) translateY(-18px); }
}

/* ===== HIGHWAY — compact, always fully on screen ===== */
#highway {
  position: absolute;
  top: max(3.2rem, 9%);
  right: max(0.5rem, 1.5%);
  bottom: max(0.9rem, 2.5%);
  width: min(32vw, 280px);
  max-height: calc(100dvh - 4.2rem);
  z-index: 4;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 5px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.42);
  border: 2px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.5), inset 0 0 20px rgba(80, 40, 160, 0.18);
  backdrop-filter: blur(2px);
}

.lane {
  position: relative;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  overflow: hidden;
  min-height: 0;
}

.lane[data-dir="left"] .receptor,
.lane[data-dir="left"] .note { --c: #ff6bb5; }
.lane[data-dir="down"] .receptor,
.lane[data-dir="down"] .note { --c: #5dffa0; }
.lane[data-dir="up"] .receptor,
.lane[data-dir="up"] .note { --c: #5db8ff; }
.lane[data-dir="right"] .receptor,
.lane[data-dir="right"] .note { --c: #ffe566; }

.receptor {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: clamp(28px, 5vw, 44px);
  height: clamp(28px, 5vw, 44px);
  border: 2px solid var(--c, #fff);
  color: var(--c, #fff);
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: clamp(0.85rem, 1.8vw, 1.25rem);
  background: rgba(0, 0, 0, 0.55);
  z-index: 2;
  box-shadow: 0 0 10px color-mix(in srgb, var(--c) 50%, transparent);
  transition: background 0.06s, box-shadow 0.06s, transform 0.06s;
}

.receptor.flash {
  background: color-mix(in srgb, var(--c) 55%, #fff);
  color: #111;
  box-shadow: 0 0 22px var(--c);
  transform: translateX(-50%) scale(1.1);
}

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

.note {
  position: absolute;
  left: 50%;
  width: clamp(26px, 4.8vw, 40px);
  height: clamp(26px, 4.8vw, 40px);
  margin-left: calc(clamp(26px, 4.8vw, 40px) / -2);
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: clamp(0.8rem, 1.6vw, 1.15rem);
  font-weight: 900;
  color: #111;
  background: var(--c, #fff);
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow:
    0 3px 0 rgba(0, 0, 0, 0.4),
    0 0 10px color-mix(in srgb, var(--c) 70%, transparent);
  will-change: top;
}

.note.left { --c: #ff6bb5; }
.note.down { --c: #5dffa0; }
.note.up { --c: #5db8ff; }
.note.right { --c: #ffe566; }

#progress-wrap {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 5px;
  z-index: 5;
  background: rgba(0, 0, 0, 0.65);
}

#progress {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #5cf, #ffe566, #f55);
  box-shadow: 0 0 8px #f55;
}

/* ===== SONG SELECT ===== */
.select-ui {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  width: min(400px, 92vw);
  max-height: min(88dvh, 640px);
  overflow: auto;
  padding: 1rem 1.15rem;
  background: rgba(8, 4, 22, 0.88);
  border: 3px solid #ffe566;
  border-radius: 12px;
  box-shadow: 0 0 32px rgba(255, 200, 50, 0.3);
  text-align: center;
}

.select-ui .legal {
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 0.65rem;
  color: #aaa;
  margin: 0.3rem 0 0.75rem;
  letter-spacing: 0.02em;
}

.song-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  text-align: left;
}

.song-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.2rem 0.6rem;
  padding: 0.55rem 0.75rem;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  cursor: pointer;
  font-family: "Segoe UI", system-ui, sans-serif;
  transition: border-color 0.1s, background 0.1s, transform 0.1s;
}

.song-item .song-title {
  font-weight: 800;
  font-size: 0.95rem;
  color: #fff;
  letter-spacing: 0.05em;
}

.song-item .song-sub {
  grid-column: 1;
  font-size: 0.7rem;
  color: #9ab;
}

.song-item .song-bpm {
  grid-row: 1 / span 2;
  align-self: center;
  color: #ffe566;
  font-weight: 800;
  font-size: 0.8rem;
}

.song-item:hover,
.song-item.selected {
  border-color: #ffe566;
  background: rgba(255, 200, 50, 0.12);
  transform: translateX(3px);
}

.song-item.selected {
  box-shadow: 0 0 14px rgba(255, 200, 50, 0.35);
}

.select-hint {
  margin-top: 0.75rem;
}

/* ===== RESULTS UI ===== */
.results-ui {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  width: min(300px, 90vw);
  max-height: 90dvh;
  overflow: auto;
  padding: 1rem 1.2rem;
  background: rgba(10, 5, 25, 0.88);
  border: 3px solid #ffe566;
  border-radius: 12px;
  box-shadow: 0 0 32px rgba(255, 200, 50, 0.35);
  text-align: center;
}

.results-ui .tag {
  margin-bottom: 0.15rem;
}

.grade {
  font-size: clamp(2.5rem, 10vw, 3.6rem);
  line-height: 1;
  color: #5cf;
  text-shadow: 0 0 20px #5cf, 0 2px 0 #000;
  margin: 0.15rem 0 0.6rem;
}

.results-ui ul {
  list-style: none;
  text-align: left;
  font-family: "Segoe UI", system-ui, sans-serif;
  margin-bottom: 0.75rem;
}

.results-ui li {
  display: flex;
  justify-content: space-between;
  padding: 0.28rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  color: #ccc;
  font-weight: 600;
  font-size: 0.9rem;
}

.results-ui li span {
  color: #fff;
  font-weight: 800;
}

/* Short / narrow screens */
@media (max-width: 900px), (max-height: 700px) {
  #highway {
    width: min(36vw, 240px);
    top: 2.8rem;
    gap: 3px;
    padding: 4px;
  }

  .hud-title {
    letter-spacing: 0.04em;
  }
}

@media (max-width: 640px) {
  #hud {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
  }

  .hud-title {
    grid-column: 1 / -1;
    grid-row: 1;
    order: -1;
    font-size: clamp(1rem, 5vw, 1.35rem);
  }

  .hud-left { grid-row: 2; }
  .hud-right { grid-row: 2; }

  #highway {
    top: auto;
    bottom: 0.55rem;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: min(92vw, 340px);
    height: min(36dvh, 260px);
    max-height: 36dvh;
  }

  #judgment {
    top: 18%;
  }

  .play-scrim {
    background: linear-gradient(
      180deg,
      transparent 0%,
      transparent 45%,
      rgba(0, 0, 0, 0.35) 70%,
      rgba(0, 0, 0, 0.55) 100%
    );
  }

  #dance-stage .dance-frame {
    object-position: center 30%;
  }
}
