/* Phone navigation shares the main site's bold, centered links and quiet settings. */
.phone-navigation-links, .phone-navigation-settings, .phone-navigation-control-label { display: none; }

html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] .site-header {
  --phone-navigation-left: max(16px, calc(env(safe-area-inset-left, 0px) + 8px));
  --phone-navigation-right: max(16px, calc(env(safe-area-inset-right, 0px) + 8px));
  --phone-navigation-top: calc(76px + env(safe-area-inset-top, 0px));
  --phone-navigation-bottom: max(20px, calc(env(safe-area-inset-bottom, 0px) + 8px));
}
html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] .site-header .menu-toggle {
  position: absolute !important;
  inset: calc(var(--site-header-center-y) - 22px) var(--phone-navigation-right) auto auto !important;
  width: 44px !important; height: 44px !important; min-width: 44px !important; min-height: 44px !important;
  display: grid !important; place-items: center;
  border: 1px solid var(--header-line) !important;
  background: var(--header-control) !important;
  color: var(--header-ink) !important;
  border-radius: 0 !important;
  z-index: 3;
}
html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'].phone-match-active .site-header .menu-toggle {
  position: fixed !important;
  inset: calc(8px + env(safe-area-inset-top, 0px)) var(--phone-navigation-right) auto auto !important;
}
html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] .site-header > .header-controls > :is(.theme-toggle) { display: none !important; }
html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #setup-screen .setup-audio-group { display: none !important; }
html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav:not(.open) { display: none !important; }

html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] .site-header #main-nav.open.phone-navigation-ready {
  position: fixed !important; inset: 0 !important;
  width: 100vw !important; height: 100dvh !important; max-height: 100dvh !important;
  box-sizing: border-box;
  display: grid !important; grid-template-columns: minmax(0, 1fr) !important;
  grid-template-rows: minmax(0, 1fr) auto !important;
  align-items: stretch !important; align-content: stretch !important; justify-content: stretch !important;
  gap: 20px !important;
  padding: var(--phone-navigation-top) var(--phone-navigation-right) var(--phone-navigation-bottom) var(--phone-navigation-left) !important;
  margin: 0 !important; border: 0 !important; border-radius: 0 !important;
  overflow: hidden !important; overscroll-behavior: none;
  background: var(--header-bg) !important; color: var(--header-ink) !important;
  z-index: 1 !important;
}
html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav .phone-navigation-links {
  display: grid; grid-template-columns: minmax(0, 1fr);
  grid-auto-rows: 56px; align-content: center; justify-content: center;
  gap: 12px; min-width: 0; min-height: 0;
}
html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav .phone-navigation-links > .nav-link {
  display: flex !important; align-items: center !important; justify-content: center !important;
  position: relative; width: 100% !important; height: 56px !important; min-height: 56px !important;
  padding: 8px !important; margin: 0 !important;
  font: 800 clamp(24px, 6vw, 32px)/1.15 ScalarNavigation, Orbitron, sans-serif !important;
  letter-spacing: .03em !important; text-align: center !important;
  color: var(--header-ink) !important; border: 0 !important; background: none !important;
  transform: none !important;
}
html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav .phone-navigation-links > .nav-link.active { color: var(--header-accent) !important; }
html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav .phone-navigation-links > .nav-link::after {
  inset: auto 50% 2px auto !important; width: 40px !important; height: 2px !important;
  margin: 0 !important; transform: translateX(50%) !important;
}
html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav .phone-navigation-settings {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch; gap: 8px; min-width: 0; min-height: 0;
  border-top: 1px solid var(--header-line); padding-top: 12px;
}
html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav .phone-navigation-settings :is(.phone-match-tools, #game-site-audio, .ghdr-right) {
  display: contents !important; position: static !important; margin: 0 !important; padding: 0 !important;
}
html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav .phone-navigation-settings :is(button, .theme-toggle, #phone-log-toggle, #btn-exit-game) {
  position: relative !important; inset: auto !important; transform: none !important;
  display: flex !important; flex-direction: column; align-items: center; justify-content: center;
  box-sizing: border-box;
  width: 100% !important; height: 48px !important; min-width: 44px !important; min-height: 44px !important;
  margin: 0 !important; padding: 5px 6px !important; gap: 2px !important;
  border: 1px solid var(--header-line) !important; border-radius: 0 !important;
  background: var(--header-control) !important; color: var(--header-ink) !important;
  font: 700 12px/1.25 Inter, sans-serif !important; letter-spacing: 0 !important;
  box-shadow: none !important; clip-path: none !important;
  visibility: visible; pointer-events: auto;
}
html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav .phone-navigation-settings :is(button, #btn-exit-game)::before,
html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav .phone-navigation-settings :is(button, #btn-exit-game)::after { display: none !important; content: none !important; }
html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav .phone-navigation-settings :is(.theme-label, .phone-navigation-control-label) {
  display: block !important; font: 700 10px/1.2 Inter, sans-serif !important; letter-spacing: 0;
}
html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav .phone-navigation-settings svg {
  flex: 0 0 auto; width: 18px !important; height: 18px !important;
}
html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav .phone-navigation-settings #btn-exit-game { font-size: 18px !important; }
html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav .phone-navigation-settings #phone-log-toggle { font-size: 11px !important; }
html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav .phone-navigation-settings .theme-toggle { order: 1 !important; }
html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav .phone-navigation-settings #in-game-music-toggle { order: 3 !important; }
html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav .phone-navigation-settings #in-game-audio-toggle { order: 4 !important; }
html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav .phone-navigation-settings #phone-log-toggle { order: 5 !important; }
html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav .phone-navigation-settings #btn-exit-game { order: 6 !important; }
html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play']:not(.game-active) .site-header #main-nav .phone-navigation-settings :is(#phone-log-toggle, #btn-exit-game) { display: none !important; }
html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav :is(#phone-inspect-toggle, #left-sidebar, #rb-sidebar, .phone-tutorial-details) { display: none !important; }
html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav :is(a, button):focus-visible { outline: 2px solid var(--header-accent) !important; outline-offset: 2px !important; }

html.site-menu-open[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] .site-header .brand {
  display: flex !important; position: fixed !important;
  inset: calc(12px + env(safe-area-inset-top, 0px)) auto auto 50% !important;
  transform: translateX(-50%) !important; width: 52px !important; min-width: 52px !important; height: 52px !important;
  z-index: 2;
}
html.site-menu-open[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] .site-header :is(.brand-symbol, .brand-symbol img) {
  width: 52px !important; height: 52px !important; flex-basis: 52px !important;
}
html.site-menu-open[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] .site-header .menu-toggle {
  position: fixed !important; inset: calc(16px + env(safe-area-inset-top, 0px)) var(--phone-navigation-right) auto auto !important;
}
html.site-menu-open[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'].game-active .site-header .brand {
  left: var(--phone-navigation-left) !important; transform: none !important;
}
html.site-menu-open[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'].game-active .site-header .game-site-mode:not([hidden]) {
  display: block !important; position: fixed !important;
  inset: calc(31px + env(safe-area-inset-top, 0px)) auto auto calc(var(--phone-navigation-left) + 64px) !important;
  transform: none !important; border: 0 !important; padding: 0 !important;
  font: 700 11px/1.3 ScalarNavigation, Orbitron, sans-serif !important; color: var(--header-ink);
  z-index: 2;
}

@media (orientation: landscape) and (max-height: 599px) {
  html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] .site-header {
    --phone-navigation-top: calc(68px + env(safe-area-inset-top, 0px));
    --phone-navigation-bottom: max(12px, calc(env(safe-area-inset-bottom, 0px) + 6px));
  }
  html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] .site-header #main-nav.open.phone-navigation-ready { gap: 12px !important; }
  html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav .phone-navigation-links {
    grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: 52px; gap: 8px 20px;
  }
  html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav .phone-navigation-links > .nav-link { height: 52px !important; min-height: 52px !important; font-size: clamp(20px, 3.7vw, 28px) !important; }
  html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav .phone-navigation-settings {
    grid-template-columns: repeat(var(--phone-navigation-control-count, 6), minmax(0, 1fr)); gap: 6px; padding-top: 10px;
  }
  html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav .phone-navigation-settings :is(button, .theme-toggle, #phone-log-toggle, #btn-exit-game) { height: 44px !important; }
}

@media (orientation: portrait) and (max-height: 600px) {
  html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] .site-header #main-nav.open.phone-navigation-ready { gap: 12px !important; }
  html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav .phone-navigation-links {
    grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: 48px; gap: 8px 12px;
  }
  html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav .phone-navigation-links > .nav-link {
    height: 48px !important; min-height: 48px !important; font-size: clamp(18px, 5.4vw, 22px) !important;
  }
  html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav .phone-navigation-settings {
    grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; padding-top: 10px;
  }
  html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'] #main-nav .phone-navigation-settings :is(button, .theme-toggle, #phone-log-toggle, #btn-exit-game) { height: 44px !important; }
}

/* Match navigation has a stable close target and a separate, distant Exit. */
@media (orientation: landscape) and (max-width: 1100px) and (max-height: 599px) {
  html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'].phone-match-active .site-header #main-nav.open.phone-navigation-ready {
    grid-template-rows: minmax(0, 1fr) !important;
    padding-bottom: calc(var(--phone-action-bottom) + var(--phone-action-height) + 16px) !important;
  }
  html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'].phone-match-active #main-nav .phone-navigation-settings {
    position: fixed !important;
    inset: auto calc(var(--phone-dock-right) + var(--phone-menu-size) + var(--phone-footer-control-gap)) var(--phone-action-bottom) calc(var(--phone-dock-left) + 116px) !important;
    display: grid !important; grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
    align-items: stretch; height: var(--phone-action-height); min-height: 0;
    margin: 0 !important; padding: 0 !important; gap: 6px !important; border: 0 !important;
  }
  html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'].phone-match-active #main-nav .phone-navigation-settings :is(button, .theme-toggle, #phone-log-toggle) {
    height: var(--phone-action-height) !important;
    min-height: var(--phone-action-height) !important;
  }
  html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'].phone-match-active #main-nav .phone-navigation-settings #btn-exit-game {
    position: fixed !important;
    inset: auto auto var(--phone-action-bottom) var(--phone-dock-left) !important;
    width: 104px !important; height: var(--phone-action-height) !important;
    flex-direction: row; gap: 8px !important;
    border-color: var(--phone-line) !important; border-radius: 9px !important;
    background: var(--phone-surface) !important;
  }
  html[data-theme]:is([data-phone-device='true'],[data-tablet-menu='true']) body#top[data-page='play'].phone-match-active #main-nav .phone-navigation-settings #btn-exit-game .phone-navigation-control-label {
    font-size: 12px !important;
  }
}
