:root{
  --bg:#05060a;
  --bg2:#0b1020;
  --gridMinor:#182238;
  --gridMajor:#223053;

  --panel:rgba(10,12,18,.62);
  --panelBorder:rgba(255,255,255,.10);

  --text:rgba(255,255,255,.92);
  --muted:rgba(255,255,255,.70);

  --accent1:#b7ff3c;
  --accent2:#ffb24a;
  --accent3:#3c7dff;
  --danger:#ff3c2e;

  --accent1RGB:183,255,60;
  --accent2RGB:255,178,74;
  --accent3RGB:60,125,255;
  --dangerRGB:255,60,46;

  --btnBorder:rgba(255,255,255,.14);

  --glow:0 0 18px rgba(var(--accent1RGB), .28), 0 0 46px rgba(var(--accent2RGB), .10);
}

*{ box-sizing:border-box; }

html, body{
  width:100%;
  height:100%;
  margin:0;
  padding:0;
  overflow:hidden;
  background:var(--bg);
  color:var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
}

#gl, #fx, #hud{
  position:fixed;
  inset:0;
  width:100%;
  height:100%;
  display:block;
}

#gl{ z-index:0; }
#fx{
  z-index:1;
  pointer-events:none;
  mix-blend-mode:screen;
}
#hud{
  z-index:2;
  pointer-events:none;
  mix-blend-mode:normal;
}

#ui{
  position:fixed;
  inset:0;
  z-index:3;
  pointer-events:none;
  padding:
    max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  display:flex;
  flex-direction:column;
  justify-content:space-between;
  gap:12px;
}

/* ---------- HUD ---------- */
.hud{
  display:flex;
  gap:12px;
  align-items:stretch;
  justify-content:space-between;
  pointer-events:none;
}

.panel{
  background:var(--panel);
  border:1px solid var(--panelBorder);
  border-radius:16px;
  padding:12px 12px 10px;
  box-shadow: 0 18px 40px rgba(0,0,0,.35);
  backdrop-filter: blur(12px) saturate(1.15);
}

.panelTitle{
  font-size:11px;
  letter-spacing:.24em;
  color:var(--muted);
  text-transform:uppercase;
  margin-bottom:6px;
}

.panelBig{
  font-variant-numeric: tabular-nums;
  font-weight:900;
  font-size:18px;
  line-height:1.15;
  letter-spacing:.08em;
  text-transform:uppercase;
  text-shadow: var(--glow);
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  max-width:240px;
}

.panelRow{
  margin-top:8px;
  display:flex;
  align-items:baseline;
  justify-content:space-between;
  gap:12px;
}

.panelLabel{
  font-size:11px;
  letter-spacing:.18em;
  color:var(--muted);
  text-transform:uppercase;
}

.panelValue{
  font-variant-numeric: tabular-nums;
  font-weight:800;
  font-size:14px;
  color:rgba(255,255,255,.92);
}

.timerPanel{ min-width:190px; }
.speedPanel{ min-width:210px; }
.hintPanel{ flex:1; min-width:260px; }

.speedBar{
  position:relative;
  height:14px;
  border-radius:999px;
  background:rgba(255,255,255,.06);
  border:1px solid rgba(255,255,255,.12);
  overflow:hidden;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.2);
}

.speedFill{
  position:absolute;
  inset:0;
  width:40%;
  border-radius:999px;
  background: linear-gradient(90deg, var(--accent3), var(--accent2), var(--accent1));
  box-shadow:
    0 0 18px rgba(var(--accent2RGB), .28),
    0 0 38px rgba(var(--accent1RGB), .16),
    0 0 52px rgba(var(--accent3RGB), .10);
  transform-origin:left center;
}

.speedTicks{
  position:absolute;
  inset:0;
  background:
    repeating-linear-gradient(
      90deg,
      rgba(255,255,255,.0),
      rgba(255,255,255,.0) 14px,
      rgba(255,255,255,.10) 15px
    );
  opacity:.55;
  pointer-events:none;
}

.medalRow{
  margin-top:10px;
  gap:8px;
  justify-content:flex-start;
}

.medal{
  font-size:10px;
  letter-spacing:.16em;
  text-transform:uppercase;
  padding:5px 8px;
  border-radius:999px;
  border:1px solid rgba(255,255,255,.14);
  background:rgba(0,0,0,.22);
  opacity:.55;
  transition: opacity .18s ease, transform .18s ease, filter .18s ease;
}
.medal.on{
  opacity:1;
  transform: translateY(-1px);
  filter: brightness(1.05) saturate(1.1);
  box-shadow: var(--glow);
}
.medal.bronze{ border-color: rgba(255,178,74,.35); }
.medal.silver{ border-color: rgba(210,220,255,.30); }
.medal.gold{ border-color: rgba(183,255,60,.35); }

.nextWrap{
  display:flex;
  gap:10px;
  align-items:center;
}

.nextIcon{
  width:36px;
  height:36px;
  border-radius:12px;
  background:
    radial-gradient(circle at 30% 30%, rgba(255,255,255,.16), rgba(255,255,255,.02));
  border:1px solid rgba(255,255,255,.12);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.2), var(--glow);
  position:relative;
}
.nextIcon::before{
  content:"→";
  position:absolute;
  inset:0;
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight:900;
  font-size:18px;
  color:rgba(255,255,255,.92);
  text-shadow: var(--glow);
}
.nextIcon.turnL::before{ content:"↶"; }
.nextIcon.turnR::before{ content:"↷"; }
.nextIcon.straight::before{ content:"→"; }

.nextText{
  font-size:14px;
  color:rgba(255,255,255,.88);
}

.kbdRow{
  margin-top:8px;
  color:rgba(255,255,255,.70);
  font-size:12px;
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  align-items:center;
}

.kbd{
  font-size:11px;
  padding:2px 7px;
  border-radius:8px;
  border:1px solid rgba(255,255,255,.14);
  background:rgba(0,0,0,.20);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.12);
  color:rgba(255,255,255,.86);
}

/* ---------- Banner ---------- */
.centerBanner{
  pointer-events:none;
  align-self:center;
  max-width:min(640px, 92vw);
  text-align:center;
  padding:14px 16px;
  border-radius:18px;
  background: linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.03));
  border:1px solid rgba(255,255,255,.10);
  box-shadow: 0 24px 70px rgba(0,0,0,.40);
  backdrop-filter: blur(10px) saturate(1.15);
  opacity:0;
  transform: translateY(8px);
  transition: opacity .22s ease, transform .22s ease;
}

.centerBanner.show{
  opacity:1;
  transform: translateY(0);
}

.bannerTitle{
  font-weight:900;
  font-size:20px;
  letter-spacing:.22em;
  text-transform:uppercase;
  text-shadow: var(--glow);
}

.bannerSub{
  margin-top:6px;
  font-size:13px;
  color:rgba(255,255,255,.75);
}

/* ---------- Controls ---------- */
.controls{
  pointer-events:auto;
  display:flex;
  gap:10px;
  align-items:stretch;
  justify-content:center;
  user-select:none;
  -webkit-user-select:none;
}

.btn{
  border-radius:18px;
  border:1px solid var(--btnBorder);
  background: linear-gradient(180deg, rgba(255,255,255,.10), rgba(255,255,255,.05));
  color:rgba(255,255,255,.92);
  box-shadow:
    0 16px 40px rgba(0,0,0,.35),
    inset 0 0 0 1px rgba(0,0,0,.18);
  cursor:pointer;
  padding:10px 14px;
  min-width:96px;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:5px;
  transition: transform .06s ease, filter .18s ease, box-shadow .18s ease;
  touch-action:none;
}

.btn:active{
  transform: translateY(1px) scale(.99);
  filter:brightness(1.06) saturate(1.06);
}

.btnIcon{
  font-size:20px;
  line-height:1;
  text-shadow: var(--glow);
}

.btnText{
  font-size:11px;
  letter-spacing:.18em;
  text-transform:uppercase;
  color:rgba(255,255,255,.82);
}

.btnTurn{
  min-width:120px;
  background:
    radial-gradient(circle at 30% 30%, rgba(var(--accent1RGB), .14), rgba(255,255,255,.05)),
    linear-gradient(180deg, rgba(255,255,255,.10), rgba(255,255,255,.04));
  border-color: rgba(var(--accent1RGB), .22);
  box-shadow:
    0 18px 46px rgba(0,0,0,.40),
    0 0 28px rgba(var(--accent1RGB), .18),
    inset 0 0 0 1px rgba(0,0,0,.18);
}

.btnAlt{
  min-width:108px;
  background:
    radial-gradient(circle at 30% 30%, rgba(var(--accent2RGB), .14), rgba(255,255,255,.05)),
    linear-gradient(180deg, rgba(255,255,255,.10), rgba(255,255,255,.04));
  border-color: rgba(var(--accent2RGB), .22);
  box-shadow:
    0 18px 46px rgba(0,0,0,.40),
    0 0 28px rgba(var(--accent2RGB), .18),
    inset 0 0 0 1px rgba(0,0,0,.18);
}

.btnGhost{
  min-width:104px;
  background:
    radial-gradient(circle at 30% 30%, rgba(var(--accent3RGB), .12), rgba(255,255,255,.05)),
    linear-gradient(180deg, rgba(255,255,255,.10), rgba(255,255,255,.04));
  border-color: rgba(var(--accent3RGB), .22);
  box-shadow:
    0 18px 46px rgba(0,0,0,.40),
    0 0 28px rgba(var(--accent3RGB), .14),
    inset 0 0 0 1px rgba(0,0,0,.18);
}

/* ---------- Modal ---------- */
.modal{
  position:fixed;
  inset:0;
  z-index:10;
  background: rgba(0,0,0,.62);
  backdrop-filter: blur(10px) saturate(1.1);
  display:none;
  align-items:center;
  justify-content:center;
  padding:16px;
  pointer-events:auto;
}
.modal.show{ display:flex; }

.modalCard{
  width:min(920px, 96vw);
  max-height:min(82vh, 720px);
  overflow:hidden;
  border-radius:20px;
  border:1px solid rgba(255,255,255,.12);
  background: linear-gradient(180deg, rgba(10,12,18,.86), rgba(10,12,18,.62));
  box-shadow: 0 40px 120px rgba(0,0,0,.55);
  display:flex;
  flex-direction:column;
}

.modalHeader{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:14px 14px 10px;
  border-bottom:1px solid rgba(255,255,255,.10);
}
.modalTitle{
  font-weight:900;
  letter-spacing:.18em;
  text-transform:uppercase;
  font-size:14px;
  text-shadow: var(--glow);
}
.modalClose{
  cursor:pointer;
  border-radius:12px;
  border:1px solid rgba(255,255,255,.14);
  background:rgba(255,255,255,.06);
  color:rgba(255,255,255,.88);
  padding:8px 10px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.12);
}
.modalSub{
  padding:10px 14px 12px;
  color:rgba(255,255,255,.72);
  font-size:13px;
  border-bottom:1px solid rgba(255,255,255,.10);
}
.trackList{
  padding:12px;
  overflow:auto;
  display:grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap:12px;
}
.trackCard{
  border-radius:18px;
  border:1px solid rgba(255,255,255,.12);
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,.08), rgba(255,255,255,.03));
  padding:12px 12px 10px;
  cursor:pointer;
  transition: transform .08s ease, filter .18s ease, box-shadow .18s ease;
}
.trackCard:hover{ transform: translateY(-1px); filter:brightness(1.02); }
.trackTop{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
}
.trackName{
  font-weight:900;
  letter-spacing:.10em;
  text-transform:uppercase;
  font-size:13px;
}
.badge{
  font-size:10px;
  letter-spacing:.14em;
  text-transform:uppercase;
  padding:5px 8px;
  border-radius:999px;
  border:1px solid rgba(255,255,255,.14);
  background:rgba(0,0,0,.22);
  color:rgba(255,255,255,.84);
  white-space:nowrap;
}
.badge.easy{ border-color: rgba(183,255,60,.32); }
.badge.hard{ border-color: rgba(255,178,74,.32); }
.badge.demon{ border-color: rgba(255,60,46,.32); }

.trackMeta{
  margin-top:8px;
  display:flex;
  justify-content:space-between;
  gap:10px;
  color:rgba(255,255,255,.75);
  font-size:12px;
}
.trackDesc{
  margin-top:10px;
  color:rgba(255,255,255,.70);
  font-size:12px;
  line-height:1.35;
  min-height:34px;
}
.trackTargets{
  margin-top:10px;
  display:flex;
  gap:8px;
  flex-wrap:wrap;
}
.pill{
  font-size:10px;
  letter-spacing:.12em;
  text-transform:uppercase;
  padding:5px 8px;
  border-radius:999px;
  border:1px solid rgba(255,255,255,.14);
  background:rgba(0,0,0,.18);
  color:rgba(255,255,255,.82);
}
.pill.on{
  box-shadow: var(--glow);
  opacity:1;
}
.pill.off{ opacity:.62; }

.modalFooter{
  padding:12px 14px;
  border-top:1px solid rgba(255,255,255,.10);
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
}
.btnInline{
  cursor:pointer;
  border-radius:14px;
  border:1px solid rgba(255,255,255,.14);
  background:rgba(255,255,255,.06);
  color:rgba(255,255,255,.88);
  padding:10px 12px;
  font-weight:700;
  letter-spacing:.08em;
  text-transform:uppercase;
  font-size:11px;
}
.modalHint{
  color:rgba(255,255,255,.70);
  font-size:12px;
}

/* ---------- Layout modes ---------- */
body.layout-desktop #controls{ justify-content:flex-end; }
body.layout-desktop .btn{ min-width:108px; }
body.layout-desktop .centerBanner{ max-width:560px; }
body.layout-desktop .trackList{ grid-template-columns: repeat(3, minmax(0, 1fr)); }

body.layout-portrait .hud{
  flex-wrap:wrap;
  justify-content:center;
}
body.layout-portrait .timerPanel{ flex:1; min-width:160px;}
body.layout-portrait .speedPanel{ flex:1; min-width:180px;}
body.layout-portrait .hintPanel{ flex-basis:100%; }

body.layout-portrait #controls{
  display:grid;
  grid-template-columns:repeat(4, 1fr);
  grid-template-areas:
    "left left right right"
    "brake brake boost boost"
    "restart restart map map"
    "theme theme theme theme";
  gap:10px;
  width:min(720px, 100%);
  margin:0 auto;
}
body.layout-portrait #btnLeft{ grid-area:left; }
body.layout-portrait #btnRight{ grid-area:right; }
body.layout-portrait #btnBrake{ grid-area:brake; }
body.layout-portrait #btnBoost{ grid-area:boost; }
body.layout-portrait #btnRestart{ grid-area:restart; }
body.layout-portrait #btnMap{ grid-area:map; }
body.layout-portrait #btnTheme{ grid-area:theme; }
body.layout-portrait .btn{ min-width:0; padding:12px 12px; }

body.layout-landscape .hud{ justify-content:flex-start; }
body.layout-landscape #controls{
  align-self:flex-end;
  justify-content:flex-end;
}
body.layout-landscape .btn{ min-width:92px; }

body.touch .kbdRow{ display:none; }
body.touch .panelBig{ font-size:17px; }

@media (prefers-reduced-motion: reduce){
  .centerBanner{ transition:none; }
  .btn{ transition:none; }
  .trackCard{ transition:none; }
}
