@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,600&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --bg: #f6f0e8;
  --ink: #1f1b16;
  --muted: #7a6f63;
  --panel: #fbf7f1;
  --accent: #cc5b2c;
  --accent-2: #1c6b6e;
  --ring: rgba(31, 27, 22, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(circle at top left, #fff4e3, #f0e7dc 55%, #ece2d6 100%);
  color: var(--ink);
  font-family: 'IBM Plex Mono', monospace;
}

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

.sidebar {
  background: linear-gradient(to bottom, #fbf9f6 0%, var(--panel) 100%);
  border-right: 1px solid var(--ring);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  box-shadow: 2px 0 12px rgba(0, 0, 0, 0.03);
}

.brand .title {
  font-family: 'Fraunces', serif;
  font-size: 24px;
  letter-spacing: 0.5px;
}

.brand .subtitle {
  color: var(--muted);
  margin-top: 6px;
  font-size: 12px;
}

.controls {
  display: grid;
  gap: 18px;
  font-size: 12px;
}

.controls > * + * {
  padding-top: 4px;
}

.metric-buttons {
  display: grid;
  gap: 10px;
}

.metric-btn {
  border: 2px solid transparent;
  background: linear-gradient(135deg, #fff8ef 0%, #ffeee0 100%);
  border-radius: 16px;
  padding: 14px 16px;
  font-family: 'Fraunces', serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.metric-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
  transition: left 0.5s ease;
}

.metric-btn:hover::before {
  left: 100%;
}

.metric-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
  border-color: rgba(204, 91, 44, 0.3);
}

.metric-btn.active {
  background: linear-gradient(135deg, #ff8c5a 0%, #cc5b2c 100%);
  color: white;
  border-color: var(--accent);
  box-shadow: 0 8px 24px rgba(204, 91, 44, 0.4);
  transform: translateY(-1px);
}

.range {
  display: grid;
  gap: 8px;
  padding: 4px 0;
}

.range > span:first-child {
  font-weight: 500;
  color: var(--ink);
  font-size: 12px;
  letter-spacing: 0.3px;
}

.range-slider {
  position: relative;
  height: 26px;
}

.range-track,
.range-fill {
  position: absolute;
  top: 50%;
  height: 6px;
  border-radius: 999px;
  transform: translateY(-50%);
}

.range-track {
  width: 100%;
  background: linear-gradient(to right, rgba(31, 27, 22, 0.08), rgba(31, 27, 22, 0.12));
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}

.range-fill {
  background: linear-gradient(90deg, #2fd0b3 0%, #1c6b6e 100%);
  left: 0;
  width: 100%;
  box-shadow: 0 0 8px rgba(47, 208, 179, 0.3);
}

.range-slider input[type="range"] {
  position: absolute;
  left: 0;
  top: 50%;
  width: 100%;
  height: 26px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  transform: translateY(-50%);
  pointer-events: none;
}

.range-slider input[type="range"]::-webkit-slider-thumb {
  pointer-events: auto;
  -webkit-appearance: none;
  appearance: none;
  height: 20px;
  width: 20px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2fd0b3 0%, #1c6b6e 100%);
  border: 3px solid white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2), 0 0 0 1px rgba(28, 107, 110, 0.1);
  cursor: grab;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.range-slider input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3), 0 0 0 1px rgba(28, 107, 110, 0.2);
}

.range-slider input[type="range"]::-webkit-slider-thumb:active {
  cursor: grabbing;
  transform: scale(1.05);
}

.range-slider input[type="range"]::-moz-range-thumb {
  pointer-events: auto;
  height: 20px;
  width: 20px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2fd0b3 0%, #1c6b6e 100%);
  border: 3px solid white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2), 0 0 0 1px rgba(28, 107, 110, 0.1);
  cursor: grab;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.range-slider input[type="range"]::-moz-range-thumb:hover {
  transform: scale(1.15);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3), 0 0 0 1px rgba(28, 107, 110, 0.2);
}

.range-slider input[type="range"]::-moz-range-thumb:active {
  cursor: grabbing;
  transform: scale(1.05);
}

.range-slider input[type="range"]::-webkit-slider-runnable-track {
  background: transparent;
  border: none;
  height: 6px;
}

.range-slider input[type="range"]::-moz-range-track {
  background: transparent;
  border: none;
  height: 6px;
}

select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 2px solid rgba(31, 27, 22, 0.1);
  background: linear-gradient(to bottom, #ffffff 0%, #fff8ef 100%);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--ink);
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

select:hover {
  border-color: rgba(204, 91, 44, 0.3);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

select:focus {
  outline: none;
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(28, 107, 110, 0.1);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 8px;
  border-radius: 10px;
  transition: background 0.2s ease;
}

.toggle:hover {
  background: rgba(28, 107, 110, 0.05);
}

.toggle input {
  accent-color: var(--accent-2);
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.range input {
  width: 100%;
  accent-color: var(--accent);
}

.list {
  overflow-y: auto;
  padding-right: 6px;
  display: grid;
  gap: 6px;
  max-height: calc(100vh - 240px);
}

.list button {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 12px;
  color: var(--ink);
}

.list button.active,
.list button:hover {
  border-color: var(--accent);
  background: rgba(204, 91, 44, 0.08);
}

.stage {
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 24px;
  gap: 16px;
}

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

.stage-title {
  font-family: 'Fraunces', serif;
  font-size: 28px;
}

.stage-meta {
  color: var(--muted);
  font-size: 12px;
}

.stage-explain {
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
  max-width: 520px;
}

.legend {
  display: flex;
  gap: 16px;
  font-size: 11px;
  color: var(--muted);
  flex-wrap: wrap;
  align-items: center;
}

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

.legend-authors {
  gap: 6px;
  margin-top: 8px;
}

.legend-label {
  color: var(--muted);
  font-size: 11px;
  margin-right: 6px;
}

.author-swatch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--ink);
}

.author-swatch::before {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--swatch);
  border: 1px solid rgba(31, 27, 22, 0.4);
}

.legend .dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
}

.legend .center {
  background: var(--accent);
}

.legend .close {
  background: var(--accent-2);
}

.legend .far {
  background: #9f9a92;
}

.viz {
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--ring);
  border-radius: 20px;
  position: relative;
  overflow: hidden;
  cursor: grab;
}

.details {
  background: var(--panel);
  border: 1px solid var(--ring);
  border-radius: 16px;
  padding: 16px;
  display: grid;
  gap: 6px;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(31, 27, 22, 0.9);
  color: #f6f0e8;
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 11px;
  font-family: 'IBM Plex Mono', monospace;
  max-width: 220px;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  box-shadow: 0 8px 16px rgba(0,0,0,0.2);
  z-index: 2;
}

.tooltip.show {
  opacity: 1;
  transform: translateY(0);
}

.node-group.dim {
  opacity: 0.25;
}

.node-group.highlight circle {
  stroke-width: 3px;
}

.details-title {
  font-family: 'Fraunces', serif;
  font-size: 18px;
}

.details-body {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.details-link {
  border: none;
  background: none;
  color: var(--accent);
  font-size: 12px;
  font-family: 'IBM Plex Mono', monospace;
  padding: 0;
  margin-top: 6px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.details-link:hover {
  color: #0f6f76;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 18, 16, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 20;
  padding: 20px;
}

.modal.show {
  opacity: 1;
  pointer-events: auto;
}

.modal-panel {
  background: #fff8ef;
  border: 1px solid var(--ring);
  border-radius: 18px;
  padding: 20px 22px;
  max-width: 520px;
  width: 100%;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.2);
  position: relative;
}

.modal-title {
  font-family: 'Fraunces', serif;
  font-size: 20px;
  margin-bottom: 10px;
}

.modal-body {
  color: var(--ink);
  font-size: 13px;
  line-height: 1.5;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: none;
  background: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--muted);
}

.modal-close:hover {
  color: var(--ink);
}

.footer-note {
  margin-top: 16px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
  text-align: center;
}

.mobile-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.mobile-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

.mobile-menu-toggle {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 100;
  background: var(--accent);
  border: none;
  border-radius: 12px;
  width: 48px;
  height: 48px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  padding: 0;
}

.mobile-menu-toggle span {
  display: block;
  width: 24px;
  height: 3px;
  background: #fff;
  border-radius: 2px;
  transition: all 0.3s ease;
}

.mobile-menu-toggle.active span:nth-child(1) {
  transform: rotate(45deg) translate(7px, 7px);
}

.mobile-menu-toggle.active span:nth-child(2) {
  opacity: 0;
}

.mobile-menu-toggle.active span:nth-child(3) {
  transform: rotate(-45deg) translate(7px, -7px);
}

@media (max-width: 980px) {
  .mobile-backdrop {
    display: block;
  }

  .mobile-menu-toggle {
    display: flex;
  }

  .app {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 85%;
    max-width: 320px;
    height: 100vh;
    z-index: 90;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    border-right: 1px solid var(--ring);
    border-bottom: none;
    overflow-y: auto;
    box-shadow: 4px 0 12px rgba(0, 0, 0, 0.2);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .brand .title {
    font-size: 18px;
    padding-right: 20px;
  }

  .stage {
    position: relative;
    width: 100%;
    padding: 80px 12px 12px 12px;
    grid-template-rows: auto 1fr auto;
    min-height: 100vh;
  }

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

  .stage-title {
    font-size: 20px;
  }

  .stage-meta {
    font-size: 11px;
  }

  .stage-explain {
    font-size: 11px;
  }

  .viz {
    min-height: 400px;
    touch-action: pan-x pan-y;
  }

  .details {
    padding: 12px;
    font-size: 11px;
  }

  .details-title {
    font-size: 16px;
  }

  .details-body {
    font-size: 11px;
  }

  .metric-btn {
    padding: 10px 12px;
    font-size: 14px;
  }

  .controls {
    gap: 12px;
    font-size: 11px;
  }

  select {
    font-size: 11px;
    padding: 8px 6px;
  }

  .footer-note {
    font-size: 10px;
    margin-top: 12px;
  }

  .tooltip {
    font-size: 10px;
    max-width: 180px;
    padding: 5px 8px;
  }

  .modal-panel {
    max-width: 90%;
    padding: 16px 18px;
    margin: 20px;
  }

  .modal-title {
    font-size: 18px;
  }

  .modal-body {
    font-size: 12px;
  }

  .list {
    max-height: 220px;
  }
}

@media (max-width: 480px) {
  .sidebar {
    width: 90%;
    max-width: none;
  }

  .stage {
    padding: 70px 8px 8px 8px;
  }

  .stage-title {
    font-size: 18px;
  }

  .viz {
    min-height: 350px;
  }

  .metric-btn {
    font-size: 13px;
    padding: 9px 10px;
  }

  .mobile-menu-toggle {
    width: 44px;
    height: 44px;
    top: 12px;
    left: 12px;
  }

  .mobile-menu-toggle span {
    width: 22px;
  }
}
