:root {
  color-scheme: dark;
  --bg: #111827;
  --panel: #1f2937;
  --accent: #22d3ee;
  --text-primary: #f9fafb;
  --text-secondary: #cbd5f5;
  --border: #374151;
  --no-data: #4b5563;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  display: flex;
  flex-direction: column;
}

header {
  padding: 1rem 2rem;
  background: #0f172a;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

header h1 {
  margin: 0;
  font-size: clamp(1.2rem, 2.4vw, 1.8rem);
  font-weight: 700;
}

header nav {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

header nav a {
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid transparent;
  transition: background 0.2s ease, border-color 0.2s ease;
}

header nav a:hover,
header nav a:focus-visible {
  background: rgba(34, 211, 238, 0.12);
  border-color: rgba(34, 211, 238, 0.5);
  color: var(--text-primary);
  outline: none;
}

header nav .active {
  background: rgba(34, 211, 238, 0.2);
  border-color: rgba(34, 211, 238, 0.7);
  color: var(--text-primary);
}

.app {
  flex: 1;
  display: flex;
  min-height: 0;
}

.sidebar {
  width: min(340px, 100%);
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.sidebar h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.control {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

label {
  font-size: 0.95rem;
  color: var(--text-secondary);
}

input[type="number"],
input[type="file"],
input[type="range"] {
  width: 100%;
}

input[type="number"],
input[type="range"],
button {
  border-radius: 0.6rem;
  border: 1px solid var(--border);
  background: #111827;
  color: var(--text-primary);
  padding: 0.5rem 0.75rem;
  font-size: 0.95rem;
}

input[type="range"] {
  accent-color: var(--accent);
  padding: 0;
  height: 2px;
}

button {
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}

button:hover {
  background: #0f172a;
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.download-buttons {
  display: grid;
  gap: 0.5rem;
}

.summary {
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.75rem;
  background: #111827;
  white-space: pre-line;
}

.error {
  background: rgba(248, 113, 113, 0.15);
  color: #fecaca;
  border: 1px solid rgba(248, 113, 113, 0.4);
  border-radius: 0.75rem;
  padding: 0.75rem;
  font-size: 0.9rem;
}

main {
  flex: 1;
  padding: 1.5rem;
  overflow: auto;
}

.visual-grid {
  display: grid;
  gap: 1.5rem;
}

.viz-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  min-height: 320px;
  position: relative;
}

.viz-panel h3 {
  margin: 0 0 0.5rem 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--accent);
}

.viz-container {
  flex: 1;
  min-height: 260px;
  position: relative;
  overflow: auto;
}

svg {
  width: auto;
  height: auto;
  min-width: 100%;
  min-height: 100%;
}

.legend {
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.legend-bar {
  height: 12px;
  flex: 1;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.tooltip {
  position: absolute;
  pointer-events: none;
  padding: 0.5rem 0.65rem;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.4);
  border-radius: 0.5rem;
  font-size: 0.85rem;
  color: #f9fafb;
  white-space: nowrap;
  z-index: 20;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.placeholder {
  font-size: 0.95rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: 1rem;
}

@media (min-width: 1200px) {
  .visual-grid.multi-column {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}