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

:root {
  --bg: #ffffff;
  --bg-raised: #f9fafb;
  --bg-surface: #f3f4f6;
  --bg-hover: #e5e7eb;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --color-distance: #3b82f6;
  --color-speed: #ef4444;
  --color-acceleration: #22c55e;
  --color-track: #f59e0b;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-soft: #eef2ff;
  --graph-bg: #ffffff;
  --grid-line: rgba(0, 0, 0, 0.05);
  --grid-axis: rgba(0, 0, 0, 0.12);
  --grid-text: rgba(0, 0, 0, 0.75);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
}

html, body {
  height: 100%;
  background: var(--bg-raised);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

button, canvas, .scenario-btn, .playback-btn {
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

canvas {
  touch-action: none; /* so touchmove on graphs doesn't scroll the page */
}

/* === Layout === */
.app {
  display: grid;
  grid-template-columns: 230px 1fr;
  height: 100vh;
}

/* === Sidebar === */
.sidebar {
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 24px 14px 16px;
}

.sidebar__header {
  margin-bottom: 28px;
  padding: 0 8px;
}

.sidebar__title {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text);
}

.sidebar__subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 3px;
  letter-spacing: 0.005em;
}

.scenario-nav {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.scenario-group__label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0 8px;
  margin-bottom: 6px;
}

.scenario-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.12s ease;
}

.scenario-btn:hover {
  color: var(--text);
  background: var(--bg-surface);
}

.scenario-btn--active {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.scenario-btn--active:hover {
  background: var(--accent-soft);
}

/* === Content area === */
.content {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: 16px 20px 12px;
  gap: 10px;
}

/* === Description bar === */
.description-bar {
  padding: 10px 16px;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  line-height: 1.5;
  box-shadow: var(--shadow-sm);
}

/* === Track === */
.track-container {
  height: 100px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.track-container canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* === Graphs === */
.graphs-container {
  flex: 1;
  display: flex;
  gap: 10px;
  min-height: 0;
}

.graph-wrapper {
  flex: 1;
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 0;
  box-shadow: var(--shadow-sm);
}

.graph-wrapper canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* === Overlay legend (only visible for "Compare" scenarios) === */
.overlay-legend {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.overlay-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text);
  font: 500 0.92rem var(--font);
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: background 0.12s, opacity 0.12s;
}

.overlay-chip:hover {
  background: var(--bg-hover);
}

.overlay-chip--off {
  opacity: 0.4;
}

.overlay-chip--off .overlay-chip__name {
  text-decoration: line-through;
}

.overlay-chip--off .overlay-chip__swatch {
  background: var(--text-muted) !important;
}

.overlay-chip__swatch {
  width: 22px;
  height: 4px;
  border-radius: 2px;
}

/* === Playback bar === */
.playback-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.playback-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.12s ease;
  flex-shrink: 0;
}

.playback-btn:hover {
  color: var(--text);
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.playback-btn--play {
  width: 36px;
  height: 36px;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.playback-btn--play:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}

.slider-track {
  flex: 1;
  display: flex;
  align-items: center;
}

.time-slider {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--bg-hover);
  border-radius: 2px;
  outline: none;
}

.time-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15);
}

.time-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}

.time-slider::-moz-range-track {
  height: 4px;
  background: var(--bg-hover);
  border-radius: 2px;
}

.time-display {
  font-size: 0.9rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  min-width: 44px;
  text-align: right;
}

/* === iPad optimizations (touch-friendly, portrait and landscape) === */
@media (pointer: coarse) {
  .scenario-btn {
    padding: 10px 12px;
    font-size: 0.88rem;
  }

  .playback-btn {
    width: 40px;
    height: 40px;
  }

  .playback-btn--play {
    width: 44px;
    height: 44px;
  }

  .time-slider {
    height: 6px;
  }

  .time-slider::-webkit-slider-thumb {
    width: 24px;
    height: 24px;
  }

  .time-slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
  }
}

/* Tighter layout on narrower tablets / iPad portrait */
@media (max-width: 1024px) {
  .app {
    grid-template-columns: 200px 1fr;
  }

  .sidebar { padding: 18px 10px 12px; }
  .content { padding: 12px 14px 10px; gap: 8px; }
  .graphs-container { gap: 8px; }
}

/* iPad: let the whole page scroll as one unit */
@media (pointer: coarse) and (max-width: 1024px) {
  html, body {
    height: auto;
    overscroll-behavior: auto;
  }

  .app {
    height: auto;
    min-height: 100vh;
  }

  .sidebar {
    position: sticky;
    top: 0;
    align-self: start;
    max-height: 100vh;
    overflow-y: auto;
  }

  .content {
    overflow: visible;
    min-height: 100vh;
  }

  .track-container { height: 110px; }
}

/* Narrow viewport (iPad portrait, resized window): stack graphs vertically
   so the larger projector-friendly labels don't get clipped. */
@media (max-width: 900px) {
  .graphs-container {
    flex-direction: column;
  }

  .graph-wrapper {
    min-height: 260px;
  }
}

/* === Phone: stack everything === */
@media (max-width: 700px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    overflow-y: visible;
  }

  .sidebar__header { margin-bottom: 0; margin-right: 16px; }
  .sidebar__subtitle { display: none; }
  .scenario-nav { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .scenario-group { display: contents; }
  .scenario-group__label { display: none; }

  .graphs-container {
    flex-direction: column;
  }

  .graph-wrapper { min-height: 240px; }
}
