:root {
  --carbon: #0b0b0d; --asphalt: #16161a; --pit: #2a2a31; --paper: #f2f0ea; --mut: #8a8a94;
  --red: #e10600; --redhot: #ff3b2f; --amber: #ffb000;
  --f-num: 'Saira', sans-serif; --f-ui: 'Chakra Petch', sans-serif;
  --r: 4px; --gut: 16px; --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--carbon); color: var(--paper); font-family: var(--f-ui); font-size: 16px; -webkit-tap-highlight-color: transparent; }
body {
  min-height: 100dvh;
  background-image:
    repeating-linear-gradient(45deg, rgba(255,255,255,.018) 0 2px, transparent 2px 4px),
    repeating-linear-gradient(-45deg, rgba(255,255,255,.018) 0 2px, transparent 2px 4px);
}
a { color: inherit; }
:focus-visible { outline: 2px solid var(--redhot); outline-offset: 2px; }

/* shell */
.app { max-width: 480px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 10px var(--gut) 4px; }
.logo { font-family: var(--f-num); font-stretch: 75%; font-style: italic; font-weight: 800; font-size: 24px; letter-spacing: 1px; text-decoration: none; }
.logo i { color: var(--red); }
.topbar-right { display: flex; align-items: center; gap: 6px; }
.icon-btn { display: inline-flex; width: 44px; height: 44px; align-items: center; justify-content: center; color: var(--mut); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.view { flex: 1; padding: 0 var(--gut) calc(88px + var(--safe-b)); outline: none; }
.no-nav .tabbar, .no-nav .topbar { display: none; }
.no-nav .view { padding-bottom: 24px; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; background: #08080a; border-top: 1px solid var(--pit); padding-bottom: var(--safe-b); z-index: 10; }
.tabbar-in { display: flex; width: 100%; max-width: 480px; }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 58px; font-size: 12px; font-weight: 600; letter-spacing: 1px; color: var(--mut); text-decoration: none; }
.tabbar a.on { color: var(--paper); }
.tabbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.tabbar a.on svg { stroke: var(--red); }

/* type */
.lbl { font-size: 11px; font-weight: 600; letter-spacing: 2px; color: var(--mut); text-transform: uppercase; }
.lbl-th { font-size: 12px; font-weight: 600; letter-spacing: .5px; color: var(--mut); }
.num { font-family: var(--f-num); font-stretch: 75%; font-style: italic; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .5px; }

/* dashboard */
.dash { display: flex; flex-direction: column; gap: 12px; }
.stage { height: 210px; perspective: 520px; position: relative; margin: 0 calc(-1 * var(--gut)); overflow: hidden; background: radial-gradient(ellipse at 50% 62%, #1c1c22 0, transparent 70%); }
.stage-top { position: absolute; top: 8px; left: var(--gut); right: var(--gut); display: flex; justify-content: space-between; z-index: 2; }
.stage-top .lbl { color: var(--paper); }
.tilt { position: absolute; left: 50%; top: 50%; width: 250px; height: 175px; margin: -92px 0 0 -125px; transform: rotateX(55deg) rotateZ(-16deg); transform-style: preserve-3d; animation: orbit 10s ease-in-out infinite alternate; }
@keyframes orbit { from { transform: rotateX(58deg) rotateZ(-24deg); } to { transform: rotateX(52deg) rotateZ(-8deg); } }
.grid3d { position: absolute; inset: -70px; background-image: linear-gradient(var(--pit) 1px, transparent 1px), linear-gradient(90deg, var(--pit) 1px, transparent 1px); background-size: 22px 22px; opacity: .35; -webkit-mask: radial-gradient(circle, #000 30%, transparent 70%); mask: radial-gradient(circle, #000 30%, transparent 70%); }
.track { width: 100%; height: 100%; overflow: visible; }
.track .asphalt { stroke: #26262d; stroke-width: 10; stroke-linejoin: round; }
.track .trail { stroke-dasharray: 100; stroke-dashoffset: 100; }
.track .glow { stroke: var(--red); stroke-width: 4; }
.track .core { stroke: #ff6a60; stroke-width: 1.3; }
.track .halo { fill: var(--paper); opacity: .55; }
.track .dot { fill: var(--paper); }
.track.over .halo, .track.over .dot { fill: var(--redhot); }
.track.over .halo { transform-box: fill-box; transform-origin: center; animation: halo .9s ease-in-out infinite; }
@keyframes halo { 50% { transform: scale(1.8); opacity: .25; } }
.hero { display: flex; justify-content: space-between; align-items: flex-end; gap: 8px; }
.big { font-size: 84px; line-height: .82; letter-spacing: -1px; }
.big small { font-size: 20px; color: var(--mut); margin-left: 4px; letter-spacing: 1px; }
.is-over .big { color: var(--redhot); }
.chip { display: inline-flex; font-size: 12px; font-weight: 700; letter-spacing: 1px; padding: 4px 10px; margin-bottom: 6px; white-space: nowrap; transform: skewX(-14deg); }
.chip span { transform: skewX(14deg); }
.chip.ok { border: 1px solid var(--pit); }
.chip.near { background: var(--amber); color: #000; }
.chip.over { background: var(--red); color: #fff; animation: strobe .7s steps(1) infinite; }
@keyframes strobe { 50% { background: #5a0200; } }
.seg { display: grid; grid-template-columns: repeat(32, 1fr); gap: 2px; height: 10px; transform: skewX(-20deg); }
.seg b { background: #222228; }
.seg b.f { background: var(--paper); }
.seg b.f.hot { background: var(--red); }
.tgrid { display: grid; grid-template-columns: 1fr 1fr; margin: 0; border: 1px solid var(--pit); border-radius: var(--r); overflow: hidden; }
.tgrid > div { padding: 8px 12px; border-right: 1px solid var(--pit); border-bottom: 1px solid var(--pit); }
.tgrid > div:nth-child(2n) { border-right: none; }
.tgrid > div:nth-child(n+3) { border-bottom: none; }
.tgrid dt { margin: 0; }
.tgrid dd { margin: 0; font-size: 24px; line-height: 1.15; }
.of { color: var(--mut); font-size: 15px; }

/* inputs + buttons */
.inp { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--asphalt); border: 1px solid var(--pit); border-radius: var(--r); padding: 6px 12px; }
.inp:focus-within { border-color: var(--red); }
.inp input { flex: 1; min-width: 0; background: none; border: none; outline: none; color: var(--paper); font-size: 30px; text-align: right; padding: 4px 0; caret-color: var(--red); }
.inp input::placeholder { color: #4a4a53; }
.btn-row { display: flex; gap: 8px; }
.btn { --cut: 10px; flex: 1; display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 10px 16px; border: none; font-family: var(--f-ui); font-weight: 700; font-size: 15px; letter-spacing: .5px; line-height: 1.15; text-align: center; text-decoration: none; color: var(--paper); background: var(--asphalt); clip-path: polygon(var(--cut) 0, 100% 0, calc(100% - var(--cut)) 100%, 0 100%); cursor: pointer; position: relative; overflow: hidden; }
.btn[hidden] { display: none; }
.btn.primary { background: var(--red); color: #fff; flex: 1.4; }
.btn.primary::after { content: ""; position: absolute; top: 0; left: -60%; width: 40%; height: 100%; background: linear-gradient(100deg, transparent, rgba(255,255,255,.3), transparent); animation: sheen 3.4s ease-in-out infinite; }
@keyframes sheen { 0%, 65% { left: -60%; } 100% { left: 130%; } }
.btn.ghost { background: var(--asphalt); }
.btn.danger { background: #3a0b0b; color: #ff8a80; }
.btn.small { font-size: 13px; font-weight: 600; flex: 1; }
.btn:disabled { opacity: .5; cursor: wait; }
.btn:focus-visible { outline: none; filter: brightness(1.3); box-shadow: inset 0 0 0 2px var(--paper); }

/* pages */
.page { display: flex; flex-direction: column; gap: 14px; padding-top: 6px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.page-head .btn { flex: 0 0 auto; }
.page-title { font-size: 22px; font-weight: 700; margin: 0; }
.hint { color: var(--mut); font-size: 14px; margin: 0; }
.empty { color: var(--mut); text-align: center; padding: 32px 0; list-style: none; }
.rows { list-style: none; margin: 0; padding: 0; border: 1px solid var(--pit); border-radius: var(--r); overflow: hidden; }
.rows > li + li { border-top: 1px solid var(--pit); }
.row { width: 100%; display: grid; grid-template-columns: 1fr auto 72px; align-items: baseline; gap: 2px 12px; padding: 12px; min-height: 52px; background: none; border: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.row:hover { background: var(--asphalt); }
.row-date { font-size: 14px; color: var(--mut); }
.row-odo { font-size: 22px; }
.row-delta { font-size: 18px; text-align: right; }
.row-delta.neg { color: var(--redhot); }
.row-note { grid-column: 1 / -1; font-size: 13px; color: var(--mut); }
.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.summary > div { background: var(--asphalt); padding: 10px 12px; border-left: 2px solid var(--red); display: flex; flex-direction: column; gap: 2px; }
.big-s { font-size: 28px; line-height: 1.1; }
.laps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.lap { display: block; text-decoration: none; background: var(--asphalt); border: 1px solid var(--pit); border-radius: var(--r); padding: 12px; }
.lap.current { border-color: var(--red); }
.lap-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.lap-no { font-size: 22px; }
.lap.current .lap-no { color: var(--redhot); }
.lap-oil { font-size: 16px; font-weight: 600; margin: 4px 0 10px; }
.lap-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.lap-stats span { display: flex; flex-direction: column; }
.lap-stats b { font-size: 19px; }
.lap-stats i { font-style: normal; font-size: 12px; color: var(--mut); }

/* forms */
.form { display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--asphalt); border: 1px solid var(--pit); border-radius: var(--r); padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.card-title { font-size: 16px; margin: 0; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--mut); flex: 1; min-width: 0; }
.field input { width: 100%; min-height: 48px; padding: 11px 12px; background: var(--carbon); border: 1px solid var(--pit); border-radius: var(--r); color: var(--paper); font-family: var(--f-ui); font-size: 17px; }
.field input.num { font-family: var(--f-num); font-size: 22px; }
.field input:focus { outline: none; border-color: var(--red); }
.field-row { display: flex; gap: 10px; }
input[type=date], input[type=datetime-local] { color-scheme: dark; }

/* PIN */
.pin-screen { display: flex; flex-direction: column; align-items: center; gap: 16px; padding-top: 10vh; }
.big-logo { font-size: 44px; }
.pin-leds { display: flex; gap: 10px; }
.pin-leds b { width: 14px; height: 14px; border-radius: 2px; background: #1e1e22; transform: skewX(-14deg); }
.pin-leds b.on { background: var(--red); box-shadow: 0 0 10px var(--red); }
.pin-leds.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.pin-msg { min-height: 1.4em; margin: 0; color: var(--redhot); font-size: 14px; text-align: center; }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 12px; }
.keypad button { height: 64px; background: var(--asphalt); border: 1px solid var(--pit); border-radius: var(--r); color: var(--paper); font-family: var(--f-num); font-stretch: 75%; font-style: italic; font-weight: 700; font-size: 30px; cursor: pointer; }
.keypad button:active { background: var(--pit); }
.keypad .ok { background: var(--red); border-color: var(--red); }

/* toast + sheet */
.toast { position: fixed; left: 50%; bottom: calc(80px + var(--safe-b)); transform: translate(-50%, 20px); max-width: calc(100% - 32px); padding: 10px 18px; background: var(--paper); color: #000; font-weight: 700; clip-path: polygon(8px 0, 100% 0, calc(100% - 8px) 100%, 0 100%); opacity: 0; pointer-events: none; transition: .2s; z-index: 50; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--red); color: #fff; }
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 40; }
.sheet { position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); width: 100%; max-width: 480px; background: var(--asphalt); border-top: 2px solid var(--red); padding: 18px var(--gut) calc(18px + var(--safe-b)); z-index: 41; display: flex; flex-direction: column; gap: 14px; animation: up .2s ease-out; }
@keyframes up { from { transform: translate(-50%, 100%); } }
.sheet-title { font-size: 18px; margin: 0; }
.sheet-msg { margin: 0; font-size: 16px; line-height: 1.5; }

@media (max-width: 359px) { .big { font-size: 68px; } .keypad { grid-template-columns: repeat(3, 68px); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
