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

:root {
  --ink: #ffffff;
  --dim: #cfe0ee;
  --accent: #ffd21f;
  --accent-deep: #f5a300;
  --panel: rgba(14, 28, 44, 0.86);
  --glass: rgba(255, 255, 255, 0.16);
  --glass-edge: rgba(255, 255, 255, 0.55);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --display: "Arial Black", "Segoe UI Black", "Helvetica Neue", Impact, sans-serif;
}

html,
body {
  height: 100%;
  overflow: hidden;
  background: #8fc6ec;
  font-family: var(--font);
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

#game {
  display: block;
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
}

.hidden {
  display: none !important;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
}

/* ---------------- HUD ---------------- */

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

#minimap {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  left: calc(74px + env(safe-area-inset-left));
  width: 150px;
  height: 150px;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(20, 24, 30, 0.85), 0 6px 20px rgba(0, 0, 0, 0.35);
}

#speedo {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top));
  right: calc(70px + env(safe-area-inset-right));
  width: 170px;
  height: 170px;
}

#topbar {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  left: calc(14px + env(safe-area-inset-left));
  right: calc(14px + env(safe-area-inset-right));
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

#topbar .spacer {
  flex: 1;
}

.hud-btn {
  pointer-events: auto;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: rgba(20, 30, 42, 0.45);
  border: 2px solid var(--glass-edge);
  display: grid;
  place-items: center;
  color: #fff;
  backdrop-filter: blur(4px);
  transition: transform 0.1s, background 0.2s;
}

.hud-btn:active {
  transform: scale(0.92);
}

.hud-btn svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

#btn-reset,
#btn-cam {
  flex-direction: column;
}

#topbar #btn-reset {
  margin-top: 190px;
}

#topbar #btn-cam {
  margin-top: 0;
}

#points {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: 0;
  padding: 7px 18px;
  border-radius: 999px;
  background: rgba(20, 30, 42, 0.5);
  font-family: var(--display);
  font-size: 20px;
  letter-spacing: 0.02em;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

#points .star {
  color: var(--accent);
}

#drift-meter {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  font-family: var(--display);
  font-style: italic;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.25), 0 4px 14px rgba(0, 0, 0, 0.45);
}

.dm-label {
  font-size: 16px;
  letter-spacing: 0.3em;
  color: #fff;
}

.dm-num {
  font-size: 44px;
  line-height: 1;
  color: var(--accent);
}

.dm-mult {
  font-size: 18px;
  color: #ff8a3d;
}

#toasts {
  position: absolute;
  top: 34%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.toast {
  font-family: var(--display);
  font-style: italic;
  font-size: 30px;
  color: var(--accent);
  white-space: nowrap;
  text-shadow: 0 3px 0 #b45d00, 0 6px 18px rgba(0, 0, 0, 0.45);
  animation: toast 1.9s ease-out forwards;
}

.toast small {
  display: block;
  text-align: center;
  font-size: 17px;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}

@keyframes toast {
  0% { transform: scale(0.4); opacity: 0; }
  12% { transform: scale(1.18); opacity: 1; }
  22% { transform: scale(1); }
  78% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-26px); }
}

#hint {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  padding: 9px 16px;
  border-radius: 10px;
  background: rgba(14, 24, 36, 0.62);
  font-size: 13px;
  color: var(--dim);
  white-space: nowrap;
  transition: opacity 1s;
}

#hint b {
  color: #fff;
}

#hint.fade {
  opacity: 0;
}

/* ---------------- Touch controls ---------------- */

#touch {
  position: fixed;
  inset: auto 0 0 0;
  height: 0;
  pointer-events: none;
}

.tgroup {
  position: fixed;
  bottom: calc(18px + env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  gap: 16px;
}

.tgroup.left {
  left: calc(22px + env(safe-area-inset-left));
}

.tgroup.right {
  right: calc(22px + env(safe-area-inset-right));
}

.tbtn {
  pointer-events: auto;
  touch-action: none;
  display: grid;
  place-items: center;
  color: rgba(255, 255, 255, 0.95);
  background: rgba(255, 255, 255, 0.14);
  border: 2.5px solid rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(3px);
  transition: transform 0.08s, background 0.12s;
}

.tbtn.on {
  background: rgba(255, 255, 255, 0.4);
  transform: scale(0.94);
}

.tbtn svg {
  width: 55%;
  height: 55%;
}

.tbtn.steer {
  width: 88px;
  height: 88px;
  border-radius: 50%;
}

.tbtn.hb {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  margin-bottom: 110px;
}

.tbtn.pedal {
  width: 74px;
  border-radius: 16px;
}

.tbtn.brake {
  height: 92px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
}

.tbtn.brake span {
  display: block;
  width: 36px;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.9);
}

.tbtn.gas {
  height: 150px;
}

/* ---------------- Screens ---------------- */

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#title {
  flex-direction: column;
  justify-content: space-between;
  padding: calc(34px + env(safe-area-inset-top)) 20px calc(26px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(10, 40, 80, 0.15), rgba(0, 0, 0, 0) 40%, rgba(5, 15, 30, 0.45));
}

.logo {
  text-align: center;
  font-family: var(--display);
  font-style: italic;
  transform: skewX(-6deg);
  animation: logo-in 0.8s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.logo-top {
  font-size: clamp(48px, 10vw, 104px);
  line-height: 0.95;
  color: var(--accent);
  letter-spacing: 0.01em;
  -webkit-text-stroke: 3px #1b1b1b;
  paint-order: stroke fill;
  text-shadow: 0 6px 0 #1b1b1b, 0 14px 30px rgba(0, 0, 0, 0.35);
}

.logo-sub {
  margin-top: 8px;
  font-size: clamp(18px, 3.2vw, 32px);
  color: #fff;
  letter-spacing: 0.32em;
  -webkit-text-stroke: 1.5px #1b1b1b;
  paint-order: stroke fill;
  text-shadow: 0 4px 0 #1b1b1b;
}

@keyframes logo-in {
  from { transform: skewX(-6deg) translateY(-40px) scale(0.8); opacity: 0; }
  to { transform: skewX(-6deg); opacity: 1; }
}

.title-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 18px 26px 16px;
  border-radius: 22px;
  background: rgba(12, 26, 42, 0.6);
  backdrop-filter: blur(6px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}

.paint-label {
  font-size: 13px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--dim);
}

#swatches {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.swatch {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.35);
  box-shadow: inset 0 -6px 10px rgba(0, 0, 0, 0.25), inset 0 5px 8px rgba(255, 255, 255, 0.35);
  transition: transform 0.12s, border-color 0.12s;
}

.swatch:hover {
  transform: scale(1.1);
}

.swatch.on {
  border-color: #fff;
  transform: scale(1.18);
}

.big-btn {
  min-width: 240px;
  padding: 16px 40px;
  border-radius: 18px;
  font-family: var(--display);
  font-style: italic;
  font-size: 30px;
  letter-spacing: 0.04em;
  color: #1b1b1b;
  background: linear-gradient(180deg, #ffe45c, var(--accent) 45%, var(--accent-deep));
  box-shadow: 0 6px 0 #b86f00, 0 12px 24px rgba(0, 0, 0, 0.35);
  transition: transform 0.08s, box-shadow 0.08s;
  animation: pulse 1.6s ease-in-out infinite;
}

.big-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #b86f00, 0 6px 14px rgba(0, 0, 0, 0.35);
}

@keyframes pulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.12); }
}

.title-foot {
  font-size: 13px;
  color: var(--dim);
  display: flex;
  gap: 8px;
  align-items: center;
}

.soft-link {
  color: #fff;
  text-decoration: none;
  opacity: 0.85;
}

.soft-link:hover {
  opacity: 1;
  text-decoration: underline;
}

/* Pause / info panels */

.screen .panel {
  width: min(360px, calc(100vw - 32px));
  padding: 24px 22px;
  border-radius: 20px;
  background: var(--panel);
  backdrop-filter: blur(8px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel h2 {
  font-family: var(--display);
  font-style: italic;
  font-size: 30px;
  text-align: center;
  margin-bottom: 6px;
  color: var(--accent);
}

.panel p {
  line-height: 1.5;
  color: var(--dim);
}

.panel a {
  color: var(--accent);
}

#pause {
  background: rgba(4, 12, 22, 0.35);
}

.menu-btn {
  padding: 13px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 17px;
  background: rgba(255, 255, 255, 0.1);
  transition: background 0.15s, transform 0.08s;
}

.menu-btn:hover {
  background: rgba(255, 255, 255, 0.18);
}

.menu-btn:active {
  transform: scale(0.97);
}

.menu-btn.primary {
  color: #1b1b1b;
  background: var(--accent);
}

.menu-btn.ghost {
  background: none;
  color: var(--dim);
  font-weight: 600;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 4px 4px 8px;
  color: var(--dim);
}

.chip {
  min-width: 96px;
  padding: 7px 14px;
  border-radius: 999px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.chip:hover {
  background: rgba(255, 255, 255, 0.2);
}

#loading {
  background: linear-gradient(180deg, #5aa9e6, #bfe3ff);
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  transition: opacity 0.5s;
}

#loading.done {
  opacity: 0;
  pointer-events: none;
}

.loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.loader .wheel {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 10px solid #1d1f24;
  background: radial-gradient(circle, #d8dde3 0 30%, #9aa3ad 31% 45%, #1d1f24 46%);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#nogl {
  background: #1a3d5c;
}

/* Small screens: shrink HUD */
@media (max-width: 760px), (max-height: 480px) {
  #minimap {
    width: 108px;
    height: 108px;
    left: calc(66px + env(safe-area-inset-left));
  }
  #speedo {
    width: 124px;
    height: 124px;
    right: calc(62px + env(safe-area-inset-right));
  }
  #topbar #btn-reset {
    margin-top: 132px;
  }
  .tbtn.steer {
    width: 74px;
    height: 74px;
  }
  .tbtn.gas {
    height: 122px;
  }
  .tbtn.brake {
    height: 78px;
  }
  .tbtn.hb {
    margin-bottom: 88px;
    width: 56px;
    height: 56px;
  }
  #points {
    font-size: 16px;
  }
  .toast {
    font-size: 24px;
  }
  #hint {
    display: none;
  }
}
