/* Mobile keeps the same night-racing palette and angular controls. */
.touch-device, .touch-device body { touch-action: manipulation; overscroll-behavior: none; }
.touch-device body { height: 100dvh; }
#gl { touch-action: none; }
.touch-device button, .touch-device select { -webkit-tap-highlight-color: transparent; }
.touch-device .btn, .touch-device .seg button, .touch-device .select { min-height: 44px; }
.touch-device select { font-size: 16px; }
.touch-device .sw { width: 44px; height: 44px; }
.touch-device .screen, .touch-device .modal .box { overscroll-behavior: contain; }
.touch-device .modal .box, .touch-device #chapterList, .touch-device .course-pane,
.touch-device .rival-pane, .touch-device .carlist, .touch-device .carinfo,
.touch-device .kg-body, .touch-device #setGrid, .touch-device #keyPane { touch-action: pan-y; -webkit-overflow-scrolling: touch; }
.touch-device .controls-ref { display: none; }
.touch-device #paneCar { touch-action: pan-y; }
.touch-device { scrollbar-width: thin; scrollbar-color: #46526a transparent; }
.touch-device *::-webkit-scrollbar { width: 4px; height: 4px; }
.touch-device *::-webkit-scrollbar-thumb { background: #46526a; border-radius: 2px; }

#orientationGate { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: max(28px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left)); background: var(--ink); overflow-y: auto; touch-action: pan-y; }
.rotate-content { width: min(360px, 100%); display: grid; justify-items: center; gap: 20px; text-align: center; }
.rotate-content .logo { gap: 12px; }
.rotate-content .logo .word { font-size: 30px; }
.rotate-content .logo .jp { font-size: 14px; }
.rotate-phone { width: 112px; height: 100px; margin-top: 18px; stroke: var(--amber); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.rotate-content h1 { margin: 0; font-size: clamp(32px, 9vw, 42px); font-weight: 900; font-style: italic; line-height: 1.05; letter-spacing: -0.025em; }
.rotate-content p { margin: 0; max-width: 28ch; font-size: 16px; line-height: 1.6; color: #c3cad8; }
.rotate-content .rotate-help { max-width: 30ch; margin-top: 4px; font-size: 13px; color: #a4aec0; }
#mobileFullscreen { position: fixed; z-index: 4; top: max(12px, env(safe-area-inset-top)); right: var(--padr); padding: 8px 14px; font-size: 13px; background: var(--panel-solid); }

#touch .tb { padding: 0; -webkit-user-select: none; user-select: none; }
#touch .tb svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
#touch .touch-tools { position: absolute; left: 50%; top: max(10px, env(safe-area-inset-top)); transform: translateX(-50%); display: flex; gap: 8px; }
#touch .touch-tools .tb, #touch .touch-shifts .tb { position: static; width: 44px; height: 44px; border-width: 1px; border-radius: 8px; background: rgba(10,13,20,0.72); }
#touch .touch-shifts { position: absolute; left: var(--pad); bottom: max(130px, calc(env(safe-area-inset-bottom) + 130px)); display: none; gap: 10px; }
#touch.manual .touch-shifts { display: flex; }
#touch .touch-shifts .tb { font-size: 24px; }
#touch .touch-context { left: 50%; bottom: max(64px, calc(env(safe-area-inset-bottom) + 64px)); transform: translateX(-50%); width: auto; height: 44px; padding: 0 18px; border-radius: 6px; border-width: 1px; color: var(--ink); background: var(--amber); font-size: 14px; font-weight: 700; }

/* Phone landscape is wide but short: keep the primary actions on screen. */
@media (orientation: landscape) and (max-height: 600px) and (max-width: 1100px) {
  .touch-device { --pad: max(12px, env(safe-area-inset-left)); --padr: max(12px, env(safe-area-inset-right)); --control-size: clamp(56px, 17vh, 72px); --control-bottom: max(12px, env(safe-area-inset-bottom)); }
  .touch-device .screen { padding-block: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-bottom)); }
  .touch-device .head { gap: 8px; flex-wrap: nowrap; }
  .touch-device .h1 { font-size: clamp(26px, 4vw, 36px); }
  .touch-device .btn { padding: 9px 16px; font-size: 14px; }
  .touch-device .row { gap: 8px; }
  .touch-device #title { padding-bottom: max(48px, env(safe-area-inset-bottom)); }
  .touch-device #title .logo .word { font-size: clamp(54px, 9vw, 90px); }
  .touch-device #title .logo .moon { width: 44px; height: 44px; box-shadow: inset -10px 4px 0 var(--moon); }
  .touch-device #title .tag { font-size: 14px; letter-spacing: 0.18em; }
  .touch-device #pressStart { margin-top: 18px; min-height: 44px; font-size: 17px; letter-spacing: 0.15em; }
  .touch-device #title .credit { max-width: calc(100% - var(--pad) - var(--padr)); font-size: 9px; text-align: right; bottom: max(8px, env(safe-area-inset-bottom)); }

  .touch-device #menu { grid-template-columns: 1fr; align-items: stretch; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .touch-device #menu .info-col, .touch-device #hints { display: none; }
  .touch-device #menu .col { width: min(680px, 100%); padding-top: 0; gap: 12px; justify-content: center; min-height: 0; }
  .touch-device #menu .logo .word { font-size: 28px; }
  .touch-device #menu .logo .moon { width: 26px; height: 26px; box-shadow: inset -6px 3px 0 var(--moon); }
  .touch-device #menu .menu-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 20px; }
  .touch-device #menu .menu-list .mi { min-height: 48px; padding: 7px 8px 7px 20px; font-size: clamp(22px, 3vw, 28px); line-height: 1.1; transform: none; }
  .touch-device #menu .mi small { font-size: 11px; line-height: 1.4; letter-spacing: 0.09em; }
  .touch-device #menu .keys { display: none; }

  .touch-device #story, .touch-device #setup, .touch-device #kings { gap: 10px; }
  .touch-device .steps { gap: 12px; font-size: 12px; }
  .touch-device .car-pane { grid-template-columns: 170px minmax(0, 1fr); gap: 12px; overflow: hidden; align-items: stretch; }
  .touch-device .car-pane .drag-hint { display: none; }
  .touch-device .carlist { flex-direction: column; min-width: 0; max-height: 100%; overflow-x: hidden; overflow-y: auto; }
  .touch-device .carbtn { min-width: 0; min-height: 64px; padding: 9px; }
  .touch-device .carbtn .n { font-size: 16px; }
  .touch-device .carbtn .tag { font-size: 10px; padding: 2px 4px; }
  .touch-device .carinfo { width: min(260px, 100%); justify-self: end; max-height: 100%; overflow-y: auto; padding: 12px; gap: 10px; }
  .touch-device .carinfo .name { font-size: 22px; }
  .touch-device .carinfo p { font-size: 13px; }
  .touch-device .specs b { font-size: 19px; }
  .touch-device .swatches { gap: 4px; flex-wrap: wrap; }
  .touch-device .bar { grid-template-columns: 76px 1fr; }
  .touch-device .opts { gap: 8px 16px; flex-wrap: nowrap; overflow-x: auto; touch-action: pan-x; }
  .touch-device .opts .row { flex-wrap: nowrap; flex-shrink: 0; }
  .touch-device .seg button { padding: 8px 12px; }
  .touch-device .course-pane { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
  .touch-device .course { padding: 8px 10px; gap: 4px; }
  .touch-device .course canvas { height: 64px; }
  .touch-device .course .t { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .touch-device .course .t .kanji { display: none; }
  .touch-device .course .meta { font-size: 10px; gap: 2px 8px; letter-spacing: 0.06em; }
  .touch-device .course p { display: none; }
  .touch-device .rival-pane { grid-template-columns: repeat(2, minmax(0, 1fr)); overflow-y: auto; gap: 10px; }
  .touch-device .tier { padding: 12px; }
  .touch-device .tier .n { font-size: 23px; }
  .touch-device .chap { min-height: 100px; }

  .touch-device #kings .kg-body { grid-template-columns: 112px minmax(220px, 1fr) minmax(200px, 0.9fr); gap: 10px; align-items: stretch; overflow: hidden; }
  .touch-device #kings .kg-passes { display: flex; flex-direction: column; overflow-y: auto; }
  .touch-device #kings .kg-ladder { display: flex; flex-direction: column; overflow-y: auto; padding-right: 4px; }
  .touch-device #kings .kg-info { overflow-y: auto; padding: 12px; gap: 8px; }
  .touch-device #kings .kg-pass { flex-shrink: 0; min-height: 76px; padding: 8px; }
  .touch-device #kings .kg-pass .t { font-family: var(--display); font-size: 17px; font-weight: 700; }
  .touch-device #kings .kg-pass .p { font-size: 10px; letter-spacing: 0.06em; }
  .touch-device #kings .kg-row { flex-shrink: 0; min-height: 60px; grid-template-columns: 22px 36px minmax(0, 1fr); gap: 2px 6px; padding: 7px; transform: none; }
  .touch-device #kings .kg-row .rk { font-size: 27px; }
  .touch-device #kings .kg-row .ml-por { width: 36px; height: 36px; }
  .touch-device #kings .kg-row .n { font-size: 16px; overflow-wrap: anywhere; }
  .touch-device #kings .kg-row .m { font-size: 10px; letter-spacing: 0.04em; }
  .touch-device #kings .kg-row .st { grid-column: 3; grid-row: 3; justify-self: start; font-size: 9px; padding: 1px 5px; }
  .touch-device #kings .kg-info .top { gap: 8px; }
  .touch-device #kings .kg-info .ml-por { width: 48px; height: 48px; }
  .touch-device #kings .kg-info .nm { font-size: 20px; }
  .touch-device #kings .kg-info .car { font-size: 10px; }
  .touch-device #kings .kg-info .per, .touch-device #kings .kg-info dd, .touch-device #kings .kg-info q { font-size: 13px; line-height: 1.45; }
  .touch-device #kings > .row { flex-wrap: nowrap; }
  .touch-device #kings > .row .label { display: none; }
  .touch-device #kgCar { flex: 1; width: 0; min-width: 100px; }
  .touch-device #kgAssist { max-width: 104px; }
  .touch-device #kings > .row .spacer { display: none; }

  .touch-device .modal .box { padding: 16px; gap: 12px; }
  .touch-device #settings .box { grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden; }
  .touch-device #setGrid { min-height: 0; overflow-y: auto; padding-right: 6px; gap: 8px 16px; }
  .touch-device #keyPane { min-height: 0; overflow-y: auto; padding-right: 6px; }
  .touch-device .bind { min-height: 44px; }
  .touch-device #setGrid input[type=range] { height: 44px; touch-action: pan-y; }
  .touch-device #setGrid .seg button { min-width: 44px; padding: 8px; font-size: 12px; }
  .touch-device #resTitle { font-size: 48px; }
  .touch-device .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .touch-device #dialogue, .touch-device #mlChat { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .touch-device .dlg { width: min(700px, 100%); grid-template-columns: 44px minmax(0, 1fr); padding: 12px 16px 12px 12px; gap: 12px; }
  .touch-device #dlgPortrait, .touch-device #mlChat .dlg .ml-por { width: 44px; height: 44px; font-size: 24px; }
  .touch-device #dlgText, .touch-device #mlChatText { font-size: 16px; line-height: 1.4; min-height: 2.8em; }
  .touch-device #dlgChapter, .touch-device #mlChat .hd { top: max(12px, env(safe-area-inset-top)); }
  .touch-device #mlChat .hd .t { font-size: 26px; }

  .touch-device #hud .tl { top: max(10px, env(safe-area-inset-top)); gap: 3px; }
  .touch-device #hudMode { font-size: 11px; }
  .touch-device #hudTime { font-size: 27px; }
  .touch-device #hudBest { font-size: 11px; max-width: 170px; }
  .touch-device #hud .tc { top: max(60px, calc(env(safe-area-inset-top) + 54px)); width: min(230px, 34vw); gap: 2px; }
  .touch-device #hudPos { font-size: 19px; }
  .touch-device #hudGap { font-size: 17px; }
  .touch-device #elev { height: 22px; }
  .touch-device #minimap { width: 80px; height: 80px; }
  .touch-device #hud .tr { top: max(10px, env(safe-area-inset-top)); }
  .touch-device #hud .br { top: max(8px, env(safe-area-inset-top)); right: calc(var(--padr) + 86px); bottom: auto; }
  .touch-device #tach { width: 112px; height: 112px; }
  .touch-device #wearHud { bottom: auto; top: 0; padding: 4px 6px; gap: 6px; }
  .touch-device #wearHud svg { width: 16px; height: 31px; }
  .touch-device #wearHud .wl { font-size: 9px; gap: 0 6px; }
  .touch-device #mlRev { width: 112px; font-size: 10px; }
  .touch-device #mlRev .lab { font-size: 10px; }
  .touch-device #hud #mlRadio { position: fixed; left: 50%; bottom: var(--control-bottom); transform: translateX(-50%); margin: 0; min-height: 44px; width: min(260px, calc(100vw - 380px)); max-width: none; font-size: 11px; padding: 5px 8px; gap: 6px; }
  .touch-device #mlRadio .stn, .touch-device #mlRadio kbd { display: none; }
  .touch-device #hud #mlAssist { bottom: calc(var(--control-bottom) + 50px); max-width: calc(100vw - 380px); white-space: normal; padding: 4px 8px; font-size: 10px; gap: 6px; }
  .touch-device #mlAssist .act { min-width: 0; font-size: 11px; }
  .touch-device #hud #mlSay { top: 115px; max-width: 270px; padding: 5px 8px; gap: 8px; }
  .touch-device #mlSay .ml-por { width: 32px; height: 32px; }
  .touch-device #mlSay .tx { font-size: 12px; }
  .touch-device #mlKing .who { font-size: 10px; }
  .touch-device #mlKing .mt { font-size: 10px; gap: 4px; }
  .touch-device #drift { bottom: 34%; }
  .touch-device #driftScore { font-size: 32px; }
  .touch-device #introCard { bottom: 110px; max-width: calc(100% - var(--pad) - var(--padr)); }
  .touch-device #introCard .sub { font-size: 11px; letter-spacing: 0.1em; }
  .touch-device #introCard .vs { font-size: 30px; }
  .touch-device #introCard .skip { display: none; }
  .touch-device #countdown { font-size: 88px; }
  .touch-device #aiPanel { bottom: calc(var(--control-bottom) + var(--control-size) + 8px); padding: 6px 10px; gap: 4px; }
  .touch-device #aiPanel .ai-keys, .touch-device #aiPanel .ai-hint { display: none; }
  .touch-device #aiAct { min-width: 0; font-size: 11px; }

  .touch-device #touch .tl1, .touch-device #touch .tl2, .touch-device #touch .tr1, .touch-device #touch .tr2 { width: var(--control-size); height: var(--control-size); bottom: var(--control-bottom); border-width: 1px; background: rgba(10,13,20,0.6); font-size: 13px; }
  .touch-device #touch .tl1 { left: var(--pad); }
  .touch-device #touch .tl2 { left: calc(var(--pad) + var(--control-size) + 10px); }
  .touch-device #touch .tr1 { right: var(--padr); background: rgba(255,171,64,0.2); border-color: var(--amber); color: #ffca85; }
  .touch-device #touch .tr2 { right: calc(var(--padr) + var(--control-size) + 10px); }
  .touch-device #touch .tr3 { right: var(--padr); bottom: calc(var(--control-bottom) + var(--control-size) + 10px); width: var(--control-size); height: 44px; border-radius: 8px; border-width: 1px; font-size: 12px; }
  .touch-device #touch .touch-shifts { bottom: calc(var(--control-bottom) + var(--control-size) + 10px); }
  .touch-device #touch .tb.down { background: rgba(255,171,64,0.55); border-color: var(--amber); color: #fff; }
  .touch-device #touch .touch-context { bottom: calc(var(--control-bottom) + 94px); }
}

@media (orientation: landscape) and (max-width: 650px) and (max-height: 600px) {
  .touch-device #kings .kg-body { grid-template-columns: 92px minmax(180px, 1fr) minmax(170px, 0.9fr); gap: 8px; }
  .touch-device #kings .kg-info .top { grid-template-columns: 1fr; }
  .touch-device #kings .kg-info .top > .ml-por { display: none; }
  .touch-device #kings .kg-info .nm { font-size: 18px; }
  .touch-device .car-pane { grid-template-columns: 140px minmax(0, 1fr); gap: 8px; }
  .touch-device .carinfo { width: 210px; }
  .touch-device .steps { font-size: 10px; gap: 6px; }
}

@media (orientation: landscape) and (max-height: 350px) {
  .touch-device #menu .col { gap: 8px; }
  .touch-device #menu .menu-list { gap: 2px 16px; }
  .touch-device #menu .menu-list .mi { min-height: 44px; font-size: 22px; padding-block: 5px; }
  .touch-device #hud #mlSay { top: 108px; max-width: 220px; }
}

/* ---- phone pass 2: Pass Kings as tabs + two columns, results that fit, options that wrap, HUD odds and ends ---- */
@media (orientation: landscape) and (max-height: 600px) and (max-width: 1100px) {
  /* Pass Kings: the four passes become a tab strip; the ladder and the racer's card share the rest */
  .touch-device #kings .kg-body { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); gap: 8px 10px; }
  .touch-device #kings .kg-passes { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; overflow: visible; }
  .touch-device #kings .kg-pass { min-height: 40px; padding: 4px 10px; display: flex; flex-direction: row; align-items: center; justify-content: space-between; gap: 8px; }
  .touch-device #kings .kg-pass .k { display: none; }
  .touch-device #kings .kg-pass .t { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .touch-device #kings .kg-pass .p { white-space: nowrap; }
  .touch-device #kings .kg-ladder { gap: 6px; }
  .touch-device #kings .kg-row { min-height: 44px; grid-template-columns: 20px 34px minmax(0, 1fr) auto; gap: 0 8px; padding: 4px 8px; }
  .touch-device #kings .kg-row .rk { font-size: 24px; }
  .touch-device #kings .kg-row .ml-por { width: 34px; height: 34px; }
  .touch-device #kings .kg-row .n { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; overflow-wrap: normal; }
  .touch-device #kings .kg-row .m { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .touch-device #kings .kg-row .st { grid-column: 4; grid-row: 1 / span 2; justify-self: end; }
  .touch-device #kings .kg-row .crown { font-size: 10px; padding: 0 5px; margin-left: 6px; }
  .touch-device #kgAssist, .touch-device #kgWx { max-width: none; }
  /* pre-race chat: the box keeps to the left so the racer's portrait is seen beside it */
  .touch-device #mlChat .dlg { width: min(62%, 560px); margin: 0 auto 0 0; }
  .touch-device #mlChat .big { height: 96vh; right: 0; }
  /* results fit without scrolling */
  .touch-device #results .box { width: min(780px, 100%); padding: 10px 16px; gap: 8px; }
  .touch-device #resTitle { font-size: 30px; }
  .touch-device #resSub { font-size: 11px; }
  .touch-device #results .stats { grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 4px 10px; }
  .touch-device #results .stats div { padding-top: 4px; }
  .touch-device #results .stats b { font-size: 18px; }
  .touch-device #results .stats span { font-size: 9px; letter-spacing: 0.1em; }
  .touch-device #mlResQuote { padding: 5px 10px 5px 5px; gap: 10px; }
  .touch-device #mlResQuote .ml-por { width: 42px; height: 42px; font-size: 20px; }
  .touch-device #mlResQuote q { font-size: 13px; line-height: 1.35; }
  .touch-device #resUnlock { padding: 6px 10px; font-size: 12px; }
  /* setup options wrap onto a second line instead of scrolling off the edge */
  .touch-device .opts { flex-wrap: wrap; overflow-x: visible; gap: 6px 14px; }
  .touch-device .opts .seg button { min-height: 38px; padding: 6px 10px; font-size: 11px; letter-spacing: 0.08em; }
  /* HUD: the drift score moves out from under the centre controls; chips are finger sized */
  .touch-device #drift { left: auto; right: var(--padr); top: 34%; bottom: auto; transform: none; text-align: right; }
  .touch-device #driftScore { font-size: 30px; }
  .touch-device #driftMult { font-size: 20px; }
  .touch-device #mlLights { min-height: 36px; padding: 6px 12px; font-size: 11px; }
  .touch-device #mlLights kbd { display: none; }
  .touch-device #mlPov { min-height: 36px; padding: 6px 12px; font-size: 11px; }
  .touch-device #mlPov kbd { display: none; }
  .touch-device #mlWxChip { font-size: 10px; padding: 2px 8px; }
  .touch-device #mlGutter { font-size: 11px; padding: 3px 10px; }
}
