/* Mobile / touch controls — only when body.mobile-controls-on (see game.js) */

body.mobile-controls-on #game-canvas {
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.mobile-controls-root {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 35;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding-left: max(8px, env(safe-area-inset-left));
  padding-right: max(8px, env(safe-area-inset-right));
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

body.mobile-controls-on #screen-game,
body.mobile-controls-on #screen-game * {
  -webkit-tap-highlight-color: transparent;
}

body.mobile-controls-on #screen-game *:not(input):not(textarea):not(select):not(option) {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.mobile-controls-root.hidden {
  display: none !important;
}

.mobile-action-btn.hidden {
  display: none !important;
}

.mobile-portrait-hint {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  max-width: min(92vw, 420px);
  text-align: center;
  font-size: 0.85rem;
  color: var(--text);
  background: rgba(22, 27, 34, 0.92);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  pointer-events: none;
  z-index: 36;
}

.mobile-portrait-hint.hidden {
  display: none;
}

/* "Touch controls are off" prompt — shown on coarse-pointer devices in-game when controls are disabled */
.mobile-controls-off-hint {
  display: none;
  position: fixed;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
  color: var(--text);
  background: rgba(22, 27, 34, 0.92);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  z-index: 40;
  pointer-events: auto;
}

.mobile-controls-off-hint.hidden {
  display: none !important;
}

.mobile-controls-enable-btn {
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.mobile-controls-enable-btn:active {
  background: #1d4ed8;
}

.mobile-controls-keep-btn {
  background: transparent;
  color: var(--text-muted, #8b9dc3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.mobile-controls-keep-btn:hover {
  background: rgba(255,255,255,0.06);
}

@media (pointer: coarse) {
  body:not(.mobile-controls-on) #screen-game.active .mobile-controls-off-hint:not(.hidden) {
    display: flex;
  }
}

/* Camera follow hint — offset above the touch-controls hint so they don't overlap */
.mobile-camera-follow-hint:not(.hidden) {
  display: flex;
}
.mobile-camera-follow-hint {
  bottom: max(62px, calc(env(safe-area-inset-bottom) + 58px));
}

/* Desktop hint: show on any pointer type when not dismissed */
#screen-game.active #mobile-controls-desktop-hint:not(.hidden) {
  display: flex;
}

@media (pointer: coarse) {
}

@media (orientation: landscape) {
  body.mobile-controls-on .mobile-portrait-hint {
    display: none !important;
  }
}

@media (orientation: portrait) and (pointer: coarse) {
  /* Portrait: block gameplay UI and show rotate instruction only.
     Only applies when touch controls are enabled. */
  body.mobile-controls-on #screen-game.active .hud,
  body.mobile-controls-on #screen-game.active .shot-clock-bar {
    display: none !important;
  }

  body.mobile-controls-on #screen-game.active #game-canvas,
  body.mobile-controls-on #screen-game.active #game-chat-overlay,
  body.mobile-controls-on #screen-game.active #goal-banner,
  body.mobile-controls-on #screen-game.active #mobile-shot-bars,
  body.mobile-controls-on #screen-game.active #game-menu-overlay,
  body.mobile-controls-on #screen-game.active #vote-kick-banner,
  body.mobile-controls-on #screen-game.active #period-break-overlay,
  body.mobile-controls-on #screen-game.active #pause-overlay,
  body.mobile-controls-on #screen-game.active #end-overlay,
  body.mobile-controls-on #screen-game.active #game-intro-overlay,
  body.mobile-controls-on #screen-game.active #countdown-overlay {
    display: none !important;
  }

  body.mobile-controls-on #screen-game.active .mobile-joystick-root,
  body.mobile-controls-on #screen-game.active .mobile-pan-joystick-root,
  body.mobile-controls-on #screen-game.active .mobile-zoom-buttons,
  body.mobile-controls-on #screen-game.active .mobile-action-buttons,
  body.mobile-controls-on #screen-game.active .mobile-utility-btns {
    display: none !important;
  }

  body.mobile-controls-on #screen-game.active .mobile-controls-root,
  body.mobile-controls-on #screen-game.active .mobile-controls-root.hidden {
    display: flex !important;
    justify-content: center;
    align-items: center;
    padding: max(14px, env(safe-area-inset-top))
      max(14px, env(safe-area-inset-right))
      max(14px, env(safe-area-inset-bottom))
      max(14px, env(safe-area-inset-left));
    pointer-events: none;
  }

  body.mobile-controls-on #screen-game.active .mobile-portrait-hint,
  body.mobile-controls-on #screen-game.active .mobile-portrait-hint.hidden {
    display: block !important;
    position: static;
    transform: none;
    max-width: min(92vw, 560px);
    text-align: center;
    font-size: clamp(1.2rem, 4.6vw, 2rem);
    font-weight: 900;
    line-height: 1.25;
    letter-spacing: 0.02em;
    color: #eef6ff;
    background: rgba(12, 16, 26, 0.88);
    border: 1px solid rgba(120, 155, 205, 0.6);
    border-radius: 14px;
    padding: 20px 22px;
    box-shadow: 0 10px 34px rgba(0, 0, 0, 0.42);
    text-transform: uppercase;
  }
}

.mobile-joystick-root {
  position: absolute;
  left: max(12px, env(safe-area-inset-left));
  bottom: max(12px, env(safe-area-inset-bottom));
  width: 132px;
  height: 132px;
  pointer-events: auto;
}

.mobile-joystick-base {
  position: relative;
  width: 100%;
  height: 100%;
  touch-action: none;
  border-radius: 50%;
  background: rgba(22, 27, 34, 0.75);
  border: 2px solid var(--border);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.mobile-joystick-knob {
  position: absolute;
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  left: 50%;
  top: 50%;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--blue) 0%, var(--blue-dark) 100%);
  border: 2px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  touch-action: none;
}

.mobile-action-buttons {
  position: absolute;
  right: max(10px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  align-content: flex-end;
  gap: 8px;
  max-height: min(70vh, 420px);
  width: auto;
  pointer-events: auto;
}

.mobile-action-btn {
  min-width: 52px;
  min-height: 48px;
  padding: 8px 12px;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(22, 27, 34, 0.9);
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  -webkit-tap-highlight-color: transparent;
}

.mobile-action-btn:focus,
.mobile-action-btn:focus-visible,
.mobile-joystick-base:focus,
.mobile-joystick-base:focus-visible,
.mobile-pan-joystick-base:focus,
.mobile-pan-joystick-base:focus-visible {
  outline: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.mobile-action-btn:active {
  transform: scale(0.96);
  background: var(--panel2);
}

.mobile-action-btn--small {
  min-height: 40px;
  font-size: 0.75rem;
}

.mobile-pan-joystick-root {
  position: absolute;
  left: max(36px, env(safe-area-inset-left));
  bottom: max(148px, calc(env(safe-area-inset-bottom) + 138px));
  width: 76px;
  height: 76px;
  pointer-events: auto;
}

.mobile-pan-joystick-base {
  position: relative;
  width: 100%;
  height: 100%;
  touch-action: none;
  border-radius: 50%;
  background: rgba(22, 27, 34, 0.62);
  border: 1px solid var(--border);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.28);
}

.mobile-pan-joystick-knob {
  position: absolute;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  left: 50%;
  top: 50%;
  border-radius: 50%;
  background: linear-gradient(145deg, #8ea0b8 0%, #66778f 100%);
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  touch-action: none;
}

.mobile-zoom-buttons {
  position: absolute;
  left: max(8px, env(safe-area-inset-left));
  bottom: max(228px, calc(env(safe-area-inset-bottom) + 206px));
  display: flex;
  flex-direction: row;
  gap: 4px;
  pointer-events: auto;
}

/* Utility buttons (PP, ⇆ reverse, G goalie) — top-left corner */
.mobile-utility-btns {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  left: max(8px, env(safe-area-inset-left));
  display: flex;
  flex-direction: row;
  gap: 4px;
  pointer-events: auto;
}

body.mobile-controls-on.mobile-controls-reversed .mobile-utility-btns {
  left: auto;
  right: max(8px, env(safe-area-inset-right));
}

body.mobile-controls-on.mobile-controls-reversed .mobile-joystick-root {
  left: auto;
  right: max(12px, env(safe-area-inset-right));
}

body.mobile-controls-on.mobile-controls-reversed .mobile-pan-joystick-root {
  left: auto;
  right: max(36px, env(safe-area-inset-right));
}

body.mobile-controls-on.mobile-controls-reversed .mobile-zoom-buttons {
  left: auto;
  right: max(8px, env(safe-area-inset-right));
}

body.mobile-controls-on.mobile-controls-reversed .mobile-action-buttons {
  right: auto;
  left: max(10px, env(safe-area-inset-left));
  align-content: flex-start;
}

.options-select {
  margin-left: auto;
  max-width: 200px;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  font-size: 0.9rem;
}

.options-mobile-pref {
  align-items: center;
  gap: 10px;
}

/* -------------------------------------------------------------------------- */
/* Broad mobile layout pass (menus, lobby, loading, overlays)                */
/* -------------------------------------------------------------------------- */
@media (max-width: 900px) {
  html, body {
    overflow: auto;
  }

  .screen {
    align-items: stretch;
    justify-content: stretch;
    overflow-y: auto;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }

  .center-card {
    max-width: none;
    width: 100%;
    padding: 22px 18px;
    gap: 10px;
    margin: auto 0;
  }

  .logo-zealot {
    font-size: 2.2rem;
    letter-spacing: 2px;
  }

  .logo-hockey {
    font-size: 1.15rem;
    letter-spacing: 4px;
  }

  .tagline {
    font-size: 0.72rem;
    letter-spacing: 1px;
    margin-bottom: 16px;
  }

  .btn {
    padding: 11px 14px;
    font-size: 0.88rem;
  }

  .browser-container {
    width: 100%;
    max-height: none;
    min-height: 0;
  }

  .browser-header {
    padding: 12px;
    gap: 10px;
    flex-wrap: wrap;
  }

  .browser-header h2 {
    width: 100%;
    font-size: 1.02rem;
  }

  .header-actions {
    width: 100%;
  }

  .header-actions .btn {
    flex: 1;
  }

  .browser-container .lobby-list {
    max-height: none;
  }

  .active-game-item,
  .lobby-item {
    padding: 10px 12px;
    gap: 8px;
  }

  .active-game-score {
    font-size: 1.08rem;
  }

  .lobby-room {
    width: 100%;
    max-height: none;
    border-radius: 10px;
  }

  .lobby-header {
    padding: 12px;
    flex-wrap: wrap;
    gap: 10px;
  }

  .lobby-header h2 {
    width: 100%;
    font-size: 1rem;
  }

  .lobby-header > div {
    width: 100%;
    display: flex;
    gap: 8px;
  }

  .lobby-header > div .btn {
    flex: 1;
  }

  .teams-container {
    grid-template-columns: 1fr;
  }

  .team-column {
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 10px;
    min-height: 120px;
  }

  .team-column:last-child {
    border-bottom: none;
  }

  .lobby-chat {
    margin-top: 0;
    padding: 8px;
  }

  .lobby-chat-messages {
    max-height: 96px;
  }

  .loading-screen {
    min-width: 0;
    width: 100%;
    max-width: none;
    padding: 20px 14px;
  }

  .loading-main-panel {
    min-width: 0;
    padding: 20px 14px 18px;
  }

  .loading-tips {
    padding: 12px 12px 10px;
  }

  .loading-tips-badge-label {
    font-size: 1rem;
  }

  .loading-logo {
    font-size: 1.65rem;
    letter-spacing: 2px;
  }

  .loading-subtitle {
    font-size: 0.72rem;
    letter-spacing: 1.4px;
  }

  .modal-card,
  .modal-box,
  .horn-modal-card,
  .boost-modal-card,
  .options-card {
    width: 100%;
    max-width: none;
  }

  .modal-card,
  .modal-box,
  .horn-modal-card,
  .boost-modal-card {
    padding: 18px 14px;
  }

  .options-card {
    max-height: calc(100dvh - 16px);
    border-radius: 10px;
  }

  .options-header {
    padding: 12px 14px 8px;
  }

  .options-body {
    padding: 2px 14px 6px;
  }

  .options-actions {
    padding: 10px 14px;
    gap: 8px;
  }

  .options-card h2 {
    font-size: 1.25rem;
    letter-spacing: 2px;
    margin-bottom: 4px;
  }

  .options-help {
    font-size: 0.78rem;
  }

  .options-section-title {
    font-size: 0.7rem;
    letter-spacing: 2px;
  }

  .options-section {
    margin-top: 10px;
  }

  .options-toggle-row {
    font-size: 0.8rem;
    gap: 8px;
    padding: 2px 0;
  }

  .options-toggle-row input[type="checkbox"] {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
  }

  .rebind-list {
    grid-template-columns: 1fr;
  }

  .options-slider-row,
  .options-name-row {
    flex-direction: column;
    align-items: stretch;
  }

  .options-slider-control {
    min-width: 0;
    width: 100%;
  }

  .options-slider-control input[type="range"] {
    width: 100%;
  }

  .modal-actions,
  .horn-modal-actions,
  .customize-actions {
    flex-direction: column;
    gap: 8px;
  }

  .options-actions {
    flex-wrap: wrap;
    gap: 8px;
  }

  .options-actions .btn {
    flex: 1 1 auto;
    min-width: 80px;
  }

  .modal-actions .btn,
  .horn-modal-actions .btn,
  .customize-actions .btn {
    width: 100%;
  }

  .customize-card {
    width: 100%;
    max-height: min(92vh, 100dvh - 16px);
    min-height: 0;
  }

  .horn-grid {
    grid-template-columns: 1fr;
  }

  .horn-card-wide {
    grid-column: auto;
  }

  .horn-playlist-slot-row,
  .horn-lib-row {
    flex-direction: column;
    align-items: stretch;
  }

  .horn-playlist-slot-row .btn,
  .horn-lib-row .btn {
    width: 100%;
  }

  .boost-skin-grid {
    grid-template-columns: 1fr 1fr;
  }

  .boost-skin-preview {
    width: 100%;
    max-width: 130px;
    height: auto;
    aspect-ratio: 12 / 7;
  }
}

@media (max-width: 900px) and (orientation: landscape) {
  .screen {
    padding-top: max(6px, env(safe-area-inset-top));
    padding-bottom: max(6px, env(safe-area-inset-bottom));
  }

  .center-card {
    max-width: 620px;
    margin: 0 auto;
  }

  .teams-container {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .team-column {
    border-bottom: none;
    border-right: 1px solid var(--border);
    min-height: 0;
  }

  .team-column:last-child {
    border-right: none;
  }
}

@media (max-width: 900px), (max-height: 760px) {
  .hud {
    padding: 3px 60px 4px 18px;
  }

  .team-label {
    font-size: 0.86rem;
    letter-spacing: 1.6px;
  }

  .score-num {
    font-size: 1.45rem;
    min-width: 22px;
  }

  .score-dash {
    font-size: 1.2rem;
  }

  #game-clock {
    font-size: 1.35rem;
    letter-spacing: 1px;
  }

  #game-period {
    font-size: 0.82rem;
    letter-spacing: 1px;
  }

  .hud-shot-counter {
    font-size: 0.62rem;
  }

  .hud .btn-game-menu,
  .hud .btn-fullscreen {
    top: calc(100% + 2px);
    padding: 2px 6px;
  }

  .vote-kick-banner {
    top: max(6px, env(safe-area-inset-top));
    left: max(6px, env(safe-area-inset-left));
    max-width: min(92vw, 300px);
  }

  .goal-banner {
    font-size: clamp(1.6rem, 6.2vw, 2.9rem);
    letter-spacing: 1px;
  }

  #game-chat-overlay {
    width: min(68vw, 270px);
    left: 6px;
    bottom: 70px;
  }

  .pause-card {
    min-width: 0;
    width: min(92vw, 360px);
    padding: 20px 18px;
  }

  .pause-title {
    font-size: 1.5rem;
    letter-spacing: 2px;
  }

  .pause-countdown {
    font-size: 2.3rem;
  }

  .end-card {
    min-width: 0;
    width: min(92vw, 520px);
    padding: 18px 12px;
    gap: 10px;
    max-height: calc(100% - 14px);
    overflow-y: auto;
  }

  .end-card h2 {
    font-size: 1.4rem;
    letter-spacing: 1.5px;
  }

  .break-card {
    width: min(96vw, 980px);
    padding: 10px 8px;
    max-height: calc(100% - 14px);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
  }

  .break-card h2 {
    font-size: 1.2rem;
    letter-spacing: 1.5px;
  }
}

/* -------------------------------------------------------------------------- */
/* Mobile touch gameplay: full-viewport rink (object-fit: cover). Any width — */
/* tablets in landscape were still capped at 900px and showed side/bottom bg. */
/* -------------------------------------------------------------------------- */
body.mobile-controls-on #screen-game.screen {
  padding: 0 !important;
}

body.mobile-controls-on #screen-game.screen.active {
  align-items: stretch;
  justify-content: stretch;
  overflow: hidden !important;
}

body.mobile-controls-on .game-wrapper {
  justify-content: stretch;
  align-items: stretch;
  padding: 0 !important;
  flex: 1;
  width: 100%;
  max-width: none;
  height: 100dvh;
  min-height: 100dvh;
  max-height: 100dvh;
  box-sizing: border-box;
}

body.mobile-controls-on #game-content {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 0;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/*
 * Size the canvas-container to exactly the canvas dimensions (not full screen).
 * This ensures transform-origin: center aligns with the rink center, so CSS
 * zoom/pan transforms scale around the correct point without clipping boards.
 *
 * Width: whichever is smaller — full viewport width, or the width that makes
 *        the canvas exactly 100dvh tall (16:9 of screen height).
 * Height: derived from width via aspect-ratio.
 */
body.mobile-controls-on .canvas-container {
  position: relative;
  inset: unset;
  width: min(100vw, calc(100dvh * 16 / 9)) !important;
  height: auto !important;
  aspect-ratio: 16 / 9 !important;
  max-width: none !important;
  flex: none;
  border-radius: 0;
  z-index: 0;
  transform: translate(var(--mobile-pan-x, 0px), var(--mobile-pan-y, 0px))
    scale(var(--mobile-rink-zoom, 1));
  transform-origin: center center;
}

body.mobile-controls-on #game-canvas {
  width: 100% !important;
  height: auto !important;
}

/*
 * Full-bleed rink sits in a covering .canvas-container; the scoreboard must be
 * position:fixed + z-index above the rink for every viewport width (the compact
 * HUD rules below used to be max-width:900px only, so tablets hid the bar).
 */
body.mobile-controls-on #screen-game.screen.active .hud {
  position: fixed;
  top: max(6px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: auto;
  max-width: min(96vw, 1173px);
  min-height: 40px;
  padding: 9px 16px 11px;
  box-sizing: border-box;
  border-radius: 8px;
  border: 1px solid rgba(120, 145, 178, 0.28);
  background: rgba(10, 14, 22, 0.22);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 40;
  pointer-events: none;
  opacity: 0.88;
  transition: opacity 0.16s ease;
}

body.mobile-controls-on #game-canvas,
body.mobile-controls-on #game-3d-canvas {
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  border-radius: 0;
  object-fit: cover;
  object-position: center center;
}

body.mobile-controls-on .shot-clock-bar {
  position: fixed;
  left: 0;
  right: 0;
  width: 100% !important;
  max-width: none !important;
  top: max(calc(env(safe-area-inset-top) + 44px), 48px);
  z-index: 39;
  padding: 0 max(8px, env(safe-area-inset-left)) 0 max(8px, env(safe-area-inset-right));
  box-sizing: border-box;
  pointer-events: none;
}

body.mobile-controls-on #game-chat-overlay {
  bottom: 8px;
}

body.mobile-controls-on .mobile-controls-root {
  z-index: 45;
}

body.mobile-controls-on .mobile-joystick-root {
  bottom: max(8px, env(safe-area-inset-bottom));
}

body.mobile-controls-on .mobile-action-buttons {
  bottom: max(8px, env(safe-area-inset-bottom));
}

body.mobile-controls-on .mobile-joystick-base,
body.mobile-controls-on .mobile-action-btn {
  opacity: 0.92;
}

/* Hide seam buttons on the scoreboard HUD only — keep intro-bar copies during broadcast intro */
body.mobile-controls-on .hud .btn-fullscreen,
body.mobile-controls-on .hud .btn-game-menu {
  display: none !important;
}

/* -------------------------------------------------------------------------- */
/* Touch gameplay refinement: bigger rink, left scoreboard, right cooldowns   */
/* -------------------------------------------------------------------------- */
body.mobile-controls-on .mobile-action-btn {
  position: relative;
  overflow: hidden;
}

body.mobile-controls-on .mobile-action-btn::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc((1 - var(--mobile-cd-frac, 1)) * 100%);
  background: linear-gradient(
    to top,
    rgba(20, 35, 58, 0.95) 0%,
    rgba(18, 56, 108, 0.82) 55%,
    rgba(66, 170, 255, 0.62) 100%
  );
  border-top: 1px solid rgba(130, 220, 255, 0.92);
  pointer-events: none;
}

body.mobile-controls-on .mobile-action-btn-disabled {
  color: #b7d7ff;
  border-color: #4a8fd6;
  box-shadow: inset 0 0 0 1px rgba(120, 200, 255, 0.22);
}

body.mobile-controls-on .mobile-action-btn-disabled::before {
  background: linear-gradient(
    to top,
    rgba(36, 84, 140, 0.95) 0%,
    rgba(26, 124, 214, 0.82) 55%,
    rgba(98, 210, 255, 0.72) 100%
  );
  border-top-color: rgba(185, 240, 255, 0.96);
}

@media (max-width: 900px) and (orientation: landscape) {
  body.mobile-controls-on #game-chat-overlay {
    bottom: 6px;
    left: 6px;
    width: min(44vw, 250px);
  }

  body.mobile-controls-on .mobile-shot-bars {
    bottom: 11px;
    width: min(48vw, 300px);
    z-index: 36;
  }

  body.mobile-controls-on .mobile-controls-root {
    z-index: 45;
  }

  body.mobile-controls-on .mobile-joystick-root {
    width: 116px;
    height: 116px;
    left: max(6px, env(safe-area-inset-left));
    bottom: max(6px, env(safe-area-inset-bottom));
  }

  body.mobile-controls-on .mobile-pan-joystick-root {
    width: 64px;
    height: 64px;
    left: max(32px, env(safe-area-inset-left));
    bottom: max(124px, calc(env(safe-area-inset-bottom) + 112px));
  }

  body.mobile-controls-on .mobile-zoom-buttons {
    left: max(8px, env(safe-area-inset-left));
    bottom: max(200px, calc(env(safe-area-inset-bottom) + 186px));
    gap: 3px;
  }

  body.mobile-controls-on .mobile-action-buttons {
    right: max(-4px, env(safe-area-inset-right));
    bottom: max(4px, env(safe-area-inset-bottom));
    gap: 4px;
    align-items: flex-end;
  }

  /* Main ability stack: nudge farther right so rink center stays clearer. */
  body.mobile-controls-on #mobile-btn-boost,
  body.mobile-controls-on #mobile-btn-slide,
  body.mobile-controls-on #mobile-btn-onetime,
  body.mobile-controls-on #mobile-btn-stop,
  body.mobile-controls-on #mobile-btn-check {
    margin-right: -16px;
  }

  /* Small right-edge utility buttons (stats, menu only — PP/reverse/goalie moved to utility bar). */
  body.mobile-controls-on #mobile-btn-stats,
  body.mobile-controls-on #mobile-btn-menu {
    min-width: 40px;
    min-height: 30px;
    font-size: 0.62rem;
    margin-right: -14px;
    padding: 4px 4px;
  }

  /* Utility bar (PP, reverse, goalie) — top-left in landscape, small. */
  body.mobile-controls-on .mobile-utility-btns {
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    gap: 4px;
  }

  body.mobile-controls-on .mobile-utility-btns .mobile-action-btn {
    min-width: 36px;
    min-height: 28px;
    font-size: 0.6rem;
    padding: 3px 5px;
  }

  /* Keep menu far from gameplay buttons on mobile. */
  body.mobile-controls-on #mobile-btn-menu {
    position: fixed;
    top: max(8px, env(safe-area-inset-top));
    right: max(8px, env(safe-area-inset-right));
    margin-right: 0;
    min-width: 34px;
    min-height: 30px;
    z-index: 46;
  }

  body.mobile-controls-on #mobile-btn-stats {
    position: fixed;
    top: max(8px, env(safe-area-inset-top));
    right: max(46px, calc(env(safe-area-inset-right) + 42px));
    margin-right: 0;
    min-width: 34px;
    min-height: 30px;
    z-index: 46;
  }

  body.mobile-controls-on.mobile-controls-reversed .mobile-joystick-root {
    left: auto;
    right: max(6px, env(safe-area-inset-right));
  }

  body.mobile-controls-on.mobile-controls-reversed .mobile-pan-joystick-root {
    left: auto;
    right: max(32px, env(safe-area-inset-right));
  }

  body.mobile-controls-on.mobile-controls-reversed .mobile-zoom-buttons {
    left: auto;
    right: max(8px, env(safe-area-inset-right));
  }

  body.mobile-controls-on.mobile-controls-reversed .mobile-action-buttons {
    right: auto;
    left: max(-4px, env(safe-area-inset-left));
    align-content: flex-start;
    align-items: flex-start;
  }

  body.mobile-controls-on.mobile-controls-reversed #mobile-btn-boost,
  body.mobile-controls-on.mobile-controls-reversed #mobile-btn-slide,
  body.mobile-controls-on.mobile-controls-reversed #mobile-btn-onetime,
  body.mobile-controls-on.mobile-controls-reversed #mobile-btn-stop,
  body.mobile-controls-on.mobile-controls-reversed #mobile-btn-check {
    margin-right: 0;
    margin-left: -16px;
  }

  body.mobile-controls-on.mobile-controls-reversed #mobile-btn-stats,
  body.mobile-controls-on.mobile-controls-reversed #mobile-btn-menu {
    margin-right: 0;
    margin-left: -14px;
  }

  body.mobile-controls-on.mobile-controls-reversed .mobile-utility-btns {
    left: auto;
    right: max(8px, env(safe-area-inset-right));
  }

  body.mobile-controls-on.mobile-controls-reversed #mobile-btn-menu {
    right: auto;
    left: max(8px, env(safe-area-inset-left));
    margin-left: 0;
  }

  body.mobile-controls-on.mobile-controls-reversed #mobile-btn-stats {
    right: auto;
    left: max(46px, calc(env(safe-area-inset-left) + 42px));
    margin-left: 0;
  }

  body.mobile-controls-on .mobile-action-btn {
    min-width: 58px;
    min-height: 44px;
    font-size: 0.82rem;
    padding: 6px 8px;
    touch-action: none;
  }

  body.mobile-controls-on .mobile-action-btn--small {
    min-height: 38px;
    font-size: 0.72rem;
  }

  body.mobile-controls-on .goal-banner {
    font-size: clamp(1.45rem, 4.6vw, 2.4rem);
  }
}

@media (max-width: 900px) and (orientation: landscape) {
  body.mobile-controls-on .break-card {
    width: min(96vw, 980px);
    padding: 8px 6px;
  }
  body.mobile-controls-on .break-card h2 {
    font-size: 1.12rem;
    letter-spacing: 1px;
  }
  body.mobile-controls-on .break-subtitle {
    font-size: 0.78rem;
  }
  body.mobile-controls-on .break-teams {
    gap: 8px;
    margin-top: 6px;
  }
  body.mobile-controls-on .break-team {
    padding: 7px 6px 5px;
  }
  body.mobile-controls-on .break-team-title {
    font-size: 1.15rem;
    letter-spacing: 1.6px;
  }
  body.mobile-controls-on .break-player-name {
    width: 110px;
    font-size: 1.06rem;
  }
  body.mobile-controls-on .break-player-stats {
    grid-template-columns: repeat(12, minmax(30px, 1fr)) minmax(44px, 1.55fr);
    gap: 3px;
    min-width: 0;
  }
  body.mobile-controls-on .break-stat-cell {
    padding: 6px 3px 5px;
    border-radius: 6px;
  }
  body.mobile-controls-on .break-stat-label {
    font-size: 0.72rem;
    letter-spacing: 0.38px;
  }
  body.mobile-controls-on .break-stat-value {
    font-size: 1.02rem;
  }
  body.mobile-controls-on .end-card {
    width: min(98vw, 720px);
    padding: 12px 8px;
  }
  body.mobile-controls-on .end-card h2 {
    font-size: 1.05rem;
    letter-spacing: 1px;
  }
  body.mobile-controls-on .end-team {
    padding: 6px 5px 4px;
  }
  body.mobile-controls-on .end-team-title {
    font-size: 0.78rem;
    letter-spacing: 1.6px;
  }
}

/* -------------------------------------------------------------------------- */
/* Mobile scoreboard overlay: top-of-rink, compact, transparent               */
/* -------------------------------------------------------------------------- */
@media (max-width: 900px) {
  /* Same specificity as global overlay so these padding/opacity wins on small screens */
  body.mobile-controls-on #screen-game.screen.active .hud {
    max-width: min(98vw, 900px);
    min-height: 34px;
    padding: 7px 10px 8px;
    border-radius: 6px;
    border: 1px solid rgba(120, 145, 178, 0.24);
    background: rgba(10, 14, 22, 0.16);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 40;
    opacity: 0.78;
    transition: opacity 0.16s ease;
  }

  body.mobile-controls-on .hud.mobile-hud-near-action {
    opacity: 0.16;
  }

  body.mobile-controls-on .hud.mobile-hud-over-black {
    background: rgba(255, 255, 255, 0.92);
    border-color: rgba(50, 70, 95, 0.38);
    opacity: 0.94;
  }

  body.mobile-controls-on .hud.mobile-hud-over-black.mobile-hud-near-action {
    opacity: 0.8;
  }

  body.mobile-controls-on .hud-center {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    width: auto;
    gap: 4px;
    flex-wrap: nowrap;
  }

  body.mobile-controls-on .hud-scoreboard {
    display: flex;
    flex-direction: row;
    align-items: center;
    width: auto;
    gap: 4px;
  }

  body.mobile-controls-on .hud-clock-block,
  body.mobile-controls-on .hud-period-block {
    width: auto;
    text-align: center;
  }

  body.mobile-controls-on .hud-period-block {
    flex-direction: row;
    align-items: baseline;
    gap: 5px;
    line-height: 1;
  }

  body.mobile-controls-on .team-label {
    font-size: 0.56rem;
    letter-spacing: 0.8px;
    line-height: 1;
    white-space: nowrap;
  }

  body.mobile-controls-on .score-num {
    font-size: 0.82rem;
    min-width: 11px;
    line-height: 1;
    color: #0b0b0b;
  }

  body.mobile-controls-on .score-dash {
    font-size: 0.7rem;
    line-height: 1;
    color: #0b0b0b;
  }

  body.mobile-controls-on .hud-divider {
    height: 10px;
    margin: 0 4px;
  }

  body.mobile-controls-on #game-clock {
    font-size: 0.86rem;
    letter-spacing: 0.5px;
    white-space: nowrap;
    color: #0b0b0b !important;
  }

  body.mobile-controls-on #game-period {
    font-size: 0.5rem;
    letter-spacing: 0.5px;
    white-space: nowrap;
    color: #0b0b0b;
  }

  body.mobile-controls-on .hud-shot-counter {
    display: none;
  }
}

@media (max-width: 900px) and (orientation: landscape) {
  body.mobile-controls-on #screen-game.screen.active .hud {
    width: min(96vw, 1173px);
    max-width: min(96vw, 1173px);
    min-height: 32px;
    border-radius: 6px;
    padding: 6px 12px 7px;
  }

  body.mobile-controls-on .hud-scoreboard {
    flex-direction: row;
    width: auto;
  }
}

/* PowerPlay button — gold accent when available */
body.mobile-controls-on #mobile-btn-powerplay:not(.mobile-action-btn-disabled) {
  border-color: #f0c040;
  color: #f0c040;
}

/* -------------------------------------------------------------------------- */
/* Mobile: overlays (intro, break, end, pause, menu) use fixed positioning   */
/* so they cover the full viewport regardless of canvas zoom / pan state.    */
/* -------------------------------------------------------------------------- */
body.mobile-controls-on #game-intro-overlay,
body.mobile-controls-on #period-break-overlay,
body.mobile-controls-on #end-overlay,
body.mobile-controls-on #pause-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  border-radius: 0;
}

/* Game menu overlay: fixed so it doesn't pan/zoom with the rink canvas */
body.mobile-controls-on #game-menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 85;
}

/* Game menu card: compact for mobile landscape */
body.mobile-controls-on .game-menu-card {
  padding: 18px 24px;
  gap: 8px;
  min-width: 200px;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
}

body.mobile-controls-on .game-menu-card h2 {
  font-size: 1.1rem;
  letter-spacing: 2px;
  margin-bottom: 2px;
}

body.mobile-controls-on .game-menu-card .btn {
  padding: 8px 18px;
  font-size: 0.85rem;
}

/* Options overlay: position:fixed globally; fully opaque on mobile so panning rink isn't visible */
body.mobile-controls-on #options-overlay {
  background: rgba(7, 9, 13, 0.97);
  padding: 8px max(8px, env(safe-area-inset-right)) 8px max(8px, env(safe-area-inset-left));
  align-items: flex-start;
  overflow-y: auto;
}

body.mobile-controls-on .options-card {
  width: 100%;
  max-width: 680px;
  margin: auto;
  max-height: calc(100dvh - 16px);
  border-radius: 10px;
}

body.mobile-controls-on .options-header {
  padding: 10px 14px 6px;
}

body.mobile-controls-on .options-card h2 {
  font-size: 1.05rem;
  letter-spacing: 2px;
  margin-bottom: 2px;
}

body.mobile-controls-on .options-help {
  font-size: 0.72rem;
}

body.mobile-controls-on .options-body {
  padding: 2px 12px 6px;
}

body.mobile-controls-on .options-section {
  margin-top: 8px;
}

body.mobile-controls-on .options-section-title {
  font-size: 0.68rem;
  letter-spacing: 2px;
}

body.mobile-controls-on .options-slider-row {
  padding: 7px 10px;
  gap: 8px;
  flex-wrap: wrap;
}

body.mobile-controls-on .options-slider-control {
  min-width: 0;
  flex: 1;
}

body.mobile-controls-on .options-slider-control input[type="range"] {
  width: 100%;
  min-width: 100px;
}

body.mobile-controls-on .options-toggle-row {
  font-size: 0.82rem;
}

body.mobile-controls-on .options-actions {
  padding: 8px 12px;
  gap: 6px;
}

/* Hide touch controls while options is open */
body.mobile-options-open .mobile-controls-root {
  visibility: hidden;
  pointer-events: none;
}

/* Sub-menus (goal horn, boost skin, etc.): modal-overlay already fixed; just compact the card */
body.mobile-controls-on .modal-overlay {
  padding: 10px;
}

body.mobile-controls-on .modal-card,
body.mobile-controls-on .modal-card-wide,
body.mobile-controls-on .modal-box {
  width: 100%;
  max-width: none;
  padding: 16px 14px;
  gap: 12px;
  max-height: calc(100dvh - 20px);
  overflow-y: auto;
}

body.mobile-controls-on .modal-title {
  font-size: 1.1rem;
  letter-spacing: 2px;
}

/* HUD controls above fixed full-screen overlays */
body.mobile-controls-on .hud .btn-game-menu,
body.mobile-controls-on .hud .btn-fullscreen {
  z-index: 70;
}

/* Intro overlay — compact layout for mobile landscape */
@media (max-width: 900px) and (orientation: landscape) {
  body.mobile-controls-on .game-intro-overlay {
    overflow-y: auto;
  }

  body.mobile-controls-on .intro-network-bar {
    padding: 5px 12px 4px;
  }

  body.mobile-controls-on .intro-network-logo {
    font-size: 0.88rem;
    letter-spacing: 4px;
  }

  body.mobile-controls-on .intro-main-card {
    padding: 4px 14px 2px;
  }

  body.mobile-controls-on .intro-matchup-label {
    font-size: 0.7rem;
    letter-spacing: 5px;
    margin-bottom: 5px;
  }

  body.mobile-controls-on .intro-team-name-text {
    font-size: 1.5rem;
    letter-spacing: 5px;
  }

  body.mobile-controls-on .intro-team-header {
    padding: 5px 10px 4px;
    gap: 8px;
  }

  body.mobile-controls-on .intro-team-accent {
    height: 28px;
  }

  body.mobile-controls-on .intro-player-list {
    padding: 2px 8px 3px;
    gap: 2px;
  }

  body.mobile-controls-on .intro-player-row {
    padding: 3px 8px;
  }

  body.mobile-controls-on .intro-player-name {
    font-size: 0.72rem;
  }

  body.mobile-controls-on .intro-goalie-badge {
    font-size: 0.62rem;
    padding: 2px 6px 1px;
  }

  body.mobile-controls-on .intro-vs-row {
    margin: 4px 4px;
  }

  body.mobile-controls-on .intro-vs-badge {
    padding: 0 10px;
  }

  body.mobile-controls-on .intro-vs-puck-icon {
    font-size: 1.0rem;
  }

  body.mobile-controls-on .intro-vs-text {
    font-size: 0.85rem;
    letter-spacing: 4px;
  }

  body.mobile-controls-on .intro-bottom-bar {
    padding: 4px 14px 6px;
    gap: 4px;
  }

  body.mobile-controls-on .intro-goalie-hint {
    font-size: 0.68rem;
  }

  body.mobile-controls-on .intro-progress-wrap {
    width: min(380px, 88%);
  }

  body.mobile-controls-on .intro-countdown-label {
    font-size: 0.62rem;
    letter-spacing: 3px;
  }
}

/* Period break overlay — compact, scrollable on mobile */
@media (max-width: 900px) and (orientation: landscape) {
  body.mobile-controls-on #period-break-overlay {
    align-items: flex-start;
    padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
      max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    overflow-y: auto;
  }

  body.mobile-controls-on .break-card {
    margin: auto;
    max-height: calc(100dvh - 12px);
    overflow-y: auto;
  }

  /* Replay layout: stack vertically on small mobile screens */
  body.mobile-controls-on .replay-layout {
    flex-direction: column;
    gap: 6px;
  }

  body.mobile-controls-on .replay-video-wrap {
    max-height: min(40dvh, 260px);
  }

  body.mobile-controls-on .replay-list-col {
    max-height: min(30dvh, 200px);
    overflow-y: auto;
  }

  /* Shot map: stack insights below chart on small screen */
  body.mobile-controls-on .break-shotmap-body {
    grid-template-columns: 1fr;
  }

  body.mobile-controls-on .break-shotmap-insights-col {
    max-height: min(25dvh, 180px);
    overflow-y: auto;
  }
}
