:root {
  --bg: #FAFAF7;
  --panel-bg: #FFFFFF;
  --sidebar-bg: #1C2126;
  --sidebar-bg-raised: #262C33;
  --sidebar-text: #E7E9EA;
  --sidebar-text-dim: #9AA3AB;
  --accent: #4F8A8B;
  --accent-soft: rgba(79, 138, 139, 0.18);
  --rule-light: #E4E1D8;
  --rule-dark: #333A41;
  --hover-highlight: rgba(212, 175, 55, 0.18);

  --font-ui: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --font-display: "IBM Plex Serif", Georgia, serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--bg);
  color: #22262A;
}

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
}

/* ---------------- Sidebar ---------------- */

.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 24px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.sidebar-header h1 {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  font-size: 21px;
  margin: 0 0 4px 0;
  letter-spacing: 0.2px;
}

.subtitle {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--sidebar-text-dim);
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.control-group {
  border-top: 1px solid var(--rule-dark);
  padding-top: 16px;
}

.control-group h2 {
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--sidebar-text-dim);
  margin: 0 0 10px 0;
  font-weight: 500;
}

.check-row, .radio-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 6px;
  margin: 0 -6px;
  border-radius: 5px;
  font-size: 13.5px;
  cursor: pointer;
  transition: background 0.12s ease;
}

.check-row:hover, .radio-row:hover {
  background: var(--sidebar-bg-raised);
}

.check-row input, .radio-row input {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.check-row em, .radio-row em {
  font-style: normal;
  color: var(--sidebar-text-dim);
  font-size: 12px;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--rule-dark);
}

/* ---------------- Legend / key panel ---------------- */

.legend-block {
  margin-bottom: 14px;
}

.legend-block h3 {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--sidebar-text);
  margin: 0 0 6px 0;
}

.legend-swatch-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
}

.legend-swatch-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--sidebar-text-dim);
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.15);
  flex-shrink: 0;
}

.legend-swatch-icon {
  width: 16px;
  height: 16px;
  object-fit: contain;
  flex-shrink: 0;
}

.legend-static-image {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  display: block;
}

.legend-gradient-bar {
  height: 10px;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.15);
}

.legend-gradient-labels {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--sidebar-text-dim);
  margin-top: 4px;
}

.legend-empty {
  font-size: 12px;
  color: var(--sidebar-text-dim);
  margin: 0;
}

#active-count-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 5px 10px;
  border-radius: 4px;
  display: inline-block;
}

/* ---------------- Main viewport ---------------- */

.viewport {
  background: var(--panel-bg);
  overflow: hidden;
  position: relative;
}

.tree-scroll {
  width: 100%;
  height: 100%;
  overflow: auto;
  padding: 24px;
}

.tree-stack {
  position: relative;
  min-width: 1400px;
}

.tree-stack img.sizer {
  display: block;
  width: 100%;
  height: auto;
  visibility: hidden;
  pointer-events: none;
}

.tree-stack img.layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: auto;
  pointer-events: none;
  user-select: none;
}

.hover-cell {
  position: absolute;
  box-sizing: border-box;
}

.hover-cell:hover {
  background: var(--hover-highlight);
}

.tippy-box {
  font-family: var(--font-ui);
  font-size: 12px;
  line-height: 1.5;
}

.tippy-box[data-theme~='light'] {
  background: var(--panel-bg);
}

/* ---------------- Scrollbars (subtle, matches tone) ---------------- */

.sidebar::-webkit-scrollbar, .tree-scroll::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
.sidebar::-webkit-scrollbar-thumb {
  background: var(--rule-dark);
  border-radius: 5px;
}
.tree-scroll::-webkit-scrollbar-thumb {
  background: #D8D5CA;
  border-radius: 5px;
}
