:root {
  --bg: #090b0e;
  --bg-elev: #12161c;
  --bg-panel: #171c23;
  --line: #2a323c;
  --text: #eceff3;
  --muted: #8b939e;
  --accent: #e31937;
  --accent-2: #3d8bfd;
  --ok: #3dd68c;
  --warn: #f5c242;
  --hud-bg: rgba(255, 255, 255, 0.28);
  --hud-ink: #2c2c2c;
  --hud-faint: #c8c8c8;
  --hud-chip: rgba(255, 255, 255, 0.22);
  --hud-line: rgba(255, 255, 255, 0.28);
  --radius: 14px;
  --font: "SF Pro Text", "Segoe UI", "PingFang SC", "Hiragino Sans GB", sans-serif;
}

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

html, body, .app {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

button, select, input { font-family: inherit; }

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(9, 11, 14, 0.92);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  object-fit: cover;
  box-shadow: 0 0 16px rgba(227, 25, 55, 0.45);
}
.brand h1 { font-size: 16px; letter-spacing: 0.04em; font-weight: 700; }
.brand p { font-size: 11px; color: var(--muted); margin-top: 1px; }

.topbar-meta {
  flex: 1;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.topbar-actions { display: flex; gap: 8px; }

.btn {
  height: 34px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
}
.btn:hover { border-color: #44505e; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}
.btn-primary:hover { filter: brightness(1.08); }

.layout {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.gallery,
.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.app.is-detail .gallery,
.app:not(.is-detail) .stage { display: none; }

.gallery { background: var(--bg); }
.stage { background: #000; }

.drop {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4;
  background:
    radial-gradient(ellipse at center, rgba(227, 25, 55, 0.12), transparent 55%),
    #0c0f13;
}
.drop.hidden { display: none; }
.drop.dragover { background: #151018; }

.drop-card {
  width: min(560px, calc(100% - 48px));
  padding: 36px 32px;
  border: 1px dashed #3a4450;
  border-radius: 20px;
  text-align: center;
  background: rgba(18, 22, 28, 0.7);
}
.drop.dragover .drop-card { border-color: var(--accent); }
.drop-icon { width: 48px; height: 48px; margin: 0 auto 14px; color: var(--muted); }
.drop-card h2 { font-size: 20px; font-weight: 650; margin-bottom: 10px; }
.drop-card p { color: var(--muted); font-size: 13px; line-height: 1.6; }
.drop-note { margin-top: 12px; font-size: 12px !important; }

.stage-view {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  container-type: size;
  display: grid;
  place-items: center;
  background: #000;
}
.cam-grid[hidden] { display: none; }

.cam {
  position: relative;
  overflow: hidden;
  background: #000;
  min-width: 0;
  min-height: 0;
}
.cam video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  background: #000;
}
.cam-label {
  position: absolute;
  top: 8px;
  right: 8px;
  left: auto;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 11px;
  letter-spacing: 0.04em;
  pointer-events: none;
}
.cam.empty::after {
  content: attr(data-label);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #4a5360;
  font-size: 13px;
}
.cam.active { outline: 1px solid rgba(227, 25, 55, 0.7); }

.grid-1 { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
.grid-2 {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
}
.grid-4 {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
}
.grid-4 .cam-front { grid-column: 1; grid-row: 1; }
.grid-4 .cam-back { grid-column: 2; grid-row: 1; }
.grid-4 .cam-left_repeater { grid-column: 1; grid-row: 2; }
.grid-4 .cam-right_repeater { grid-column: 2; grid-row: 2; }
.grid-6 {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
}
.grid-6 .cam-left_pillar { grid-column: 1; grid-row: 1; }
.grid-6 .cam-front { grid-column: 2; grid-row: 1; }
.grid-6 .cam-right_pillar { grid-column: 3; grid-row: 1; }
.grid-6 .cam-left_repeater { grid-column: 1; grid-row: 2; }
.grid-6 .cam-back { grid-column: 2; grid-row: 2; }
.grid-6 .cam-right_repeater { grid-column: 3; grid-row: 2; }

.cam-grid {
  --grid-ar: 1.333333;
  width: min(100cqw, calc(100cqh * var(--grid-ar)));
  height: min(100cqh, calc(100cqw / var(--grid-ar)));
  min-width: 0;
  min-height: 0;
  display: grid;
  gap: 0;
  padding: 0;
  background: #000;
  overflow: hidden;
}
.cam { cursor: pointer; }
.cam-grid.focus {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: row;
  align-items: stretch;
}
.cam-grid.focus .cam.focused {
  flex: 1;
  min-width: 0;
  min-height: 0;
  cursor: pointer;
}
.cam-grid.focus .cam-thumbs {
  flex: 0 0 auto;
  height: 100%;
  width: auto;
  aspect-ratio: calc(var(--thumb-ar, 1.333) / var(--thumb-slots, 4));
  max-width: 45%;
  min-width: 132px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.cam-grid.focus .cam-thumbs .cam,
.cam-grid.focus .cam-thumbs .cam-quad {
  position: relative;
  width: 100%;
  flex: 1 1 0;
  min-height: 0;
  height: auto;
}
.cam-grid.focus .cam-thumbs .cam video,
.cam-grid.focus .cam-thumbs .cam-quad canvas {
  object-fit: contain;
}
.cam-grid.focus .cam-thumbs .cam-quad {
  cursor: pointer;
  background: #000;
}
.cam-grid.focus .cam-thumbs .cam-quad canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.cam-grid.focus .cam.empty { display: none; }
.stage-view.is-focus .hud {
  top: 12px;
  left: calc((100% - min(45%, max(132px, 100cqh * var(--thumb-ar, 1.333) / var(--thumb-slots, 4)))) / 2);
  transform: translate(-50%, 0);
}
.hud {
  --hud-bg: rgba(255, 255, 255, 0.28);
  --hud-ink: #2c2c2c;
  --hud-chip: rgba(255, 255, 255, 0.22);
  --hud-line: rgba(255, 255, 255, 0.28);
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 228px;
  height: 148px;
  border-radius: 22px;
  background: var(--hud-bg);
  backdrop-filter: blur(22px) saturate(1.4);
  -webkit-backdrop-filter: blur(22px) saturate(1.4);
  border: 1px solid var(--hud-line);
  box-shadow: 0 10px 36px rgba(0, 0, 0, 0.28);
  z-index: 5;
  pointer-events: none;
}
.hud.dark {
  --hud-bg: rgba(22, 24, 28, 0.22);
  --hud-ink: #f3f4f6;
  --hud-chip: rgba(255, 255, 255, 0.1);
  --hud-line: rgba(255, 255, 255, 0.14);
}
.hud[hidden] { display: none; }

.hud-gear,
.hud-steer,
.hud-pedal {
  position: absolute;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--hud-chip);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
  color: var(--hud-ink);
  display: flex;
  align-items: center;
  justify-content: center;
}
.hud-gear,
.hud-steer {
  top: 12px;
  font-weight: 700;
  font-size: 16px;
}
.hud-gear { left: 14px; }
.hud-steer { right: 14px; }
.hud-steer img {
  width: 22px;
  height: 22px;
  object-fit: contain;
  transform-origin: 50% 50%;
  display: block;
}

.hud-speed {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--hud-ink);
}
.hud-speed-value {
  font-size: 58px;
  font-weight: 720;
  line-height: 0.9;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}
.hud-speed-unit {
  pointer-events: auto;
  margin-top: 4px;
  border: 0;
  background: none;
  color: var(--hud-ink);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  cursor: pointer;
}
.hud-ap {
  height: 14px;
  margin-top: 2px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #3d8bfd;
  opacity: 0;
}
.hud.ap .hud-ap { opacity: 1; }
.hud.dark .hud-ap { color: #6eb3ff; }

.hud-pedal {
  --travel: 0;
  bottom: 12px;
  overflow: hidden;
}
.hud-pedal.brake { left: 14px; }
.hud-pedal.accel { right: 14px; }
.hud-pedal .pedal-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  pointer-events: none;
  z-index: 0;
}
.hud-pedal.brake .pedal-fill {
  inset: 0;
  border-radius: 50%;
  background: #e31937;
  opacity: var(--travel);
}
.hud-pedal.accel .pedal-fill {
  height: var(--fill, 0%);
  background: #7dcc96;
  border-radius: 0;
}
.hud-pedal img {
  position: relative;
  z-index: 1;
  display: block;
  object-fit: contain;
  pointer-events: none;
}
.hud-pedal.brake img {
  width: 24px;
  height: 18px;
}
.hud-pedal.accel img {
  width: 13px;
  height: 24px;
}

.hud-blinker {
  position: absolute;
  top: 50%;
  width: 0;
  height: 0;
  border-style: solid;
  opacity: 0.18;
  transform: translateY(-50%);
}
.hud-blinker.left {
  left: 52px;
  border-width: 7px 10px 7px 0;
  border-color: transparent var(--hud-ink) transparent transparent;
}
.hud-blinker.right {
  right: 52px;
  border-width: 7px 0 7px 10px;
  border-color: transparent transparent transparent var(--hud-ink);
}
.hud-blinker.on { opacity: 1; animation: blink 0.7s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0.15; } }

.hud.ap .hud-steer { background: var(--accent-2); color: #fff; }
.hud.dark .hud-steer img,
.hud.ap .hud-steer img { filter: invert(1); }

.transport {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  height: 64px;
  padding: 0 14px 6px;
  background: linear-gradient(180deg, transparent, #0a0c10 28%);
  z-index: 3;
}
.transport[hidden] { display: none; }

.play-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.play-btn svg { width: 16px; height: 16px; fill: currentColor; }

.time {
  width: 108px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.timeline { flex: 1; position: relative; height: 40px; }
.timeline canvas {
  position: absolute;
  left: 0;
  right: 0;
  top: 15px;
  width: 100%;
  height: 10px;
  border-radius: 2px;
  pointer-events: none;
}
.timeline input[type="range"] {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  width: 100%;
  appearance: none;
  background: transparent;
  height: 40px;
  cursor: pointer;
  outline: none;
}
.timeline input[type="range"]:focus,
.timeline input[type="range"]:focus-visible {
  outline: none;
  box-shadow: none;
}
.timeline input[type="range"]::-moz-focus-outer { border: 0; }
.timeline input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: #3a4450;
  border-radius: 2px;
}
.timeline input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border-radius: 50%;
  background: #fff;
  cursor: grab;
}
.timeline input[type="range"]:active::-webkit-slider-thumb { cursor: grabbing; }

.rate select {
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  padding: 0 8px;
}

.gallery-page {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 22px 24px 36px;
}
.gallery-head { margin-bottom: 18px; }
.gallery-head h3 {
  font-size: 22px;
  font-weight: 650;
  color: var(--text);
}
.clip-summary {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin-top: 6px;
}
.clip-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.data-float {
  position: absolute;
  left: 12px;
  top: 12px;
  width: 168px;
  max-height: calc(100% - 24px);
  overflow: auto;
  z-index: 6;
  padding: 10px;
  border-radius: 16px;
  background: rgba(12, 16, 22, 0.28);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
}
.data-float h3,
.gauges h3 {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}
.gear-rail {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 36px;
  padding: 0 14px;
  margin-bottom: 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.42);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.gear-rail span {
  font-size: 15px;
  font-weight: 700;
  color: #4a4f57;
  letter-spacing: 0.06em;
}
.gear-rail span.on { color: #fff; }
.gallery-card {
  display: block;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #161b22;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.gallery-card:hover { border-color: #3d4754; background: #1a2028; }
.gallery-card.active { border-color: #3d8bfd; }
.gallery-thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  overflow: hidden;
  background: #0c1016;
}
.gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.gallery-badges {
  position: absolute;
  left: 8px;
  top: 8px;
  display: flex;
  gap: 6px;
  align-items: center;
}
.gallery-kind,
.gallery-dur,
.gallery-cams,
.gallery-tags span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  line-height: 1;
}
.gallery-kind svg { width: 12px; height: 12px; }
.gallery-kind.saved { background: #2d6a4a; color: #fff; }
.gallery-kind.sentry { background: #8a5a12; color: #fff; }
.gallery-kind.recent { background: #2a3340; color: #d5dde6; }
.gallery-dur { background: rgba(12, 16, 22, 0.72); color: #fff; }
.gallery-go {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(12, 16, 22, 0.7);
  color: #fff;
  display: grid;
  place-items: center;
}
.gallery-go svg { width: 14px; height: 14px; }
.gallery-body { padding: 10px 4px 2px; }
.gallery-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.gallery-title strong {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gallery-cams { background: #242b34; color: #c5cdd6; flex-shrink: 0; }
.gallery-date {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}
.gallery-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
  font-size: 12px;
  color: var(--muted);
}
.gallery-meta svg { width: 13px; height: 13px; flex-shrink: 0; }
.gallery-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.gallery-tags span {
  background: #242b34;
  color: #c5cdd6;
  font-variant-numeric: tabular-nums;
}
.drop-card code {
  font-size: 11px;
  color: #c9d2dc;
}

.empty { color: var(--muted); font-size: 12px; line-height: 1.5; }

.meta-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}
.meta-item {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 2px 8px;
}
.meta-item .label { font-size: 11px; color: var(--muted); flex: 0 0 auto; }
.meta-item .value {
  font-size: 13px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  text-align: right;
  flex: 1 1 10ch;
  min-width: 10ch;
  overflow-wrap: anywhere;
  word-break: break-all;
}

.gauges {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}
.gauges canvas {
  width: 100%;
  height: auto;
  background: #0e1218;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.data-foot {
  font-size: 11px;
  color: var(--muted);
  margin-top: 12px;
}
.data-float .about {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.about-list {
  display: grid;
  gap: 6px;
}
.about-item {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 2px 8px;
  color: inherit;
  text-decoration: none;
}
.about-item .label {
  font-size: 11px;
  color: var(--muted);
  flex: 0 0 auto;
}
.about-item .value {
  font-size: 12px;
  font-weight: 650;
  text-align: right;
  flex: 1 1 8ch;
  min-width: 0;
  overflow-wrap: anywhere;
}
.about-item:hover .value {
  color: var(--accent-2);
}
.about-owner .value {
  text-align: left;
  font-weight: 500;
  letter-spacing: 0.04em;
}
.about-page {
  display: none;
}
.app:not(.is-detail) .about-page {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 28px;
  padding: 12px 16px 16px;
  pointer-events: none;
}
.app:not(.is-detail) .about-page .about-item {
  flex-wrap: nowrap;
  gap: 8px;
  pointer-events: auto;
}
.app:not(.is-detail) .about-page .about-item .value {
  text-align: left;
  flex: 0 0 auto;
}

@media (max-width: 960px) {
  .data-float { width: 152px; }
  .hud { transform: translate(-50%, -50%) scale(0.86); }
  .stage-view.is-focus .hud { transform: translate(-50%, 0) scale(0.86); }
}
