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

:root {
  --bg: #0a0a0f;
  --panel: #12121a;
  --border: #2a2a3a;
  --text: #e8e8f0;
  --muted: #8888a0;
  --accent: #6c8cff;
  --accent2: #ff6c8c;
  --green: #4ade80;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

#app {
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  gap: 0;
}

header {
  grid-column: 1 / -1;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

#video-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  padding: 9px 16px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 0 16px rgba(108, 140, 255, 0.4);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

#video-link:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 24px rgba(255, 108, 140, 0.55);
}

#video-link .video-icon {
  font-size: 0.9rem;
}

@media (max-width: 560px) {
  #video-link .video-label {
    display: none;
  }
}

header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.tagline {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 2px;
}

#controls {
  grid-row: 2;
  padding: 16px;
  border-right: 1px solid var(--border);
  background: var(--panel);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#controls h2 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 8px;
}

#controls section label {
  display: block;
  margin-top: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

#controls select,
#controls input[type="range"] {
  width: 100%;
  margin-top: 4px;
}

#controls select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
}

.hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 6px;
}

.btn-row {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

button {
  flex: 1;
  padding: 8px 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
}

button:hover {
  filter: brightness(1.1);
}

button#btn-reset {
  background: var(--border);
  color: var(--text);
}

.checkbox {
  display: flex !important;
  align-items: center;
  gap: 8px;
  margin-top: 10px !important;
}

.checkbox input {
  width: auto !important;
  margin: 0 !important;
}

#stats .stat {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}

#stats .stat strong {
  color: var(--green);
  font-variant-numeric: tabular-nums;
}

.caption {
  font-size: 0.8rem;
  color: var(--muted);
  padding: 10px;
  background: var(--bg);
  border-radius: 8px;
  border-left: 3px solid var(--accent);
}

.caption strong {
  color: var(--text);
}

#viewport {
  position: relative;
  grid-row: 2;
  min-height: 0;
}

#canvas-3d {
  width: 100%;
  height: 100%;
  display: block;
}

.overlay-hint {
  position: absolute;
  bottom: 12px;
  right: 16px;
  font-size: 0.75rem;
  color: var(--muted);
  pointer-events: none;
}

#legend {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  background: rgba(10, 10, 18, 0.7);
  border: 1px solid var(--border);
  border-radius: 8px;
  backdrop-filter: blur(6px);
  pointer-events: none;
}

#legend .legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text);
}

#legend .legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: 0 0 8px currentColor;
}

#loss-panel {
  grid-column: 1 / -1;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

#loss-panel h2 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 8px;
}

#canvas-loss {
  width: 100%;
  height: 80px;
  display: block;
  border-radius: 6px;
  background: var(--bg);
}

@media (max-width: 768px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr auto;
  }

  #controls {
    grid-row: 2;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 40vh;
  }

  #viewport {
    grid-row: 3;
    min-height: 300px;
  }
}
