/* Eins, Zwei, Drei — Office Escape Rhythm Runner
   Self-contained styles: underlay + overlay, motivation saturation, phase/chorus */

:root {
  --saturation: 0.3;
  --phase-bg: rgba(40, 40, 45, 0.85);
  --phase-accent: #666;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #1a1a1a;
  color: #fff;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Phase 0: demotivational */
[data-phase="0"] {
  --phase-bg: rgba(50, 50, 55, 0.9);
  --phase-accent: #555;
}

[data-phase="1"] {
  --phase-bg: rgba(45, 48, 55, 0.88);
  --phase-accent: #6a7;
}

[data-phase="2"] {
  --phase-bg: rgba(40, 50, 55, 0.82);
  --phase-accent: #8c8;
}

[data-phase="3"] {
  --phase-bg: rgba(35, 52, 58, 0.78);
  --phase-accent: #9f9;
}

/* Phase 4: chorus / hyper */
[data-phase="4"],
[data-chorus="true"] {
  --phase-bg: rgba(20, 55, 60, 0.7);
  --phase-accent: #0ff;
}

[data-chorus="true"] .game-overlay {
  filter: saturate(calc(var(--saturation) * 1.3)) hue-rotate(5deg);
  box-shadow: inset 0 0 60px rgba(0, 255, 255, 0.15);
}

.game-overlay {
  filter: saturate(var(--saturation));
  transition: filter 0.4s ease, box-shadow 0.4s ease;
}

/* Header */
.game-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--phase-bg);
  border-bottom: 1px solid var(--phase-accent);
  flex-shrink: 0;
}

.back-link {
  color: var(--phase-accent);
  text-decoration: none;
  font-weight: 600;
}

.back-link:hover {
  text-decoration: underline;
}

.game-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.practice-toggle {
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* YouTube underlay: full viewport behind everything */
.yt-underlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  background: #000;
}

.yt-underlay iframe {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100vw;
  height: 56.25vw;
  min-height: 100vh;
  min-width: 177.78vh;
  transform: translate(-50%, -50%);
  border: none;
}

/* Game overlay: on top of video, transparent where possible */
.game-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.game-overlay > * {
  pointer-events: auto;
}

.game-canvas {
  display: block;
  width: 100%;
  max-width: 900px;
  height: auto;
  max-height: 70vh;
  aspect-ratio: 16 / 10;
  background: rgba(0, 0, 0, 0.4);
  border: 2px solid var(--phase-accent);
  cursor: default;
}

/* HUD — drawn inside game canvas in the ground; HTML HUD hidden */
.hud {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
}

.hud-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.hud-label {
  font-size: 0.8rem;
  opacity: 0.9;
}

.motivation-bar {
  width: 100px;
  height: 12px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--phase-accent);
  border-radius: 4px;
  overflow: hidden;
}

.motivation-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #6a6, #0f8);
  transition: width 0.2s ease;
}

.hud-value {
  font-weight: 700;
  min-width: 2.5rem;
  transition: transform 0.12s ease-out;
}

.hud-value.score-pop {
  animation: score-pop 0.22s ease-out;
}

@keyframes score-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.beat-feedback {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--phase-accent);
  text-shadow: 0 0 8px var(--phase-accent);
  min-height: 1.5rem;
  transition: opacity 0.2s;
}

/* Start prompt */
.start-prompt {
  position: absolute;
  bottom: 4rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.75rem 1.25rem;
  background: var(--phase-bg);
  border: 1px solid var(--phase-accent);
  border-radius: 8px;
  font-size: 0.9rem;
  text-align: center;
}

/* Game over screen */
.game-over-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.8);
  gap: 1rem;
}

.game-over-screen[hidden] {
  display: none;
}

.game-over-title {
  font-size: 2.5rem;
  font-weight: 800;
  margin: 0;
  color: #f88;
}

.final-score {
  font-size: 1.25rem;
  margin: 0;
}

.restart-btn {
  padding: 0.6rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--phase-accent);
  color: #000;
  border: none;
  border-radius: 6px;
}

.restart-btn:hover {
  filter: brightness(1.2);
}

/* Leaderboard (game over) */
.game-over-screen .leaderboard-section {
  margin-top: 0.5rem;
  padding: 1rem;
  max-width: 90vw;
  max-height: 40vh;
  overflow: auto;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid var(--phase-accent);
  border-radius: 8px;
  -webkit-overflow-scrolling: touch;
}

.game-over-screen .leaderboard-title {
  color: var(--phase-accent);
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  text-align: center;
  text-transform: uppercase;
}

.game-over-screen .leaderboard-loading,
.game-over-screen .leaderboard-section .loading {
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.9rem;
  text-align: center;
  padding: 0.5rem 0;
}

.game-over-screen .leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.game-over-screen .leaderboard-table th {
  color: var(--phase-accent);
  text-transform: uppercase;
  padding: 6px 8px;
  border-bottom: 1px solid var(--phase-accent);
  text-align: left;
}

.game-over-screen .leaderboard-table td {
  color: #fff;
  padding: 4px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.game-over-screen .leaderboard-table .player-rank {
  font-weight: 700;
  color: var(--phase-accent);
}

.game-over-screen .leaderboard-table .player-you {
  background: rgba(0, 255, 136, 0.15);
  font-weight: 600;
}

/* Footer */
.game-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  padding: 0.5rem 1rem;
  background: var(--phase-bg);
  border-top: 1px solid var(--phase-accent);
  font-size: 0.8rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.game-footer a {
  color: var(--phase-accent);
  text-decoration: none;
}

.game-footer a:hover {
  text-decoration: underline;
}

@media (max-width: 600px) {
  .game-header {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .game-title {
    order: -1;
    width: 100%;
    text-align: center;
  }
  .hud {
    bottom: 4.5rem;
    left: 0.75rem;
  }
  .game-canvas {
    max-height: 55vh;
  }
}
