:root {
  color-scheme: dark;
  font-family: Inter, ui-rounded, "SF Pro Rounded", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #f7f6e8;
  --muted: #aeb8cf;
  --panel: rgba(14, 21, 42, 0.76);
  --line: rgba(255, 255, 255, 0.13);
  --orange: #ff9b50;
  --mint: #77efbd;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 0%, rgba(89, 78, 145, 0.42), transparent 36rem),
    #0b1124;
}

button, input { font: inherit; }
button { color: inherit; }

.app {
  width: min(1500px, 100%);
  min-height: 100dvh;
  margin: auto;
  padding: 18px clamp(12px, 2.4vw, 34px) 12px;
  display: grid;
  grid-template-rows: auto minmax(510px, 1fr) auto;
  gap: 14px;
}

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.brand { display: flex; align-items: center; gap: 12px; letter-spacing: .09em; }
.brand strong { display: block; font-size: clamp(1rem, 2vw, 1.35rem); line-height: 1; }
.brand small { display: block; margin-top: 5px; color: var(--orange); font-size: .66rem; font-weight: 800; letter-spacing: .17em; text-transform: uppercase; }
.brand-mark { position: relative; width: 42px; height: 42px; border: 2px solid var(--mint); border-radius: 14px 6px 14px 6px; transform: rotate(-5deg); }
.brand-mark::before, .brand-mark::after { content: ""; position: absolute; left: 7px; right: 7px; height: 3px; background: var(--mint); border-radius: 5px; transform: rotate(-28deg); }
.brand-mark::before { top: 13px; }.brand-mark::after { top: 23px; width: 16px; }

.seed-control { display: grid; grid-template-columns: auto minmax(110px, 170px) 38px; align-items: center; gap: 8px; }
.seed-control label { color: var(--muted); font-size: .72rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.seed-control input {
  width: 100%; min-height: 38px; padding: 8px 11px; color: var(--ink); background: #121b34; border: 1px solid var(--line); border-radius: 10px; outline: none;
}
.seed-control input:focus { border-color: var(--mint); box-shadow: 0 0 0 3px rgba(119, 239, 189, .16); }
.icon-button, .restart-button { border: 1px solid var(--line); background: #18233f; cursor: pointer; }
.icon-button { width: 38px; height: 38px; padding: 8px; border-radius: 10px; }
svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round; }

.game-frame {
  position: relative;
  min-height: 510px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: clamp(18px, 3vw, 30px);
  background: #e79775;
  box-shadow: 0 22px 70px rgba(0,0,0,.36), inset 0 1px rgba(255,255,255,.28);
  isolation: isolate;
}

canvas { display: block; width: 100%; height: 100%; min-height: 510px; touch-action: none; }

.hud { position: absolute; z-index: 3; inset: 16px 16px auto; display: grid; grid-template-columns: 112px 138px minmax(150px, 230px) minmax(155px, auto); gap: 9px; pointer-events: none; }
.hud-card, .fuel-card, .run-card { min-height: 64px; padding: 10px 13px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 9px 24px rgba(4,8,20,.16); backdrop-filter: blur(10px); }
.hud span, .hud-card span, .fuel-card span { color: var(--muted); font-size: .62rem; font-weight: 850; letter-spacing: .12em; text-transform: uppercase; }
.hud-card strong { display: inline-block; margin-top: 3px; font-size: 1.45rem; font-variant-numeric: tabular-nums; line-height: 1.05; }
.hud-card small { margin-left: 3px; color: var(--muted); font-size: .62rem; }
.distance strong { display: block; font-size: 1.2rem; }
.fuel-card strong { float: right; color: var(--mint); font-size: .82rem; font-variant-numeric: tabular-nums; }
.fuel-track { height: 8px; margin-top: 13px; overflow: hidden; background: rgba(255,255,255,.1); border-radius: 9px; }
.fuel-track i { display: block; width: 100%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #58dda8, #c9ff97); box-shadow: 0 0 14px rgba(119,239,189,.5); transform-origin: left; transition: transform .15s, background .25s; }
.run-card { margin-left: auto; text-align: right; }
.run-card > span { display: block; color: var(--orange); }
.run-card strong { display: block; margin: 2px 0; font-size: .92rem; }
.run-card small { color: var(--muted); font-size: .67rem; }.run-card b { color: var(--ink); font-weight: 700; }

.restart-button { position: absolute; z-index: 4; top: 92px; right: 16px; min-height: 36px; padding: 7px 12px; display: flex; align-items: center; gap: 7px; border-radius: 10px; font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.restart-button svg { width: 16px; height: 16px; }
.restart-button:hover, .icon-button:hover { border-color: rgba(119,239,189,.6); background: #1e2e4e; }

.controls { position: absolute; z-index: 4; left: clamp(15px, 3vw, 34px); right: clamp(15px, 3vw, 34px); bottom: max(18px, env(safe-area-inset-bottom)); display: flex; align-items: end; justify-content: space-between; pointer-events: none; }
.pedal { pointer-events: auto; width: clamp(98px, 12vw, 142px); height: 76px; padding: 8px 14px; display: grid; grid-template-columns: 26px 1fr; grid-template-rows: 1fr 1fr; align-items: center; border: 1px solid rgba(255,255,255,.2); border-radius: 19px; background: rgba(13,20,38,.84); box-shadow: 0 10px 26px rgba(0,0,0,.25); cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: none; backdrop-filter: blur(10px); }
.pedal-icon { grid-row: 1 / 3; display: flex; flex-direction: column; gap: 4px; }.pedal-icon i { width: 22px; height: 4px; border-radius: 3px; background: currentColor; }
.pedal strong { align-self: end; font-size: .88rem; letter-spacing: .08em; text-transform: uppercase; }.pedal small { align-self: start; color: var(--muted); font-size: .61rem; }
.pedal.gas { color: var(--mint); }.pedal.brake { color: var(--orange); }
.pedal:hover, .pedal:focus-visible { outline: none; transform: translateY(-2px); border-color: currentColor; }
.pedal.is-pressed { transform: translateY(3px) scale(.98); filter: brightness(1.25); box-shadow: 0 5px 10px rgba(0,0,0,.25), inset 0 0 20px rgba(255,255,255,.08); }
.control-tip { padding: 8px 14px; display: flex; align-items: center; gap: 8px; color: rgba(255,255,255,.65); background: rgba(10,16,33,.45); border-radius: 20px; font-size: .59rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.control-tip i { width: 28px; height: 1px; background: rgba(255,255,255,.3); }

.toast { position: absolute; z-index: 5; top: 108px; left: 50%; padding: 9px 15px; border: 1px solid rgba(255,255,255,.25); border-radius: 20px; background: rgba(16,24,45,.85); font-size: .75rem; font-weight: 850; letter-spacing: .08em; text-transform: uppercase; opacity: 0; transform: translate(-50%, -10px); transition: .22s; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.end-panel { position: absolute; z-index: 7; top: 50%; left: 50%; width: min(360px, calc(100% - 34px)); padding: 28px; text-align: center; background: rgba(11,17,36,.92); border: 1px solid rgba(255,255,255,.18); border-radius: 24px; box-shadow: 0 26px 80px rgba(0,0,0,.45); transform: translate(-50%, -50%); backdrop-filter: blur(14px); }
.end-panel[hidden] { display: none; }.end-panel p { margin: 0 0 8px; color: var(--muted); }.end-panel #end-kicker { color: var(--orange); font-size: .7rem; font-weight: 850; letter-spacing: .16em; text-transform: uppercase; }.end-panel h1 { margin: 5px 0 8px; font-size: clamp(1.7rem, 4vw, 2.5rem); }.primary-button { margin-top: 14px; padding: 12px 21px; border: 0; border-radius: 12px; color: #102135; background: var(--mint); font-weight: 900; cursor: pointer; }.primary-button:hover, .primary-button:focus-visible { outline: 3px solid rgba(119,239,189,.3); transform: translateY(-1px); }

footer { display: flex; align-items: center; justify-content: center; gap: 10px; color: #818da8; font-size: .66rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
footer i { width: 3px; height: 3px; border-radius: 50%; background: var(--orange); }

@media (max-width: 760px) {
  .app { padding: 10px 8px 8px; grid-template-rows: auto minmax(530px, 1fr); gap: 9px; }
  .topbar { gap: 8px; }.brand-mark { width: 34px; height: 34px; }.brand small { display: none; }
  .seed-control { grid-template-columns: minmax(92px, 128px) 36px; }.seed-control label { display: none; }.seed-control input, .icon-button { min-height: 36px; height: 36px; }
  .game-frame, canvas { min-height: 530px; border-radius: 20px; }
  .hud { inset: 10px 10px auto; grid-template-columns: 1fr 1fr 1.25fr; gap: 6px; }
  .hud-card, .fuel-card, .run-card { min-height: 57px; padding: 8px 9px; border-radius: 11px; }
  .hud-card strong { font-size: 1.17rem; }.distance strong { font-size: 1rem; }.fuel-track { margin-top: 9px; }
  .run-card { grid-column: 1 / 4; width: 100%; min-height: 33px; display: flex; justify-content: space-between; align-items: center; text-align: left; padding: 7px 10px; }
  .run-card > span { display: none; }.run-card strong { margin: 0; }.run-card small { order: -1; }
  .restart-button { top: 113px; right: 10px; }.restart-button span { display: none; }.restart-button { width: 34px; padding: 8px; }
  .toast { top: 118px; }
  .control-tip { display: none; }.pedal { width: 103px; height: 70px; }
  footer { display: none; }
}

@media (max-height: 650px) and (orientation: landscape) {
  .app { min-height: 100vh; padding-top: 7px; grid-template-rows: auto minmax(420px, 1fr); }
  .game-frame, canvas { min-height: 420px; }.topbar { min-height: 34px; }.pedal { height: 62px; }.controls { bottom: 10px; }
}

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