@property --beam-angle {
  syntax: "<angle>";
  initial-value: 0deg;
  inherits: false;
}

:root {
  color-scheme: dark;
  --void: #03040a;
  --glass: rgba(11, 15, 28, 0.62);
  --glass-strong: rgba(15, 20, 38, 0.86);
  --border: rgba(255, 255, 255, 0.09);
  --border-hi: rgba(255, 255, 255, 0.22);
  --text: #f8fafc;
  --text-dim: #94a3b8;
  --text-mute: #64748b;
  --cyan: #38bdf8;
  --violet: #818cf8;
  --gold: #f5c97b;
  --up: #ff2e63;
  --up-glow: rgba(255, 46, 99, 0.45);
  --up-soft: rgba(255, 46, 99, 0.14);
  --down: #00f5a0;
  --down-glow: rgba(0, 245, 160, 0.4);
  --down-soft: rgba(0, 245, 160, 0.13);
  --flat: #cbd5e1;
  --grid: rgba(148, 163, 184, 0.075);
  --baseline: rgba(226, 232, 240, 0.24);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  overflow-x: hidden;
  background: var(--void);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Background layers */
#bg-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

.aurora-layer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.aurora-blob {
  position: absolute;
  border-radius: 999px;
  filter: blur(95px);
  opacity: 0.34;
  will-change: transform;
}

.aurora-a {
  width: 520px;
  height: 520px;
  top: -180px;
  left: -120px;
  background: radial-gradient(circle, rgba(56, 189, 248, 0.55) 0%, transparent 70%);
  animation: driftA 18s ease-in-out infinite alternate;
}

.aurora-b {
  width: 480px;
  height: 480px;
  top: -120px;
  right: -140px;
  background: radial-gradient(circle, rgba(255, 46, 99, 0.45) 0%, transparent 70%);
  animation: driftB 22s ease-in-out infinite alternate;
}

.aurora-c {
  width: 540px;
  height: 420px;
  bottom: -180px;
  left: 28%;
  background: radial-gradient(circle, rgba(0, 245, 160, 0.32) 0%, transparent 70%);
  animation: driftC 26s ease-in-out infinite alternate;
}

@keyframes driftA {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(90px, 60px) scale(1.16); }
}

@keyframes driftB {
  0% { transform: translate(0, 0) scale(1.05); }
  100% { transform: translate(-110px, 80px) scale(0.92); }
}

@keyframes driftC {
  0% { transform: translate(0, 0) scale(0.95); }
  100% { transform: translate(70px, -90px) scale(1.12); }
}

.scan-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.022) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(ellipse 85% 75% at 50% 30%, #000 35%, transparent 100%);
}

/* Main Shell */
.shell {
  position: relative;
  z-index: 2;
  max-width: 1020px;
  margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) 20px max(36px, env(safe-area-inset-bottom));
}

.mono,
.kpi-value,
.tab-chip,
.status-pill,
.stage-pill,
.hover-hud,
.chart-tooltip,
.axis-foot {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

/* Topbar */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px 18px;
  margin-bottom: 22px;
}

/* Sliding Account Tabs */
.tabs {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 4px;
  border-radius: 14px;
  background: var(--glass);
  border: 1px solid var(--border);
  backdrop-filter: blur(18px);
  box-shadow: 0 12px 32px -12px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.tab-glider {
  position: absolute;
  top: 4px;
  left: 0;
  height: calc(100% - 8px);
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.22), rgba(129, 140, 248, 0.18));
  border: 1px solid rgba(56, 189, 248, 0.42);
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.22);
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1), width 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
  z-index: 0;
}

.tab {
  position: relative;
  z-index: 1;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  min-height: 36px;
  padding: 6px 15px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: color 0.2s ease;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: #ffffff;
}

.tab-dot {
  width: 6.5px;
  height: 6.5px;
  border-radius: 999px;
  background: var(--text-mute);
  flex-shrink: 0;
}

.tab-dot[data-state="ready"] {
  background: var(--down);
  box-shadow: 0 0 10px var(--down);
}

.tab-chip {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-dim);
}

.tab-chip.up {
  background: var(--up-soft);
  color: #ff6b91;
}

.tab-chip.down {
  background: var(--down-soft);
  color: #4adeb8;
}

/* Status Pill */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--border);
  backdrop-filter: blur(14px);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.pulse-dot {
  position: relative;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--text-mute);
}

.status-pill[data-state="ready"] .pulse-dot {
  background: var(--down);
  box-shadow: 0 0 10px var(--down);
}

.status-pill[data-state="ready"] .pulse-dot::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 15px;
  height: 15px;
  border-radius: 999px;
  border: 1px solid var(--down);
  animation: radarPing 2.2s cubic-bezier(0, 0, 0.2, 1) infinite;
}

.status-pill[data-state="pending"] .pulse-dot {
  background: var(--gold);
  box-shadow: 0 0 10px rgba(245, 201, 123, 0.5);
}

.status-pill[data-state="error"] .pulse-dot {
  background: var(--up);
  box-shadow: 0 0 10px var(--up);
}

@keyframes radarPing {
  0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0.9; }
  100% { transform: translate(-50%, -50%) scale(1.45); opacity: 0; }
}

/* Kinetic 3D KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
  perspective: 1000px;
}

.kpi-card {
  position: relative;
  border-radius: 18px;
  padding: 20px 22px;
  background: var(--glass);
  border: 1px solid var(--border);
  backdrop-filter: blur(22px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  box-shadow: 0 18px 40px -20px rgba(0, 0, 0, 0.9), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transform-style: preserve-3d;
  transition: transform 0.22s ease, border-color 0.22s ease, box-shadow 0.22s ease;
}

.kpi-card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: conic-gradient(
    from var(--beam-angle),
    transparent 0deg,
    transparent 290deg,
    rgba(56, 189, 248, 0.45) 330deg,
    transparent 360deg
  );
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0;
  transition: opacity 0.25s ease;
  animation: rotateBeam 7s linear infinite;
  pointer-events: none;
}

.kpi-card:hover::after {
  opacity: 1;
}

.card-glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.7;
  transition: opacity 0.25s ease;
}

.kpi-card[data-tone="up"] .card-glow {
  background: radial-gradient(100% 90% at 100% 0%, rgba(255, 46, 99, 0.18) 0%, transparent 62%);
}

.kpi-card[data-tone="down"] .card-glow {
  background: radial-gradient(100% 90% at 100% 0%, rgba(0, 245, 160, 0.16) 0%, transparent 62%);
}

.kpi-label {
  position: relative;
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}

.kpi-value {
  position: relative;
  font-size: clamp(28px, 3.2vw, 38px);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.035em;
}

.up {
  color: #ff4778;
  text-shadow: 0 0 26px var(--up-glow);
}

.down {
  color: #16f5ad;
  text-shadow: 0 0 26px var(--down-glow);
}

.flat {
  color: var(--flat);
}

/* Holographic Chart Stage Card */
.stage-card {
  position: relative;
  border-radius: 22px;
  padding: 20px 22px 16px;
  background: var(--glass);
  border: 1px solid var(--border);
  backdrop-filter: blur(24px);
  box-shadow: 0 24px 60px -24px rgba(0, 0, 0, 0.95), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.stage-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: conic-gradient(
    from var(--beam-angle),
    transparent 0deg,
    transparent 265deg,
    rgba(56, 189, 248, 0.55) 315deg,
    rgba(0, 245, 160, 0.45) 345deg,
    transparent 360deg
  );
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0.65;
  animation: rotateBeam 10s linear infinite;
  pointer-events: none;
}

@keyframes rotateBeam {
  to { --beam-angle: 360deg; }
}

.stage-bar {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  margin-bottom: 14px;
}

.stage-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stage-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.stage-pill {
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
}

.stage-pill[data-tone="up"] {
  background: var(--up-soft);
  color: #ff6b91;
  border-color: rgba(255, 46, 99, 0.35);
  box-shadow: 0 0 18px rgba(255, 46, 99, 0.22);
}

.stage-pill[data-tone="down"] {
  background: var(--down-soft);
  color: #3df7ba;
  border-color: rgba(0, 245, 160, 0.35);
  box-shadow: 0 0 18px rgba(0, 245, 160, 0.2);
}

.stage-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.hover-hud {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  font-size: 12px;
  color: var(--text-dim);
}

.hud-date {
  color: #ffffff;
  font-weight: 700;
}

.hud-sep {
  color: var(--text-mute);
}

.hud-item b {
  font-weight: 700;
  text-shadow: none;
}

.period-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 3px;
  border-radius: 10px;
  background: rgba(3, 6, 16, 0.65);
  border: 1px solid var(--border);
}

.period-glider {
  position: absolute;
  top: 3px;
  left: 0;
  height: calc(100% - 6px);
  border-radius: 7px;
  background: rgba(56, 189, 248, 0.2);
  border: 1px solid rgba(56, 189, 248, 0.45);
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.24);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), width 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}

.period-btn {
  position: relative;
  z-index: 1;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  padding: 4px 11px;
  border-radius: 7px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.16s ease;
}

.period-btn:hover:not(:disabled) {
  color: #ffffff;
}

.period-btn.active {
  color: #ffffff;
}

.period-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* SVG Stage */
.chart-stage {
  position: relative;
  width: 100%;
  height: 360px;
  border-radius: 16px;
  background:
    radial-gradient(85% 60% at 50% 0%, rgba(56, 189, 248, 0.06) 0%, transparent 70%),
    rgba(3, 5, 13, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.065);
  overflow: hidden;
}

#nav-chart {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  cursor: crosshair;
}

/* Neon Tooltip */
.chart-tooltip {
  position: absolute;
  top: 12px;
  left: 12px;
  pointer-events: none;
  min-width: 152px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--glass-strong);
  border: 1px solid rgba(56, 189, 248, 0.34);
  box-shadow: 0 14px 32px -10px rgba(0, 0, 0, 0.85), 0 0 24px rgba(56, 189, 248, 0.15);
  backdrop-filter: blur(14px);
  font-size: 11.5px;
  z-index: 5;
}

.chart-tooltip.hidden {
  display: none;
}

.tt-date {
  font-weight: 700;
  color: #ffffff;
  padding-bottom: 5px;
  margin-bottom: 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.tt-rows {
  display: flex;
  flex-direction: column;
  gap: 3.5px;
}

.tt-rows > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.tt-rows span {
  color: var(--text-mute);
}

.tt-rows strong {
  font-weight: 700;
  text-shadow: none;
}

/* Orbital Empty State */
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 20px;
}

.empty-state.hidden {
  display: none;
}

.orbital {
  position: relative;
  width: 82px;
  height: 82px;
  display: grid;
  place-items: center;
}

.orbit {
  position: absolute;
  border-radius: 999px;
  border: 1.5px solid transparent;
}

.orbit-1 {
  inset: 0;
  border-top-color: var(--cyan);
  border-right-color: rgba(56, 189, 248, 0.25);
  animation: spinOrbit 3.4s linear infinite;
}

.orbit-2 {
  inset: 13px;
  border-bottom-color: var(--down);
  border-left-color: rgba(0, 245, 160, 0.25);
  animation: spinOrbitReverse 2.4s linear infinite;
}

.orbit-core {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: radial-gradient(circle, #fff 0%, var(--cyan) 55%, transparent 100%);
  box-shadow: 0 0 22px var(--cyan), 0 0 40px rgba(0, 245, 160, 0.45);
  animation: coreBeat 2.2s ease-in-out infinite;
}

@keyframes spinOrbit {
  to { transform: rotate(360deg); }
}

@keyframes spinOrbitReverse {
  to { transform: rotate(-360deg); }
}

@keyframes coreBeat {
  0%, 100% { transform: scale(0.9); opacity: 0.75; }
  50% { transform: scale(1.18); opacity: 1; }
}

.empty-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.axis-foot {
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 11.5px;
  color: var(--text-mute);
}

button:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

/* Mobile Responsive */
@media (max-width: 780px) {
  .topbar {
    gap: 12px;
  }

  .stage-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .stage-controls {
    width: 100%;
    justify-content: space-between;
  }
}

@media (max-width: 580px) {
  .shell {
    padding: max(18px, env(safe-area-inset-top)) 14px max(24px, env(safe-area-inset-bottom));
  }

  .topbar {
    gap: 10px;
    margin-bottom: 14px;
  }

  .status-pill {
    margin-left: auto;
  }

  .tabs {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tab {
    justify-content: center;
    padding: 6px 8px;
    font-size: 13px;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 12px;
  }

  .kpi-card {
    padding: 14px 15px;
    border-radius: 15px;
  }

  .kpi-card:last-child {
    grid-column: 1 / -1;
  }

  .kpi-value {
    font-size: 26px;
  }

  .stage-card {
    padding: 14px 14px 12px;
    border-radius: 18px;
  }

  .stage-controls {
    flex-direction: column-reverse;
    align-items: flex-start;
    gap: 8px;
  }

  .hover-hud {
    font-size: 11px;
  }

  .chart-stage {
    height: 256px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .aurora-blob,
  .status-pill[data-state="ready"] .pulse-dot::after,
  .kpi-card::after,
  .stage-card::before,
  .orbit-1,
  .orbit-2,
  .orbit-core {
    animation: none !important;
  }
}
