/* ==================== THEMES ==================== */
:root {
  /* Default Theme: Cyber */
  --ui-accent: #00D2D3;
  --ui-accent-rgb: 0, 210, 211;
  --powerup-color: #00D2D3;
}

body.theme-sunset {
  --ui-accent: #F4A261;
  --ui-accent-rgb: 244, 162, 97;
  --powerup-color: #F4A261;
}

body.theme-coral {
  --ui-accent: #F25F5C;
  --ui-accent-rgb: 242, 95, 92;
  --powerup-color: #F25F5C;
}



/* ==================== BASE ==================== */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  height: 100%;
  height: 100dvh;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-touch-callout: none;
}

body {
  height: 100%;
  height: 100dvh;
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(to bottom, #172b36 0%, #d9e8e3 100%);
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
  font-family: monospace;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#game-wrapper {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;
}

/* ==================== CONTAINER ==================== */
#container {
  display: flex;
  align-items: center;
  flex-direction: column;
  width: min(70vh, 80%);
  max-width: 600px;
  height: 100%;
  position: relative;
}

/* ==================== CANVAS ==================== */
#pongCanvas {
  display: block;
  border-radius: 4px;
  overflow: hidden;
  width: 100%;
  margin-top: auto;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
}

/* ==================== HUD ==================== */
#hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-top: 10px;
  font-size: 13px;
  color: #172b36;
  padding: 0 4px;
}

.team {
  display: flex;
  align-items: center;
  gap: 5px;
}

.team-score {
  font-weight: bold;
  font-size: 15px;
}

.powerup-icons {
  display: flex;
  gap: 3px;
}

.powerup-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  padding: 0 3px;
  background: var(--ui-accent);
  color: #fff;
  font-size: 10px;
  font-weight: bold;
  text-align: center;
  line-height: 18px;
  white-space: nowrap;
  box-sizing: border-box;
}

#timer-display {
  font-size: 15px;
  font-weight: bold;
  color: #172b36;
  min-width: 40px;
  text-align: center;
}

#duration-label {
  cursor: pointer;
}

/* Progress bar — ONLY visible in-game */
#progression-bar {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
  margin-top: 6px;
  display: none;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.15);
}

body.game-active #progression-bar {
  display: flex;
}

#prog-day {
  height: 100%;
  background: #D9E8E3;
  transition: width 0.3s;
}

#prog-night {
  height: 100%;
  background: #114C5A;
  transition: width 0.3s;
}

/* HUD — ONLY visible in-game */
body:not(.game-active) #hud {
  display: none;
}

/* ==================== FOOTER ==================== */
#made {
  text-align: center;
  line-height: 1.5;
  margin-top: auto;
  margin-bottom: 16px;
  font-size: 10px;
  position: relative;
  z-index: 15;
  /* above overlay so links are clickable on menu */
}

#made a {
  color: #172b36;
  text-decoration: underline;
}

#made .gh-icon {
  width: 12px;
  height: 12px;
  vertical-align: -1px;
  margin-right: 2px;
}

/* Small screen: pin footer to bottom */
body.is-small-screen #made {
  position: fixed;
  bottom: 16px;
  left: 16px;
  right: 16px;
  margin: 0;
}

/* Hide footer in landscape on phone-sized screens */
@media (orientation: landscape) and (max-height: 500px) {
  #made {
    display: none;
  }
}

/* ==================== TOUCH CONTROLS ==================== */
.mobile-panel {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 4px;
  width: 70px;
  flex-shrink: 0;
}

/* Standard control pad: buttons col 1 (left), joystick col 2 (right) — rotated per orientation */
body.is-mobile.game-active .mobile-panel {
  display: grid;
  width: auto;
  grid-template-columns: auto auto;
  grid-template-rows: 1fr 1fr;
  gap: 14px 12px;
  align-items: center;
  justify-items: center;
  padding: 6px 10px;
}

body.is-mobile.game-active .mobile-panel .rot-btn-top {
  grid-row: 1;
  grid-column: 1;
}

body.is-mobile.game-active .mobile-panel .rot-btn-bottom {
  grid-row: 2;
  grid-column: 1;
}

body.is-mobile.game-active .mobile-panel .joystick-area {
  grid-row: 1 / 3;
  grid-column: 2;
}

/* Premium 'large-scale' controls component system */
body.is-mobile.game-active .mobile-panel.large-controls {
  gap: 14px 80px;
}

body.is-mobile.game-active .mobile-panel.large-controls .joystick-area {
  width: 84px;
  height: 84px;
}

body.is-mobile.game-active .mobile-panel.large-controls .joystick-knob {
  width: 36px;
  height: 36px;
}

body.is-mobile.game-active .mobile-panel.large-controls .rot-btn {
  width: 62px;
  height: 62px;
  font-size: 24px;
}


/* Unified Solo Desktop Touch Layout (Strictly for laptops/monitors with touch enabled) */
body.is-mobile.has-fine-pointer.game-active.ai-mode #made,
body.is-mobile.has-fine-pointer.game-active.ai-mode .side-hud-bar,
body.is-mobile.has-fine-pointer.game-active.ai-mode #mobile-panel-left,
body.is-mobile.has-fine-pointer.game-active.ai-mode #mobile-panel-right {
  display: none !important;
}

body.is-mobile.has-fine-pointer.game-active.ai-mode #hud,
body.is-mobile.has-fine-pointer.game-active.ai-mode #progression-bar {
  display: flex !important;
}

body.is-mobile.has-fine-pointer.game-active.ai-mode #mobile-panel-bottom {
  display: grid !important;
  position: fixed;
  bottom: 72px;
  left: 50%;
  transform: translateX(-50%);
  width: auto;
  margin: 0;
  z-index: 10;
}

body.is-mobile.has-fine-pointer.game-active.ai-mode #game-wrapper {
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  padding-top: 0 !important;
  padding-bottom: 220px !important;
}

body.is-mobile.has-fine-pointer.game-active.ai-mode #container {
  width: auto !important;
  max-width: 100% !important;
  margin: 0 auto !important;
  flex: 0 0 auto !important;
  height: auto !important;
}

body.is-mobile.has-fine-pointer.game-active.ai-mode #pongCanvas {
  /* Restore square aspect ratio and cap height to clear the bottom panel */
  aspect-ratio: 1 / 1 !important;
  width: auto !important;
  height: min(calc(100vh - 275px), 600px) !important;
  margin-top: 0 !important;
}

#mobile-panel-bottom {
  display: none;
}

/* Base AI Mode hiding: ensure right panel is always hidden in solo matches */
body.is-mobile.game-active.ai-mode #mobile-panel-right {
  display: none;
}

.joystick-area {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(23, 43, 54, 0.25);
  border: 2px solid rgba(var(--ui-accent-rgb), 0.4);
  position: relative;
  touch-action: none;
}

.joystick-knob {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(var(--ui-accent-rgb), 0.5);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  will-change: transform;
}

.rotate-btns {
  display: flex;
  gap: 16px;
}

.rot-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(23, 43, 54, 0.4);
  border: 2px solid rgba(var(--ui-accent-rgb), 0.35);
  color: #D9E8E3;
  font-size: 16px;
  cursor: pointer;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.rot-btn:active,
.rot-btn.pressed {
  background: rgba(var(--ui-accent-rgb), 0.5);
}

/* Side HUD bars — hidden by default, shown in landscape in-game */
.side-hud-bar {
  display: none;
}

#fullscreen-btn {
  display: none;
  position: fixed;
  top: 6px;
  left: 6px;
  z-index: 20;
  background: rgba(23, 43, 54, 0.7);
  border: 1px solid rgba(var(--ui-accent-rgb), 0.4);
  color: #D9E8E3;
  font-size: 18px;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  padding: 0;
}

body.is-mobile.game-active #fullscreen-btn {
  display: flex;
}

#pause-btn {
  display: none;
  position: fixed;
  top: 6px;
  left: 46px;
  z-index: 20;
  background: rgba(23, 43, 54, 0.7);
  border: 1px solid rgba(var(--ui-accent-rgb), 0.4);
  color: #D9E8E3;
  font-size: 18px;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  padding: 0;
}

body.is-mobile.game-active #pause-btn {
  display: flex;
}

/* Hide gear button on mobile/touch (pause menu has settings access) */
body.is-mobile #gear-btn {
  display: none;
}

/* ==================== MOBILE ==================== */
body.is-small-screen #pongCanvas {
  border-radius: 0;
  box-shadow: none;
}

/* Mobile in-game footer hidden when touch controls active (prevent accidental taps) */
body.is-mobile:not(.has-fine-pointer).game-active #made {
  display: none;
}

/* ==================== PORTRAIT MOBILE IN-GAME ==================== */
@media (orientation: portrait) {

  /* --- Layout: applies to all mobile/touch-active devices --- */
  body.is-mobile.game-active #made {
    display: none;
  }

  body.is-mobile.game-active #game-wrapper {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    align-content: center;
    gap: 0;
  }

  body.is-mobile.game-active #container {
    width: 100%;
    max-width: 600px;
    padding: 0;
    margin: 0 auto 20vh auto;
    flex: 0 0 auto;
    order: 0;
    height: auto;
  }

  body.is-mobile.game-active #pongCanvas {
    margin-top: 0;
  }

  body.is-mobile.game-active .side-hud-bar {
    display: none !important;
  }

  /* --- Touch controls: only when touch enabled --- */
  body.is-mobile.game-active #mobile-panel-left {
    order: 1;
    margin-left: 26px;
    position: fixed;
    bottom: 72px;
    left: 0;
  }

  body.is-mobile.game-active #mobile-panel-right {
    order: 2;
    margin-right: 26px;
    position: fixed;
    bottom: 72px;
    right: 0;
  }

  /* Standard portrait sizes (applied to 2P mode side-panels if not overridden) */
  body.is-mobile.game-active .mobile-panel:not(.large-controls) .joystick-area {
    width: 62px;
    height: 62px;
  }

  body.is-mobile.game-active .mobile-panel:not(.large-controls) .joystick-knob {
    width: 26px;
    height: 26px;
  }

  body.is-mobile.game-active .mobile-panel:not(.large-controls) .rot-btn {
    width: 48px;
    height: 48px;
    font-size: 19px;
  }

  /* AI mode touch controls: hide side panels and use centered bottom panel (Mobile Only) */
  body.is-mobile:not(.has-fine-pointer).game-active.ai-mode #mobile-panel-left,
  body.is-mobile:not(.has-fine-pointer).game-active.ai-mode #mobile-panel-right {
    display: none;
  }

  body.is-mobile:not(.has-fine-pointer).game-active.ai-mode #mobile-panel-bottom {
    display: grid;
    position: fixed;
    bottom: 72px;
    left: 50%;
    transform: translateX(-50%);
  }

  body.is-mobile:not(.has-fine-pointer).game-active.ai-mode #container {
    width: auto;
    max-width: 100%;
  }
}

/* ===== LANDSCAPE MOBILE IN-GAME (touch enabled) ===== */
@media (orientation: landscape) {

  /* --- ALL TOUCH: same standard grid as portrait, rotated per player ---
     Standard layout: buttons col 1, joystick col 2 (buttons-left, joystick-right).
     Left player faces right: rotate 90° CW → joystick at bottom (player's right), buttons at top (player's left).
     Right player faces left: rotate 90° CCW → joystick at bottom (player's right), buttons at top (player's left). */
  /* --- PREMIUM CONTROL COMPONENT: Standard layout for side panels --- */
  body.is-mobile.game-active #mobile-panel-left,
  body.is-mobile.game-active #mobile-panel-right {
    display: grid;
    flex-shrink: 0;
    gap: 14px 80px;
  }

  /* In landscape AI mode, explicitly hide the right panel */
  body.is-mobile.game-active.ai-mode #mobile-panel-right {
    display: none !important;
  }

  /* Control sizes for all premium panels (both orientations) */
  body.is-mobile.game-active #mobile-panel-left .joystick-area,
  body.is-mobile.game-active #mobile-panel-right .joystick-area,
  body.is-mobile.game-active.ai-mode #mobile-panel-bottom .joystick-area {
    width: 84px;
    height: 84px;
  }
  body.is-mobile.game-active #mobile-panel-left .joystick-knob,
  body.is-mobile.game-active #mobile-panel-right .joystick-knob,
  body.is-mobile.game-active.ai-mode #mobile-panel-bottom .joystick-knob {
    width: 36px;
    height: 36px;
  }
  body.is-mobile.game-active #mobile-panel-left .rot-btn,
  body.is-mobile.game-active #mobile-panel-right .rot-btn,
  body.is-mobile.game-active.ai-mode #mobile-panel-bottom .rot-btn {
    width: 62px;
    height: 62px;
    font-size: 24px;
  }

  /* --- Orientation Overrides --- */
  body.is-mobile.game-active .mobile-panel:not(.large-controls) {
    /* Lower gap for small orientation-specific panels */
    gap: 14px 12px;
  }

  /* Pin panels to screen edges and rotate. translateX pushes them to the right from the player's perspective */
  body.is-mobile:not(.has-fine-pointer).game-active #mobile-panel-left {
    position: fixed;
    left: 0px;
    /* changed from 22px to compensate for rotated box dimensions */
    top: 50%;
    transform: translateY(-50%) rotate(90deg) translateX(30px);
  }

  body.is-mobile:not(.has-fine-pointer).game-active #mobile-panel-right {
    position: fixed;
    right: 0px;
    /* changed from 22px to compensate for rotated box dimensions */
    top: 50%;
    transform: translateY(-50%) rotate(-90deg) translateX(30px);
  }

  /* --- Layout: applies to ALL small screens (touch on or off) --- */
  body.is-small-screen.game-active #game-wrapper {
    align-items: center;
  }

  body.is-small-screen.game-active #container {
    width: auto;
    max-width: none;
    flex: 0 0 auto;
    height: 100%;
    padding: 0;
  }

  body.is-small-screen.game-active #pongCanvas {
    width: auto;
    height: 100%;
    aspect-ratio: 1 / 1;
    margin-top: 0;
  }

  /* Hide center HUD + progress bar — side HUD bars replace them */
  body.is-small-screen.game-active #hud {
    display: none !important;
  }

  body.is-small-screen.game-active #progression-bar {
    display: none !important;
  }

  /* Side HUD bars: 2-column grid — progress bar inner, text outer */
  body.is-small-screen.game-active .side-hud-bar {
    display: grid;
    flex-shrink: 0;
    flex-grow: 0;
    grid-template-rows: auto 1fr auto;
    gap: 2px;
    padding: 4px 0;
    height: 100%;
    font-family: monospace;
    font-size: 10px;
    color: #D9E8E3;
  }

  /* Left bar: [text | prog] — 5px gap between prog and canvas */
  body.is-small-screen.game-active #side-hud-bar-left {
    grid-template-columns: auto 6px;
    column-gap: 3px;
    padding-left: 2px;
    padding-right: 5px;
  }

  body.is-small-screen.game-active #side-hud-bar-left .side-score {
    grid-column: 1;
    grid-row: 1;
  }

  body.is-small-screen.game-active #side-hud-bar-left .side-timer {
    grid-column: 1;
    grid-row: 2;
  }

  body.is-small-screen.game-active #side-hud-bar-left .side-powerups {
    grid-column: 1;
    grid-row: 3;
  }

  body.is-small-screen.game-active #side-hud-bar-left .side-prog-track {
    grid-column: 2;
    grid-row: 1 / 4;
  }

  /* Right bar: [prog | text] — 5px gap between prog and canvas */
  body.is-small-screen.game-active #side-hud-bar-right {
    grid-template-columns: 6px auto;
    column-gap: 3px;
    padding-right: 2px;
    padding-left: 5px;
  }

  body.is-small-screen.game-active #side-hud-bar-right .side-prog-track {
    grid-column: 1;
    grid-row: 1 / 4;
  }

  body.is-small-screen.game-active #side-hud-bar-right .side-score {
    grid-column: 2;
    grid-row: 1;
  }

  body.is-small-screen.game-active #side-hud-bar-right .side-timer {
    grid-column: 2;
    grid-row: 2;
  }

  body.is-small-screen.game-active #side-hud-bar-right .side-powerups {
    grid-column: 2;
    grid-row: 3;
  }

  body.is-small-screen.game-active .side-hud-bar .side-score {
    font-weight: bold;
    font-size: 12px;
    white-space: nowrap;
  }

  body.is-small-screen.game-active .side-hud-bar .side-timer {
    font-size: 10px;
    font-weight: bold;
    white-space: nowrap;
  }

  body.is-small-screen.game-active .side-hud-bar .side-powerups {
    display: flex;
    gap: 2px;
    flex-direction: column;
  }

  /* Touch ON: players face short edges, so rotate text vertically */
  body.is-small-screen.is-mobile.game-active .side-hud-bar .side-score {
    writing-mode: vertical-rl;
    align-self: start;
  }

  body.is-small-screen.is-mobile.game-active .side-hud-bar .side-timer {
    writing-mode: vertical-rl;
    align-self: center;
  }

  body.is-small-screen.is-mobile.game-active .side-hud-bar .side-powerups {
    writing-mode: vertical-rl;
    align-self: end;
    flex-direction: row;
    align-items: center;
  }

  body.is-small-screen.is-mobile.game-active #side-hud-bar-right .side-score,
  body.is-small-screen.is-mobile.game-active #side-hud-bar-right .side-timer,
  body.is-small-screen.is-mobile.game-active #side-hud-bar-right .side-powerups {
    transform: rotate(180deg);
  }

  body.is-small-screen.game-active .side-hud-bar .side-prog-track {
    width: 6px;
    border-radius: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.15);
    margin: -4px 0;
    /* negate parent's 4px top/bottom padding so prog track is full height */
    align-self: stretch;
  }

  body.is-small-screen.game-active .side-hud-bar .vprog-day {
    background: #D9E8E3;
    transition: height 0.3s;
  }

  body.is-small-screen.game-active .side-hud-bar .vprog-night {
    background: #114C5A;
    transition: height 0.3s;
  }

  body.is-small-screen.game-active .side-hud-bar.prog-hidden .side-prog-track {
    display: none;
  }

  /* --- Touch controls only --- */
  body.is-mobile:not(.has-fine-pointer).game-active #made {
    display: none;
  }

  body.is-mobile:not(.has-fine-pointer).game-active .joystick-area,
  body.is-mobile:not(.has-fine-pointer).game-active.ai-mode #mobile-panel-bottom .joystick-area {
    width: 84px;
    height: 84px;
  }

  body.is-mobile:not(.has-fine-pointer).game-active .joystick-knob,
  body.is-mobile:not(.has-fine-pointer).game-active.ai-mode #mobile-panel-bottom .joystick-knob {
    width: 36px;
    height: 36px;
  }

  body.is-mobile:not(.has-fine-pointer).game-active .rot-btn,
  body.is-mobile:not(.has-fine-pointer).game-active.ai-mode #mobile-panel-bottom .rot-btn {
    width: 62px;
    height: 62px;
    font-size: 24px;
  }

  /* Move top-left buttons just to the left of the DAY score in landscape */
  body.is-mobile:not(.has-fine-pointer).game-active #fullscreen-btn {
    left: max(6px, calc(50dvw - 50dvh - 110px));
  }

  body.is-mobile:not(.has-fine-pointer).game-active #pause-btn {
    left: max(46px, calc(50dvw - 50dvh - 66px));
  }

  /* AI mode landscape — touch only */
  body.is-mobile:not(.has-fine-pointer).game-active.ai-mode #mobile-panel-left {
    display: grid;
  }

  body.is-mobile:not(.has-fine-pointer).game-active.ai-mode .side-hud-bar {
    display: none !important;
  }

  body.is-mobile:not(.has-fine-pointer).game-active.ai-mode #hud {
    display: flex !important;
    font-size: 11px;
    margin-top: 4px;
  }

  body.is-mobile:not(.has-fine-pointer).game-active.ai-mode #progression-bar {
    display: flex !important;
    margin-top: 2px;
  }

  body.is-mobile:not(.has-fine-pointer).game-active.ai-mode #pongCanvas {
    height: calc(100% - 26px);
  }
}

/* ===== LANDSCAPE DESKTOP TOUCH (has-fine-pointer + touch enabled) ===== */
@media (orientation: landscape) {

  /* Container + canvas: landscape layout like mobile, capped to same max as non-touch */
  body.is-mobile.has-fine-pointer.game-active #game-wrapper {
    align-items: center;
  }

  body.is-mobile.has-fine-pointer.game-active #container {
    width: auto;
    max-width: none;
    flex: 0 0 auto;
    padding: 0;
  }

  body.is-mobile.has-fine-pointer.game-active #pongCanvas {
    width: auto;
    height: min(calc(100vh - 46px), 600px);
    aspect-ratio: 1 / 1;
    margin-top: auto;
  }

  body.is-mobile.has-fine-pointer.game-active.ai-mode #pongCanvas {
    /* Adjust canvas height in AI mode to fit the bottom panel */
    height: min(calc(100vh - 165px), 600px);
    margin-top: auto;
  }

  /* Panel positioning — same as mobile landscape */
  body.is-mobile.has-fine-pointer.game-active #mobile-panel-left {
    position: fixed;
    left: 0px;
    top: 50%;
    transform: translateY(-50%) rotate(90deg) translateX(30px);
  }

  body.is-mobile.has-fine-pointer.game-active #mobile-panel-right {
    position: fixed;
    right: 0px;
    top: 50%;
    transform: translateY(-50%) rotate(-90deg) translateX(30px);
  }

  /* Control sizes — same as mobile landscape */
  body.is-mobile.has-fine-pointer.game-active .joystick-area,
  body.is-mobile.has-fine-pointer.game-active.ai-mode #mobile-panel-bottom .joystick-area {
    width: 84px;
    height: 84px;
  }

  body.is-mobile.has-fine-pointer.game-active .joystick-knob,
  body.is-mobile.has-fine-pointer.game-active.ai-mode #mobile-panel-bottom .joystick-knob {
    width: 36px;
    height: 36px;
  }

  body.is-mobile.has-fine-pointer.game-active .rot-btn,
  body.is-mobile.has-fine-pointer.game-active.ai-mode #mobile-panel-bottom .rot-btn {
    width: 62px;
    height: 62px;
    font-size: 24px;
  }

  /* In AI mode on desktop touch, hide side HUDs and use standard top HUD */
  body.is-mobile.has-fine-pointer.game-active.ai-mode .side-hud-bar {
    display: none !important;
  }

  body.is-mobile.has-fine-pointer.game-active.ai-mode #hud,
  body.is-mobile.has-fine-pointer.game-active.ai-mode #progression-bar {
    display: flex !important;
  }

  /* Left bar: [text | prog] */
  body.is-mobile.has-fine-pointer.game-active #side-hud-bar-left {
    grid-template-columns: auto 6px;
    column-gap: 3px;
    padding-left: 2px;
    padding-right: 5px;
  }

  body.is-mobile.has-fine-pointer.game-active #side-hud-bar-left .side-score { grid-column: 1; grid-row: 1; }
  body.is-mobile.has-fine-pointer.game-active #side-hud-bar-left .side-timer { grid-column: 1; grid-row: 2; }
  body.is-mobile.has-fine-pointer.game-active #side-hud-bar-left .side-powerups { grid-column: 1; grid-row: 3; }
  body.is-mobile.has-fine-pointer.game-active #side-hud-bar-left .side-prog-track { grid-column: 2; grid-row: 1 / 4; }

  /* Right bar: [prog | text] */
  body.is-mobile.has-fine-pointer.game-active #side-hud-bar-right {
    grid-template-columns: 6px auto;
    column-gap: 3px;
    padding-right: 2px;
    padding-left: 5px;
  }

  body.is-mobile.has-fine-pointer.game-active #side-hud-bar-right .side-prog-track { grid-column: 1; grid-row: 1 / 4; }
  body.is-mobile.has-fine-pointer.game-active #side-hud-bar-right .side-score { grid-column: 2; grid-row: 1; }
  body.is-mobile.has-fine-pointer.game-active #side-hud-bar-right .side-timer { grid-column: 2; grid-row: 2; }
  body.is-mobile.has-fine-pointer.game-active #side-hud-bar-right .side-powerups { grid-column: 2; grid-row: 3; }

  /* Text styling */
  body.is-mobile.has-fine-pointer.game-active .side-hud-bar .side-score {
    font-weight: bold;
    font-size: 12px;
    white-space: nowrap;
    writing-mode: vertical-rl;
    align-self: start;
  }

  body.is-mobile.has-fine-pointer.game-active .side-hud-bar .side-timer {
    font-size: 10px;
    font-weight: bold;
    white-space: nowrap;
    writing-mode: vertical-rl;
    align-self: center;
  }

  body.is-mobile.has-fine-pointer.game-active .side-hud-bar .side-powerups {
    display: flex;
    gap: 2px;
    writing-mode: vertical-rl;
    align-self: end;
    flex-direction: row;
    align-items: center;
  }

  /* Right bar text rotated 180° (player faces opposite direction) */
  body.is-mobile.has-fine-pointer.game-active #side-hud-bar-right .side-score,
  body.is-mobile.has-fine-pointer.game-active #side-hud-bar-right .side-timer,
  body.is-mobile.has-fine-pointer.game-active #side-hud-bar-right .side-powerups {
    transform: rotate(180deg);
  }

  /* Progress track */
  body.is-mobile.has-fine-pointer.game-active .side-hud-bar .side-prog-track {
    width: 6px;
    border-radius: 3px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.15);
    margin: 0;
    align-self: stretch;
  }

  body.is-mobile.has-fine-pointer.game-active .side-hud-bar .vprog-day {
    background: #D9E8E3;
    transition: height 0.3s;
  }

  body.is-mobile.has-fine-pointer.game-active .side-hud-bar .vprog-night {
    background: #114C5A;
    transition: height 0.3s;
  }

  body.is-mobile.has-fine-pointer.game-active .side-hud-bar.prog-hidden .side-prog-track {
    display: none;
  }
}

/* ===== LANDSCAPE DESKTOP SMALL WINDOW (excludes phones/tablets) ===== */
@media (orientation: landscape) and (max-height: 500px) {
  body:not(.is-mobile):not(.is-small-screen).game-active #container {
    width: auto;
    max-width: none;
    height: 100%;
    padding: 0;
  }

  body:not(.is-mobile):not(.is-small-screen).game-active #pongCanvas {
    margin-top: 0;
    width: auto;
    height: 100%;
    aspect-ratio: 1 / 1;
  }

  /* Hide bottom HUD — use side bars instead */
  body:not(.is-mobile):not(.is-small-screen).game-active #hud {
    display: none !important;
  }

  body:not(.is-mobile):not(.is-small-screen).game-active #progression-bar {
    display: none !important;
  }

  body:not(.is-mobile):not(.is-small-screen).game-active #made {
    display: none;
  }

  /* Side HUD bars visible — text faces the long edge (horizontal reading) */
  body:not(.is-mobile):not(.is-small-screen).game-active .side-hud-bar {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 3px;
    padding: 4px 3px;
    font-family: monospace;
    flex-shrink: 0;
    width: 36px;
    height: 100%;
  }

  body:not(.is-mobile):not(.is-small-screen).game-active .side-hud-bar .side-score {
    font-weight: bold;
    font-size: 11px;
    color: #D9E8E3;
  }

  body:not(.is-mobile):not(.is-small-screen).game-active .side-hud-bar .side-timer {
    font-size: 9px;
    color: #D9E8E3;
    font-weight: bold;
  }

  body:not(.is-mobile):not(.is-small-screen).game-active .side-hud-bar .side-powerups {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  body:not(.is-mobile):not(.is-small-screen).game-active .side-hud-bar .side-prog-track {
    flex: 1;
    width: 6px;
    min-height: 20px;
    border-radius: 3px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.15);
  }

  body:not(.is-mobile):not(.is-small-screen).game-active .side-hud-bar .vprog-day {
    background: #D9E8E3;
    transition: height 0.3s;
  }

  body:not(.is-mobile):not(.is-small-screen).game-active .side-hud-bar .vprog-night {
    background: #114C5A;
    transition: height 0.3s;
  }

  body:not(.is-mobile):not(.is-small-screen).game-active .side-hud-bar.prog-hidden .side-prog-track {
    display: none;
  }
}

/* ==================== OVERLAYS ==================== */
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
  pointer-events: auto;
}

.overlay.hidden {
  display: none !important;
}

#rotate-overlay {
  display: none !important;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(17, 43, 54, 0.98);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 10000;
  flex-direction: column;
  color: #D9E8E3;
}

@media (orientation: portrait) {
  body.is-mobile.game-active:not(.ai-mode) #rotate-overlay {
    display: flex !important;
  }
}

/* Menu overlay on launch: cover entire viewport with solid bg (no game area visible) */
body:not(.game-active) #menu {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(to bottom, #172b36 0%, #d9e8e3 100%);
}

.menu-content {
  background: rgba(23, 43, 54, 0.96);
  border-radius: 12px;
  padding: 24px 28px;
  max-width: 400px;
  width: 92%;
  color: #D9E8E3;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4);
  max-height: 92vh;
  overflow-y: auto;
  touch-action: pan-y;
}

@media (orientation: landscape) and (max-height: 500px) {
  .menu-content {
    padding: 14px 20px;
    max-height: 96vh;
  }

  .menu-content h1 {
    font-size: 18px;
    margin: 0 0 2px 0;
  }

  .menu-subtitle {
    margin: 0 0 10px 0;
  }

  .option-group {
    margin-bottom: 8px;
  }

  .start-button {
    padding: 8px;
    margin-top: 10px;
  }
}

.menu-content h1 {
  font-family: monospace;
  font-size: 22px;
  margin: 0 0 4px 0;
  letter-spacing: 2px;
  color: var(--ui-accent);
}

.menu-content h1 span {
  font-size: 14px;
  color: #D9E8E3;
  letter-spacing: 4px;
}

.menu-subtitle {
  font-size: 11px;
  color: #8ba8a0;
  margin: 0 0 18px 0;
}

.option-group {
  margin-bottom: 12px;
  text-align: left;
}

.option-group label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #8ba8a0;
  display: block;
  margin-bottom: 5px;
}

.toggle-group {
  display: flex;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #2a5260;
}

.toggle-group button {
  flex: 1;
  padding: 6px 5px;
  border: none;
  background: transparent;
  color: #8ba8a0;
  font-family: monospace;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.toggle-group button:not(:last-child) {
  border-right: 1px solid #2a5260;
}

.toggle-group button.active {
  background: #114C5A;
  color: #D9E8E3;
}

.toggle-group button:hover:not(.active) {
  background: rgba(17, 76, 90, 0.3);
}

.duration-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.duration-row input[type="range"] {
  flex: 1;
  accent-color: var(--ui-accent);
}

.duration-value {
  font-size: 14px;
  min-width: 36px;
  text-align: right;
  color: var(--ui-accent);
}

.start-button {
  display: block;
  width: 100%;
  padding: 11px;
  margin-top: 16px;
  border: none;
  border-radius: 8px;
  background: var(--ui-accent);
  color: #fff;
  font-family: monospace;
  font-size: 15px;
  font-weight: bold;
  letter-spacing: 2px;
  cursor: pointer;
  transition: background 0.15s;
}

.start-button:hover {
  background: color-mix(in srgb, var(--ui-accent), white 20%);
}

.secondary-button {
  display: block;
  width: 100%;
  padding: 9px;
  margin-top: 7px;
  border: 1px solid #2a5260;
  border-radius: 8px;
  background: transparent;
  color: #D9E8E3;
  font-family: monospace;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}

.secondary-button:hover {
  background: rgba(17, 76, 90, 0.3);
}

.controls-help {
  margin-top: 14px;
  font-size: 10px;
  color: #5a8a7e;
  line-height: 1.6;
}

.controls-help a {
  color: var(--ui-accent);
  cursor: pointer;
  text-decoration: underline;
}

.desktop-only {
  display: block;
}

.mobile-only {
  display: none;
}

body.is-small-screen .desktop-only {
  display: none;
}

body.is-small-screen .mobile-only {
  display: block;
}

.hidden {
  display: none !important;
}

/* Gear / settings button */
#gear-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  z-index: 5;
  opacity: 0.6;
  transition: opacity 0.15s;
  padding: 4px;
  color: #172b36;
}

#gear-btn:hover {
  opacity: 1;
}

/* Keybinding overlay */
.keybind-grid {
  display: flex;
  gap: 16px;
  text-align: left;
}

.keybind-section {
  flex: 1;
}

.keybind-section h3 {
  font-size: 11px;
  color: var(--ui-accent);
  margin: 0 0 8px 0;
}

.keybind-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
  font-size: 11px;
}

.keybind-btn {
  background: #1a3a45;
  border: 1px solid #2a5260;
  color: #D9E8E3;
  padding: 3px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-family: monospace;
  font-size: 11px;
  min-width: 42px;
  text-align: center;
}

.keybind-btn.listening {
  background: var(--ui-accent);
  color: #fff;
}

.keybind-btn:hover {
  border-color: var(--ui-accent);
}

/* Settings overlay */
.settings-section-title {
  font-size: 12px;
  color: var(--ui-accent);
  margin: 14px 0 8px 0;
  text-transform: uppercase;
  letter-spacing: 1px;
  text-align: left;
  border-bottom: 1px solid #2a5260;
  padding-bottom: 4px;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 11px;
  text-align: left;
}

.setting-row label {
  margin: 0;
  min-width: 80px;
}

.setting-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  justify-content: flex-end;
}

.setting-controls .toggle-group {
  min-width: 90px;
}

.setting-controls input[type="range"] {
  width: 80px;
  accent-color: var(--ui-accent);
}

.setting-value {
  font-size: 11px;
  min-width: 30px;
  text-align: right;
  color: var(--ui-accent);
}

.reset-btn {
  background: none;
  border: 1px solid #2a5260;
  color: #8ba8a0;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}

.reset-btn:hover {
  border-color: var(--ui-accent);
  color: var(--ui-accent);
}

.game-logic-setting.disabled {
  opacity: 0.35;
  pointer-events: none;
}

#gameover-content h1 {
  font-size: 26px;
  margin-bottom: 8px;
}

#final-score {
  font-size: 14px;
  color: #8ba8a0;
  margin: 8px 0;
}