/* Keep bypass links out of the way until reached by keyboard. */
.skip-link {
  position: fixed;
  z-index: 40;
  inset-block-start: max(12px, env(safe-area-inset-top, 0px));
  inset-inline-start: max(12px, env(safe-area-inset-left, 0px));
  max-inline-size: calc(100% - 24px);
  pointer-events: auto;
}
.skip-link:not(:focus) {
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.skip-link:focus {
  padding: 10px 14px;
  background: var(--panel-solid);
  color: var(--text);
  border-radius: 6px;
  text-decoration: underline;
}

.a11y-heading { margin: 0; font-weight: inherit; }

.settings > .seed-setting { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.settings :is(input, select, button, summary):focus { scroll-margin-block-end: 76px; }

/* Use a dark inner ring on the road view so focus is readable on sky, snow and asphalt. */
#view:focus-visible { box-shadow: inset 0 0 0 6px var(--bg); }
.hud .llm-menu button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.arena .import-button:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

.touch-button:focus-visible, .touch-pedal:focus-visible, .touch-steer:focus-visible { outline-offset: -4px; }
.touch-controls.autopilot :is(.touch-steer, .touch-pedal) { opacity: 1; }
.touch-button[aria-pressed="true"] { box-shadow: inset 0 -3px var(--accent); }
.touch-pedal.active { box-shadow: inset 0 -3px currentColor; }

@media (max-width: 760px) and (max-height: 460px) {
  body.touch-driving { --touch-h: 166px; }
}
@media (max-width: 340px) {
  body.touch-driving { --touch-h: 216px; }
  .touch-pedals { gap: 6px; }
  .touch-pedal { width: 54px; }
}

@media (prefers-contrast: more) {
  :root {
    --panel: var(--panel-solid);
    --muted: #c9d1df;
    --faint: #bac5d7;
    --border-strong: #95a9c1;
  }
}
@media (forced-colors: active) {
  .touch-steer-knob, .touch-steer-track { border: 1px solid ButtonText; }
  .touch-pedal.active, .touch-button[aria-pressed="true"] { border: 3px solid Highlight; }
  .paint-option[aria-pressed="true"] { outline: 2px solid Highlight; outline-offset: -2px; }
  #minimap-cursor { forced-color-adjust: none; }
}

/* Controls and sound settings (ui/controls-settings.js): driving keys and input options. */
.controls-settings { display: grid; gap: 8px; }
.controls-settings summary { cursor: pointer; }
.controls-settings[open] summary { margin-bottom: 4px; }
.binding-rows { display: grid; gap: 4px; }
.binding-row { display: grid; grid-template-columns: minmax(0, 1fr) 76px 76px; gap: 6px; align-items: center; }
.binding-action { min-width: 0; font-size: 11.5px; }
.binding-key { min-height: 28px; font-variant-numeric: tabular-nums; text-align: center; }
.binding-key.empty { color: var(--muted); border-style: dashed; }
.binding-key[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.binding-footer { display: flex; justify-content: flex-end; }
.binding-status { min-height: 1.3em; margin: 0; font-size: 11px; }
.controls-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; align-items: end; }
.controls-grid > label:not(.check) { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.controls-grid > .wide { grid-column: 1 / -1; }
.controls-grid .range-row { display: flex; gap: 8px; align-items: center; }
.controls-grid input[type="range"] { flex: 1; min-width: 0; accent-color: var(--accent); }
@media (max-width: 520px) { .controls-grid { grid-template-columns: 1fr; } }

/* Photo mode: look presets and composition guides (only the canvas is captured, never these). */
.photo-presets { display: flex; flex-wrap: wrap; gap: 6px; }
.photo-presets [aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.photo-keys { font-size: 10.5px; color: var(--muted); }
.photo-grid.photo-guide-phi {
  background:
    linear-gradient(90deg, transparent calc(38.2% - 1px), #fff7 0 38.2%, transparent 0 calc(61.8% - 1px), #fff7 0 61.8%, transparent 0),
    linear-gradient(transparent calc(38.2% - 1px), #fff7 0 38.2%, transparent 0 calc(61.8% - 1px), #fff7 0 61.8%, transparent 0);
}
.photo-grid.photo-guide-centre {
  background:
    linear-gradient(90deg, transparent calc(50% - 0.5px), #fff7 0 calc(50% + 0.5px), transparent 0) center / 48px 48px no-repeat,
    linear-gradient(transparent calc(50% - 0.5px), #fff7 0 calc(50% + 0.5px), transparent 0) center / 48px 48px no-repeat;
}
/* A crop guide shades what the crop would cut: a centred box of the crop's aspect ratio. */
.photo-grid:is(.photo-guide-square, .photo-guide-portrait) { background: none; display: grid; place-items: center; }
.photo-grid:is(.photo-guide-square, .photo-guide-portrait)[hidden] { display: none; }
.photo-grid:is(.photo-guide-square, .photo-guide-portrait)::before {
  content: ""; block-size: 100%; max-inline-size: 100%; aspect-ratio: 1; outline: 1px solid #fff9; box-shadow: 0 0 0 100vmax #0007;
}
.photo-grid.photo-guide-portrait::before { aspect-ratio: 4 / 5; }

/* Touch: on-screen controls at least 44 px tall on a touch screen (WCAG 2.5.5). The touch buttons
   grow only where they sit in one row: on phones their two rows would push the pedals off screen. */
@media (pointer: coarse) {
  .city-card, .mission-card, .binding-key { min-height: 44px; }
}
@media (pointer: coarse) and (min-width: 761px) and (min-height: 461px) {
  .touch-button { min-height: 44px; }
}

/* Increased contrast: solid touch controls with a strong border, readable over any scene. */
@media (prefers-contrast: more) {
  .touch-steer, .touch-pedal, .touch-button { background: var(--panel-solid); border: 2px solid var(--text); }
  .touch-caption, .touch-steer-knob { color: var(--text); }
  .binding-key.empty { color: var(--text); }
}

/* Forced colours: selected cards, pressed presets and the key being rebound keep a system mark. */
@media (forced-colors: active) {
  .city-card.selected, .city-card[aria-current] { outline: 3px solid Highlight; outline-offset: -3px; }
  .photo-presets [aria-pressed="true"], .photo-cameras [aria-pressed="true"], .binding-key[aria-pressed="true"] { border: 2px solid Highlight; }
  .photo-grid { forced-color-adjust: none; }
}

/* Reduced motion: the collision flash becomes a brief, faint vignette instead of a red flash. */
@media (prefers-reduced-motion: reduce) {
  .flash { background: radial-gradient(circle, transparent 55%, rgba(255, 60, 60, 0.18)); }
}
