:root {
  color-scheme: dark;
  --bg: #101113;
  --panel: rgba(20, 22, 25, 0.86);
  --panel-solid: #181b1f;
  --line: rgba(255, 255, 255, 0.16);
  --text: #f4f1ea;
  --muted: #b8b0a3;
  --green: #35e073;
  --red: #ff5a4f;
  --amber: #f8bd43;
  --blue: #5ab8ff;
  --shadow: rgba(0, 0, 0, 0.36);
  --controls-height: 176px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
}

button,
input {
  font: inherit;
}

button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #252a30;
  color: var(--text);
  font-weight: 800;
  letter-spacing: 0;
}

button:active {
  transform: translateY(1px);
}

.content-shell {
  width: min(100%, 880px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  color: #20242a;
  background:
    linear-gradient(180deg, rgba(53, 224, 115, 0.12), transparent 260px),
    #f7f6f2;
}

.content-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(180px, 0.8fr);
  gap: 20px;
  align-items: center;
  padding: 22px 0 16px;
}

.hero-copy {
  display: grid;
  gap: 12px;
}

.eyebrow {
  margin: 0;
  color: #65707b;
  font-size: 0.86rem;
  font-weight: 900;
}

.content-hero h1 {
  margin: 0;
  color: #12161b;
  font-size: clamp(2rem, 8vw, 3.3rem);
  line-height: 1.02;
  letter-spacing: 0;
}

.content-hero p,
.content-section p,
.content-section li {
  color: #4b5560;
  font-size: 1rem;
  line-height: 1.68;
}

.content-hero p {
  margin: 0;
}

.hero-action {
  width: min(100%, 260px);
  border-color: rgba(13, 130, 70, 0.28);
  background: #16814a;
  color: #fff;
  box-shadow: 0 14px 30px rgba(22, 129, 74, 0.2);
}

.phone-preview {
  position: relative;
  aspect-ratio: 9 / 16;
  min-height: 260px;
  border: 10px solid #181b1f;
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.1), transparent 42%),
    linear-gradient(90deg, #242a31 0 6%, #353c44 6% 46%, #242a31 46% 54%, #353c44 54% 94%, #242a31 94%);
  box-shadow: 0 22px 44px rgba(0, 0, 0, 0.24);
  overflow: hidden;
}

.phone-preview::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 10px;
  width: 74px;
  height: 18px;
  border-radius: 999px;
  background: #090b0d;
  transform: translateX(-50%);
}

.preview-road {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, transparent 48%, rgba(255, 255, 255, 0.38) 49% 51%, transparent 52%),
    linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.4));
}

.preview-car {
  position: absolute;
  left: 50%;
  border-radius: 12px 12px 7px 7px;
  background: linear-gradient(180deg, #eceff1, #8a949e);
  transform: translateX(-50%);
}

.preview-car.front {
  top: 34%;
  width: 78px;
  height: 52px;
}

.preview-car.back {
  bottom: 14%;
  width: 108px;
  height: 68px;
  background: linear-gradient(180deg, #35e073, #16814a);
}

.preview-box {
  position: absolute;
  left: 50%;
  top: 31%;
  width: 118px;
  height: 90px;
  border: 3px solid var(--green);
  transform: translateX(-50%);
  box-shadow: 0 0 22px rgba(53, 224, 115, 0.34);
}

.content-nav {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin: 4px 0 18px;
  padding: 6px;
  border: 1px solid rgba(20, 25, 30, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(14px);
}

.content-nav a {
  min-height: 44px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: #59636e;
  font-weight: 900;
  text-align: center;
  text-decoration: none;
}

.content-nav a:focus,
.content-nav a:hover {
  background: #ecf7f0;
  color: #16814a;
}

.content-section {
  margin: 0 0 14px;
  padding: 18px;
  border: 1px solid rgba(20, 25, 30, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 10px 28px rgba(40, 44, 48, 0.08);
}

.content-section h2 {
  margin: 0 0 10px;
  color: #15191e;
  font-size: 1.16rem;
  letter-spacing: 0;
}

.content-section p {
  margin: 0 0 10px;
}

.content-section p:last-child {
  margin-bottom: 0;
}

.content-section ol {
  margin: 0 0 12px;
  padding-left: 22px;
}

.content-section strong {
  color: #15191e;
}

.content-ad-wrap {
  padding-bottom: env(safe-area-inset-bottom);
}

body.detector-active {
  height: 100dvh;
  overflow: hidden;
}

body.detector-active .content-shell {
  display: none;
}

.app-shell {
  position: relative;
  display: block;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.app-shell[hidden] {
  display: none;
}

.stage {
  position: absolute;
  inset: 0;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0) 34%),
    #050608;
}

.camera,
.analysis-canvas,
.demo-light {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.camera,
.analysis-canvas {
  object-fit: cover;
}

.analysis-canvas {
  display: none;
}

.demo-light {
  display: none;
  place-items: center;
  background:
    radial-gradient(circle at 50% 18%, rgba(90, 184, 255, 0.16), transparent 24%),
    linear-gradient(180deg, #171a1e, #07080a 78%);
}

.demo-light.active {
  display: grid;
}

.demo-light::before {
  content: "";
  width: min(70vw, 280px);
  height: 100%;
  border-left: 1px solid rgba(255, 255, 255, 0.12);
  border-right: 1px solid rgba(255, 255, 255, 0.12);
  background: linear-gradient(90deg, #101317, #181d22 48%, #101317);
  box-shadow: 0 24px 70px var(--shadow);
}

.road-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.35), transparent);
}

.road-line.left {
  left: 34%;
}

.road-line.right {
  right: 34%;
}

.demo-car {
  position: absolute;
  left: 50%;
  top: 30%;
  width: min(30vw, 124px);
  height: min(19vw, 78px);
  border-radius: 14px 14px 8px 8px;
  transform: translateX(-50%);
  background: linear-gradient(180deg, #4c5662, #252b32);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 12px 38px rgba(0, 0, 0, 0.45);
}

.demo-light.moving .demo-car {
  animation: car-move 900ms ease-in-out infinite alternate;
}

.tail {
  position: absolute;
  bottom: 10px;
  width: 18px;
  height: 8px;
  border-radius: 999px;
  background: var(--red);
  box-shadow: 0 0 16px rgba(255, 90, 79, 0.8);
}

.tail.left {
  left: 16px;
}

.tail.right {
  right: 16px;
}

@keyframes car-move {
  from {
    transform: translate(-50%, 0);
  }
  to {
    transform: translate(-50%, -54px) scale(0.86);
  }
}

.lamp {
  position: absolute;
  left: 50%;
  width: min(22vw, 88px);
  height: min(22vw, 88px);
  border-radius: 50%;
  transform: translateX(-50%);
  background: #2b2f35;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.demo-light.far .lamp {
  width: min(12vw, 48px);
  height: min(12vw, 48px);
  transform: translate(-50%, -10vh);
}

.lamp.red {
  top: calc(50% - min(28vw, 112px));
}

.lamp.amber {
  top: 50%;
  transform: translate(-50%, -50%);
}

.lamp.green {
  top: calc(50% + min(10vw, 40px));
}

.demo-light.red-on .lamp.red,
.demo-light.green-on .lamp.green {
  box-shadow: 0 0 28px currentColor;
}

.demo-light.red-on .lamp.red {
  color: var(--red);
  background: var(--red);
}

.demo-light.green-on .lamp.green {
  color: var(--green);
  background: var(--green);
}

.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 16px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 12px;
}

.state-badge {
  min-width: 74px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: var(--panel);
  text-align: center;
  font-weight: 900;
  box-shadow: 0 10px 28px var(--shadow);
}

.state-badge.green {
  color: #092112;
  background: var(--green);
}

.state-badge.red {
  color: #fff3ef;
  background: #8d211d;
}

.state-badge.armed {
  color: #102015;
  background: var(--amber);
}

.state-badge.moving {
  color: #07180e;
  background: var(--green);
}

.yolo-overlay {
  position: absolute;
  z-index: 3;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.yolo-box {
  position: absolute;
  min-width: 18px;
  min-height: 18px;
  border: 2px solid rgba(90, 184, 255, 0.92);
  box-shadow: 0 0 22px rgba(90, 184, 255, 0.28);
}

.yolo-box.tracked {
  border-color: rgba(53, 224, 115, 0.98);
  box-shadow: 0 0 26px rgba(53, 224, 115, 0.38);
}

.yolo-box span {
  position: absolute;
  left: -2px;
  top: -26px;
  max-width: min(200px, 60vw);
  padding: 3px 7px;
  border-radius: 6px 6px 6px 0;
  background: rgba(5, 6, 8, 0.78);
  color: #f4f1ea;
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1.1;
  white-space: nowrap;
}

.yolo-box.tracked span {
  color: #07180e;
  background: rgba(53, 224, 115, 0.96);
}

.flash {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  background: rgba(53, 224, 115, 0.55);
}

.flash.active {
  animation: flash 900ms ease-out 2;
}

@keyframes flash {
  0%,
  100% {
    opacity: 0;
  }
  30% {
    opacity: 1;
  }
}

.readout-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--controls-height);
  z-index: 7;
  display: grid;
  gap: 7px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(17, 19, 22, 0.84);
  backdrop-filter: blur(14px);
  padding: 8px 14px 7px;
}

.meter-row {
  display: grid;
  grid-template-columns: 28px 1fr 48px;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 800;
}

meter {
  width: 100%;
  height: 12px;
}

.controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9;
  display: grid;
  gap: 8px;
  border-top: 0;
  background: linear-gradient(180deg, transparent, rgba(16, 17, 19, 0.86) 30%, rgba(16, 17, 19, 0.96));
  padding: 8px 14px 0;
  min-height: 0;
  overflow: visible;
}

.primary-actions {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  align-self: end;
  min-height: 0;
}

.primary-actions button {
  min-height: 50px;
  padding-inline: 8px;
  font-size: 0.92rem;
}

#startBtn,
#testBtn,
#settingsBtn {
  grid-column: span 2;
}

#aboutBtn,
#homeBtn {
  grid-column: span 3;
}

.primary {
  border-color: rgba(53, 224, 115, 0.66);
  background: var(--green);
  color: #07180e;
}

.ad-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(46px + env(safe-area-inset-bottom));
  height: calc(clamp(46px, 7dvh, 64px) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px 8px 0 0;
  background: rgba(255, 255, 255, 0.07);
  color: rgba(244, 241, 234, 0.64);
  font-size: 0.78rem;
  font-weight: 800;
  text-align: center;
}

.content-shell .ad-slot {
  min-height: 96px;
  height: auto;
  margin-top: 8px;
  padding: 18px;
  border-color: rgba(20, 25, 30, 0.22);
  background: rgba(255, 255, 255, 0.64);
  color: #626b75;
}

.detector-ad-slot {
  min-height: calc(50px + env(safe-area-inset-bottom));
  height: calc(50px + env(safe-area-inset-bottom));
}

.control-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}

.settings-panel,
.about-panel {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: calc(var(--controls-height) + 10px);
  z-index: 12;
  width: min(calc(100vw - 28px), 402px);
  max-height: min(56dvh, 460px);
  margin: 0 auto;
  display: grid;
  gap: 10px;
  min-height: 0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(24, 27, 31, 0.94);
  box-shadow: 0 18px 54px rgba(0, 0, 0, 0.46);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px;
  backdrop-filter: blur(18px);
  -webkit-overflow-scrolling: touch;
}

.settings-panel[hidden],
.about-panel[hidden] {
  display: none;
}

.about-panel h1,
.about-panel h2 {
  margin: 0;
  color: var(--text);
  letter-spacing: 0;
}

.about-panel h1 {
  font-size: 1.08rem;
}

.about-panel h2 {
  margin-top: 4px;
  font-size: 0.92rem;
}

.about-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.about-version {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  padding: 10px 12px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.about-version strong {
  color: var(--text);
}

.update-btn {
  width: 100%;
  border-color: rgba(90, 184, 255, 0.36);
  background: #1f2a34;
  color: var(--text);
}

.update-btn:disabled {
  opacity: 0.62;
}

.control-grid label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  min-width: 0;
  width: 100%;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--green);
}

.toggles {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
}

.switch {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #20242a;
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 800;
}

.switch span {
  min-width: 0;
  overflow: hidden;
  text-overflow: clip;
  white-space: nowrap;
}

@media (max-width: 380px) {
  .content-shell {
    padding-inline: 12px;
  }

  .control-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .toggles {
    grid-template-columns: minmax(0, 1fr);
  }
}

.switch input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.switch.disabled {
  opacity: 0.52;
}

.message {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.34;
}

@media (min-width: 760px) {
  body.detector-active {
    display: grid;
    place-items: center;
    overflow: auto;
    padding: 24px;
  }

  .app-shell {
    width: min(430px, 100%);
    height: min(900px, calc(100dvh - 48px));
    min-height: 0;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 24px 80px var(--shadow);
  }

  .stage {
    min-height: 0;
  }

  .settings-panel,
  .about-panel {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: min(402px, calc(100vw - 48px));
  }
}

@media (max-width: 640px) {
  .content-hero {
    grid-template-columns: minmax(0, 1fr);
  }

  .phone-preview {
    width: min(72vw, 260px);
    justify-self: center;
    min-height: 0;
  }
}

@media (max-height: 720px) {
  :root {
    --controls-height: 160px;
  }

  .control-grid label {
    gap: 3px;
    font-size: 0.76rem;
  }

  .settings-panel {
    bottom: calc(var(--controls-height) + 8px);
    max-height: min(50dvh, 300px);
    padding: 10px;
  }

  .about-panel {
    bottom: calc(var(--controls-height) + 8px);
    max-height: min(58dvh, 360px);
    padding: 10px;
  }

  .ad-slot {
    min-height: calc(42px + env(safe-area-inset-bottom));
    height: calc(42px + env(safe-area-inset-bottom));
  }

  .switch {
    min-height: 36px;
    font-size: 0.78rem;
  }

  button {
    min-height: 44px;
  }

  .primary-actions button {
    min-height: 46px;
    font-size: 0.82rem;
  }
}

@media (orientation: landscape) and (max-height: 540px) and (max-width: 960px) {
  :root {
    --controls-height: 176px;
  }

  html,
  body {
    width: 100dvw;
    height: 100dvh;
    overflow: hidden;
  }

  body {
    display: grid;
    place-items: center;
    padding: 0;
    background: #050608;
  }

  .app-shell {
    position: fixed;
    top: 50%;
    left: 50%;
    width: 100dvh;
    height: 100dvw;
    max-width: none;
    max-height: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    transform: translate(-50%, -50%) rotate(90deg);
    transform-origin: center;
  }

  .settings-panel,
  .about-panel {
    bottom: calc(var(--controls-height) + 10px);
    max-height: min(56dvh, 460px);
    padding: 12px;
  }

  .ad-slot {
    min-height: calc(46px + env(safe-area-inset-bottom));
    height: calc(clamp(46px, 7dvh, 64px) + env(safe-area-inset-bottom));
  }

  button {
    min-height: 44px;
  }

  .primary-actions button {
    font-size: 0.86rem;
  }
}

@media (orientation: landscape) and (max-height: 540px) and (max-width: 960px) {
  @supports not (width: 100dvh) {
    html,
    body {
      width: 100vw;
      height: 100vh;
    }

    .app-shell {
      width: 100vh;
      height: 100vw;
    }
  }
}
