:root {
  color-scheme: dark;
  --ink: #f6f1df;
  --muted: #aeb5ad;
  --subtle: #6f7c75;
  --panel: rgba(12, 14, 14, 0.78);
  --panel-strong: rgba(8, 9, 9, 0.9);
  --line: rgba(246, 241, 223, 0.14);
  --line-strong: rgba(246, 241, 223, 0.28);
  --accent: #3ff0c5;
  --accent-2: #ffb545;
  --accent-3: #ff5d8f;
  --good: #65e087;
  --warn: #ffcc66;
  --bad: #ff6b6b;
  --surface-radius: 8px;
  --control-h: 38px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #080909;
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button {
  color: var(--ink);
}

.app-shell {
  position: fixed;
  inset: 0;
  overflow: hidden;
  isolation: isolate;
}

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background:
    radial-gradient(circle at 50% 55%, rgba(63, 240, 197, 0.11), transparent 26rem),
    linear-gradient(180deg, #0a0c0b 0%, #11110f 58%, #10100d 100%);
  touch-action: none;
}

.glass {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(16px) saturate(140%);
}

.topbar {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  height: 58px;
  border-radius: var(--surface-radius);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 12px;
  z-index: 4;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 160px;
}

.brand strong {
  display: block;
  font-size: 15px;
}

.brand span,
.hud-label,
.clock,
.selected-card span,
label span,
legend {
  color: var(--muted);
}

.brand-mark {
  width: 34px;
  height: 34px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  position: relative;
  flex: 0 0 34px;
}

.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 50%;
  border: 2px solid var(--accent-2);
}

.brand-mark::after {
  inset: 14px;
  background: var(--ink);
  border: 0;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.status-pill {
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  color: var(--muted);
  white-space: nowrap;
}

.status-pill.good {
  color: var(--good);
  border-color: rgba(101, 224, 135, 0.42);
}

.status-pill.warn {
  color: var(--warn);
  border-color: rgba(255, 204, 102, 0.42);
}

.status-pill.bad {
  color: var(--bad);
  border-color: rgba(255, 107, 107, 0.42);
}

.panel {
  position: absolute;
  top: 86px;
  bottom: 104px;
  width: min(360px, calc(100vw - 28px));
  border-radius: var(--surface-radius);
  padding: 14px;
  z-index: 3;
  overflow: auto;
  scrollbar-width: thin;
}

.left-panel {
  left: max(14px, env(safe-area-inset-left));
}

.right-panel {
  right: max(14px, env(safe-area-inset-right));
}

.panel-header {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

h1,
h2 {
  margin: 0;
  font-size: 16px;
  line-height: 1.2;
}

.icon-button,
.command-button,
.segmented button {
  min-height: var(--control-h);
  border-radius: 7px;
  border: 1px solid var(--line);
  background: rgba(246, 241, 223, 0.06);
  cursor: pointer;
}

.icon-button {
  width: var(--control-h);
  min-width: var(--control-h);
  display: inline-grid;
  place-items: center;
}

.command-button {
  padding: 0 10px;
  font-weight: 650;
}

.command-button.primary,
.segmented button.active {
  background: rgba(63, 240, 197, 0.18);
  border-color: rgba(63, 240, 197, 0.62);
  color: #dffff7;
}

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

.control-group {
  border: 1px solid var(--line);
  border-radius: var(--surface-radius);
  margin: 12px 0 0;
  padding: 12px;
}

legend {
  padding: 0 6px;
  font-size: 12px;
  text-transform: uppercase;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.segmented button {
  min-width: 0;
  padding: 0 6px;
  font-size: 12px;
}

.compact-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

label {
  display: grid;
  gap: 5px;
  min-width: 0;
}

input,
select {
  width: 100%;
  min-height: var(--control-h);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.22);
  color: var(--ink);
  outline: 0;
}

input:focus,
select:focus,
button:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(63, 240, 197, 0.16);
}

.toggle-list,
.layer-list {
  display: grid;
  gap: 7px;
}

.toggle-row,
.layer-row,
.track-row,
.event-pill,
.metric-row {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(246, 241, 223, 0.045);
}

.toggle-row,
.layer-row,
.metric-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 36px;
  padding: 7px 9px;
}

.toggle-row input,
.layer-row input {
  width: 18px;
  height: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.layer-row small,
.track-row small {
  color: var(--subtle);
}

.api-key-panel {
  margin-top: 12px;
  color: var(--muted);
}

.api-key-panel summary {
  cursor: pointer;
}

.selected-card,
.inference-card {
  border: 1px solid var(--line);
  border-radius: var(--surface-radius);
  padding: 12px;
  background: rgba(246, 241, 223, 0.055);
  margin-bottom: 10px;
}

.selected-card strong {
  display: block;
  margin-bottom: 6px;
}

.object-list {
  display: grid;
  gap: 8px;
}

.track-row {
  width: 100%;
  min-height: 58px;
  padding: 9px;
  color: var(--ink);
  text-align: left;
}

.track-row.active {
  border-color: rgba(63, 240, 197, 0.72);
  background: rgba(63, 240, 197, 0.12);
}

.track-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.track-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  flex: 0 0 auto;
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  background: rgba(255, 181, 69, 0.16);
  color: #ffd99a;
  font-size: 12px;
}

.bottom-hud {
  position: absolute;
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  min-height: 74px;
  border-radius: var(--surface-radius);
  z-index: 4;
  display: grid;
  grid-template-columns: minmax(160px, 280px) 1fr minmax(130px, 200px);
  gap: 12px;
  align-items: center;
  padding: 12px;
}

.hud-column {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.hud-column.right {
  text-align: right;
}

.hud-column strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-rail {
  display: flex;
  gap: 8px;
  overflow: hidden;
  min-width: 0;
}

.event-pill {
  min-width: min(240px, 42vw);
  max-width: 280px;
  padding: 8px 10px;
}

.event-pill strong,
.event-pill span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-pill span {
  color: var(--muted);
  font-size: 12px;
}

.reticle {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 2;
}

.reticle span {
  width: 42px;
  height: 42px;
  border: 1px solid rgba(246, 241, 223, 0.58);
  border-radius: 50%;
  position: relative;
}

.reticle span::before,
.reticle span::after {
  content: "";
  position: absolute;
  background: rgba(246, 241, 223, 0.62);
}

.reticle span::before {
  width: 20px;
  height: 1px;
  left: 10px;
  top: 20px;
}

.reticle span::after {
  width: 1px;
  height: 20px;
  left: 20px;
  top: 10px;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 104px;
  transform: translateX(-50%) translateY(12px);
  max-width: min(560px, calc(100vw - 28px));
  min-height: 42px;
  border-radius: var(--surface-radius);
  padding: 11px 14px;
  background: var(--panel-strong);
  border: 1px solid var(--line-strong);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 6;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 1100px) {
  .right-panel {
    width: min(320px, calc(100vw - 28px));
  }

  .left-panel {
    width: min(330px, calc(100vw - 28px));
  }
}

@media (max-width: 820px) {
  body {
    overflow: auto;
  }

  .app-shell {
    position: relative;
    min-height: 100dvh;
    overflow: visible;
  }

  #scene {
    position: fixed;
  }

  .topbar,
  .panel,
  .bottom-hud {
    position: relative;
    left: auto;
    right: auto;
    top: auto;
    bottom: auto;
    width: calc(100vw - 24px);
    margin: 12px;
  }

  .topbar {
    height: auto;
    min-height: 58px;
    align-items: flex-start;
    flex-direction: column;
  }

  .status-strip {
    justify-content: flex-start;
  }

  .panel {
    max-height: none;
  }

  .bottom-hud {
    grid-template-columns: 1fr;
  }

  .hud-column.right {
    text-align: left;
  }

  .event-rail {
    overflow-x: auto;
    padding-bottom: 2px;
  }
}

@media (max-width: 460px) {
  .button-grid,
  .compact-grid {
    grid-template-columns: 1fr 1fr;
  }

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

  .status-pill {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
