/* Self-hosted fonts (sourced from the npmmirror @fontsource CDN) — no
   runtime dependency on Google Fonts, loads fine on any network. */
@font-face {
  font-family: 'Barlow';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/barlow-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Barlow';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../fonts/barlow-500.woff2') format('woff2');
}
@font-face {
  font-family: 'Barlow';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('../fonts/barlow-600.woff2') format('woff2');
}
@font-face {
  font-family: 'Barlow Condensed';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../fonts/barlow-condensed-500.woff2') format('woff2');
}
@font-face {
  font-family: 'Barlow Condensed';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('../fonts/barlow-condensed-600.woff2') format('woff2');
}
@font-face {
  font-family: 'Barlow Condensed';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/barlow-condensed-700.woff2') format('woff2');
}

/* BikeGuard — instrument-panel styling.
   Field-black camera view, chrome floats in thin translucent bands.
   Color is semantic: the amber/green/red scale belongs to threat states only. */

:root {
  --field: #060A0D;
  --ink: #DEE7ED;
  --dim: #8B9AA6;
  --line: rgba(222, 231, 237, 0.14);
  --amber: #F5A623;
  --caution: #FFD24A;
  --warning: #FF8A2A;
  --danger: #FF2E2E;
  --clear: #37D67A;
  --surface: rgba(10, 16, 22, 0.72);
  --radius: 14px;
  --font-body: 'Barlow', system-ui, -apple-system, sans-serif;
  --font-display: 'Barlow Condensed', 'Barlow', system-ui, sans-serif;
}

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

html, body {
  height: 100%;
  background: var(--field);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

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

:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; border-radius: 4px; }

/* ------------------------------------------------------------------ stage */

#stage {
  position: fixed;
  inset: 0;
  background: var(--field);
  overflow: hidden;
}

#cam {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}
#cam.mirrored { transform: scaleX(-1); }

#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

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

#hud {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  left: 12px;
  display: none;
  gap: 8px;
  z-index: 5;
}
body.armed #hud { display: flex; }

.chip {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px 6px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
#chip-model { color: var(--clear); }

#chip-rec { color: var(--ink); }
#chip-rec .rec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  display: inline-block;
  margin-right: 7px;
  animation: recPulse 1.1s ease-in-out infinite;
}
#chip-rec.buffering .rec-dot { background: var(--dim); animation: none; }
@keyframes recPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

/* ----------------------------------------------------------------- banner */

#banner {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 14px);
  left: 50%;
  transform: translate(-50%, -160%);
  transition: transform 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  z-index: 6;
  display: grid;
  justify-items: center;
  gap: 0;
  padding: 10px 26px 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 4px solid var(--caution);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  min-width: 220px;
  text-align: center;
}
#banner.show { transform: translate(-50%, 0); }

#banner-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 21px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--caution);
}

.readout-wrap { display: flex; align-items: baseline; gap: 4px; }
.readout-wrap.no-ttc { opacity: 0.45; }
#banner-readout {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 64px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.readout-unit {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 22px;
  color: var(--dim);
}
#banner-sub { font-size: 14px; color: var(--dim); }

body[data-level="1"] #banner { border-top-color: var(--caution); }
body[data-level="1"] #banner-title { color: var(--caution); }
body[data-level="2"] #banner { border-top-color: var(--warning); }
body[data-level="2"] #banner-title { color: var(--warning); }
body[data-level="3"] #banner {
  border-top-color: var(--danger);
  border-color: rgba(255, 46, 46, 0.55);
  animation: bannerPulse 0.5s ease-in-out infinite alternate;
}
body[data-level="3"] #banner-title { color: var(--danger); }
body[data-level="3"] #banner-readout { color: var(--danger); }

@keyframes bannerPulse {
  from { box-shadow: 0 0 0 0 rgba(255, 46, 46, 0); }
  to   { box-shadow: 0 0 34px 2px rgba(255, 46, 46, 0.45); }
}

/* --------------------------------------------------------------- vignette */

#vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  opacity: 0;
  transition: opacity 0.3s;
  box-shadow: inset 0 0 90px 14px rgba(255, 46, 46, 0.35);
}
body[data-level="3"] #vignette { opacity: 1; animation: vignettePulse 0.5s ease-in-out infinite alternate; }
@keyframes vignettePulse {
  from { box-shadow: inset 0 0 70px 10px rgba(255, 46, 46, 0.25); }
  to   { box-shadow: inset 0 0 110px 24px rgba(255, 46, 46, 0.45); }
}

/* ------------------------------------------------------------------- dock */

#dock {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
  left: 50%;
  transform: translateX(-50%);
  display: none;
  gap: 6px;
  padding: 6px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 7;
}
body.armed #dock { display: flex; }

.dock-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--ink);
  transition: background 0.15s, color 0.15s;
}
.dock-btn:hover { background: rgba(222, 231, 237, 0.1); }
.dock-btn:active { background: rgba(222, 231, 237, 0.18); }
.dock-btn svg { width: 24px; height: 24px; }

#btn-stop { color: var(--danger); }
#btn-clips { position: relative; }
.badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--amber);
  color: #16100A;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
}
#btn-mute .ic-off { display: none; }
#btn-mute.off { color: var(--dim); }
#btn-mute.off .ic-on { display: none; }
#btn-mute.off .ic-off { display: block; }

/* ----------------------------------------------------------- start screen */

#start-screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(120% 90% at 50% 0%, #0D141C 0%, var(--field) 62%),
    var(--field);
  overflow-y: auto;
}
#start-screen.hidden { display: none; }

.start-card {
  width: min(460px, 100%);
  text-align: center;
}

.logo {
  width: 84px;
  height: 84px;
  color: var(--amber);
  margin-bottom: 10px;
}

h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 52px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  line-height: 1;
}

.tagline {
  color: var(--dim);
  margin: 12px auto 26px;
  max-width: 40ch;
  line-height: 1.5;
}

.steps {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 0 0 28px;
  text-align: left;
  counter-reset: step;
  position: relative;
}
.steps li {
  counter-increment: step;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 12px 12px 42px;
  position: relative;
  min-height: 86px;
}
.steps li::before {
  content: counter(step);
  position: absolute;
  left: 12px;
  top: 12px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--amber);
  color: var(--amber);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  display: grid;
  place-items: center;
}
.steps b {
  display: block;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 2px;
}
.steps span { font-size: 14px; color: var(--dim); line-height: 1.4; display: block; }

#btn-start, #btn-demo {
  display: block;
  width: 100%;
  border-radius: var(--radius);
  padding: 16px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: transform 0.1s, filter 0.15s;
}
#btn-start {
  background: var(--amber);
  color: #16100A;
  margin-bottom: 10px;
}
#btn-start:hover { filter: brightness(1.08); }
#btn-start:active { transform: scale(0.985); }
#btn-start:disabled { opacity: 0.5; }
#btn-demo {
  border: 1px solid rgba(222, 231, 237, 0.3);
  color: var(--ink);
  font-size: 18px;
  padding: 12px;
}
#btn-demo:hover { color: var(--ink); border-color: rgba(222, 231, 237, 0.45); }

#insecure-note {
  margin-top: 18px;
  font-size: 14px;
  color: var(--warning);
  border: 1px solid rgba(255, 138, 42, 0.4);
  border-radius: var(--radius);
  padding: 10px 14px;
  text-align: left;
  line-height: 1.45;
}
#insecure-note code { color: var(--caution); }
.hidden { display: none !important; }

.disclaimer {
  margin-top: 26px;
  font-size: 12.5px;
  color: var(--dim);
  max-width: 46ch;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.5;
}

/* ------------------------------------------------------------------ sheet */

#sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 9, 0.55);
  z-index: 19;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
#sheet-backdrop.show { opacity: 1; pointer-events: auto; }

#sheet {
  position: fixed;
  z-index: 20;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 78vh;
  overflow-y: auto;
  background: #0B1218;
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  padding: 6px 20px calc(env(safe-area-inset-bottom, 0px) + 20px);
  transform: translateY(105%);
  transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
}
#sheet.open { transform: translateY(0); }

@media (min-width: 720px) {
  #sheet {
    left: auto;
    top: 0;
    bottom: 0;
    width: 380px;
    border-radius: 0;
    border-left: 1px solid var(--line);
    transform: translateX(105%);
  }
  #sheet.open { transform: translateX(0); }
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0 6px;
  position: sticky;
  top: 0;
  background: #0B1218;
}
.sheet-head h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 24px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
#sheet-close {
  font-size: 28px;
  line-height: 1;
  color: var(--dim);
  padding: 4px 10px;
}

.group { border-top: 1px solid var(--line); padding: 12px 0 16px; }
.group h3 {
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
  font-weight: 600;
  margin-bottom: 6px;
}

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 10px 0;
  font-size: 15.5px;
}
.row span { color: var(--ink); }

input[type="range"] {
  flex: 1;
  max-width: 200px;
  accent-color: var(--amber);
  height: 28px;
}

select {
  background: #121B22;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
}

.switch {
  appearance: none;
  -webkit-appearance: none;
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: #1B262F;
  border: 1px solid var(--line);
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
  flex: none;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--dim);
  transition: transform 0.15s, background 0.15s;
}
.switch:checked { background: rgba(245, 166, 35, 0.28); border-color: var(--amber); }
.switch:checked::after { transform: translateX(20px); background: var(--amber); }

/* ------------------------------------------------------------------ clips  */

.ghost {
  display: block;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  font: inherit;
}
.ghost:hover { border-color: rgba(222, 231, 237, 0.35); }
.ghost.danger { color: var(--danger); border-color: rgba(255, 46, 46, 0.4); }

#clips-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 9, 0.55);
  z-index: 19;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
#clips-backdrop.show { opacity: 1; pointer-events: auto; }

#clips {
  position: fixed;
  z-index: 20;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 78vh;
  overflow-y: auto;
  background: #0B1218;
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  padding: 6px 20px calc(env(safe-area-inset-bottom, 0px) + 20px);
  transform: translateY(105%);
  transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
}
#clips.open { transform: translateY(0); }

@media (min-width: 720px) {
  #clips {
    left: auto;
    top: 0;
    bottom: 0;
    width: 380px;
    border-radius: 0;
    border-left: 1px solid var(--line);
    transform: translateX(105%);
  }
  #clips.open { transform: translateX(0); }
}

.panel-hint { margin: 4px 0 8px; }
.hint {
  font-size: 13px;
  color: var(--dim);
  line-height: 1.45;
}
.empty {
  font-size: 14px;
  color: var(--dim);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 22px 16px;
  text-align: center;
  margin-top: 10px;
}

.clip {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-top: 10px;
}
.clip video {
  width: 100%;
  border-radius: 8px;
  background: #000;
  margin-bottom: 8px;
}
.clip-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.clip-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.clip-name .tag-threat { color: var(--warning); }
.clip-name .tag-ride { color: var(--clear); }
.clip-meta {
  font-size: 12.5px;
  color: var(--dim);
  margin: 2px 0 8px;
}
.clip-actions {
  display: flex;
  gap: 8px;
}
.clip-actions a,
.clip-actions button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 13.5px;
  text-decoration: none;
}
.clip-actions a { color: var(--amber); border-color: rgba(245, 166, 35, 0.45); }
.clip-actions a:hover, .clip-actions button:hover { filter: brightness(1.15); }
.clip-actions svg { width: 15px; height: 15px; }

/* ------------------------------------------------------------------- toast */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 84px);
  transform: translate(-50%, 16px);
  max-width: min(480px, calc(100vw - 32px));
  background: #101920;
  border: 1px solid var(--line);
  border-left: 3px solid var(--amber);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 14.5px;
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 30;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------------------------------------- landscape  */

@media (orientation: landscape) and (max-height: 480px) {
  #banner {
    flex-direction: row;
    align-items: center;
    gap: 14px;
    padding: 8px 20px;
    min-width: 0;
  }
  #banner-readout { font-size: 44px; }
  #banner-sub { display: none; }
  .logo { width: 64px; height: 64px; }
  h1 { font-size: 38px; }
  .steps { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .steps li { min-height: 0; padding-bottom: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  #banner, #sheet, #toast { transition: none; }
  body[data-level="3"] #banner, body[data-level="3"] #vignette { animation: none; }
}
