@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&display=swap');

:root {
  --bg-0: #0d0f12;
  --bg-1: #12151a;
  --bg-2: #1a1f27;
  --panel: #242424;
  --panel-2: #2b2b2b;
  --line: #333;
  --text: #e5e5e5;
  --muted: #9a9a9a;
  --accent: #bfbfbf;
  --accent-2: #a8a8a8;
  --danger: #c66060;
  --radius-xs: 2px;
  --radius-sm: 3px;
  --radius-md: 4px;
  --delta: #5ad1ff;
  --theta: #7b6dff;
  --alpha: #8cff8c;
  --beta: #ffcc5c;
  --gamma: #ff7bd9;
  --space-1: clamp(6px, 1.0vh, 10px);
  --space-2: clamp(8px, 1.3vh, 12px);
  --space-3: clamp(10px, 1.6vh, 14px);
  --space-4: clamp(12px, 2.0vh, 18px);
  --font-xs: clamp(9px, 1.0vh, 11px);
  --font-sm: clamp(10px, 1.2vh, 12px);
  --font-md: clamp(11px, 1.4vh, 13px);
  --font-lg: clamp(14px, 1.8vh, 17px);
  --logo-size: clamp(28px, 3.2vh, 34px);
  --bar-h: clamp(10px, 1.4vh, 14px);
}

* {
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  font-family: 'Space Grotesk', 'Avenir Next', 'Segoe UI', sans-serif;
  background: radial-gradient(circle at 10% 10%, #222 0%, #141414 55%, #0f0f0f 100%);
  color: var(--text);
  overflow: hidden;
}

body {
  display: flex;
  align-items: stretch;
  justify-content: stretch;
}

.splash {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.splash.is-hidden {
  display: none;
}

.splash-canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.splash-ui {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-align: center;
    color: #d9d9d9;
    padding: 28px 32px;
    background: rgba(0, 0, 0, 0.31);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
}

.splash-logo {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  background: #f08a24;
  color: #1b1104;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 28px;
  letter-spacing: 0.5px;
}

.splash-logo sup {
  font-size: 0.55em;
  line-height: 1;
  vertical-align: super;
}

.splash-title {
  font-size: 28px;
  font-weight: 600;
  color: #33d17a;
}

.splash-subtitle {
  max-width: 520px;
  font-size: var(--font-md);
  color: #b7b7b7;
  font-weight: 600;
}

.splash-ui #splashStart {
  min-width: 160px;
  padding: 10px 26px;
  border-radius: 10px;
  background: #f08a24;
  color: #1b1104;
  font-size: 16px;
  font-weight: 600;
  border: none;
  box-shadow: 0 10px 20px rgba(240, 138, 36, 0.35);
}

.splash-ui #splashStart:hover {
  background: #f59c3f;
}

.splash-canvas canvas {
  display: block;
}

.app {
  display: grid;
  grid-template-columns: 1fr 300px;
  width: 100vw;
  height: 100vh;
  gap: 0;
  min-height: 0;
}

.main {
  position: relative;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-height: 0;
  background-color: #0f1113;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  width: var(--logo-size);
  height: var(--logo-size);
  border-radius: var(--radius-sm);
  background: #f08a24;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font-weight: 700;
  font-size: 20px;
  color: #1b1104;
}

.logo sup {
  font-size: 0.6em;
  line-height: 1;
  vertical-align: super;
}

.title {
  font-size: var(--font-lg);
  font-weight: 600;
  letter-spacing: 0.2px;
}

.status {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--font-sm);
  color: var(--muted);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 6px rgba(255, 107, 107, 0.8);
}

.dot.ok {
  background: #3ee37b;
  box-shadow: 0 0 6px rgba(62, 227, 123, 0.8);
}

.controls {
  display: flex;
  gap: var(--space-1);
  flex-wrap: wrap;
}

.sidebar .controls {
  gap: 6px;
}

.sidebar .controls button,
.sidebar .controls select {
  flex: 1 1 auto;
}

button, select {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-family: inherit;
  font-size: var(--font-sm);
  padding: calc(var(--space-1) - 2px) var(--space-2);
  border-radius: var(--radius-xs);
  outline: none;
}

button.primary {
  background: #d6d6d6;
  color: #111;
  font-weight: 600;
  border: none;
}

button.ghost {
  background: transparent;
}

.canvas-wrap {
  flex: 1;
  background: #0f0f0f;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: var(--space-2);
  position: relative;
  overflow: hidden;
  min-height: 0;
  max-height: 90vh;
  display: flex;
}

.word-cloud {
  position: absolute;
  inset: var(--space-2);
  width: calc(100% - (var(--space-2) * 2));
  height: calc(100% - (var(--space-2) * 2));
  pointer-events: none;
  z-index: 1;
}

#plot {
  flex: 1;
  min-height: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
  z-index: 2;
}

.flash-overlay {
  position: absolute;
  inset: var(--space-2);
  background: #ffffff;
  opacity: 0;
  pointer-events: none;
  border-radius: var(--radius-md);
  transition: opacity 240ms ease-out;
  z-index: 3;
}

.flash-overlay.active {
  opacity: 1;
}

.uplot {
  font-family: 'Space Grotesk', 'Avenir Next', 'Segoe UI', sans-serif;
  background: transparent;
}

.uplot .u-legend {
  display: none !important;
}

.uplot .u-axis text {
  fill: #8f8f8f;
  font-size: 10px;
}

.uplot .u-axis line {
  stroke: #2f2f2f;
}

.uplot .u-grid line {
  stroke: #1c1c1c;
}

.canvas-wrap {
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 40px 40px;
}

.canvas-wrap.event-hidden {
  background-color: #0b0c0e;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
}

.canvas-wrap.event-hidden #plot {
  opacity: 0;
}

.canvas-overlay {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  display: flex;
  gap: var(--space-1);
  align-items: center;
  font-size: var(--font-sm);
  color: var(--muted);
  z-index: 2;
}

.badge {
  padding: 3px var(--space-1);
  border-radius: var(--radius-xs);
  border: 1px solid var(--line);
  background: #1f1f1f;
}

#rawCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.sidebar {
  padding: var(--space-2);
  background: #1b1b1b;
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: #3a3a3a transparent;
  overscroll-behavior: contain;
}

.sidebar::-webkit-scrollbar {
  width: 8px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
  background: #3a3a3a;
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: content-box;
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background: #505050;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: var(--space-1);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.panel-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.panel.is-collapsed .panel-body {
  display: none;
}

.icon-btn {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 12px;
  border-radius: var(--radius-xs);
}

.panel.is-collapsed .icon-btn {
  transform: rotate(90deg);
}

.status-row {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--font-sm);
  color: var(--muted);
}

.status-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  font-size: var(--font-xs);
}

.status-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.status-grid .label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.2px;
  font-size: 10px;
}

.status-grid .badge {
  justify-self: end;
}

.panel h3 {
  margin: 0;
  font-size: var(--font-sm);
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted);
}

.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-1);
  font-size: var(--font-md);
}

.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 36px;
  height: 18px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  background: #2a2d32;
  border: 1px solid var(--line);
  border-radius: var(--radius-xs);
  transition: background 0.18s ease, border-color 0.18s ease;
}

.slider::before {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  left: 2px;
  top: 1px;
  background: #b5b5b5;
  border-radius: var(--radius-xs);
  transition: transform 0.18s ease, background 0.18s ease;
}

.switch input:checked + .slider {
  background: #2f6f3b;
  border-color: #3a8a49;
}

.switch input:checked + .slider::before {
  transform: translateX(16px);
  background: #d8f1de;
}

.switch.small {
  width: 30px;
  height: 16px;
}

.switch.small .slider::before {
  width: 12px;
  height: 12px;
  top: 1px;
}

.switch.small input:checked + .slider::before {
  transform: translateX(13px);
}

.toggle input {
  width: 55px;
  height: 24px;
}

.legend {
  display: grid;
  gap: 4px;
  font-size: var(--font-xs);
  color: var(--muted);
}

.legend span {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend .swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.histogram {
  display: grid;
  gap: var(--space-1);
}

.histogram-row {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.band-label {
  min-width: 44px;
  font-size: var(--font-xs);
  color: var(--muted);
  letter-spacing: 0.2px;
}

.bar {
  flex: 1;
  height: var(--bar-h);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
  position: relative;
}

.bar > span {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 10%;
  border-radius: 8px;
  transition: width 120ms ease-out;
}

.histogram-row.disabled .bar > span {
  opacity: 0.2;
}

.histogram-row.disabled .band-label {
  opacity: 0.5;
}

.color-input,
.text-input {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--radius-xs);
  padding: 4px 6px;
  font-size: var(--font-sm);
  height: 24px;
  width: 60px;
}

.color-input {
  width: 54px;
  padding: 0;
}

.footer {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-left: none;
    border-top: 1px solid var(--line);
    flex-direction: row;
    flex-wrap: wrap;
    align-content: flex-start;
    overflow: hidden;
  }

  .panel {
    flex: 1 1 240px;
  }
}

@media (max-height: 980px) {
  .sidebar {
    gap: 10px;
  }

  .panel {
    padding: 8px;
    gap: 6px;
  }

  .legend {
    display: none;
  }

  .histogram {
    gap: 5px;
  }

  .bar {
    height: 12px;
  }

  .footer {
    display: none;
  }
}

@media (max-height: 820px) {
  .main {
    padding: var(--space-3);
    gap: var(--space-1);
  }

  .sidebar {
    padding: var(--space-2);
    gap: var(--space-1);
  }

  .panel {
    padding: var(--space-1);
    gap: var(--space-1);
  }

  .panel h3 {
    font-size: var(--font-xs);
  }

  .toggle {
    font-size: var(--font-sm);
  }

  .legend {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px 10px;
    font-size: 10px;
  }

  .bar {
    height: calc(var(--bar-h) - 1px);
  }
}

@media (max-height: 700px) {
  .top-bar {
    flex-wrap: wrap;
  }

  .controls {
    flex-wrap: wrap;
  }

  .legend {
    display: none;
  }

  .footer {
    display: none;
  }
}

#defaultCanvas0{
    opacity: 0.60;
}
