:root { --app-height: 100vh; }
@supports (height: 100dvh) { :root { --app-height: 100dvh; } }

/* Keep the guide heading and actions outside its only scrollable region. */
.ready-dialog[open] { display: flex; flex-direction: column; overflow: hidden; max-height: calc(var(--app-height, 100dvh) - 24px); }
.ready-heading { flex: none; }
.ready-heading h2 { margin: 0 0 6px; }
.ready-heading h2:focus { outline: none; }
.ready-content { min-height: 0; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; padding: 0 3px; }
.ready-actions { flex: none; margin: 0; padding: 12px 0 0; }
.ready-key-help { flex: none; margin: 8px 0 0; }
.title-start { position: absolute; }
.title-bottom { position: static; }
.title-route { position: absolute; left: 6%; bottom: 30px; }

@media (max-width: 820px), (pointer: coarse), (orientation: landscape) and (max-height: 500px) {
  html { height: 100%; overflow: hidden; overscroll-behavior: none; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body { position: fixed; inset: 0; width: 100%; min-width: 0; height: var(--app-height, 100dvh); min-height: 0; overflow: hidden; overscroll-behavior: none; }
  .app-shell { height: 100%; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
  body:has(dialog[open]) .app-shell { overflow: hidden; }
  button { touch-action: manipulation; }
  #landingScreen { display: block; height: 100%; min-height: 0; }
  .title-start p { display: none; }
  .title-utilities button { min-height: 44px; }
  body.real-drive-main .app-shell,
  body.real-drive-main .game-screen,
  body.real-drive-main .integrated-drive { height: 100%; min-height: 0; overflow: hidden; }
  body.real-drive-main .real-drive-exit { position: absolute; }
  dialog { max-height: calc(var(--app-height, 100dvh) - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); overscroll-behavior: contain; }
  .ready-dialog[open] { width: calc(100% - 20px); max-width: 760px; max-height: calc(var(--app-height, 100dvh) - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); padding: 14px; border-radius: 20px; }
  .ready-heading .eyebrow { font-size: 10px; margin-bottom: 5px; }
  .ready-heading h2 { font-size: 21px; }
  #readyRoute { font-size: 12px; line-height: 1.5; }
  .ready-dialog .guide-shot { margin: 10px 0; }
  .ready-dialog .guide-shot-frame { max-width: 400px; border-radius: 10px; }
  .ready-dialog .guide-shot figcaption, .ready-dialog .keyboard-picture, .ready-key-help { display: none; }
  .ready-dialog .guide-rules { grid-template-columns: 1fr; gap: 7px; margin: 10px 0 0; }
  .ready-dialog .guide-rules article { display: grid; grid-template-columns: 48px 1fr; grid-template-rows: auto auto; gap: 3px 10px; padding: 10px; border-radius: 11px; }
  .ready-dialog .guide-symbol { grid-row: 1 / 3; align-self: center; min-width: 0; width: 48px; height: 36px; font-size: 17px; border-radius: 8px; }
  .ready-dialog .guide-rules h3 { margin: 0; font-size: 13px; }
  .ready-dialog .guide-rules p { margin: 0; font-size: 12px; line-height: 1.55; }
  .ready-dialog .ready-actions { flex-direction: row; gap: 8px; }
  .ready-actions button { min-width: 0; min-height: 46px; padding: 10px 6px; font-size: 14px; }
  .ready-actions .ghost-button { flex: 0.7; }
  .visual-howto { max-height: calc(var(--app-height, 100dvh) - 20px); }
  .selected-preview { overflow: hidden; }
  .vehicle-preview-turntable { position: absolute; inset: 0; width: 100%; height: 100%; min-height: 0; object-fit: contain; }
  .prototype-note { display: none; }
}

/* Portrait uses the whole artwork instead of cropping a landscape image. */
@media (orientation: portrait) and (max-width: 820px) {
  #landingScreen .landing-content { display: grid; align-items: stretch; justify-items: stretch; grid-template-rows: auto auto auto auto auto; align-content: space-between; gap: clamp(14px, 3vh, 26px); padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); background: radial-gradient(ellipse at 50% 40%, #214755, #081c2b 75%); }
  #landingScreen .start-concept { position: static; grid-row: 3; width: 100%; height: auto; aspect-ratio: 1672 / 941; min-height: 0; object-fit: contain; object-position: center; border-radius: 12px; }
  .title-shade, .title-overline, .title-rule, .title-route { display: none; }
  .title-brand { position: static; grid-row: 1; font-size: 9px; letter-spacing: .18em; }
  .title-lockup { position: static; grid-row: 2; text-align: center; }
  #landingScreen .game-logo { transform: none; line-height: 1.15; }
  .game-logo span { font-size: clamp(24px, 6.8vw, 38px); }
  .game-logo strong { font-size: clamp(31px, 9vw, 54px); }
  .title-bottom { position: static; grid-row: 4; }
  .title-start { position: static; transform: none; width: min(340px, 100%); margin: 0 auto; }
  #landingScreen .landing-start-button { width: 100%; min-height: 56px; padding: 12px 24px; font-size: 20px; }
  .title-utilities { position: static; grid-row: 5; justify-content: flex-end; gap: 8px; }
  .title-utilities button { font-size: 12px; padding: 10px 14px; }

  body:has(#selectScreen:not([hidden])) .app-shell { display: flex; flex-direction: column; padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); gap: 8px; }
  .site-header { display: flex; flex-direction: row; align-items: center; flex-wrap: nowrap; flex: none; min-height: 44px; margin: 0; gap: 8px; }
  .site-header .eyebrow { display: none; }
  .site-header h1 { font-size: clamp(13px, 3.5vw, 20px); line-height: 1.3; letter-spacing: 0; }
  .site-header h1 span { display: block; }
  .header-actions { display: flex; flex-wrap: nowrap; gap: 5px; }
  .header-actions .ghost-button { min-height: 40px; padding: 8px; font-size: 10px; white-space: nowrap; }
  .select-screen { flex: 1 0 auto; display: flex; flex-direction: column; gap: 8px; min-height: 0; height: auto; padding: 8px; border-radius: 16px; }
  .level-picker, .machine-picker, .selection-footer { margin: 0; padding: 8px; border-radius: 12px; }
  .picker-heading { margin: 0 0 6px; min-height: 0; }
  .picker-heading span, .picker-heading b, .level-key-help, .garage-label, .selected-summary { display: none; }
  .picker-heading h3 { margin: 0; font-size: 13px; line-height: 1.4; }
  .level-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .level-card { grid-template-columns: 24px 1fr; grid-template-rows: auto auto; gap: 4px; height: 60px; min-height: 0; padding: 8px 6px; border-radius: 10px; }
  .level-index { grid-row: 1 / 3; align-self: center; font-size: 21px; }
  .level-route { padding: 0 10px 0 0; font-size: 11px; white-space: normal; line-height: 1.25; }
  .level-features { grid-column: 2; flex-wrap: nowrap; }
  .level-features .level-difficulty { padding: 1px 3px; font-size: 8px; white-space: nowrap; }
  .level-card[aria-checked="true"]::before { top: 3px; right: 3px; width: 14px; height: 14px; font-size: 9px; }
  .garage-layout { flex: 1; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
  .vehicle-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .vehicle-card { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto auto auto; min-width: 0; min-height: 0; gap: 3px; padding: 8px; border-radius: 10px; }
  .vehicle-card[aria-checked="true"]::before { top: 5px; right: 5px; width: 17px; height: 17px; font-size: 10px; }
  .vehicle-meta, .vehicle-number { font-size: 8px; letter-spacing: .06em; }
  .vehicle-card h3 { grid-row: 2; margin: 0; font-size: 16px; }
  .vehicle-card .vehicle-kind { grid-row: 3; min-height: 0; font-size: 9px; }
  .mini-stats { grid-column: 1; grid-row: 4; gap: 5px; margin: 5px 0 0; }
  .mini-stat { grid-template-columns: 52px minmax(0, 1fr); gap: 5px; font-size: 10px; line-height: 1.2; }
  .selection-footer { flex: 1; display: flex; flex-direction: column; gap: 8px; overflow: visible; }
  .selected-preview { flex: 1; height: clamp(90px, calc(var(--app-height, 100dvh) - 558px), 220px); min-height: 90px; padding: 0; }
  .vehicle-preview-turntable { height: 100%; min-height: 0; object-fit: contain; }
  #startButton { flex: none; width: 100%; min-height: 48px; padding: 9px 6px; font-size: 13px; }
  #startButton small { display: none; }
}

@media (orientation: landscape) and (max-height: 500px) {
  #landingScreen .start-concept { object-fit: contain; object-position: center; }
  .title-lockup { left: max(5%, env(safe-area-inset-left)); top: 24%; }
  .game-logo strong { font-size: clamp(30px, 5.6vw, 48px); }
  .game-logo span { font-size: 24px; }
  .title-start { top: 54%; left: 50%; width: min(300px, 40%); }
  #landingScreen .landing-start-button { width: 100%; min-width: 0; min-height: 48px; font-size: 19px; }
  .title-utilities { bottom: max(12px, env(safe-area-inset-bottom)); }
  .title-route { display: none; }
  body:has(#selectScreen:not([hidden])) .app-shell { overflow-y: auto; 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)); }
  .select-screen { height: calc(var(--app-height, 100dvh) - 56px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); min-height: 264px; }
  .garage-layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .ready-content { display: grid; grid-template-columns: 1fr 1fr; align-items: start; gap: 12px; }
  .ready-dialog .guide-rules { margin: 10px 0; }
  .ready-dialog .guide-rules article { grid-template-columns: 36px 1fr; padding: 7px; gap: 2px 7px; }
  .ready-dialog .guide-symbol { width: 36px; font-size: 12px; }
}
@media (max-width: 360px) and (orientation: portrait) {
  .difficulty-stars { display: none; }
}
@media (max-height: 620px) and (orientation: portrait) and (max-width: 820px) {
  .select-screen, .garage-layout { gap: 6px; }
  .level-picker, .machine-picker, .selection-footer { padding: 6px; }
  .level-card { height: 56px; padding-block: 5px; }
  .vehicle-card { padding: 6px; }
  .mini-stats { gap: 3px; margin-top: 3px; }
  .selected-preview { height: 70px; min-height: 70px; }
}

/* Full-bleed art: a separate portrait composition protects the main subject. */
#landingScreen { height: var(--app-height, 100dvh); min-height: 0; }
#landingScreen .landing-content { display: block; position: relative; height: 100%; padding: 0; background: none; }
#landingScreen .start-art { position: absolute; inset: 0; display: block; }
#landingScreen .start-concept { position: absolute; inset: 0; width: 100%; height: 100%; max-height: none; aspect-ratio: auto; object-fit: cover; object-position: center; border-radius: 0; }
#landingScreen .title-shade { display: block; pointer-events: none; }
@media (max-aspect-ratio: 1/1) {
  #landingScreen .start-concept { object-position: 50% 68%; }
  .title-shade { background: linear-gradient(180deg, #06244966, transparent 42%, transparent 78%, #051a35aa); }
  .title-brand { position: absolute; top: max(22px, env(safe-area-inset-top)); left: 6%; }
  .title-lockup { position: absolute; top: 13%; left: 5%; right: 5%; text-align: center; }
  .title-bottom { position: static; }
  .title-start { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(320px, 78%); margin: 0; }
  .title-utilities { position: absolute; left: auto; right: max(16px, env(safe-area-inset-right)); bottom: max(20px, env(safe-area-inset-bottom)); }
}
