/* ==========================================================================
   Headball — global styles
   Mobile-first, full-viewport canvas game.
   ========================================================================== */

:root {
  --pitch-dark: #0b6b2e;
  --pitch-light: #128a3c;
  --ui-bg: rgba(8, 20, 12, 0.72);
  --ui-fg: #ffffff;
  --team-left: #2d7dff;
  --team-right: #ff4646;
  --shadow: rgba(0, 0, 0, 0.35);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #05140a;
  color: var(--ui-fg);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
  /* Stop the browser from intercepting touch gestures we use for controls */
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#game-root {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh; /* dynamic viewport height where supported (mobile URL bars) */
}

#game-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* --------------------------------------------------------------------------
   Scoreboard overlay
   -------------------------------------------------------------------------- */
#scoreboard {
  position: absolute;
  top: calc(var(--safe-top) + 10px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: clamp(8px, 3vw, 22px);
  padding: 6px clamp(10px, 3vw, 18px);
  background: var(--ui-bg);
  border-radius: 999px;
  box-shadow: 0 6px 20px var(--shadow);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 10;
  pointer-events: none;
  font-weight: 700;
  letter-spacing: 0.04em;
}

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

.team__name {
  font-size: clamp(11px, 3.4vw, 16px);
  opacity: 0.9;
}

.team--left .team__name {
  color: var(--team-left);
}

.team--right .team__name {
  color: var(--team-right);
}

.team__score {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: clamp(26px, 8vw, 38px);
  font-size: clamp(18px, 6vw, 30px);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  transition: transform 0.18s ease;
}

.team__score.bump {
  transform: scale(1.45);
}

.scoreboard__center {
  font-size: clamp(14px, 4.5vw, 20px);
  opacity: 0.85;
}

/* --------------------------------------------------------------------------
   Boot notice (errors / loading)
   -------------------------------------------------------------------------- */
#boot-notice {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 80vw;
  padding: 18px 22px;
  background: var(--ui-bg);
  border-radius: 14px;
  text-align: center;
  font-size: 15px;
  line-height: 1.5;
  z-index: 20;
  box-shadow: 0 8px 30px var(--shadow);
}

#boot-notice[hidden] {
  display: none;
}

/* --------------------------------------------------------------------------
   Overlays (menu / match over)
   -------------------------------------------------------------------------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(
    120% 120% at 50% 0%,
    rgba(6, 20, 12, 0.55),
    rgba(4, 12, 8, 0.82)
  );
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  opacity: 1;
  transition: opacity 0.25s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.panel {
  width: min(92vw, 440px);
  text-align: center;
  background: rgba(10, 24, 16, 0.78);
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 22px;
  padding: clamp(22px, 6vw, 40px) clamp(18px, 5vw, 32px);
  box-shadow: 0 18px 50px var(--shadow);
}

.title {
  font-size: clamp(30px, 9vw, 54px);
  line-height: 1.05;
  letter-spacing: 0.02em;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
  margin-bottom: 6px;
}

.tagline {
  font-size: clamp(14px, 4vw, 18px);
  opacity: 0.85;
  margin-bottom: clamp(18px, 5vw, 28px);
}

.btn {
  display: inline-block;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #06210f;
  background: linear-gradient(180deg, #ffe14d, #ffb01f);
  padding: 14px clamp(28px, 9vw, 52px);
  font-size: clamp(18px, 5vw, 24px);
  border-radius: 999px;
  box-shadow: 0 8px 0 #b9770c, 0 12px 22px rgba(0, 0, 0, 0.4);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  touch-action: manipulation;
}

.btn:active {
  transform: translateY(5px);
  box-shadow: 0 3px 0 #b9770c, 0 6px 14px rgba(0, 0, 0, 0.4);
}

.hints {
  margin-top: clamp(16px, 5vw, 26px);
  font-size: clamp(11px, 3.4vw, 14px);
  line-height: 1.7;
  opacity: 0.78;
}

.hints strong {
  color: #ffe14d;
}

/* --------------------------------------------------------------------------
   Touch controls — large, fade when idle, brighten on press
   -------------------------------------------------------------------------- */
#touch-controls {
  position: absolute;
  inset: auto 0 0 0;
  bottom: calc(var(--safe-bottom) + 14px);
  z-index: 25;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 clamp(14px, 5vw, 40px);
  pointer-events: none;
}

/* Shown only during active play (toggled from JS), and only on touch UIs. */
body.is-touch #touch-controls.active {
  display: flex;
}

.touch-cluster {
  display: flex;
  gap: clamp(10px, 3.5vw, 22px);
}

/* --------------------------------------------------------------------------
   Virtual joystick (movement) — fixed translucent base on the left, draggable
   knob that follows the thumb. Faded when idle, brightened while active. The
   knob is translated in JS along the game-space axes (see controls.js).
   -------------------------------------------------------------------------- */
.joystick {
  position: relative;
  pointer-events: auto;
  flex: 0 0 auto;
  width: clamp(120px, 34vw, 180px);
  height: clamp(120px, 34vw, 180px);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.joystick__base {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.12);
  opacity: 0.42; /* faded when idle */
  transition: opacity 0.18s ease, background 0.12s ease;
}

.joystick__stick {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44%;
  height: 44%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.5);
  opacity: 0.5;
  transform: translate(-50%, -50%); /* home; JS adds the drag offset */
  transition: opacity 0.15s ease, background 0.12s ease;
  will-change: transform;
}

/* Pressed/active state — brighten the whole control while a thumb drives it. */
.joystick.active .joystick__base {
  opacity: 0.9;
  background: rgba(255, 255, 255, 0.18);
}

.joystick.active .joystick__stick {
  opacity: 0.98;
  background: rgba(255, 255, 255, 0.46);
}

.touch-btn {
  pointer-events: auto;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(64px, 18vw, 92px);
  height: clamp(64px, 18vw, 92px);
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  font-size: clamp(30px, 9vw, 44px);
  font-weight: 700;
  line-height: 1;
  opacity: 0.42; /* faded when idle */
  transition: opacity 0.18s ease, transform 0.08s ease, background 0.12s ease;
}

.touch-btn--jump {
  background: rgba(255, 210, 63, 0.22);
  border-color: rgba(255, 210, 63, 0.7);
  width: clamp(74px, 21vw, 108px);
  height: clamp(74px, 21vw, 108px);
}

.touch-btn.pressed {
  opacity: 0.95;
  transform: scale(0.92);
  background: rgba(255, 255, 255, 0.34);
}

.touch-btn--jump.pressed {
  background: rgba(255, 210, 63, 0.55);
}

/* --------------------------------------------------------------------------
   Match-progress pips (first to 5)
   -------------------------------------------------------------------------- */
#progress {
  position: absolute;
  top: calc(var(--safe-top) + 56px);
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 0 clamp(10px, 4vw, 26px);
  z-index: 9;
  pointer-events: none;
}

.progress__row {
  display: flex;
  gap: 5px;
}

.progress__row--right {
  flex-direction: row-reverse;
}

.pip {
  width: clamp(7px, 2vw, 11px);
  height: clamp(7px, 2vw, 11px);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}

.progress__row--left .pip.on {
  background: var(--team-left);
  box-shadow: 0 0 8px var(--team-left);
}

.progress__row--right .pip.on {
  background: var(--team-right);
  box-shadow: 0 0 8px var(--team-right);
}

/* --------------------------------------------------------------------------
   Icon buttons: pause + sound toggles
   -------------------------------------------------------------------------- */
.icon-btn {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: clamp(40px, 11vw, 50px);
  height: clamp(40px, 11vw, 50px);
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: var(--ui-bg);
  color: #fff;
  font-size: clamp(15px, 4.4vw, 20px);
  line-height: 1;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 4px 14px var(--shadow);
  transition: transform 0.08s ease, background 0.12s ease, opacity 0.12s ease;
}

.icon-btn:active {
  transform: scale(0.9);
}

.icon-btn[hidden] {
  display: none;
}

#btn-pause {
  position: absolute;
  top: calc(var(--safe-top) + 10px);
  left: calc(env(safe-area-inset-left, 0px) + 12px);
  z-index: 26;
}

#sound-toggles {
  position: absolute;
  top: calc(var(--safe-top) + 10px);
  right: calc(env(safe-area-inset-right, 0px) + 12px);
  display: flex;
  gap: 8px;
  z-index: 40; /* above overlays so it's always reachable */
}

/* A muted icon button reads dimmed with a slash-ish look. */
.icon-btn.muted {
  opacity: 0.5;
  border-color: rgba(255, 120, 120, 0.6);
  background: rgba(60, 16, 16, 0.7);
}

/* --------------------------------------------------------------------------
   Secondary buttons / chips inside panels
   -------------------------------------------------------------------------- */
.btn--ghost {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.3), 0 10px 18px rgba(0, 0, 0, 0.35);
  font-size: clamp(14px, 4vw, 18px);
  padding: 12px clamp(22px, 7vw, 40px);
  margin-top: 12px;
}

.btn--ghost:active {
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.3), 0 5px 12px rgba(0, 0, 0, 0.35);
}

.btn--online {
  background: linear-gradient(180deg, #3ddc84, #22a85e);
  box-shadow: 0 8px 0 #157a43, 0 12px 22px rgba(0, 0, 0, 0.4);
  margin-top: 12px;
}

.btn--online:active {
  box-shadow: 0 3px 0 #157a43, 0 6px 14px rgba(0, 0, 0, 0.4);
}

.panel .btn {
  display: block;
  width: 100%;
  max-width: 320px;
  margin-left: auto;
  margin-right: auto;
}

/* --------------------------------------------------------------------------
   Finding-match spinner
   -------------------------------------------------------------------------- */
.spinner {
  width: clamp(56px, 16vw, 80px);
  height: clamp(56px, 16vw, 80px);
  margin: 0 auto 18px;
  border-radius: 50%;
  border: 6px solid rgba(255, 255, 255, 0.15);
  border-top-color: #ffe14d;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --------------------------------------------------------------------------
   Opponent-left overlay
   -------------------------------------------------------------------------- */
.opponent-left-icon {
  font-size: clamp(48px, 16vw, 86px);
  line-height: 1;
  margin-bottom: 6px;
  animation: pop-in 0.5s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.sound-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 18px;
}

.chip {
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  font-size: clamp(12px, 3.6vw, 15px);
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border: 1.5px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  padding: 8px 16px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background 0.12s ease, opacity 0.12s ease;
}

.chip.muted {
  opacity: 0.45;
  text-decoration: line-through;
  border-color: rgba(255, 120, 120, 0.5);
}

/* --------------------------------------------------------------------------
   How-to-play overlay
   -------------------------------------------------------------------------- */
.panel--howto {
  text-align: left;
}

.howto-list {
  list-style: none;
  margin: 14px 0 22px;
  padding: 0;
  font-size: clamp(13px, 3.7vw, 16px);
  line-height: 1.5;
}

.howto-list li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
}

.howto-ico {
  flex: 0 0 auto;
  font-size: 1.2em;
}

.howto-list kbd {
  display: inline-block;
  min-width: 1.4em;
  text-align: center;
  padding: 1px 6px;
  font-family: inherit;
  font-size: 0.85em;
  color: #06210f;
  background: #ffe14d;
  border-radius: 6px;
  box-shadow: 0 2px 0 #b9770c;
}

.panel--howto .title {
  text-align: center;
}

/* --------------------------------------------------------------------------
   Winner banner on the match-over screen
   -------------------------------------------------------------------------- */
.winner-banner {
  font-size: clamp(48px, 16vw, 86px);
  line-height: 1;
  margin-bottom: 6px;
  animation: pop-in 0.5s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

@keyframes pop-in {
  0% { transform: scale(0) rotate(-30deg); opacity: 0; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
  .team__score,
  .btn,
  .touch-btn,
  .icon-btn,
  .chip,
  .overlay,
  .joystick__base,
  .joystick__stick {
    transition: none;
  }
  .winner-banner {
    animation: none;
  }
}

/* --------------------------------------------------------------------------
   Forced-landscape fallback (phones in portrait with no native lock)

   orientation.js sets the inline width/height/transform in CSS px so they
   exactly match window.innerHeight/innerWidth (robust to mobile URL-bar
   resizes). The values below are a static fallback that produces the same
   result if those inline styles have not been applied yet. The rotate is a
   purely visual transform: clientWidth/clientHeight still report the swapped
   (landscape) layout box, so game._resize() reads the correct logical size and
   the on-screen touch buttons (children of #game-root) rotate with the game
   and stay hit-testable.
   -------------------------------------------------------------------------- */
body.force-landscape #game-root {
  width: 100vh;
  height: 100vw;
  transform-origin: top left;
  /* Rotate 90° about the top-left corner, then shift right by the viewport
     width so the rotated box lands back inside the portrait viewport. */
  transform: translateX(100vw) rotate(90deg);
}

/* While rotated, the physical notch/home-bar insets are rotated too. Remap the
   safe-area vars so UI anchored with --safe-* keeps clear of them: the device's
   left inset becomes the rotated layout's top, and the device's top inset
   becomes the rotated layout's right. */
body.force-landscape {
  --safe-top: env(safe-area-inset-left, 0px);
  --safe-bottom: env(safe-area-inset-right, 0px);
}

/* --------------------------------------------------------------------------
   Connection quality dot
   -------------------------------------------------------------------------- */
.quality-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-left: 8px;
  background: #3ddc84;
  box-shadow: 0 0 6px #3ddc84;
  transition: background 0.3s ease, box-shadow 0.3s ease;
  vertical-align: middle;
}

.quality-dot.fair {
  background: #ffb01f;
  box-shadow: 0 0 6px #ffb01f;
}

.quality-dot.poor {
  background: #ff4646;
  box-shadow: 0 0 6px #ff4646;
}

/* --------------------------------------------------------------------------
   Reconnecting overlay
   -------------------------------------------------------------------------- */
#reconnecting .panel {
  background: rgba(10, 24, 16, 0.92);
}

#rotate-overlay {
  display: none;
}

body.show-rotate-hint #rotate-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(14px, 5vw, 24px);
  padding: 24px;
  text-align: center;
  background: rgba(4, 12, 8, 0.96);
}

.rotate-overlay__icon {
  font-size: clamp(56px, 22vw, 110px);
  line-height: 1;
  animation: rotate-hint 1.8s ease-in-out infinite;
}

.rotate-overlay__text {
  font-size: clamp(16px, 5vw, 22px);
  font-weight: 800;
  letter-spacing: 0.03em;
  max-width: 22ch;
}

@keyframes rotate-hint {
  0%, 38% { transform: rotate(0deg); }
  62%, 100% { transform: rotate(90deg); }
}

@media (prefers-reduced-motion: reduce) {
  .rotate-overlay__icon {
    animation: none;
  }
}
