@font-face { font-family: 'Rajdhani'; font-weight: 500; font-display: swap; src: url(../assets/fonts/rajdhani-500.woff2) format('woff2'); }
@font-face { font-family: 'Rajdhani'; font-weight: 600; font-display: swap; src: url(../assets/fonts/rajdhani-600.woff2) format('woff2'); }
@font-face { font-family: 'Rajdhani'; font-weight: 700; font-display: swap; src: url(../assets/fonts/rajdhani-700.woff2) format('woff2'); }

:root {
  --red: #d8121c;
  --red2: #f02430;
  --red-plate: #7c0a10;
  --bg0: #0b0c10;
  --panel: rgba(22, 24, 30, .94);
  --panel-solid: #16181e;
  --panel-2: #1e2128;
  --border: #2a2d36;
  --text: #f2f3f5;
  --muted: #8a8f9a;
  --gold: #f5b81d;
  --orange: #f08c1e;
  --purple: #b26bff;
  --green: #35d07f;
  --skew: -10deg;
  --shadow: 0 16px 40px rgba(0, 0, 0, .6);
  --plate: 5px 5px 0 rgba(0, 0, 0, .45);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: var(--bg0); color: var(--text);
  font-family: 'Rajdhani', 'Segoe UI', system-ui, sans-serif;
  font-weight: 600;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}

#game, #game canvas { width: 100vw; height: 100vh; display: block; }
#game { touch-action: none; }

.hidden { display: none !important; }
.purple { color: var(--purple); }
.green { color: var(--green); }
.red { color: var(--red); }

.btn {
  --tf: skewX(var(--skew));
  position: relative;
  border: none; cursor: pointer; color: #fff;
  font-family: inherit; font-weight: 700; font-style: italic;
  font-size: 16px; letter-spacing: 1.5px; text-transform: uppercase;
  padding: 13px 30px;
  background: var(--panel-2);
  border-radius: 2px;
  transform: var(--tf);
  box-shadow: var(--plate);
  transition: transform .12s ease, filter .15s ease, box-shadow .12s ease;
}
.btn:hover { filter: brightness(1.15); transform: var(--tf) translate(-1px, -2px); box-shadow: 6px 7px 0 rgba(0, 0, 0, .45); }
.btn:active { transform: var(--tf) translate(2px, 2px); box-shadow: 2px 2px 0 rgba(0, 0, 0, .45); }
.btn-primary { background: linear-gradient(180deg, var(--red2), var(--red)); box-shadow: 5px 5px 0 var(--red-plate); }
.btn-primary:hover { box-shadow: 6px 7px 0 var(--red-plate); }
.btn-primary:active { box-shadow: 2px 2px 0 var(--red-plate); }
.btn-ad { background: linear-gradient(180deg, #ffa53a, var(--orange)); box-shadow: 5px 5px 0 #7a4406; color: #1a1206; }
.btn-ad:hover { box-shadow: 6px 7px 0 #7a4406; }
.btn-ghost { background: transparent; border: 1px solid var(--border); box-shadow: none; color: #c6c9d0; }
.btn-ghost:hover { border-color: var(--red); color: #fff; box-shadow: none; }
.btn-disabled, .btn-disabled:hover { opacity: .4; filter: grayscale(.6); transform: var(--tf); box-shadow: var(--plate); cursor: not-allowed; }

#loader {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 30%, #1a1c22 0%, var(--bg0) 70%);
}
.loader-inner { text-align: center; width: min(460px, 82vw); }
.loader-title { font-size: 56px; font-weight: 700; font-style: italic; letter-spacing: 4px; color: #fff; text-shadow: 4px 4px 0 rgba(216, 18, 28, .55); }
.loader-sub { margin-top: 4px; font-size: 14px; font-style: italic; letter-spacing: 7px; color: var(--red2); }
.loader-bar { position: relative; margin: 30px auto 10px; height: 12px; width: 100%; background: #1b1d23; border: 1px solid var(--border); border-radius: 2px; overflow: hidden; transform: skewX(var(--skew)); }
#loader-fill { height: 100%; width: 0%; background: linear-gradient(180deg, var(--red2), var(--red)); transition: width .25s ease; }
.loader-bar::after { content: ''; position: absolute; inset: 0; background: repeating-linear-gradient(90deg, transparent 0 14px, var(--bg0) 14px 17px); pointer-events: none; }
#loader-pct { font-size: 15px; font-weight: 700; font-style: italic; color: #fff; }
#loader-status { margin-top: 6px; font-size: 13px; color: var(--muted); letter-spacing: 2px; text-transform: uppercase; }

#hud { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
.t-label { color: var(--muted); font-size: 12px; letter-spacing: 2px; }
.t-val { font-variant-numeric: tabular-nums; font-weight: 700; }

#hud-times {
  position: absolute; top: 18px; left: 18px;
  background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--red);
  border-radius: 3px; padding: 12px 16px; min-width: 210px;
  backdrop-filter: blur(8px); box-shadow: var(--shadow);
}
.time-row { display: flex; justify-content: space-between; align-items: baseline; gap: 18px; margin: 3px 0; }
.time-row.big .t-val { font-size: 32px; font-style: italic; }
.time-row.big .t-label { font-size: 12px; }
.time-row .t-val { font-size: 18px; }
.delta-row { margin-top: 8px; border-top: 1px solid var(--border); padding-top: 6px; }

#hud-top { position: absolute; top: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; }
.lap-counter { background: var(--panel); border: 1px solid var(--border); border-radius: 3px; padding: 6px 18px; font-weight: 700; font-style: italic; font-size: 24px; display: flex; align-items: baseline; gap: 4px; backdrop-filter: blur(8px); box-shadow: var(--shadow); }
.lap-sep { color: #4a4e58; }
#lap-total { color: var(--muted); }
.lap-label { font-size: 12px; letter-spacing: 2px; color: var(--muted); margin-left: 8px; }
#sectors { display: flex; gap: 6px; }
.sector { background: var(--panel); border: 1px solid var(--border); border-radius: 3px; padding: 5px 12px; display: flex; flex-direction: column; align-items: center; min-width: 80px; border-bottom: 3px solid var(--border); box-shadow: var(--shadow); }
.sector .sec-name { font-size: 11px; letter-spacing: 2px; color: var(--muted); }
.sector .sec-time { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.sector.purple { border-bottom-color: var(--purple); }
.sector.green { border-bottom-color: var(--green); }
.sector.yellow { border-bottom-color: var(--gold); }
#level-goal { background: var(--panel); border: 1px solid var(--border); border-radius: 3px; padding: 5px 15px; font-size: 14px; font-weight: 700; font-style: italic; letter-spacing: 1px; font-variant-numeric: tabular-nums; color: var(--gold); backdrop-filter: blur(8px); box-shadow: var(--shadow); }

#hud-speed { position: absolute; right: 22px; bottom: 22px; text-align: center; background: var(--panel); border: 1px solid var(--border); border-radius: 3px; padding: 10px 20px 12px; backdrop-filter: blur(8px); min-width: 150px; box-shadow: var(--shadow); border-bottom: 3px solid var(--red); }
#gear { font-size: 42px; font-weight: 700; font-style: italic; line-height: 1; color: var(--gold); }
.speed-wrap { display: flex; align-items: baseline; justify-content: center; gap: 6px; }
#speed { font-size: 56px; font-weight: 700; font-style: italic; font-variant-numeric: tabular-nums; line-height: 1; }
.speed-unit { font-size: 14px; color: var(--muted); letter-spacing: 1px; }
#rpm-bar { position: relative; margin-top: 8px; height: 9px; width: 100%; background: #1b1d23; border-radius: 2px; overflow: hidden; }
#rpm-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--green) 0%, var(--gold) 68%, var(--red) 100%); transition: width .05s linear; }
#rpm-bar::after { content: ''; position: absolute; inset: 0; background: repeating-linear-gradient(90deg, transparent 0 10px, var(--panel-solid) 10px 12px); pointer-events: none; }

#lights { position: absolute; top: 22%; left: 50%; transform: translateX(-50%); display: flex; gap: 18px; padding: 18px 24px; background: rgba(10, 11, 14, .8); border: 1px solid var(--border); border-radius: 4px; }
#lights .light { width: 48px; height: 48px; border-radius: 50%; background: #240406; box-shadow: inset 0 0 10px #000; }
#lights .light.on { background: var(--red2); box-shadow: 0 0 28px 6px rgba(216, 18, 28, .9), inset 0 0 8px #ff5a4d; }

#big-msg { position: absolute; top: 34%; left: 50%; transform: translate(-50%, -50%); font-size: 100px; font-weight: 700; font-style: italic; letter-spacing: 4px; text-shadow: 6px 6px 0 rgba(216, 18, 28, .5), 0 0 40px rgba(0, 0, 0, .8); }

#banner { position: absolute; top: 30%; left: 50%; transform: translateX(-50%) skewX(var(--skew)); padding: 14px 36px; border-radius: 2px; font-size: 24px; font-weight: 700; font-style: italic; letter-spacing: 2px; background: linear-gradient(180deg, var(--red2), var(--red)); box-shadow: 5px 5px 0 var(--red-plate); animation: bannerPop 2.2s ease forwards; }
@keyframes bannerPop { 0% { opacity: 0; transform: translateX(-50%) skewX(var(--skew)) translateY(-14px) scale(.9); } 12% { opacity: 1; transform: translateX(-50%) skewX(var(--skew)) translateY(0) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translateX(-50%) skewX(var(--skew)) translateY(-10px); } }

#help { position: fixed; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center; background: rgba(8, 9, 12, .84); backdrop-filter: blur(5px); }
.help-box { background: var(--panel-solid); border: 1px solid var(--border); border-top: 3px solid var(--red); border-radius: 4px; padding: 30px 36px; min-width: 340px; box-shadow: var(--shadow); }
.help-box h2 { font-style: italic; letter-spacing: 3px; margin-bottom: 16px; display: flex; align-items: center; gap: 12px; }
.help-box h2::before { content: '‹'; color: var(--red); font-size: 1.15em; line-height: 1; }
.help-box table { width: 100%; border-collapse: collapse; }
.help-box td { padding: 7px 8px; font-size: 15px; }
.help-box td:first-child { white-space: nowrap; }
.help-box kbd { background: #24262d; border: 1px solid #3a3d47; border-bottom-width: 3px; border-radius: 3px; padding: 2px 8px; font-size: 13px; font-family: inherit; }
.help-hint { margin-top: 18px; text-align: center; color: var(--muted); font-size: 14px; letter-spacing: 1px; text-transform: uppercase; animation: pulse 1.4s infinite; }
@keyframes pulse { 0%, 100% { opacity: .5; } 50% { opacity: 1; } }

.screen { position: fixed; inset: 0; z-index: 70; display: flex; flex-direction: column; align-items: center; pointer-events: none; background: radial-gradient(130% 100% at 50% 25%, rgba(11, 12, 16, 0) 45%, rgba(11, 12, 16, .78) 100%); }
.screen > * { pointer-events: auto; }
.screen:not(.hidden) { animation: screenIn .28s ease; }
@keyframes screenIn { from { opacity: 0; } to { opacity: 1; } }
.screen.dim { background: linear-gradient(rgba(11, 12, 16, .8), rgba(11, 12, 16, .92)); }

.screen-head {
  margin-top: 26px; width: min(560px, 92vw);
  display: flex; align-items: center; gap: 14px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 3px; padding: 12px 18px;
  font-size: 22px; font-weight: 700; font-style: italic; letter-spacing: 3px;
  box-shadow: var(--shadow); backdrop-filter: blur(6px);
}
.screen-head::before { content: '‹'; color: var(--red); font-size: 30px; font-weight: 700; line-height: .8; }
.screen-head.clickable { cursor: pointer; transition: color .15s ease; }
.screen-head.clickable:hover { color: var(--red2); }
.icon-btn { position: fixed; top: 16px; right: 16px; z-index: 78; width: 46px; height: 46px; border-radius: 8px; background: var(--panel); border: 1px solid var(--border); color: #fff; font-size: 20px; cursor: pointer; display: flex; align-items: center; justify-content: center; backdrop-filter: blur(6px); box-shadow: var(--shadow); }
.icon-btn:hover { border-color: var(--red); }
.screen-back { position: absolute; bottom: 24px; left: 50%; --tf: translateX(-50%) skewX(var(--skew)); min-width: 170px; }

#home { justify-content: flex-start; }
.home-logo { margin-top: 9vh; font-size: 70px; font-weight: 700; font-style: italic; letter-spacing: 2px; line-height: .84; text-shadow: 5px 5px 0 rgba(0, 0, 0, .6); }
.home-logo span { display: block; color: var(--red); font-size: 56px; letter-spacing: 4px; text-shadow: 4px 4px 0 rgba(0, 0, 0, .7); }
.nav { display: flex; flex-direction: column; gap: 15px; width: min(380px, 86vw); margin-top: 5vh; }
.nav-item {
  --tf: skewX(var(--skew));
  display: flex; align-items: stretch; gap: 0; text-align: left;
  background: var(--panel-solid);
  border: 1px solid var(--border); border-radius: 2px;
  padding: 0; cursor: pointer; color: #fff;
  box-shadow: var(--plate);
  transform: var(--tf); overflow: hidden;
  transition: transform .12s ease, box-shadow .12s ease, border-color .15s ease;
}
.nav-item:hover { transform: var(--tf) translate(-1px, -2px); box-shadow: 7px 7px 0 rgba(0, 0, 0, .45); border-color: #3a3d47; }
.nav-item:active { transform: var(--tf) translate(2px, 2px); box-shadow: 2px 2px 0 rgba(0, 0, 0, .45); }
.nav-ic { flex: none; width: 66px; display: grid; place-items: center; background: linear-gradient(180deg, var(--red2), var(--red)); border-radius: 0; font-size: 26px; box-shadow: none; }
.nav-ic, .nav-txt { transform: skewX(calc(-1 * var(--skew))); }
.nav-ic { margin-left: -6px; padding-left: 6px; }
.nav-txt { padding: 13px 18px 13px 14px; }
.nav-txt b { display: block; font-size: 24px; font-weight: 700; font-style: italic; letter-spacing: 2px; line-height: 1.05; }
.nav-txt i { font-style: normal; font-size: 11px; letter-spacing: 2.5px; color: var(--muted); }
.home-foot { position: absolute; bottom: 26px; display: flex; gap: 12px; }

.car-arrow { position: absolute; top: 52%; transform: translateY(-50%) skewX(var(--skew)); width: 58px; height: 66px; border-radius: 2px; background: var(--panel); color: #fff; border: 1px solid var(--border); font-size: 34px; line-height: 1; cursor: pointer; backdrop-filter: blur(6px); box-shadow: var(--plate); transition: background .15s, transform .15s; font-style: italic; }
.car-arrow:hover { background: var(--red); transform: translateY(-50%) skewX(var(--skew)) scale(1.05); }
#car-prev { left: 5%; }
#car-next { right: 5%; }

.menu-panel { position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%); width: min(440px, 90vw); background: var(--panel); border-radius: 4px; padding: 18px 22px; backdrop-filter: blur(10px); border: 1px solid var(--border); border-top: 3px solid var(--red); box-shadow: var(--shadow); }
.car-name-row { text-align: center; font-size: 28px; font-weight: 700; font-style: italic; letter-spacing: 2px; margin-bottom: 14px; }
.car-lock { font-size: 20px; margin-left: 8px; }
.car-stats { display: flex; flex-direction: column; gap: 9px; margin-bottom: 16px; }
.stat { display: flex; align-items: center; gap: 12px; }
.stat span { width: 66px; font-size: 12px; letter-spacing: 2px; color: var(--muted); }
.stat .bar { position: relative; flex: 1; height: 10px; background: #101216; border: 1px solid var(--border); border-radius: 2px; overflow: hidden; transform: skewX(var(--skew)); }
.stat .bar i { display: block; height: 100%; width: 0%; background: linear-gradient(180deg, var(--red2), var(--red)); transition: width .35s ease; }
.stat .bar::after { content: ''; position: absolute; inset: 0; background: repeating-linear-gradient(90deg, transparent 0 12px, var(--panel-solid) 12px 15px); pointer-events: none; }
.menu-buttons { display: flex; flex-direction: column; gap: 11px; }

#level-grid { margin-top: 16px; display: grid; grid-template-columns: repeat(auto-fill, 106px); gap: 14px; justify-content: center; width: min(800px, 94vw); max-height: 62vh; overflow-y: auto; padding: 8px; }
.level-tile { width: 106px; height: 138px; border-radius: 4px; background: linear-gradient(168deg, var(--ta, #2a2d36) 0%, var(--tb, #16181e) 62%, #101216 62%); border: 2px solid var(--border); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; cursor: pointer; position: relative; overflow: hidden; box-shadow: var(--shadow); transition: transform .1s ease, border-color .15s ease; }
.level-tile::before { content: ''; position: absolute; inset: 0 0 auto 0; height: 26px; background: linear-gradient(180deg, rgba(0, 0, 0, .35), transparent); }
.level-tile:hover { transform: translateY(-3px); border-color: var(--red); }
.level-tile .lt-num { font-size: 28px; font-weight: 700; font-style: italic; line-height: 1; text-shadow: 2px 2px 0 rgba(0, 0, 0, .5); }
.level-tile .lt-icon { font-size: 15px; }
.level-tile .lt-name { font-size: 9px; letter-spacing: 1.5px; color: rgba(255, 255, 255, .85); text-transform: uppercase; }
.level-tile .lt-stars { position: absolute; bottom: 0; left: 0; right: 0; padding: 4px 0 5px; background: rgba(10, 11, 14, .85); border-top: 1px solid var(--border); font-size: 12px; color: var(--gold); letter-spacing: 1px; height: auto; text-align: center; }
.level-tile.locked { opacity: .55; cursor: not-allowed; filter: grayscale(.7); background: linear-gradient(168deg, #1c1e24, #101216); }
.level-tile.locked:hover { transform: none; border-color: var(--border); }
.level-tile .lt-lock { position: absolute; font-size: 30px; opacity: .8; }
.c-day { --ta: #2f6fc0; --tb: #16324f; }
.c-sunset { --ta: #e8763a; --tb: #5f2836; }
.c-night { --ta: #3c2f8a; --tb: #14102e; }
.c-fog { --ta: #6b7280; --tb: #2c313b; }
.c-rain { --ta: #3d4a66; --tb: #171d2c; }
.c-snow { --ta: #93b4d0; --tb: #34434f; }
#ls-stars { font-size: 15px; color: var(--gold); letter-spacing: 2px; margin-left: auto; font-style: normal; }
.ls-hint { font-size: 13px; color: var(--muted); letter-spacing: 1px; margin-top: 8px; text-transform: uppercase; }

.track-buttons { display: flex; flex-direction: column; gap: 18px; margin-top: 14vh; width: min(360px, 86vw); }
.track-btn { font-size: 19px; padding: 22px; }

.results-box { margin: auto; background: var(--panel-solid); border: 1px solid var(--border); border-top: 3px solid var(--red); border-radius: 4px; padding: 30px 42px; text-align: center; min-width: 320px; box-shadow: var(--shadow); }
#res-title { font-size: 26px; font-weight: 700; font-style: italic; letter-spacing: 3px; margin-bottom: 4px; }
.res-new { color: var(--green); font-weight: 700; font-style: italic; letter-spacing: 2px; font-size: 14px; margin-bottom: 4px; animation: pulse 1s infinite; }
.res-stars { font-size: 50px; color: #26282f; letter-spacing: 8px; margin: 8px 0 16px; }
.res-stars .on { color: var(--gold); text-shadow: 0 0 18px rgba(245, 184, 29, .7); }
.res-row { display: flex; justify-content: space-between; gap: 34px; font-size: 17px; margin: 4px 0; font-variant-numeric: tabular-nums; }
.res-row span:first-child { color: var(--muted); letter-spacing: 1px; }
.results-buttons { display: flex; gap: 14px; margin-top: 24px; }
.results-buttons .btn { flex: 1; padding: 13px 14px; }

#pause { position: fixed; inset: 0; z-index: 85; display: flex; align-items: center; justify-content: center; background: rgba(8, 9, 12, .74); backdrop-filter: blur(6px); }
.pause-box { background: var(--panel-solid); border: 1px solid var(--border); border-top: 3px solid var(--red); border-radius: 4px; padding: 32px 42px; min-width: 300px; display: flex; flex-direction: column; gap: 13px; text-align: center; box-shadow: var(--shadow); }
.pause-box h2 { font-style: italic; letter-spacing: 5px; margin-bottom: 12px; color: #fff; }

#touch { position: absolute; inset: 0; pointer-events: none; display: none; }
#t-pause { display: none; }
body.touch #touch { display: block; }
body.touch #t-pause { display: flex; }
.tbtn { position: absolute; pointer-events: auto; display: flex; align-items: center; justify-content: center; width: 88px; height: 88px; border-radius: 50%; background: rgba(24, 26, 32, .8); border: 2px solid rgba(255, 255, 255, .22); color: #fff; font-size: 40px; line-height: 1; font-weight: 700; backdrop-filter: blur(3px); touch-action: none; user-select: none; -webkit-tap-highlight-color: transparent; }
.tbtn.pressed { background: rgba(216, 18, 28, .75); border-color: #fff; transform: scale(.96); }
#t-left { left: 24px; bottom: 30px; }
#t-right { left: 126px; bottom: 30px; }
#t-brake { right: 24px; bottom: 30px; }
#t-gas { right: 126px; bottom: 30px; background: rgba(53, 208, 127, .18); }
#t-gas.pressed { background: rgba(53, 208, 127, .6); }
#t-hand { left: 50%; transform: translateX(-50%) skewX(var(--skew)); bottom: 36px; width: 84px; height: 56px; border-radius: 2px; font-size: 15px; font-style: italic; letter-spacing: 1px; }
#t-hand.pressed { transform: translateX(-50%) skewX(var(--skew)) scale(.96); }
#t-pause { position: absolute; top: 16px; right: 16px; z-index: 60; pointer-events: auto; width: 46px; height: 46px; border-radius: 3px; align-items: center; justify-content: center; background: var(--panel); color: #fff; border: 1px solid var(--border); font-size: 16px; cursor: pointer; backdrop-filter: blur(4px); }

body.touch #hud-times { top: 10px; left: 10px; padding: 7px 11px; min-width: 132px; }
body.touch #hud-times .time-row.big .t-val { font-size: 20px; }
body.touch #hud-times .t-val { font-size: 13px; }
body.touch #hud-times .t-label, body.touch #hud-times .time-row.big .t-label { font-size: 10px; }
body.touch #hud-times .time-row { gap: 10px; margin: 2px 0; }
body.touch #hud-top { top: 10px; gap: 5px; }
body.touch .lap-counter { font-size: 16px; padding: 4px 12px; }
body.touch .sector { min-width: 52px; padding: 3px 7px; }
body.touch .sector .sec-time { font-size: 12px; }
body.touch #level-goal { font-size: 11px; padding: 3px 10px; }
body.touch #hud-speed { bottom: auto; top: 66px; right: 12px; min-width: 0; padding: 5px 14px; }
body.touch #hud-speed #speed { font-size: 32px; }
body.touch #hud-speed #gear { font-size: 22px; }

@media (max-width: 700px) {
  .home-logo { font-size: 48px; } .home-logo span { font-size: 38px; }
  .loader-title { font-size: 36px; }
  .screen-head { font-size: 18px; padding: 10px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
