/* DRIFT — go sideways through a tiny golden town. */
:root {
  --ink: #2A2140;
  --cream: #FFF3DC;
  --accent: #FFC53D;
  --glass: rgba(42, 33, 64, .72);
  --glass-brd: rgba(255, 243, 220, .18);
  --pot: #FFD764;
  --bank: #5BE39A;
  --crash: #FF4D3D;
  --combo1: #FF4FA0;
  --combo2: #B96BFF;
  --sab: env(safe-area-inset-bottom, 0px);
  --sat: env(safe-area-inset-top, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  background: #35306B;
  color: var(--cream);
  font-family: "Saira", system-ui, sans-serif;
  user-select: none; -webkit-user-select: none;
  position: fixed; inset: 0;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; touch-action: manipulation; }
.mono { font-family: "Chivo Mono", ui-monospace, monospace; font-weight: 500; }
.hide { opacity: 0 !important; pointer-events: none !important; }

#gl { position: fixed; inset: 0; width: 100vw; height: 100dvh; display: block; touch-action: none; }

/* ============ HUD ============ */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud::before { /* miniature-sell vignette */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse 108% 86% at 50% 42%, transparent 62%, rgba(42, 33, 64, .30) 100%);
}
#hud.lowsun::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: rgba(18, 14, 44, .38);
}
.chip {
  background: var(--glass); border: 1px solid var(--glass-brd);
  border-radius: 14px; color: var(--cream);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
#speedChip {
  position: absolute; top: calc(10px + var(--sat)); left: calc(12px + var(--sal));
  padding: 6px 12px; display: flex; align-items: baseline; gap: 5px;
}
#speedChip b { font-style: italic; font-weight: 800; font-size: 1.35rem; font-variant-numeric: tabular-nums; min-width: 2.2ch; text-align: right; }
#speedChip .unit { font-size: .68rem; opacity: .7; font-weight: 700; letter-spacing: .14em; }
#cashChip {
  position: absolute; top: calc(58px + var(--sat)); left: calc(12px + var(--sal));
  padding: 3px 10px; font-style: italic; font-weight: 800; font-size: .82rem; color: var(--accent);
  font-variant-numeric: tabular-nums; transition: transform .2s;
}
#cashChip.flash { transform: scale(1.12); }

#scoreWrap {
  position: absolute; top: 15%; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center;
}
#bankedRow { display: flex; align-items: baseline; gap: 8px; }
.bk-label { font-size: .62rem; font-weight: 700; letter-spacing: .2em; opacity: .65; }
#bankedV { font-style: italic; font-weight: 800; font-size: 1.5rem; font-variant-numeric: tabular-nums; text-shadow: 0 2px 0 rgba(42,33,64,.6); }
#bankedV.flash { color: var(--bank); }
#potRow { transition: opacity .25s; }
#potV { font-style: italic; font-weight: 800; font-size: 2.1rem; color: var(--pot); font-variant-numeric: tabular-nums; text-shadow: 0 3px 0 rgba(42,33,64,.65); }
#comboB { position: relative; width: 52px; height: 52px; margin-top: 2px; transition: opacity .25s; }
#comboB svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
#comboB .ring-bg { fill: var(--glass); stroke: var(--glass-brd); stroke-width: 3; }
#comboArc { fill: none; stroke: var(--combo1); stroke-width: 3.5; stroke-linecap: round; stroke-dasharray: 119.4; stroke-dashoffset: 0; }
#comboV { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-style: italic; font-weight: 800; font-size: 1.05rem; color: var(--combo1); }
#comboB.hot #comboArc { stroke: var(--combo2); }
#comboB.hot #comboV { color: var(--combo2); }

/* banner sits BELOW the bank/pot/combo stack in every aspect — never over the combo ring */
#banner {
  position: absolute; top: calc(15% + 158px); left: 50%; transform: translateX(-50%);
  font-family: "Bungee", Impact, sans-serif; font-size: clamp(1.3rem, 6vw, 2.2rem);
  color: var(--cream); text-shadow: 3px 3px 0 var(--ink);
  white-space: nowrap; transition: opacity .3s, transform .3s;
}
#banner.pop { animation: bannerPop .45s cubic-bezier(.2,1.6,.4,1); }
@keyframes bannerPop { 0% { transform: translateX(-50%) scale(.4); } 100% { transform: translateX(-50%) scale(1); } }
#banner.bank { color: var(--bank); }
#banner.crash { color: var(--crash); }

#modeChip {
  position: absolute; top: calc(58px + var(--sat)); left: 50%; transform: translateX(-50%);
  padding: 5px 14px; display: flex; align-items: baseline; gap: 10px; white-space: nowrap;
}
#modeChip b { font-family: "Bungee", Impact, sans-serif; font-weight: 400; font-size: .8rem; color: var(--accent); }
#modeChip #modeTimer { font-size: .95rem; font-variant-numeric: tabular-nums; }
#modeChip #modeGoal { font-size: .8rem; opacity: .85; font-weight: 700; }

#topRight { position: absolute; top: calc(10px + var(--sat)); right: calc(12px + var(--sar)); display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
#mini { width: 88px; height: 88px; border-radius: 16px; opacity: .72; border: 1px solid var(--glass-brd); background: #2E2A52; }
#mini.big { width: 240px; height: 240px; opacity: .92; }
#micro { display: flex; gap: 6px; }
#micro button {
  pointer-events: auto; width: 44px; height: 44px; border-radius: 12px;
  background: var(--glass); border: 1px solid var(--glass-brd); color: var(--cream); font-size: .95rem;
}
#micro button.off { opacity: .45; }
#mini { pointer-events: auto; }

#popupLayer { position: absolute; inset: 0; overflow: hidden; }
.popup {
  position: absolute; left: 50%; top: 40%;
  font-style: italic; font-weight: 800; font-size: 1.3rem;
  text-shadow: 0 2px 0 rgba(42,33,64,.7); white-space: nowrap;
  transform: translate(-50%, 0); opacity: 0; pointer-events: none;
}
.popup.on { animation: popRise 1.1s ease-out forwards; }
@keyframes popRise { 0% { opacity: 0; transform: translate(-50%, 12px) scale(.7); } 15% { opacity: 1; transform: translate(-50%, 0) scale(1.05); } 75% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -46px) scale(1); } }

#toastLayer { position: absolute; top: calc(15% + 214px); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; width: 100%; }
body.a-wide #toastLayer { top: calc(216px + var(--sat)); }
body.a-square #toastLayer { top: calc(252px + var(--sat)); }
.toast {
  background: var(--glass); border: 1px solid var(--glass-brd); border-radius: 14px;
  padding: 9px 16px; font-weight: 700; font-size: .85rem; max-width: 86vw; text-align: center;
  opacity: 0; transform: translateY(-8px); transition: opacity .3s, transform .3s;
}
.toast.on { opacity: 1; transform: none; }
.toast b { color: var(--accent); }
.toast.ach { border-color: var(--accent); font-family: "Bungee", Impact, sans-serif; font-weight: 400; font-size: .78rem; color: var(--accent); }

#keyHints { position: absolute; bottom: calc(14px + var(--sab)); left: 50%; transform: translateX(-50%); opacity: .25; font-size: .72rem; transition: opacity .6s; white-space: nowrap; }

/* ============ touch controls ============ */
#controls { position: fixed; inset: 0; z-index: 20; pointer-events: none; touch-action: none; }
/* on-screen controls exist ONLY for touch-capable devices, on every aspect */
body:not(.touch-on) #controls { display: none; }
#steerZone {
  position: absolute; left: 0; bottom: 0; width: 58%; height: 45%;
  pointer-events: auto; touch-action: none;
}
.glyph { position: absolute; bottom: 18%; font-size: 1.6rem; opacity: .38; color: var(--cream); transition: opacity 1s; text-shadow: 0 2px 6px rgba(42,33,64,.8); animation: glyphPulse 1.6s ease-in-out infinite; }
.gl-l { left: 14%; } .gl-r { right: 14%; }
#steerZone.used .glyph { opacity: 0; animation: none; }
@keyframes glyphPulse { 50% { opacity: .7; } }
#thumbDot {
  position: absolute; width: 58px; height: 58px; border-radius: 50%;
  background: rgba(255,243,220,.14); border: 2px solid rgba(255,243,220,.35);
  transform: translate(-50%, -50%); transition: opacity .2s;
}
#rightBtns {
  position: absolute; right: calc(16px + var(--sar)); bottom: calc(24px + var(--sab));
  display: flex; flex-direction: column; align-items: center; gap: 12px; pointer-events: none;
}
#rightBtns button[hidden] { display: none; }
#rightBtns button {
  pointer-events: auto; touch-action: none; position: relative;
  border-radius: 50%; background: var(--glass); border: 1px solid var(--glass-brd);
  color: var(--cream); font-family: "Bungee", Impact, sans-serif; font-weight: 400;
  display: flex; align-items: center; justify-content: center;
}
#driftB { width: 104px; height: 104px; font-size: .95rem; }
#driftB span { position: relative; z-index: 1; }
#driftRing {
  position: absolute; inset: -2px; border-radius: 50%;
  border: 3px solid var(--accent); opacity: .5;
  clip-path: inset(100% 0 0 0);
}
#driftB.held { background: rgba(255,197,61,.28); }
#brakeB, #gasB { width: 56px; height: 56px; font-size: .55rem; }
#brakeB.held, #gasB.held { background: rgba(255,243,220,.25); }

/* ============ intro ============ */
#intro {
  position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center;
  pointer-events: none; transition: opacity .8s, transform .8s; transform-origin: 50% 30%;
}
#intro.gone { opacity: 0; transform: scale(.6) translateY(-24vh); }
.wm { position: relative; text-align: center; filter: drop-shadow(0 10px 30px rgba(42,33,64,.5)); }
.wm-word { display: flex; justify-content: center; transform: skewX(-8deg); }
.wl {
  font-family: "Bungee", Impact, sans-serif; font-size: clamp(3.4rem, 17vw, 7rem); line-height: 1;
  color: #FFF3DC; text-shadow: 4px 4px 0 #2A2140; display: inline-block;
}
.w0 { transform: translateY(0) rotate(0deg); }
.w1 { transform: translateY(2px) rotate(1.5deg); }
.w2 { transform: translateY(5px) rotate(3deg); }
.w3 { transform: translateY(7px) rotate(4.5deg); }
.w4 { transform: translateY(8px) rotate(6deg); }
.wm-skid { width: min(76vw, 340px); margin-top: 2px; }
.wm-tag {
  font-style: italic; font-weight: 600; letter-spacing: .18em; color: var(--accent);
  margin-top: -14px; font-size: clamp(.8rem, 3.4vw, 1.05rem);
}
@media (prefers-reduced-motion: no-preference) {
  #intro:not(.gone) .wl { animation: wobble 3s ease-in-out infinite; animation-delay: calc(var(--i, 0) * .12s); }
  .w1 { --i: 1; } .w2 { --i: 2; } .w3 { --i: 3; } .w4 { --i: 4; }
  @keyframes wobble { 0%, 100% { translate: 0 0; } 50% { translate: 0 -4px; } }
}

/* ============ panels ============ */
.panel {
  position: fixed; inset: 0; z-index: 50; overflow-y: auto;
  background: rgba(30, 24, 52, .82); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  display: flex; justify-content: center;
}
.panel-inner {
  width: min(480px, 94vw); padding: calc(24px + var(--sat)) 0 calc(40px + var(--sab));
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
/* bottom fade — a cut-off row reads as "scroll for more", not as a layout bug */
.panel::after {
  content: ""; position: fixed; left: 0; right: 0; bottom: 0; height: 44px;
  background: linear-gradient(rgba(30, 24, 52, 0), rgba(30, 24, 52, .85));
  pointer-events: none;
}
.kicker { font-size: .72rem; letter-spacing: .2em; opacity: .7; }
.wordmark-mini { display: flex; transform: skewX(-8deg); justify-content: center; }
.wordmark-mini span {
  font-family: "Bungee", Impact, sans-serif; font-size: 2rem; line-height: 1;
  color: #FFF3DC; text-shadow: 3px 3px 0 #2A2140;
}
.wordmark-mini.sm span { font-size: 1.3rem; }
.wordmark-mini span:nth-child(2) { transform: translateY(1px) rotate(1deg); }
.wordmark-mini span:nth-child(3) { transform: translateY(2px) rotate(2deg); }
.wordmark-mini span:nth-child(4) { transform: translateY(3px) rotate(3deg); }
.wordmark-mini span:nth-child(5) { transform: translateY(4px) rotate(4deg); }
.wordmark-mini span:nth-child(n+6) { transform: translateY(5px) rotate(5deg); }
.cashRow { padding: 5px 16px; font-style: italic; font-weight: 800; font-size: 1.1rem; color: var(--accent); }
.sheet-btns { display: flex; flex-direction: column; gap: 10px; width: min(300px, 80vw); }
.sheet-btns.row { flex-direction: row; justify-content: center; }
.big-btn {
  font-family: "Bungee", Impact, sans-serif; font-weight: 400; font-size: 1rem;
  background: var(--accent); color: var(--ink); border-radius: 14px; padding: 13px 22px;
  border: 2px solid transparent; position: relative;
}
.big-btn.ghost { background: var(--glass); color: var(--cream); border-color: var(--glass-brd); }
.big-btn:disabled { opacity: .4; pointer-events: none; }
@media (hover: hover) {
  .big-btn:hover { transform: translateY(-2px); border-color: var(--accent); }
  .tog:hover, #micro button:hover { border-color: var(--accent); }
}
.dot { position: absolute; top: 8px; right: 10px; width: 10px; height: 10px; border-radius: 50%; background: var(--combo1); }
.setRow { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.tog {
  background: var(--glass); border: 1px solid var(--glass-brd); border-radius: 12px;
  padding: 8px 12px; min-height: 44px; font-weight: 700; font-size: .68rem; letter-spacing: .14em; opacity: .5;
}
.tog.on { opacity: 1; border-color: var(--accent); color: var(--accent); }
#bestsBox, #eggRow { font-size: .74rem; opacity: .85; text-align: center; line-height: 1.7; }
#eggRow b { color: var(--accent); }
#achGrid { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; width: min(420px, 92vw); }
.ach {
  background: var(--glass); border: 1px solid var(--glass-brd); border-radius: 10px;
  padding: 6px 9px; font-size: .62rem; font-weight: 700; letter-spacing: .06em; opacity: .35;
}
.ach.got { opacity: 1; border-color: var(--accent); color: var(--accent); }
.foot { font-size: .72rem; opacity: .7; margin-top: 6px; }
.foot a, .fine a { color: var(--cream); }
.fine { font-size: .72rem; opacity: .75; text-align: center; line-height: 1.8; }

/* ============ garage ============ */
#garage { position: fixed; inset: 0; z-index: 45; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none; }
.g-top { display: flex; justify-content: space-between; align-items: flex-start; padding: calc(16px + var(--sat)) 16px 0; }
.g-bottom {
  pointer-events: auto; background: linear-gradient(transparent, rgba(30,24,52,.9) 26%);
  padding: 30px 16px calc(20px + var(--sab)); display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.g-nav { display: flex; align-items: center; gap: 18px; }
.g-nav > button { pointer-events: auto; font-size: 1.5rem; color: var(--accent); padding: 10px 16px; min-width: 48px; min-height: 48px; }
.g-title { text-align: center; min-width: 200px; }
.g-title b { display: block; font-family: "Bungee", Impact, sans-serif; font-weight: 400; font-size: 1.7rem; }
.g-title span { font-style: italic; font-weight: 600; font-size: .85rem; opacity: .8; color: var(--accent); }
#gStats { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; width: min(300px, 76vw); align-items: center; }
#gStats label { font-size: .62rem; font-weight: 700; letter-spacing: .14em; opacity: .75; }
.sbar { height: 8px; border-radius: 4px; background: rgba(255,243,220,.12); overflow: hidden; }
.sbar i { display: block; height: 100%; border-radius: 4px; background: var(--accent); }
#gPaints { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; max-width: 92vw; }
.sw { width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--glass-brd); position: relative; }
.sw.sel { border-color: var(--cream); box-shadow: 0 0 0 2px var(--accent); }
.sw.locked::after { content: "$"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: .7rem; font-weight: 800; color: var(--ink); text-shadow: 0 0 3px #fff; }
.sw.nope { opacity: .35; }
#gUps { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.up {
  background: var(--glass); border: 1px solid var(--glass-brd); border-radius: 12px;
  padding: 7px 10px; text-align: center; font-size: .62rem; font-weight: 700; letter-spacing: .1em;
}
.up b { display: block; color: var(--accent); font-size: .72rem; }
.up .pips { letter-spacing: .2em; font-size: .8rem; color: var(--accent); }
.up.max { opacity: .6; }
.g-act { display: flex; gap: 10px; margin-top: 4px; }

/* ============ daily / result ============ */
#dailyInfo { text-align: center; font-size: .9rem; line-height: 1.8; }
#dailyInfo b { font-family: "Bungee", Impact, sans-serif; font-weight: 400; color: var(--accent); }
#dailyInfo .mod { color: var(--combo1); font-weight: 800; font-style: italic; }
#dailyBoard { width: min(340px, 86vw); display: flex; flex-direction: column; gap: 3px; }
.dbRow { display: grid; grid-template-columns: 52px 1fr 54px; gap: 8px; align-items: center; font-size: .68rem; }
.dbRow .bar { height: 10px; border-radius: 5px; background: rgba(255,243,220,.1); overflow: hidden; }
.dbRow .bar i { display: block; height: 100%; background: var(--glass-brd); border-radius: 5px; }
.dbRow.today .bar i { background: var(--accent); }
.dbRow.today { color: var(--accent); }
#card { width: min(420px, 86vw, 52vh); height: auto; border-radius: 18px; box-shadow: 0 12px 40px rgba(20,15,35,.6); }

/* ============ no-gl ============ */
#nogl { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; background: linear-gradient(#35306B, #8A5A9E 55%, #FF9A62); }
#nogl[hidden], .panel[hidden], #garage[hidden], #routes[hidden] { display: none; }
.nogl-inner { text-align: center; display: flex; flex-direction: column; gap: 18px; align-items: center; }
.nogl-inner p { font-weight: 600; line-height: 1.7; }

/* ============ aspect classes (JS sets body.a-portrait / a-square / a-wide) ============ */
body.a-square #steerZone { width: 40%; height: 55%; }
body.a-square #driftB { width: 112px; height: 112px; }
body.a-square #scoreWrap { top: calc(8px + var(--sat)); }
body.a-square #banner { top: calc(196px + var(--sat)); }
/* mode chip sits BELOW the bank/pot/combo stack — never over the combo ring */
body.a-square #modeChip { top: calc(140px + var(--sat)); }
body.a-square #potV { font-size: 1.7rem; }
body.a-square #mini { width: 72px; height: 72px; }
body.a-square #mini.big { width: 220px; height: 220px; }

body.touch-on #keyHints { display: none; }
body.a-wide #speedChip { top: auto; bottom: calc(16px + var(--sab)); left: calc(16px + var(--sal)); }
body.a-wide #cashChip { top: auto; bottom: calc(64px + var(--sab)); left: calc(16px + var(--sal)); }
body.a-wide.touch-on #cashChip { top: calc(58px + var(--sat)); bottom: auto; left: calc(12px + var(--sal)); }
body.a-wide #topRight { top: auto; bottom: calc(16px + var(--sab)); flex-direction: column-reverse; }
body.a-wide #mini { width: 110px; height: 110px; }
body.a-wide #mini.big { width: 260px; height: 260px; }
body.a-wide #scoreWrap { top: calc(14px + var(--sat)); }
body.a-wide #banner { top: calc(160px + var(--sat)); }
body.a-wide #modeChip { top: calc(148px + var(--sat)); }
/* touch landscape: keep chips at the top, thumbs own the bottom corners */
body.a-wide.touch-on #speedChip { top: calc(10px + var(--sat)); bottom: auto; }
body.a-wide.touch-on #topRight { top: calc(10px + var(--sat)); bottom: auto; flex-direction: column; }
body.a-wide.touch-on #steerZone { width: 44%; height: 62%; }
body.a-wide.touch-on #rightBtns { bottom: calc(18px + var(--sab)); }

/* BIG MAP eats the top-right — banners drop below it on tall/square aspects */
body.bigmap.a-portrait #banner, body.bigmap.a-square #banner { top: calc(268px + var(--sat)); }

/* full-screen surfaces own the screen: no HUD/control bleed-through */
body.panel-open #controls, body.garage-open #controls { display: none; }
body.garage-open #speedChip, body.garage-open #scoreWrap, body.garage-open #topRight,
body.garage-open #modeChip, body.garage-open #banner, body.garage-open #keyHints,
body.garage-open #cashChip { display: none; }

@media (prefers-reduced-motion: reduce) {
  #banner.pop { animation: none; }
  .popup.on { animation-duration: .9s; }
}
