@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@700;900&display=swap');

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

html {
  /* Prevent elastic over-scroll on iOS from pulling the layout */
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  background: #000;
  color: #eee;
  font-family: 'Orbitron', sans-serif;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  /* Use small viewport height (toolbar always "in") so layout never grows
     when the iOS Safari toolbar hides. JS --app-h is the primary lock. */
  min-height: var(--app-h, 100svh);
  overflow: hidden;
  overscroll-behavior: none;
}

/* Animated rave grid floor */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    repeating-linear-gradient(0deg,   transparent, transparent 48px, rgba(0,255,255,.04) 48px, rgba(0,255,255,.04) 49px),
    repeating-linear-gradient(90deg,  transparent, transparent 48px, rgba(255,0,255,.04) 48px, rgba(255,0,255,.04) 49px);
  animation: gridPulse 3s ease-in-out infinite;
  pointer-events: none;
  z-index: 0;
}
@keyframes gridPulse { 0%,100%{opacity:.5} 50%{opacity:1} }

/* Rotating spotlight */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background: conic-gradient(from 0deg at 50% 50%, transparent 0deg, rgba(255,0,255,.06) 15deg, transparent 30deg);
  animation: spin 6s linear infinite;
  pointer-events: none;
  z-index: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

#flash {
  position: fixed; inset: 0;
  pointer-events: none; z-index: 50; opacity: 0;
}

#app {
  display: flex; flex-direction: column; align-items: center;
  gap: 8px; position: relative; z-index: 1;
}

header { text-align: center; }

header h1 {
  font-size: 2.4rem; font-weight: 900; letter-spacing: 6px;
  background: linear-gradient(90deg, #ff00ff, #00ffff, #ff00ff);
  background-size: 200%;
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  animation: chroma 2s linear infinite;
  filter: drop-shadow(0 0 10px #ff00ff);
}
.tagline {
  text-align: center; font-size: .65rem; letter-spacing: 6px;
  color: #ff00ff; text-transform: uppercase; margin-top: 2px;
  text-shadow: 0 0 8px #ff00ff;
}
@keyframes chroma { 0%{background-position:0%} 100%{background-position:200%} }

#game-wrap {
  display: flex; align-items: center; gap: 12px;
}

#center-panel {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}

#score-board {
  display: flex; align-items: center; gap: 24px;
}
.score-block { text-align: center; }
.score-block label {
  display: block; font-size: .55rem; letter-spacing: 3px;
  color: #ff00ff; text-shadow: 0 0 6px #ff00ff; margin-bottom: 2px;
}
.score-block span {
  font-size: 2rem; font-weight: 900;
  color: #00ffff; text-shadow: 0 0 12px #00ffff;
}
#score-mid {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
#score-sep {
  font-size: .6rem; color: #888; letter-spacing: 2px;
}
#rally-display {
  display: flex; flex-direction: column; align-items: center;
}
#rally-display span {
  font-size: 1.1rem; font-weight: 900;
  color: #ffff00; text-shadow: 0 0 8px #ffff00;
}
#rally-display label {
  font-size: .45rem; letter-spacing: 3px; color: #888; text-transform: uppercase;
}
#win-condition {
  font-size: .48rem; letter-spacing: 2px; color: #444;
  text-align: center; text-transform: uppercase; margin-top: -4px;
}

#game-canvas {
  display: block;
  border: 2px solid #ff00ff;
  border-radius: 4px;
  box-shadow: 0 0 16px #ff00ff, 0 0 40px rgba(255,0,255,.3);
  animation: borderPulse 1.5s ease-in-out infinite;
  /* Scale to viewport on mobile */
  max-width: 100%;
  height: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
@keyframes borderPulse {
  0%,100% { box-shadow: 0 0 10px #ff00ff, 0 0 22px rgba(255,0,255,.18); }
  50%      { box-shadow: 0 0 14px #00ffff, 0 0 28px rgba(0,255,255,.22); }
}

#ui { display: flex; gap: 10px; }

button {
  padding: 8px 20px;
  border: none; border-radius: 4px;
  font-family: 'Orbitron', sans-serif;
  font-size: .7rem; font-weight: 700;
  letter-spacing: 2px; text-transform: uppercase;
  cursor: pointer; transition: all .2s; position: relative; overflow: hidden;
}
button::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(90deg,transparent,rgba(255,255,255,.2),transparent);
  transform: translateX(-100%); transition: transform .4s;
}
button:hover::after { transform: translateX(100%); }
button:disabled { opacity: .3; cursor: not-allowed; }

#start-btn  { background: linear-gradient(135deg,#ff00ff,#8800ff); color:#fff; box-shadow:0 0 12px rgba(255,0,255,.5); }
#pause-btn  { background: linear-gradient(135deg,#00ffff,#0088ff); color:#000; box-shadow:0 0 12px rgba(0,255,255,.5); }
#play-btn, #rematch-btn { background: linear-gradient(135deg,#ff00ff,#8800ff); color:#fff; padding:12px 32px; font-size:.9rem; box-shadow:0 0 20px rgba(255,0,255,.6); }

#difficulty-select {
  display: flex; gap: 8px; margin: 4px 0 12px;
}
.diff-btn {
  background: transparent; color: #666; border: 1px solid #333;
  padding: 6px 14px; font-size: .6rem; letter-spacing: 2px;
  box-shadow: none;
}
.diff-btn.active {
  background: rgba(255,0,255,.15); color: #ff00ff;
  border-color: #ff00ff; box-shadow: 0 0 8px rgba(255,0,255,.3);
}

#end-stats {
  font-size: .55rem; letter-spacing: 2px; color: #666;
  text-transform: uppercase; text-align: center;
}


/* Overlay screens */
.screen {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.85);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px; z-index: 100; backdrop-filter: blur(4px);
}
.screen h2 {
  font-size: 3rem; font-weight: 900; letter-spacing: 8px;
  background: linear-gradient(90deg,#ff00ff,#00ffff,#ff00ff);
  background-size: 200%;
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  animation: chroma 1s linear infinite;
  filter: drop-shadow(0 0 16px #ff00ff);
}
.screen p {
  font-size: .85rem; letter-spacing: 3px;
  color: #aaa; text-align: center; line-height: 2;
}
.hidden { display: none !important; }

/* Touch-only elements hidden by default (shown via JS on touch devices) */
.touch-only { display: none; }

#serve-btn {
  background: linear-gradient(135deg,#ff00ff,#8800ff);
  color: #fff;
  font-size: 1rem;
  padding: 14px 36px;
  box-shadow: 0 0 20px rgba(255,0,255,.6);
  min-width: 120px;
}

#hint { font-size: .5rem; letter-spacing: 2px; color: #555; text-align: center; }
.hint-touch { display: none; }

@keyframes beatPulse { 0%{transform:scale(1)} 10%{transform:scale(1.006)} 20%{transform:scale(1)} }
.beat { animation: beatPulse .15s ease-out; }

/* ── Rotate overlay ── */
#rotate-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 200;
  background: #000;
  flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px; color: #fff;
  font-family: 'Orbitron', sans-serif;
  text-align: center;
}
#rotate-icon {
  font-size: 4rem;
  animation: rotateHint 1.5s ease-in-out infinite;
  color: #ff00ff;
  text-shadow: 0 0 16px #ff00ff;
}
@keyframes rotateHint {
  0%   { transform: rotate(0deg); }
  50%  { transform: rotate(90deg); }
  100% { transform: rotate(0deg); }
}
#rotate-overlay p { font-size: .75rem; letter-spacing: 2px; line-height: 2; color: #aaa; }

/* ── Mobile responsive ── */
@media (max-width: 900px) {
  /* Hide side disco balls to save space */
  #disco-left, #disco-right { display: none; }

  #game-wrap { gap: 4px; }

  header h1 { font-size: 1.6rem; letter-spacing: 4px; }
  .tagline   { font-size: .55rem; }

  .score-block span { font-size: 1.5rem; }

  #hint { font-size: .5rem; }
  .hint-kb    { display: none; }
  .hint-touch { display: inline; }

  .touch-only { display: inline-flex; }

  button { padding: 10px 18px; font-size: .65rem; }
  #serve-btn { padding: 16px 40px; font-size: 1rem; }

  #ui { gap: 8px; flex-wrap: wrap; justify-content: center; }
}

/* ── Mobile full-screen dance floor (landscape) ── */
@media (max-width: 900px) and (orientation: landscape) {
  /* Hide header and secondary text — canvas is the star */
  header, #win-condition, #hint { display: none; }

  /* Stretch the app shell to fill the whole screen.
     Use --app-h (snapshotted at load) instead of 100vh so the iOS Safari
     toolbar animation never causes the bottom to jump. */
  #app {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--app-h, 100svh);
    gap: 0;
    padding: 0;
    overflow: hidden;
  }

  #game-wrap {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--app-h, 100svh);
    gap: 0;
    align-items: stretch;
    overflow: hidden;
  }

  /* Center-panel fills the full screen */
  #center-panel {
    position: relative;
    width: 100%;
    height: 100%;
    gap: 0;
    overflow: hidden;
  }

  /* Dance floor canvas covers every pixel */
  #game-canvas {
    position: absolute;
    top: 0; left: 0;
    width: 100% !important;
    height: 100% !important;
    max-width: none;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  /* Scoreboard floats over the canvas at the top */
  #score-board {
    position: absolute;
    top: env(safe-area-inset-top, 8px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    background: rgba(0, 0, 0, 0.55);
    padding: 4px 16px 6px;
    border-radius: 0 0 10px 10px;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    gap: 16px;
    white-space: nowrap;
  }

  /* Buttons float over the canvas at the bottom */
  #ui {
    position: absolute;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    gap: 10px;
  }

  /* Slightly smaller scores to fit the compact HUD bar */
  .score-block span { font-size: 1.3rem; }
  .score-block label { font-size: .5rem; }
  #score-sep { font-size: .55rem; }
}

@media (orientation: portrait) and (max-width: 900px) {
  #rotate-overlay { display: flex; }
}
