/* ══════════════════════════════════════════════════════════
   Turbo Rally — layout. Components come from the realm kit
   (realm/realm.css); this file arranges them and adds the few
   pieces that are Turbo Rally's own: the wordmark, the touch
   controls, the podium.
   ══════════════════════════════════════════════════════════ */
:root{ --tr-green:#96e896; --tr-green-d:rgba(150,232,150,.18); }
*{box-sizing:border-box}
html,body{margin:0;height:100%;overflow:hidden;background:var(--er-night);color:var(--er-text);overscroll-behavior:none;-webkit-user-select:none;user-select:none;-webkit-touch-callout:none}
body{font-family:var(--er-body)}
button{font:inherit;color:inherit}
kbd{display:inline-block;min-width:22px;padding:2px 6px;margin:0 1px;border-radius:6px;border:1px solid var(--er-line);border-bottom-width:2px;background:rgba(234,251,248,.06);font:600 12px/1.4 var(--er-body);text-align:center}

#cv{position:fixed;inset:0;width:100%;height:100%;display:block;touch-action:none}
#cv3d{position:fixed;inset:0;width:100%;height:100%;display:none;touch-action:none}
body.tr-3d #cv3d{display:block}
body.tr-3d #cv{background:transparent}
#hudbar{display:flex;gap:6px}
#hudbar[hidden]{display:none}

/* ── menus over the live race ── */
#menu{position:fixed;inset:0;overflow-y:auto;overflow-x:hidden;-webkit-overflow-scrolling:touch;
  background:linear-gradient(100deg,rgba(6,23,28,.94) 0%,rgba(6,23,28,.82) 45%,rgba(6,23,28,.45) 100%);
  padding:calc(64px + env(safe-area-inset-top)) max(16px,env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) max(16px,env(safe-area-inset-left))}
#menu.tr-solid{background:rgba(6,23,28,.92)}
.tr-screen{max-width:1080px;margin:0 auto;animation:tr-in .35s var(--er-ease)}
@keyframes tr-in{from{opacity:0;transform:translateY(8px)}}

/* the wordmark: Turbo Rally's own voice */
.tr-hero{margin:0 0 22px}
.tr-logo{margin:0;display:flex;flex-direction:column;line-height:.86;font:italic 800 clamp(48px,9vw,96px)/.86 var(--er-display);letter-spacing:-.04em;text-transform:uppercase}
.tr-logo span:first-child{color:var(--er-text)}
.tr-logo span:last-child{color:var(--tr-green);text-shadow:0 0 34px rgba(150,232,150,.45);margin-left:.35em}
.tr-tag{margin:10px 0 0 4px;font:600 15px/1 var(--er-body);letter-spacing:.18em;text-transform:uppercase;color:var(--er-muted)}

.tr-home-grid{display:grid;grid-template-columns:minmax(0,1.15fr) minmax(0,1fr);gap:16px;align-items:start}
.tr-daily{padding:22px;cursor:pointer;display:flex;flex-direction:column;gap:14px;outline:none;transition:transform .2s var(--er-ease)}
.tr-daily:hover,.tr-daily:focus-visible{transform:translateY(-2px)}
.tr-daily-head{display:flex;justify-content:space-between;align-items:center}
.tr-daily-body{display:flex;gap:14px;justify-content:space-between;align-items:center}
.tr-daily h2{font-size:30px;margin:6px 0}
.tr-daily-res{margin:10px 0 0;font-size:14px}
.tr-daily-res b{font-family:var(--er-display);font-size:18px}
.tr-thumb{display:inline-block;flex:0 0 auto;line-height:0}
.tr-modes{display:grid;grid-template-columns:1fr 1fr;gap:10px}
.tr-mode{display:flex;flex-direction:column;align-items:flex-start;gap:4px;padding:16px;min-height:96px;text-align:left;cursor:pointer;border-radius:20px;transition:transform .15s var(--er-ease),border-color .2s;position:relative}
.tr-mode:hover,.tr-mode:focus-visible{transform:translateY(-2px);border-color:rgba(150,232,150,.45);outline:none}
.tr-mode b{font:700 18px/1.15 var(--er-display)}
.tr-mode span{font-size:13px;color:var(--er-muted)}
.tr-mode em{font-style:normal;font-size:13px;margin-top:auto;color:#ffd45f}
.tr-garage-tile i{position:absolute;right:10px;bottom:6px;line-height:0}
.tr-foot{display:flex;gap:8px;flex-wrap:wrap;margin-top:18px}

/* headers on inner screens */
.tr-head{display:flex;align-items:center;gap:14px;margin:0 0 16px}
.tr-head .er-title{font-size:30px}
.tr-head p{margin:4px 0 0;font-size:14px}
.tr-back{width:40px;padding:0}
.tr-tabs-row{display:flex;align-items:center;gap:14px;flex-wrap:wrap;margin:0 0 16px}
.tr-scroll-tabs{max-width:100%;overflow-x:auto}
.tr-scroll-tabs button{white-space:nowrap}
.er-tabs button[aria-disabled="true"],.er-tabs button[disabled]{opacity:.5}
.tr-cls-blurb{margin:0;font-size:14px}
.tr-stars{color:#ffd45f;letter-spacing:2px}
.tr-stars i{font-style:normal;color:rgba(234,251,248,.18)}

.tr-cups{display:grid;grid-template-columns:repeat(auto-fill,minmax(240px,1fr));gap:12px}
.tr-cup{padding:16px;text-align:left;cursor:pointer;display:flex;flex-direction:column;gap:10px;transition:transform .15s var(--er-ease)}
.tr-cup:hover{transform:translateY(-2px)}
.tr-cup-top{display:flex;justify-content:space-between;align-items:center;gap:8px}
.tr-cup-top b{font:700 18px/1.1 var(--er-display)}
.tr-cup-thumbs{display:flex;gap:4px}
.tr-cup p{margin:0;font-size:13px}
.locked{opacity:.55}
.locked .tr-thumb{filter:grayscale(1)}

.tr-tracks{display:grid;grid-template-columns:repeat(auto-fill,minmax(180px,1fr));gap:12px}
.tr-track{padding:14px;display:flex;flex-direction:column;gap:4px;align-items:flex-start;text-align:left;cursor:pointer;transition:transform .15s var(--er-ease)}
.tr-track:hover{transform:translateY(-2px)}
.tr-track b{font:700 16px/1.2 var(--er-display);margin-top:6px}
.tr-track span{font-size:13px}
.tr-best{font:700 15px/1.2 var(--er-display);margin-top:4px}
.tr-lockline{margin:-6px 0 14px}

.tr-brief{padding:22px;max-width:860px}
.tr-setup{display:grid;grid-template-columns:auto 1fr;gap:22px;align-items:start}
.tr-setup .er-actions{grid-column:1/-1;margin-top:4px}
.tr-big-thumb{padding:10px;border-radius:18px;background:rgba(6,23,28,.5);border:1px solid var(--er-line)}
.tr-opts{display:grid;gap:14px}
.tr-opt{display:grid;gap:8px;margin:0 0 12px}
.tr-statrow{display:flex;flex-wrap:wrap;gap:22px;margin:4px 0 16px}
.tr-medals{display:grid;grid-template-columns:repeat(4,1fr);gap:6px;margin:8px 0 14px}
.tr-medals .er-tile{display:grid;gap:2px;text-align:center;padding:8px 6px;opacity:.75}
.tr-medals .er-tile.got{opacity:1;border-color:rgba(150,232,150,.5);background:var(--tr-green-d)}
.tr-medals span{font-size:20px}
.tr-medals b{font:700 14px/1.2 var(--er-display)}
.tr-medals em{font-style:normal;font-size:11px;color:var(--er-muted);letter-spacing:.08em;text-transform:uppercase}
.tr-race-list{list-style:none;padding:0;margin:8px 0 18px;display:grid;grid-template-columns:repeat(auto-fill,minmax(220px,1fr));gap:8px}
.tr-race-list li{display:flex;align-items:center;gap:10px}
.tr-race-list b,.tr-rival b{display:block;font-size:14px}
.tr-race-list span,.tr-rival span{display:block;font-size:12.5px}
.tr-rivals{display:grid;grid-template-columns:repeat(auto-fill,minmax(240px,1fr));gap:8px;margin:8px 0 14px}
.tr-rival{display:flex;gap:10px;align-items:center}
.tr-small{font-size:13px}
.tr-daily-page h2{font-size:28px;margin:0 0 6px}
.tr-daily-page p{margin:0 0 10px}

/* duo */
.tr-duo{display:grid;grid-template-columns:1fr 1fr;gap:12px;margin:0 0 16px}
.tr-keys{font-size:13px;color:var(--er-muted);margin:8px 0}
.tr-carpick{display:flex;flex-wrap:wrap;gap:6px}
.tr-carpick .er-tile{padding:4px 6px;cursor:pointer;line-height:0}
.tr-carpick .is-on,.tr-car.is-on{border-color:var(--tr-green);background:var(--tr-green-d)}
.tr-select,.tr-input{height:40px;border-radius:12px;border:1px solid var(--er-line);background:rgba(6,23,28,.6);color:var(--er-text);font:500 15px var(--er-body);padding:0 12px;max-width:320px;width:100%}
.tr-field{display:grid;gap:8px;margin:0 0 14px}
input[type=range]{width:100%;max-width:320px;accent-color:var(--er-mint)}
.tr-settings{max-width:560px}

/* garage */
.tr-promise{margin:-4px 0 16px;color:var(--er-muted);font-size:14px}
.tr-promise b{color:var(--tr-green)}
.tr-garage{display:grid;grid-template-columns:minmax(260px,360px) 1fr;gap:16px;align-items:start}
.tr-showroom{padding:18px;text-align:center;position:sticky;top:0}
.tr-showroom canvas{width:100%;max-width:320px;aspect-ratio:4/3;height:auto}
.tr-showroom h2{font-size:26px;margin:4px 0}
.tr-showroom p{margin:0;font-size:14px}
.tr-garage-side .er-kicker{margin:4px 0 8px}
.tr-cars{display:grid;grid-template-columns:repeat(auto-fill,minmax(96px,1fr));gap:8px;margin-bottom:14px}
.tr-car{display:flex;flex-direction:column;align-items:center;gap:4px;cursor:pointer;font-size:12px;text-align:center}
.tr-paints{display:grid;grid-template-columns:repeat(auto-fill,minmax(86px,1fr));gap:8px;margin-bottom:14px}
.tr-swatch{display:flex;flex-direction:column;align-items:center;gap:4px;padding:8px 4px;border-radius:14px;border:1px solid var(--er-line);background:rgba(234,251,248,.04);cursor:pointer;font-size:11.5px;position:relative}
.tr-swatch i{width:34px;height:34px;border-radius:50%;box-shadow:inset 0 0 0 2px rgba(255,255,255,.25)}
.tr-swatch em{font-style:normal;font-size:10.5px;color:#D3E1FF}
.tr-swatch.is-on{border-color:var(--tr-green);background:var(--tr-green-d)}
.tr-swatch.locked{opacity:.7}

.tr-help{margin:0 0 14px;padding-left:20px;display:grid;gap:10px;font-size:15px;line-height:1.5}

/* ── in-race ── */
#hudbar{position:fixed;top:calc(10px + env(safe-area-inset-top));right:calc(10px + env(safe-area-inset-right));z-index:5}
.tr-pausebtn{width:44px;padding:0;background:rgba(6,23,28,.6);backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px)}

#overlay{position:fixed;inset:0;z-index:20;display:grid;place-items:center;padding:16px;overflow-y:auto;background:radial-gradient(circle at 50% 40%,rgba(6,23,28,.55),rgba(6,23,28,.85));animation:tr-fade .3s ease}
#overlay[hidden]{display:none}
@keyframes tr-fade{from{opacity:0}}
.tr-pause{padding:28px;width:min(360px,100%);text-align:center}
.tr-pause .er-title{font-size:26px;margin:8px 0 6px}
.tr-col{flex-direction:column}
.tr-results{width:min(620px,100%);max-height:calc(100svh - 32px);overflow-y:auto;animation:er-pop .4s var(--er-ease)}
.tr-results .er-result{padding:26px 22px 22px}
.tr-result-title{font-size:clamp(34px,6vw,48px);margin:6px 0 10px;font-style:italic}
.tr-center{justify-content:center}
.tr-medal,.tr-trophy{font-size:64px;line-height:1;margin:10px 0 0;animation:er-star .6s cubic-bezier(.2,1.6,.4,1) both}
.tr-trophy.none{filter:grayscale(1);opacity:.4}
.tr-trophy.silver{filter:grayscale(1) brightness(1.3)}
.tr-trophy.bronze{filter:sepia(1) saturate(1.4) hue-rotate(-20deg) brightness(.9)}
.tr-pb{color:var(--tr-green);font-weight:600;margin:6px 0}
.tr-pb.worse{color:var(--er-peach)}
.tr-table{width:100%;border-collapse:collapse;margin:14px 0;font-size:14px;text-align:left}
.tr-table th{font:600 10.5px/1 var(--er-body);letter-spacing:.12em;text-transform:uppercase;color:var(--er-muted);padding:6px 8px;border-bottom:1px solid var(--er-line)}
.tr-table td{padding:8px;border-bottom:1px solid rgba(234,251,248,.06)}
.tr-table tr.me td{background:var(--tr-green-d);font-weight:600}
.tr-table td:first-child{width:28px;font-family:var(--er-display);font-weight:700}
.tr-dot{display:inline-block;width:10px;height:10px;border-radius:50%;margin-right:8px;vertical-align:middle;box-shadow:0 0 0 2px rgba(255,255,255,.2)}
.tr-podium{display:flex;justify-content:center;align-items:flex-end;gap:6px;margin:8px 0 4px}
.tr-step{display:flex;flex-direction:column;align-items:center;gap:4px;width:92px}
.tr-step b{font-size:13px}
.tr-step span{display:block;width:100%;border-radius:12px 12px 0 0;background:rgba(234,251,248,.08);border:1px solid var(--er-line);font:800 22px/1 var(--er-display);padding-top:10px;text-align:center}
.tr-step.s1 span{height:72px;background:linear-gradient(rgba(255,212,95,.35),rgba(255,212,95,.08));color:#ffd45f}
.tr-step.s2 span{height:52px}
.tr-step.s3 span{height:38px}
.tr-laps{display:flex;flex-wrap:wrap;justify-content:center;gap:6px;margin:14px 0}
.tr-laps .er-tile{display:grid;gap:2px;padding:8px 14px;text-align:center}
.tr-laps .er-tile span{font-size:11px;color:var(--er-muted);letter-spacing:.1em;text-transform:uppercase}
.tr-laps .er-tile b{font:700 16px/1.2 var(--er-display)}
.tr-laps .best{border-color:rgba(150,232,150,.5);background:var(--tr-green-d)}
.tr-next{display:flex;align-items:center;gap:12px;text-align:left;margin:6px auto 0;max-width:340px}
.tr-next b{display:block}
.tr-next span{display:block;font-size:12.5px}
.tr-unlocks{margin:8px 0 12px;display:flex;flex-wrap:wrap;gap:6px;justify-content:center}
.tr-unlocks .er-kicker{width:100%;margin:0 0 2px}

/* ── touch controls ── */
#touch{position:fixed;inset:auto 0 0 0;height:min(46vh,220px);z-index:4;pointer-events:none;touch-action:none}
#touch[hidden]{display:none}
#touch > *{pointer-events:auto}
.tc-steer{position:absolute;left:calc(14px + env(safe-area-inset-left));bottom:calc(14px + env(safe-area-inset-bottom));width:min(42vw,240px);height:min(30vh,130px);border-radius:24px;display:flex;
  background:rgba(6,23,28,.35);border:1px solid rgba(234,251,248,.18);backdrop-filter:blur(6px);-webkit-backdrop-filter:blur(6px);touch-action:none}
.tc-steer span{flex:1;display:grid;place-items:center;font-size:30px;color:rgba(234,251,248,.75);transition:background .08s}
.tc-steer span:first-child{border-right:1px solid rgba(234,251,248,.12)}
.tc-steer[data-dir="l"] .tc-l,.tc-steer[data-dir="r"] .tc-r{background:rgba(150,232,150,.25);color:#fff}
.tc-steer span:first-child{border-radius:24px 0 0 24px}.tc-steer span:last-child{border-radius:0 24px 24px 0}
#touch.tilt .tc-steer{display:none}
.tc-right{position:absolute;right:calc(14px + env(safe-area-inset-right));bottom:calc(14px + env(safe-area-inset-bottom));display:grid;grid-template-columns:auto auto;grid-template-rows:auto auto;gap:10px;align-items:end}
.tc-btn{border:1px solid rgba(234,251,248,.2);border-radius:50%;background:rgba(6,23,28,.38);backdrop-filter:blur(6px);-webkit-backdrop-filter:blur(6px);color:rgba(234,251,248,.85);font:700 11px/1 var(--er-body);letter-spacing:.08em;touch-action:none;transition:transform .06s,background .08s}
.tc-btn.on{transform:scale(.94);background:rgba(150,232,150,.3);color:#fff}
.tc-hand{width:92px;height:92px;grid-column:2;grid-row:1/3;background:rgba(255,179,138,.22);border-color:rgba(255,179,138,.45)}
.tc-hand.on{background:rgba(255,179,138,.5)}
.tc-brake{width:64px;height:64px;grid-column:1;grid-row:2}
.tc-gas{width:64px;height:64px;grid-column:1;grid-row:1}
#touch.autogas .tc-gas{visibility:hidden}

/* first race on a touch screen: name each control for a few seconds */
.tc-teach .tc-steer::after,.tc-teach .tc-btn::after{position:absolute;left:50%;bottom:calc(100% + 6px);transform:translateX(-50%);white-space:nowrap;
  font:600 11px/1 var(--er-body);letter-spacing:.06em;color:var(--er-night);background:var(--er-mint);padding:5px 8px;border-radius:999px;animation:tr-pulse 1.2s ease-in-out infinite}
.tc-teach .tc-steer::after{content:"Slide to steer"}
.tc-teach .tc-hand::after{content:"Hold to drift"}
.tc-teach .tc-brake::after{content:"Brake / reverse"}
.tc-teach .tc-gas::after{content:"Gas"}
.tc-btn{position:relative}
@keyframes tr-pulse{50%{transform:translateX(-50%) translateY(-3px)}}

/* ── phones ── */
@media (max-width:820px){
  .tr-home-grid{grid-template-columns:1fr}
  .tr-setup{grid-template-columns:1fr}
  .tr-big-thumb{justify-self:center}
  .tr-garage{grid-template-columns:1fr}
  .tr-showroom{position:static}
}
@media (max-width:520px){
  .tr-modes{grid-template-columns:1fr 1fr}
  .tr-mode{min-height:84px;padding:12px}
  .tr-mode b{font-size:16px}
  .tr-daily{padding:16px}
  .tr-daily h2{font-size:24px}
  .tr-daily-body .tr-thumb{display:none}
  .tr-medals{grid-template-columns:repeat(2,1fr)}
  .tr-duo{grid-template-columns:1fr}
  .tr-hide-s{display:none}
  .tr-step{width:76px}
}
/* phones held sideways: short screens need compact menus */
@media (max-height:500px){
  #menu{padding-top:calc(54px + env(safe-area-inset-top))}
  .tr-hero{margin-bottom:12px}
  .tr-logo{font-size:44px;flex-direction:row;gap:.25em}
  .tr-logo span:last-child{margin-left:0}
  .tr-tag{display:none}
  .tr-home-grid{grid-template-columns:1.1fr 1fr}
  .tr-daily{padding:14px;gap:8px}
  .tr-daily h2{font-size:22px}
  .tr-mode{min-height:0;padding:10px 12px}
  .tr-mode span{display:none}
  .tr-mode b{font-size:16px}
  .tr-modes{gap:8px}
  .tr-daily-body .tr-thumb{display:none}
  .tr-daily-body .er-muted{display:none}
  .tr-daily-res{margin-top:4px}
  .tr-daily .er-btn.lg{height:44px}
  .tr-garage-tile i{bottom:2px;transform:scale(.75);transform-origin:bottom right}
  .tr-foot{margin-top:10px}
  .tr-head .er-title{font-size:24px}
  .tr-results .er-result{padding:16px}
  .tr-medal,.tr-trophy{font-size:44px}
  .tr-podium{display:none}
}
@media (prefers-reduced-motion:reduce){.tr-screen,.tr-results,.tc-teach .tc-btn::after,.tc-teach .tc-steer::after{animation:none}}
#camBtn[hidden]{display:none}

.tr-comfort{display:flex;align-items:center;gap:14px;justify-content:space-between;margin:0 0 16px}
.tr-comfort b{display:block;font-size:14px}
.tr-comfort span{display:block;font-size:12.5px;margin-top:3px}
@media (max-width:520px){.tr-comfort{flex-direction:column;align-items:flex-start}}

/* ── phones ──
   The notch: a probe the game reads for the canvas HUD */
#safeProbe{position:fixed;left:0;top:0;width:0;height:0;visibility:hidden;pointer-events:none;padding-left:env(safe-area-inset-left);padding-right:env(safe-area-inset-right)}

/* held upright: a full-screen card asking to turn the phone */
#rotateCard{position:fixed;inset:0;z-index:2147483300;display:grid;place-items:center;padding:24px;text-align:center;
  background:radial-gradient(120% 70% at 50% 0%,rgba(150,232,150,.16),transparent 60%),radial-gradient(90% 60% at 50% 100%,rgba(45,226,196,.14),transparent 60%),var(--er-night)}
#rotateCard[hidden]{display:none}
#rotateCard .rc-in{max-width:320px;display:grid;justify-items:center;gap:10px}
#rotateCard h2{font-size:28px}
#rotateCard p{margin:0}
.rc-phone{width:64px;height:110px;border-radius:14px;border:3px solid var(--er-mint);box-shadow:0 0 30px rgba(45,226,196,.35);position:relative;margin-bottom:18px;animation:rc-turn 2.6s var(--er-ease) infinite}
.rc-phone i{position:absolute;left:50%;top:7px;width:16px;height:3px;border-radius:3px;background:var(--er-mint);transform:translateX(-50%)}
.rc-phone::after{content:"";position:absolute;inset:16px 7px;border-radius:6px;background:linear-gradient(160deg,rgba(150,232,150,.35),rgba(45,226,196,.08))}
@keyframes rc-turn{0%,20%{transform:rotate(0)}55%,80%{transform:rotate(-90deg)}100%{transform:rotate(0)}}
.rc-anyway{margin-top:14px;border:0;background:none;color:var(--er-muted);font:600 13px/1 var(--er-body);text-decoration:underline;text-underline-offset:3px;padding:12px;cursor:pointer}
@media (prefers-reduced-motion:reduce){.rc-phone{animation:none;transform:rotate(-90deg)}}

/* held sideways: the race fills the screen, the pause sits clear of the notch */
body.tr-phone-land #hudbar{top:calc(6px + env(safe-area-inset-top));right:calc(8px + env(safe-area-inset-right))}
body.tr-phone-land .tr-pausebtn{width:40px;height:34px}
body.tr-phone-land #menu{padding-left:max(16px,calc(env(safe-area-inset-left) + 8px));padding-right:max(16px,calc(env(safe-area-inset-right) + 8px))}
body.tr-phone-land .tc-steer{width:min(38vw,230px);height:min(36vh,132px)}
body.tr-phone-land .tc-hand{width:84px;height:84px}
body.tr-phone-land .tc-gas,body.tr-phone-land .tc-brake{width:62px;height:62px}
/* first-race labels on a phone held sideways: brake's label sits beside it, clear of GAS */
body.tr-phone-land .tc-teach .tc-brake::after{bottom:auto;top:50%;left:auto;right:calc(100% + 8px);transform:translateY(-50%);animation:none}
body.tr-phone-land #menu{padding-top:calc(60px + env(safe-area-inset-top))}
/* paused, held sideways: a wide panel, two columns of buttons, clear of the realm bar */
body.tr-phone-land #overlay{padding-top:calc(52px + env(safe-area-inset-top))}
body.tr-phone-land .tr-pause{width:min(560px,100%);padding:14px 20px 18px}
body.tr-phone-land .tr-pause .er-title{font-size:20px;margin:4px 0 10px}
body.tr-phone-land .tr-pause .tr-col{display:grid;grid-template-columns:1fr 1fr;gap:8px}
body.tr-phone-land .tr-pause .tr-col > *{margin:0;width:100%}
body.tr-phone-land .tr-pause #pResume{grid-column:1 / -1}
body.tr-phone-land .tr-pause .er-kicker{display:none}
body.tr-phone-land .tr-pause #pResume{min-height:44px;font-size:17px}
