:root {
  --ink: #061018;
  --bg: #05090c;
  --bg-mid: #07151c;
  --panel: #101c24;
  --panel-2: #17303a;
  --cyan: #2ee6c5;
  --cyan-dim: #1a8f7c;
  --text: #e8f4f1;
  --muted: #9bb2ac;
  --chart: #000000;
  --cursor-a: #ff6b6b;
  --cursor-b: #ffd166;
  --error: #ff8a80;
  --line: rgba(72, 224, 200, 0.22);
  --radius: 22px;
  --safe-t: env(safe-area-inset-top);
  --safe-b: env(safe-area-inset-bottom);
  --safe-l: env(safe-area-inset-left);
  --safe-r: env(safe-area-inset-right);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Manrope, "Segoe UI", sans-serif;
}

body {
  min-height: 100dvh;
  overflow: hidden;
}

h1,
h2,
p {
  margin: 0;
}

.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
  background:
    radial-gradient(1200px 700px at 12% -10%, rgba(46, 230, 197, 0.08), transparent 55%),
    linear-gradient(180deg, #07151c 0%, #0b1f27 48%, #061018 100%);
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(48px);
  opacity: 0.28;
  animation: drift 28s ease-in-out infinite;
}

.orb-a {
  width: 280px;
  height: 280px;
  left: -80px;
  top: 12%;
  background: #1a8f7c;
}

.orb-b {
  width: 340px;
  height: 340px;
  right: -120px;
  bottom: 8%;
  background: #0d4d5c;
  animation-delay: -12s;
}

.app {
  position: relative;
  z-index: 1;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: calc(12px + var(--safe-t)) calc(14px + var(--safe-r)) calc(10px + var(--safe-b)) calc(14px + var(--safe-l));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 0 6px rgba(46, 230, 197, 0.08);
  animation: pulse 6.5s ease-in-out infinite;
  flex-shrink: 0;
}

.brand h1 {
  font-size: clamp(18px, 4vw, 22px);
  font-weight: 650;
  letter-spacing: -0.02em;
}

.brand p {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(58vw, 420px);
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 14px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, filter 0.2s ease, background 0.2s ease;
}

.btn.primary {
  background: var(--cyan);
  color: var(--ink);
}

.btn.ghost {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
}

.empty-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.btn:hover {
  filter: brightness(1.06);
}

.btn:active {
  transform: scale(0.98);
}

.info-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px;
  display: grid;
  gap: 10px;
}

.info-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 8px;
}

.topbar .bresler {
  display: none;
}

.bresler {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  padding-right: 4px;
}

.industry-icons {
  display: flex;
  align-items: center;
  gap: 10px;
}

.industry-icon {
  width: 28px;
  height: 28px;
  color: #f4f7f6;
  opacity: 0.4;
  transform-origin: center;
  animation: iconPulse 10s ease-in-out infinite;
  animation-delay: calc(var(--i, 0) * 3.33s);
}

.bresler-word {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1;
  background-image: linear-gradient(
    110deg,
    #f4f7f6 0%,
    #f4f7f6 38%,
    #2ee6c5 48%,
    #fff6d2 52%,
    #f4f7f6 62%,
    #f4f7f6 100%
  );
  background-size: 260% 100%;
  background-position: 100% 50%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: logoShine 16s ease-in-out infinite;
}

.chip,
.measure {
  background: var(--panel-2);
  border-radius: 14px;
  padding: 8px 10px;
}

.chip {
  min-width: 132px;
  width: max-content;
}

.chip span,
.measure p,
.measure span,
.fault-value span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.chip strong,
.measure strong {
  display: block;
  margin-top: 2px;
  font-size: 15px;
  font-weight: 600;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
}

.measure-head,
.measure-row,
.fault {
  display: flex;
  align-items: center;
}

.measure-head {
  justify-content: space-between;
  margin-bottom: 6px;
}

.measure-row {
  flex-wrap: wrap;
  gap: 8px 12px;
}

.measure-row strong {
  margin: 0;
  font-size: 13px;
}

.measure-row .delta,
.fault-value strong {
  margin-left: auto;
  color: var(--cyan);
  font-size: 18px;
}

.fault {
  justify-content: space-between;
  gap: 12px;
}

.fault-value {
  text-align: right;
}

.badge {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: #000000;
  flex-shrink: 0;
}

.badge svg {
  display: block;
  width: 24px;
  height: 24px;
}

.badge.a { background: var(--cursor-a); }
.badge.b { background: var(--cursor-b); }

.signal-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
}

.channels {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
  flex: 1 1 auto;
  min-width: 0;
}

.overlay-toggles {
  display: flex;
  gap: 12px;
  flex-shrink: 0;
}

.overlay-check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.overlay-check:has(input:checked) {
  color: var(--text);
}

.overlay-check input {
  appearance: none;
  width: 16px;
  height: 16px;
  margin: 0;
  border-radius: 4px;
  border: 1.5px solid color-mix(in srgb, var(--cyan) 45%, var(--muted));
  background: var(--panel-2);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.overlay-check input:checked {
  background: var(--cyan);
  border-color: var(--cyan);
}

.overlay-check input:checked::after {
  content: "";
  width: 8px;
  height: 5px;
  border: solid #061018;
  border-width: 0 0 2px 2px;
  transform: rotate(-45deg) translate(0, -1px);
}

.channel-chip {
  border: 0;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  padding: 8px 12px;
  font: inherit;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.channel-chip.on {
  color: var(--text);
  background: color-mix(in srgb, var(--ch, var(--cyan)) 28%, var(--panel-2));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ch, var(--cyan)) 55%, transparent);
}

.channel-chip.imax {
  font-weight: 700;
}

.channel-chip:active {
  transform: scale(0.98);
}

.chart-stage {
  position: relative;
  flex: 1;
  min-height: 240px;
  background: var(--chart);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid rgba(46, 230, 197, 0.16);
  animation: borderBreath 14s ease-in-out infinite;
  touch-action: none;
}

.chart-stage.drop {
  border-color: rgba(46, 230, 197, 0.7);
  box-shadow: inset 0 0 0 1px rgba(46, 230, 197, 0.25);
}

.chart-stage canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: #000;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #000;
}

.empty-inner {
  max-width: 440px;
  text-align: center;
}

.empty-inner h2 {
  font-size: 20px;
  font-weight: 650;
  margin-bottom: 8px;
}

.empty-inner p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
  margin-bottom: 16px;
}

.empty-pulse {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  border-radius: 50%;
  border: 2px solid rgba(46, 230, 197, 0.35);
  position: relative;
}

.empty-pulse::after {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  background: rgba(46, 230, 197, 0.18);
  animation: pulse 5.5s ease-in-out infinite;
}

.error {
  color: var(--error) !important;
}

.chart-hud {
  position: absolute;
  inset: 8px 8px auto 8px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
}

.chart-hud[hidden],
.hint[hidden],
.signal-bar[hidden],
.channels[hidden],
.chart-empty[hidden] {
  display: none !important;
}

.hud-buttons {
  display: flex;
  gap: 8px;
  margin-left: auto;
  pointer-events: auto;
}

.icon-btn,
.xf-pill {
  background: rgba(16, 28, 36, 0.82);
  color: var(--cyan);
  border: 0;
  border-radius: 999px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  cursor: pointer;
  pointer-events: auto;
  transition: background 0.2s ease, transform 0.2s ease;
}

.icon-btn svg[hidden] {
  display: none !important;
}

.icon-btn:hover {
  background: rgba(23, 48, 58, 0.92);
}

.xf-pill {
  padding: 8px 12px;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-weight: 650;
  font-size: 16px;
}

.hint {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 8px;
  margin: 0;
  color: rgba(155, 178, 172, 0.72);
  font-size: 11px;
  text-align: center;
  pointer-events: none;
}

.app.fullscreen .topbar,
.app.fullscreen .info-card,
.app.fullscreen .signal-bar,
.app.fullscreen .channels,
.app.fullscreen .hint {
  display: none;
}

.app.fullscreen {
  position: fixed;
  inset: 0;
  height: 100dvh;
  width: 100dvw;
  padding: 0;
  gap: 0;
  z-index: 8;
}

.app.fullscreen .chart-stage {
  border-radius: 0;
  min-height: 0;
  height: 100%;
  flex: 1;
}

.app.fullscreen #xfPill {
  display: block;
}

.app.force-landscape {
  top: 0;
  left: 100vw;
  width: 100dvh;
  height: 100dvw;
  transform: rotate(90deg);
  transform-origin: top left;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe-b));
  transform: translateX(-50%);
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  z-index: 5;
  animation: fadeUp 0.28s ease;
}

@keyframes drift {
  0%, 100% { transform: translate3d(0, 0, 0); }
  50% { transform: translate3d(24px, -18px, 0); }
}

@keyframes pulse {
  0%, 100% { opacity: 0.55; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.08); }
}

@keyframes borderBreath {
  0%, 100% { border-color: rgba(46, 230, 197, 0.12); }
  50% { border-color: rgba(46, 230, 197, 0.28); }
}

@keyframes fadeUp {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes logoShine {
  0%, 72%, 100% { background-position: 100% 50%; }
  80%, 88% { background-position: 0% 50%; }
}

@keyframes iconPulse {
  0%, 8%, 100% {
    opacity: 0.38;
    transform: scale(1);
  }
  4% {
    opacity: 1;
    transform: scale(1.14);
  }
}

@media (min-width: 761px) {
  .info-top .bresler {
    display: flex;
  }
}

@media (max-width: 760px) {
  body { overflow: auto; }
  .app { min-height: 100dvh; height: auto; gap: 8px; padding: calc(8px + var(--safe-t)) 10px calc(8px + var(--safe-b)); }
  .topbar {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "mark mark"
      "brand actions";
    align-items: center;
    gap: 8px 10px;
  }
  .topbar .bresler {
    display: flex;
    grid-area: mark;
    justify-self: end;
  }
  .info-top .bresler {
    display: none;
  }
  .topbar .brand { grid-area: brand; }
  .topbar .top-actions { grid-area: actions; }
  .bresler-word { font-size: 20px; }
  .industry-icon { width: 22px; height: 22px; }
  .info-top { justify-content: flex-start; }
  .chips { width: 100%; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .chip { min-width: 0; width: auto; }
  .chart-stage { min-height: 48vh; height: 56vh; }
  .info-card { padding: 10px; }
  .chip strong { font-size: 13px; }
  .measure-row .delta,
  .fault-value strong { font-size: 16px; }
  .brand p { max-width: 46vw; }
  .hint { display: none; }
  .btn { padding: 10px 12px; }
}

@media (max-width: 760px) and (orientation: landscape) {
  .info-card { display: none; }
  .chart-stage { height: calc(100dvh - 118px); min-height: 220px; }
}

@media (prefers-reduced-motion: reduce) {
  .orb,
  .brand-mark,
  .empty-pulse::after,
  .chart-stage,
  .toast,
  .bresler-word,
  .industry-icon {
    animation: none;
  }

  .bresler-word {
    color: #f4f7f6;
    background: none;
  }

  .industry-icon {
    opacity: 0.85;
    transform: none;
  }
}
