/* Phones and tablets (touch): one layout for the HUD, the touch controls, the
   full-screen prompt, notches and the home bar, steering and the handbrake. Loads
   after hud.css, so it wins over the older touch rules there. */

/* ================= Phones and tablets (touch): one layout =================
   --peek: how much of the tucked-away phone shows at the bottom.
   Portrait: the clock and money top left, the minimap and speedometer top
   right; the Directions and Phone buttons down the left with toasts under
   them; the tutorial's prompt and hints full width under those; the
   objective and new-order banners at the bottom, above the phone and left of
   the touch buttons (handbrake, action) in the bottom right corner.
   Landscape: the timer, objective and banners top middle, the phone tucked
   right down to a handle, the touch buttons side by side bottom right. */
body.touch { --peek: 64px; }
body.touch:has(#phone.music) { --peek: 100px; }

/* the handbrake: a big round mustard sticker, orange (pressed into its shadow) while you hold it */
body.touch #touchBtns .tbtn.hand { --c: var(--gd-mustard); position: relative; width: 96px; height: 96px; border-radius: 50%; font-size: 13px; transition: transform .06s, background .06s, box-shadow .06s; }
body.touch #touchBtns .tbtn.hand.down { --c: var(--gd-dash); transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--gd-ink); }
body.touch #touchBtns .tbtn.hand.down::after { content: ''; position: absolute; inset: -10px; border-radius: 50%; border: 3px dashed var(--gd-dash); animation: hbHold .7s ease-out infinite; pointer-events: none; }
@keyframes hbHold { from { transform: scale(.9); opacity: 1; } to { transform: scale(1.25); opacity: 0; } }
body.touch #touchBtns .tbtn.action { width: 74px; height: 74px; }
html body.touch #touchBtns, html body.touch:has(#phone.music) #touchBtns { bottom: calc(var(--peek) + 16px); right: 12px; gap: 14px; } /* (html: over the older rules in phone.css) */

/* only the newest two toasts, smaller */
body.touch #hud #toast { gap: 6px; }
body.touch #hud #toast .toastItem { font-size: 13px; padding: 7px 11px; }
body.touch #hud #toast .toastItem:nth-last-child(n+3) { display: none; }
/* the tutorial's prompt says what to do: no objective as well */
body:has(#tutBox:not(.hidden)) #hud #objective { display: none; }

@media (orientation: portrait) {
  body.touch #hud #timer { top: 64px; left: 50%; transform: translateX(-50%); min-width: 96px; padding: 3px 12px 5px; }
  body.touch #hud #timer b { font-size: 24px; }
  body.touch #hud #hudBtns { top: 110px; left: 10px; }
  body.touch #hud #toast { top: 196px; left: 10px; right: auto; max-width: 64vw; }
  body.touch #hud #tutBox { top: 196px; left: 10px; right: 10px; width: auto; transform: none; }
  body.touch:has(#tutBox:not(.hidden)) #hud #toast { top: 300px; }
  body.touch #hint { top: 196px; left: 10px; right: 10px; transform: none; max-width: none; }
  body.touch:has(#hint:not(.hidden)) #hud #toast { top: 300px; }
  /* the bottom lane, centered just above the phone: the objective, or a new
     order coming in (it slides up; tap it to see the order) */
  body.touch #hud #objective, body.touch #hud #timer.hidden + #objective, body.touch.driving #hud #objective, body.touch #hud #timer:not(.hidden) + #objective {
    top: auto; bottom: calc(var(--peek) + 14px); left: 50%; right: auto; transform: translateX(-50%); max-width: calc(100vw - 20px); width: max-content; font-size: 13px; padding: 7px 12px; }
  body.touch #hud #notify { top: auto; bottom: calc(var(--peek) + 12px); left: 50%; right: auto; width: min(420px, calc(100vw - 20px)); transform: translate(-50%, calc(100% + var(--peek) + 40px)); transition: transform .35s cubic-bezier(.2,1.3,.4,1); flex-direction: column-reverse; } /* (the newest nearest the phone) */
  body.touch #hud #notify .nItem { padding: 8px 10px; gap: 8px; }
  body.touch #hud #notify.show { top: auto; transform: translateX(-50%); }
  /* (the same width as the phone under it: centered on a phone, over the
     phone in the bottom-right corner on a tablet; phone.css sizes it) */
  body.touch #hud #notify { width: min(360px, 94vw); }
  @media (min-width: 701px) and (min-height: 521px) {
    body.touch #hud #notify { width: 330px; left: auto; right: 24px; transform: translateY(calc(100% + var(--peek) + 40px)); }
    body.touch #hud #notify.show { transform: none; }
  }
  /* the touch buttons sit above that lane: the action button on top, over the handbrake */
  html body.touch #touchBtns, html body.touch:has(#phone.music) #touchBtns { flex-direction: column-reverse; align-items: flex-end; bottom: calc(var(--peek) + 86px); }
  body.touch #touchBtns .tbtn.action { margin-right: 11px; } /* (centered over the 96px handbrake) */
  body.touch #hud #bustBar { top: 30%; width: 200px; }
  body.touch #hud #scoreboard { position: fixed; top: auto; bottom: calc(var(--peek) + 290px); right: 10px; width: 170px; font-size: 11px; }
}
@media (orientation: landscape) {
  html body.touch, html body.touch:has(#phone.music) { --peek: 24px; }
  /* the phone tucks right down to a handle (tap it, or Phone, to bring it up) */
  html body.touch #phoneWrap:not(.open), html body.touch #phoneWrap:not(.open):has(#phone.music), html body.touch.driving #phoneWrap:not(.open), html body.touch.driving #phoneWrap:not(.open):has(#phone.music) { transform: translateY(calc(100% - 24px)); }
  html body.touch #phoneWrap:not(.open) #phone .statusbar, html body.touch #phoneWrap:not(.open) #phone .notch, html body.touch #phoneWrap:not(.open) #phone #miniPlayer { opacity: 0; }
  body.touch #hud #timer { top: 10px; }
  body.touch #hud #objective, body.touch #hud #timer.hidden + #objective, body.touch.driving #hud #objective, body.touch #hud #timer:not(.hidden) + #objective {
    top: 86px; bottom: auto; left: 50%; right: auto; transform: translateX(-50%); max-width: 46vw; font-size: 13px; padding: 6px 12px; } /* (86: under the speedometer, which sits beside the minimap sideways) */
  body.touch #hud #timer.hidden + #objective { top: 86px; }
  body.touch #hud #notify.show { top: 86px; }
  body.touch:has(#bustBar:not(.hidden)) #hud #notify.show { top: 186px; } /* (under the BUSTED meter while it's up) */
  body.touch #hud #notify { width: min(400px, 52vw); }
  body.touch #hud #notify .nItem { padding: 7px 10px; }
  body.touch #hud #toast { top: 196px; left: 10px; max-width: 38vw; }
  body.touch #hud #tutBox { top: 86px; width: min(440px, 50vw); }
  body.touch #hint { top: auto; bottom: 34px; left: 50%; right: auto; transform: translateX(-50%); max-width: 52vw; }
  html body.touch #touchBtns, html body.touch:has(#phone.music) #touchBtns { flex-direction: row; align-items: flex-end; bottom: calc(var(--peek) + 12px); right: 12px; } /* (clear of the phone's handle) */
  body.touch #touchBtns .tbtn.hand { width: 90px; height: 90px; }
  body.touch #joyZone, body.touch.driving #joyZone { bottom: 30px; }
}

/* "Play full screen" (js/install.js): the first thing on a phone or tablet */
#playBetter { position: fixed; inset: 0; z-index: 45; display: grid; place-items: center; background: rgba(12,14,22,.6); padding: 16px; pointer-events: auto; animation: toastIn .3s ease-out; }
#playBetter .pbCard { width: min(420px, 100%); max-height: calc(100% - 8px); overflow-y: auto; background: #fff; color: var(--gd-ink); border: var(--gd-line) solid var(--gd-ink); border-radius: var(--gd-r-lg); padding: 18px 18px 14px; text-align: center; box-shadow: 0 0 0 5px var(--gd-dash), 6px 6px 0 5px var(--gd-ink); }
#playBetter img { width: 76px; height: 76px; border-radius: 18px; display: block; margin: 0 auto 6px; border: var(--gd-line) solid var(--gd-ink); box-shadow: 3px 3px 0 var(--gd-ink); }
#playBetter h2 { margin: 2px 0 6px; font: 700 22px/1.15 var(--gd-font); text-transform: uppercase; }
#playBetter p { margin: 0 0 12px; font: 500 14px/1.4 var(--gd-font); color: #4a4f5c; }
/* (the steps: numbered mustard dots) */
#playBetter .pbSteps { list-style: none; counter-reset: pbs; display: grid; gap: 9px; text-align: left; margin: 0 0 14px; padding: 0; font: 500 14px/1.3 var(--gd-font); color: var(--gd-ink); }
#playBetter .pbSteps li { counter-increment: pbs; display: flex; align-items: center; gap: 10px; }
#playBetter .pbSteps li::before { content: counter(pbs); display: grid; place-items: center; width: 26px; height: 26px; flex: none; border: 2px solid var(--gd-ink); border-radius: 50%; background: var(--gd-mustard); font: 700 13px/1 var(--gd-font); }
#playBetter .pbShare { display: inline-block; width: 14px; height: 16px; vertical-align: -2px; border: 2px solid var(--gd-blue); border-top: 0; border-radius: 0 0 3px 3px; position: relative; }
#playBetter .pbShare::before { content: ''; position: absolute; left: 50%; top: -7px; width: 2px; height: 12px; background: var(--gd-blue); transform: translateX(-50%); }
#playBetter .pbBtns { display: flex; flex-direction: column; gap: 8px; }
#playBetter .pbBtns .btn { margin: 0; }
#playBetter .pbNever { margin-top: 10px; background: none; border: 0; color: var(--gd-mute); font: 700 12px/1 var(--gd-font); text-transform: uppercase; letter-spacing: .04em; text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; padding: 6px 4px; cursor: pointer; }
@media (orientation: landscape) and (max-height: 520px) {
  #playBetter .pbCard { padding: 12px 16px 8px; }
  #playBetter img { width: 48px; height: 48px; }
  #playBetter h2 { font-size: 20px; }
  #playBetter p { font-size: 13px; margin-bottom: 8px; }
  #playBetter .pbBtns { flex-direction: row; }
  #playBetter .pbBtns .btn { flex: 1; }
}
/* No tips on phones and tablets for now (hints, flashed tips, labels over
   things, key prompts, "open your phone"): the "play full screen" card, the
   tutorial, objectives, banners and toasts still show. */
body.touch #hint, body.touch #flashTip, body.touch #worldTip, body.touch #hud #prompts, body.touch #phoneTip, body.touch #corner { display: none !important; }

/* Phones with a notch, a Dynamic Island or a home bar (an iPhone, installed as
   an app, draws right to the edges): everything on screen stays inside the
   safe area, clear of the clock, battery, island and home bar. (env() is 0
   everywhere else.) --vgap is how far short of the bottom of the screen an
   installed iPhone app's page comes up (install.js fitStandalone; 0 almost
   always): the bottom edge reaches down by that much, so there's no black
   strip under the game. */
#hud, #touch { top: env(safe-area-inset-top, 0px); right: env(safe-area-inset-right, 0px); bottom: calc(env(safe-area-inset-bottom, 0px) - var(--vgap, 0px)); left: env(safe-area-inset-left, 0px); }
#playBetter, #tutWelcome, #tutCard, #gamePopup { padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); }
#phoneWrap { margin-bottom: calc(env(safe-area-inset-bottom, 0px) - var(--vgap, 0px)); }
@media (orientation: landscape) {
  /* (sideways, the phone keeps clear of the island on either side) */
  #phoneWrap { padding: 0 env(safe-area-inset-right, 0px) 0 env(safe-area-inset-left, 0px); }
}

/* The Reverse button (touch, driving): beside the handbrake, the size of the
   action button; held, it brakes and then backs up (game/player.js). */
body.touch #touchBtns .tbRow { display: flex; align-items: center; gap: 12px; }
#touchBtns .tbtn.rev { display: none; }
body.touch.driving #touchBtns .tbtn.rev { display: flex; position: relative; width: 74px; height: 74px; border-radius: 50%; font-size: 11px; transition: transform .06s, background .06s, box-shadow .06s; }
body.touch #touchBtns .tbtn.rev.down { --c: #dcebff; transform: translate(3px, 3px); box-shadow: 0 0 0 4px var(--gd-blue), 1px 1px 0 4px var(--gd-ink); }
body.touch #touchBtns .tbtn.rev.down::after { content: ''; position: absolute; inset: -12px; border-radius: 50%; border: 3px dashed var(--gd-blue); animation: hbHold .7s ease-out infinite; pointer-events: none; }

/* Touch: the HUD sits over the touch layer (the steering area), so the new
   order banner and the Directions button can be tapped; the rest of the HUD
   lets taps through. (There's no Phone button: the phone peeking up at the
   bottom, or its handle sideways, is what you tap.) */
body.touch #hud { z-index: 12; }

/* Touch driving with the sides of the screen (the default; Settings can
   switch to the joystick or tilting): hold the left half to steer left, the
   right half to steer right, both to brake and back up (input.js,
   sideControls() in game/player.js). START, in Reverse's place, turns the
   engine on and the car drives itself forward. */
#steerZone { position: absolute; inset: 0; display: none; pointer-events: auto; touch-action: none; }
body.touch.driving.side-steer #steerZone { display: block; }
body.touch.driving.side-steer #joyZone, body.touch.driving.side-steer #joyBase { display: none !important; }
/* (each side's arrow: a see-through round sticker, white while held, red with the handbrake on) */
#steerZone i { position: absolute; top: 42%; width: 64px; height: 64px; margin-top: -32px; border-radius: 50%; border: 3px solid var(--gd-ink); background: rgba(255,255,255,.45); opacity: .85; transition: transform .06s, background .06s, opacity .06s, box-shadow .06s; }
#steerZone i::before { content: ''; position: absolute; inset: 0; background: var(--gd-ink); clip-path: polygon(58% 26%, 34% 50%, 58% 74%, 66% 66%, 50% 50%, 66% 34%); }
#steerZone .sideL { left: 12px; }
#steerZone .sideR { right: 12px; transform: scaleX(-1); }
#steerZone.l .sideL, #steerZone.r .sideR { opacity: 1; background: #fff; box-shadow: 0 0 0 4px var(--gd-mustard); }
#steerZone.l .sideL { transform: scale(.92); }
#steerZone.r .sideR { transform: scaleX(-1) scale(.92); }
#steerZone.lh .sideL, #steerZone.rh .sideR { background: var(--gd-red); } /* (handbrake on: that side's arrow goes red) */
#steerZone.lh .sideL::before, #steerZone.rh .sideR::before { background: #fff; }
body.tilt-steer #steerZone i { display: none; } /* (tilting steers; both sides still brake) */
#touchBtns .tbtn.engine { display: none; }
body.touch.driving.side-steer #touchBtns .tbtn.rev, body.touch.driving.side-steer #touchBtns .tbtn.hand { display: none; } /* (the handbrake: slide a held thumb down) */
body.touch.driving.side-steer #touchBtns .tbtn.engine { --c: var(--gd-green); display: flex; position: relative; width: 74px; height: 74px; border-radius: 50%; font-size: 13px; animation: gd-breathe 1.6s infinite; }
#touchBtns .tbtn.engine .on, body.engine-on #touchBtns .tbtn.engine .off { display: none; }
body.engine-on #touchBtns .tbtn.engine .on { display: inline; }
body.touch.driving.side-steer.engine-on #touchBtns .tbtn.engine { --c: var(--gd-red); --t: #fff; animation: none; }
@media (orientation: landscape) {
  /* (sideways: on the edges halfway up, like upright, so there's room under
     your thumb to slide down for the handbrake; the speedometer moves up beside
     the minimap to leave the right edge free) */
  #steerZone i { top: 43%; } /* (clear of the minimap above and the toasts under it on the left) */
  body.touch #bottomLeft { flex-direction: row-reverse; align-items: flex-start; gap: 8px; }
}

/* Teaching the slide-down handbrake on a phone (guidance.js touchDriftHelp):
   a little down arrow by the side you're holding, sliding down, until you've
   used it a few times; and once, after a few turns, a tip saying so. */
#slideNudge, #slideSay { position: absolute; display: none; pointer-events: none; }
#slideNudge.on { display: block; width: 40px; height: 46px; top: calc(42% + 38px); }
#slideNudge.l { left: 24px; }
#slideNudge.r { right: 24px; }
#slideNudge::before, #slideNudge::after { content: ''; position: absolute; left: 6px; width: 28px; height: 16px; background: #fff; clip-path: polygon(0 0, 50% 60%, 100% 0, 100% 40%, 50% 100%, 0 40%); filter: drop-shadow(2px 2px 0 var(--gd-ink)); animation: slideNudge 1s ease-in infinite; }
#slideNudge::after { animation-delay: .5s; }
@keyframes slideNudge { from { top: 0; opacity: 0; } 30% { opacity: 1; } to { top: 30px; opacity: 0; } }
#slideSay.on { display: block; left: 50%; top: calc(42% + 46px); transform: translateX(-50%); width: max-content; max-width: min(260px, calc(100vw - 150px)); background: #fff; color: var(--gd-ink); border: var(--gd-line) solid var(--gd-ink); border-radius: 999px; padding: 9px 15px; font: 700 14px/1.25 var(--gd-font); text-align: center; box-shadow: var(--gd-sh-sm) var(--gd-sh-sm) 0 var(--gd-ink); animation: slideSayIn .3s ease-out; }
@keyframes slideSayIn { from { opacity: 0; } }
@media (orientation: landscape) {
  /* (sideways the nudge is under the arrow, as upright) */
  #slideNudge.on { top: calc(43% + 38px); }
  #slideSay.on { top: auto; bottom: calc(var(--peek) + 110px); }
}
