/* Turbo TukTuk Drift 3D — focused device-fit and accessibility polish.
   Loaded after the original theme so gameplay/rendering rules stay untouched. */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

html,
body,
.game-shell {
  width: 100%;
  height: 100%;
  min-height: 100%;
}

@supports (height: 100dvh) {
  html,
  body,
  .game-shell {
    height: 100dvh;
    min-height: 100dvh;
  }
}

.game-shell {
  overflow: hidden;
}

.game-bar {
  min-height: calc(52px + var(--safe-top));
  height: auto;
  padding: var(--safe-top) calc(12px + var(--safe-right)) 0 calc(12px + var(--safe-left));
  gap: 8px;
}

.back-link,
.icon-btn {
  min-width: 44px;
  min-height: 44px;
}

.back-link {
  padding: 0 4px;
}

.icon-btn {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
}

.header-controls {
  gap: 6px;
}

.player-pill {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud {
  padding: calc(60px + var(--safe-top)) calc(16px + var(--safe-right)) calc(18px + var(--safe-bottom)) calc(16px + var(--safe-left));
}

.touch-btn-zone {
  bottom: calc(16px + var(--safe-bottom));
}

.touch-btn-zone.left {
  left: calc(14px + var(--safe-left));
}

.touch-btn-zone.right {
  right: calc(14px + var(--safe-right));
}

.modal-screen {
  height: 100%;
  padding: calc(60px + var(--safe-top)) calc(12px + var(--safe-right)) calc(12px + var(--safe-bottom)) calc(12px + var(--safe-left));
  align-items: flex-start;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.menu-card {
  width: min(100%, 480px);
  margin: auto;
  flex: 0 0 auto;
}

.mode-option {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  color: inherit;
  font: inherit;
}

.back-link:focus-visible,
.icon-btn:focus-visible,
.touch-btn:focus-visible,
.mode-option:focus-visible,
.btn-primary:focus-visible,
.btn-secondary:focus-visible {
  outline: 3px solid var(--neon-yellow);
  outline-offset: 3px;
}

#game-canvas:focus {
  outline: none;
}

@media (max-width: 520px) {
  .game-bar-title {
    display: none;
  }

  .player-pill {
    max-width: 92px;
  }

  .hud {
    padding: calc(56px + var(--safe-top)) calc(10px + var(--safe-right)) calc(12px + var(--safe-bottom)) calc(10px + var(--safe-left));
  }

  .hud-top-bar {
    gap: 5px;
  }

  .hud-card {
    min-width: 0;
    flex: 1 1 0;
    padding: 5px 6px;
  }

  .hud-card .label {
    font-size: 9px;
    letter-spacing: .06em;
  }

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

  .hud-bottom-bar {
    justify-content: center;
    gap: 24px;
    padding-bottom: 76px;
  }

  .gauge-speed {
    align-items: center;
  }

  .menu-card {
    padding: 18px 14px;
    gap: 14px;
  }

  .mode-option {
    padding: 12px;
  }
}

@media (max-height: 540px) and (orientation: landscape) {
  .game-bar {
    min-height: calc(48px + var(--safe-top));
  }

  .game-bar-title,
  .player-pill {
    display: none;
  }

  .hud {
    padding: calc(50px + var(--safe-top)) calc(10px + var(--safe-right)) calc(8px + var(--safe-bottom)) calc(10px + var(--safe-left));
  }

  .hud-top-bar {
    gap: 6px;
  }

  .hud-card {
    flex: 0 1 auto;
    padding: 4px 8px;
  }

  .hud-card .val {
    font-size: 14px;
  }

  .hud-bottom-bar {
    justify-content: center;
    gap: 20px;
    padding-bottom: 0;
  }

  .speed-num {
    font-size: 30px;
  }

  .gauge-n2o {
    width: 120px;
  }

  .touch-btn-zone {
    gap: 10px;
    bottom: calc(8px + var(--safe-bottom));
  }

  .touch-btn,
  .touch-btn.drift-btn,
  .touch-btn.n2o-btn {
    width: 54px;
    height: 54px;
    min-width: 54px;
    min-height: 54px;
  }

  .modal-screen {
    padding-top: calc(50px + var(--safe-top));
  }

  #modal-title .menu-card {
    max-width: 760px;
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(220px, .8fr);
    grid-template-areas:
      "title hint"
      "sub hint"
      "modes start";
    gap: 7px 14px;
    align-items: center;
    padding: 12px 16px;
    text-align: left;
  }

  #modal-title .title-logo { grid-area: title; font-size: 22px; }
  #modal-title .subtitle { grid-area: sub; margin-top: 0; }
  #modal-title .mode-selector { grid-area: modes; gap: 5px; }
  #modal-title .mode-option { padding: 7px 9px; }
  #modal-title .mode-name { font-size: 13px; }
  #modal-title .mode-desc { font-size: 10px; }
  #modal-title .controls-hint { grid-area: hint; align-self: stretch; display: flex; align-items: center; }
  #modal-title .btn-primary { grid-area: start; align-self: end; }

  #modal-pause .menu-card,
  #modal-results .menu-card {
    max-width: 620px;
    padding: 12px 16px;
    gap: 8px;
  }

  #modal-results .stats-grid {
    gap: 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
