/* ==========================================================================
   NEON PONG - HIGH-VELOCITY CURVE RALLY STYLESHEET
   ========================================================================== */

:root {
  --neon-cyan: #00f3ff;
  --neon-pink: #ff007f;
  --neon-purple: #9d00ff;
  --neon-yellow: #ffe600;
  --neon-green: #05ffa1;
  --bg-dark: #06030c;
  --bg-card: rgba(13, 7, 26, 0.94);
  --border-neon: rgba(0, 243, 255, 0.4);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-dark);
  color: #fff;
  font-family: 'Rajdhani', -apple-system, BlinkMacSystemFont, sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  background: radial-gradient(circle at 50% 30%, #17092b 0%, #080312 70%, #030107 100%);
  overscroll-behavior: none;
  -webkit-touch-callout: none;
}

.game-wrapper {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 12px;
}

#game-container {
  position: relative;
  width: min(960px, 96vw, calc((100dvh - 24px) * 16 / 9));
  aspect-ratio: 16 / 9;
  background: #04010a;
  box-shadow: 
    0 0 45px rgba(0, 243, 255, 0.22),
    0 0 85px rgba(255, 0, 127, 0.18);
  border: 1px solid rgba(0, 243, 255, 0.35);
  border-radius: 10px;
  overflow: hidden;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* CRT Scanlines */
.crt-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.26) 50%);
  background-size: 100% 4px;
  box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.65);
  z-index: 5;
}

/* Touch paddle zones */
.touch-paddle-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  z-index: 8;
  cursor: ns-resize;
  touch-action: none;
}

.touch-p1 {
  left: 0;
}

.touch-p2 {
  right: 0;
}

/* In-game HUD */
.overlay-hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 16px 24px;
  z-index: 10;
}

.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.hud-player-box {
  background: rgba(12, 6, 26, 0.85);
  padding: 8px 18px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 140px;
  backdrop-filter: blur(4px);
}

.p1-box {
  border: 1px solid rgba(0, 243, 255, 0.4);
  box-shadow: 0 0 15px rgba(0, 243, 255, 0.2);
}

.p2-box {
  border: 1px solid rgba(255, 0, 127, 0.4);
  box-shadow: 0 0 15px rgba(255, 0, 127, 0.2);
}

.hud-label {
  font-family: 'Orbitron', monospace;
  font-size: 10px;
  color: #99a0b5;
  letter-spacing: 1px;
}

.hud-score {
  font-family: 'Orbitron', monospace;
  font-size: 32px;
  font-weight: 900;
  line-height: 1.1;
}

.neon-cyan {
  color: var(--neon-cyan);
  text-shadow: 0 0 15px rgba(0, 243, 255, 0.7);
}

.neon-pink {
  color: var(--neon-pink);
  text-shadow: 0 0 15px rgba(255, 0, 127, 0.7);
}

.hud-center-info {
  display: flex;
  gap: 12px;
}

.hud-box {
  background: rgba(12, 6, 26, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 6px 14px;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hud-val {
  font-family: 'Orbitron', monospace;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
}

.rally-box .hud-val {
  color: var(--neon-yellow);
  text-shadow: 0 0 10px rgba(255, 230, 0, 0.6);
}

.best-rally-box .hud-val {
  color: var(--neon-green);
}

/* Bottom HUD */
.hud-bottom {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

.mode-tag-display {
  font-family: 'Orbitron', monospace;
  font-size: 11px;
  color: #798299;
  letter-spacing: 1.5px;
  background: rgba(12, 6, 26, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 6px 14px;
  border-radius: 6px;
}

.hud-controls-hint {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.neon-icon-btn {
  background: rgba(15, 10, 35, 0.85);
  border: 1px solid var(--neon-cyan);
  border-radius: 6px;
  color: #fff;
  width: 38px;
  height: 38px;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition: all 0.2s ease;
  box-shadow: 0 0 10px rgba(0, 243, 255, 0.2);
}

.neon-icon-btn:hover {
  background: rgba(0, 243, 255, 0.25);
  transform: translateY(-2px);
  box-shadow: 0 0 15px rgba(0, 243, 255, 0.5);
}

/* Notification banner */
.banner-notification {
  position: absolute;
  top: 25%;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  font-family: 'Orbitron', monospace;
  font-size: 20px;
  font-weight: 900;
  color: var(--neon-cyan);
  background: rgba(8, 3, 20, 0.9);
  border: 1px solid var(--neon-cyan);
  padding: 8px 24px;
  border-radius: 30px;
  box-shadow: 0 0 25px rgba(0, 243, 255, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  letter-spacing: 2px;
  text-transform: uppercase;
}

.banner-notification.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Modals */
.game-modal {
  position: absolute;
  inset: 0;
  background: rgba(5, 2, 12, 0.88);
  backdrop-filter: blur(6px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 25;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.game-modal.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--neon-cyan);
  border-radius: 12px;
  padding: 26px 36px;
  text-align: center;
  box-shadow: 0 0 35px rgba(0, 243, 255, 0.35);
  max-width: 520px;
  width: 92%;
  position: relative;
}

.mini-card {
  max-width: 380px;
}

.glitch-title {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(2rem, 4.5vw, 2.6rem);
  font-weight: 900;
  color: var(--neon-cyan);
  letter-spacing: 3px;
  text-shadow: 0 0 20px rgba(0, 243, 255, 0.7);
  margin-bottom: 2px;
}

.gameover-title {
  font-family: 'Orbitron', sans-serif;
  font-size: 26px;
  font-weight: 900;
  color: var(--neon-cyan);
  text-shadow: 0 0 20px rgba(0, 243, 255, 0.7);
  letter-spacing: 2px;
  margin-bottom: 4px;
}

.pause-title {
  font-family: 'Orbitron', sans-serif;
  font-size: 26px;
  font-weight: 900;
  color: var(--neon-yellow);
  text-shadow: 0 0 20px rgba(255, 230, 0, 0.7);
  letter-spacing: 2px;
  margin-bottom: 4px;
}

.subtitle, .gameover-sub, .pause-sub {
  font-size: 13px;
  color: #8c93a8;
  letter-spacing: 2px;
  margin-bottom: 18px;
}

/* Select Groups */
.mode-select-group {
  margin-bottom: 14px;
  text-align: left;
}

.group-title {
  display: block;
  font-family: 'Orbitron', monospace;
  font-size: 10px;
  color: #798299;
  letter-spacing: 1px;
  margin-bottom: 6px;
}

.btn-group {
  display: flex;
  gap: 8px;
}

.toggle-btn, .diff-btn, .pts-btn {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #c2c8dc;
  font-family: 'Orbitron', sans-serif;
  font-size: 11px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  letter-spacing: 0.5px;
}

.toggle-btn:hover, .diff-btn:hover, .pts-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: #fff;
  color: #fff;
}

.toggle-btn.active {
  background: rgba(0, 243, 255, 0.2);
  border-color: var(--neon-cyan);
  color: var(--neon-cyan);
  box-shadow: 0 0 12px rgba(0, 243, 255, 0.4);
}

.diff-btn.active {
  background: rgba(255, 0, 127, 0.2);
  border-color: var(--neon-pink);
  color: var(--neon-pink);
  box-shadow: 0 0 12px rgba(255, 0, 127, 0.4);
}

.pts-btn.active {
  background: rgba(255, 230, 0, 0.2);
  border-color: var(--neon-yellow);
  color: var(--neon-yellow);
  box-shadow: 0 0 12px rgba(255, 230, 0, 0.4);
}

/* Instructions */
.instructions-panel {
  background: rgba(0, 0, 0, 0.45);
  border-radius: 8px;
  padding: 10px 14px;
  margin: 16px 0 20px;
  text-align: left;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  margin: 5px 0;
  color: #ddd;
}

.key-badge {
  font-family: 'Orbitron', monospace;
  font-size: 10px;
  background: rgba(0, 243, 255, 0.15);
  border: 1px solid var(--neon-cyan);
  padding: 3px 8px;
  border-radius: 4px;
  color: var(--neon-cyan);
  white-space: nowrap;
}

/* Results Grid */
.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 18px 0;
}

.result-item {
  background: rgba(0, 0, 0, 0.5);
  padding: 10px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.res-label {
  display: block;
  font-size: 10px;
  color: #798099;
  margin-bottom: 4px;
  letter-spacing: 1px;
}

.res-val {
  font-family: 'Orbitron', monospace;
  font-size: 24px;
  font-weight: 700;
}

.neon-yellow { color: var(--neon-yellow); }
.neon-green { color: var(--neon-green); }

.modal-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.neon-btn {
  font-family: 'Orbitron', sans-serif;
  font-size: 13px;
  font-weight: 700;
  padding: 11px 24px;
  border-radius: 6px;
  cursor: pointer;
  border: none;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  letter-spacing: 1px;
}

.primary-btn {
  background: var(--neon-cyan);
  color: #030109;
  box-shadow: 0 0 15px rgba(0, 243, 255, 0.4);
}

.primary-btn:hover {
  background: #fff;
  box-shadow: 0 0 25px rgba(0, 243, 255, 0.8);
  transform: translateY(-2px);
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.secondary-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: #fff;
}

/* ==========================================================================
   MOBILE LAYOUTS
   Portrait turns the court a quarter turn so it fills the phone (see render()
   in game.js). Touch zones must stay below the HUD or its buttons stop working.
   ========================================================================== */

.touch-only {
  display: none;
}

@media (pointer: coarse) {
  .keys-only {
    display: none;
  }

  .touch-only {
    display: inline;
  }

  .control-row.touch-only {
    display: flex;
  }

  .control-row {
    justify-content: flex-start;
  }

  .key-badge {
    min-width: 108px;
    text-align: center;
  }
}

@media (max-width: 820px) and (orientation: portrait) {
  :root {
    --hud-h: calc(58px + env(safe-area-inset-top));
    /* Largest 9:16 court that fits under the HUD and leaves a strip for thumbs */
    --court-w: min(100vw, calc((100dvh - var(--hud-h) - 28px) * 9 / 16));
  }

  .game-wrapper {
    padding: 0;
  }

  #game-container {
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
  }

  #gameCanvas,
  .crt-overlay {
    position: absolute;
    top: var(--hud-h);
    right: auto;
    bottom: auto;
    left: 50%;
    width: var(--court-w);
    height: auto;
    aspect-ratio: 9 / 16;
    transform: translateX(-50%);
  }

  .touch-paddle-zone {
    left: 0;
    right: 0;
    width: 100%;
    cursor: ew-resize;
  }

  .touch-p1 {
    top: 50%;
  }

  .touch-p2 {
    bottom: 50%;
  }

  /* HUD: one slim bar above the court */
  .overlay-hud {
    bottom: auto;
    height: var(--hud-h);
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    gap: 6px;
    padding: env(safe-area-inset-top) 8px 0;
  }

  .hud-top {
    flex: 1;
    min-width: 0;
    gap: 4px;
  }

  .hud-player-box {
    flex: 1;
    min-width: 0;
    padding: 2px 6px;
    backdrop-filter: none;
  }

  .hud-player-box .hud-label {
    max-width: 100%;
    font-size: 8px;
    letter-spacing: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .hud-score {
    font-size: 20px;
  }

  .hud-center-info .hud-box:not(.rally-box),
  .mode-tag-display {
    display: none;
  }

  .hud-center-info .hud-box {
    padding: 3px 6px;
  }

  .hud-center-info .hud-label {
    font-size: 8px;
    letter-spacing: 0;
  }

  .hud-center-info .hud-val {
    font-size: 15px;
  }

  .hud-controls-hint {
    gap: 4px;
  }

  .neon-icon-btn {
    width: 40px;
    height: 44px;
  }

  .banner-notification {
    top: 42dvh;
    padding: 6px 16px;
    font-size: 13px;
    letter-spacing: 1px;
    white-space: nowrap;
  }

  /* Menus */
  .game-modal {
    padding: calc(env(safe-area-inset-top) + 12px) 12px calc(env(safe-area-inset-bottom) + 12px);
  }

  .modal-card {
    width: min(460px, 100%);
    max-height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 18px 16px;
  }

  .mini-card {
    max-width: 340px;
  }

  .glitch-title {
    font-size: 30px;
    letter-spacing: 2px;
  }

  .subtitle {
    font-size: 11px;
    margin-bottom: 12px;
  }

  .group-title {
    font-size: 10px;
  }

  .btn-group {
    gap: 6px;
  }

  .diff-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .toggle-btn, .diff-btn, .pts-btn {
    min-height: 44px;
    padding: 6px 4px;
    font-size: 12px;
  }

  .instructions-panel {
    margin: 12px 0 14px;
    padding: 8px 10px;
  }

  .control-row {
    font-size: 13px;
    gap: 8px;
  }

  .key-badge {
    font-size: 9px;
    padding: 3px 5px;
  }

  .gameover-title,
  .pause-title {
    font-size: 22px;
  }

  .results-grid {
    gap: 8px;
    margin: 14px 0;
  }

  .modal-buttons {
    flex-direction: column;
    gap: 8px;
  }

  .neon-btn {
    width: 100%;
    min-height: 48px;
    font-size: 14px;
  }
}

/* Short phones: the drag hint is shown as a banner anyway, so keep START on screen */
@media (max-width: 820px) and (orientation: portrait) and (max-height: 640px) {
  .instructions-panel {
    display: none;
  }

  #btn-start {
    margin-top: 6px;
  }
}

@media (orientation: landscape) and (max-height: 600px) {
  .game-wrapper {
    padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left);
  }

  #game-container {
    width: min(100%, calc(100dvh * 16 / 9));
    border: none;
    border-radius: 0;
    box-shadow: none;
  }

  /* HUD: scores in the corners, buttons by the net, all see-through over the court */
  .overlay-hud {
    padding: 4px 8px;
  }

  .hud-center-info,
  .mode-tag-display {
    display: none;
  }

  .hud-player-box {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    min-width: 0;
    padding: 2px 8px;
    background: rgba(12, 6, 26, 0.45);
    backdrop-filter: none;
  }

  .hud-score {
    font-size: 18px;
  }

  .hud-bottom {
    position: absolute;
    top: 4px;
    left: 50%;
    transform: translateX(-50%);
  }

  .hud-controls-hint {
    opacity: 0.8;
  }

  .neon-icon-btn {
    width: 40px;
    height: 36px;
  }

  .banner-notification {
    top: 20%;
    padding: 5px 16px;
    font-size: 14px;
    white-space: nowrap;
  }

  /* Menus: two columns, so nothing needs scrolling on a short screen */
  .game-modal {
    padding: 8px;
  }

  .modal-card {
    max-height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 18px;
  }

  #start-screen .modal-card {
    display: grid;
    grid-template-columns: 1fr 1.35fr;
    gap: 2px 20px;
    align-items: center;
    max-width: 660px;
  }

  #start-screen .glitch-title {
    grid-area: 1 / 1;
    font-size: 22px;
    margin: 0;
  }

  #start-screen .subtitle {
    grid-area: 2 / 1;
    font-size: 10px;
    margin: 0;
  }

  #start-screen #btn-start {
    grid-area: 3 / 1;
    min-height: 48px;
  }

  #start-screen .mode-select-group {
    margin-bottom: 6px;
  }

  #mode-group {
    grid-area: 1 / 2;
  }

  #difficulty-group {
    grid-area: 2 / 2;
  }

  #length-group {
    grid-area: 3 / 2;
  }

  .toggle-btn, .diff-btn, .pts-btn {
    min-height: 40px;
    padding: 4px;
    font-size: 10px;
  }

  .instructions-panel {
    display: none;
  }

  .gameover-title,
  .pause-title {
    font-size: 20px;
  }

  .gameover-sub,
  .pause-sub {
    margin-bottom: 8px;
  }

  .results-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin: 8px 0 10px;
  }

  .mini-card {
    max-width: 480px;
  }

  .neon-btn {
    min-height: 44px;
    padding: 8px 18px;
    white-space: nowrap;
  }
}
