:root {
  --bg: #101218;
  --surface: #17191f;
  --border: #2c2f38;
  --text-primary: #e6e8f0;
  --text-secondary: #adafb8;
  --up: #90e58c;
  --up-bg: rgba(144, 229, 140, 0.12);
  --down: #ffa9af;
  --down-bg: rgba(255, 169, 175, 0.12);
  --accent: #8ab4f8;
  --series-1: #90e58c;
  --series-2: #8ab4f8;
  --series-3: #c792ea;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: "Google Sans", Roboto, Arial, sans-serif;
}

.page {
  max-width: 1720px;
  margin: 0 auto;
  padding: 40px 24px 64px;
}

.header h1 {
  font-size: 28px;
  font-weight: 500;
  margin: 0 0 12px;
}

.subtitle {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-secondary);
  max-width: 640px;
  margin: 0 0 28px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 24px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.file-upload input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}

.file-upload span {
  display: inline-block;
  padding: 8px 20px;
  border-radius: 4px;
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.file-upload span:hover {
  background: rgba(138, 180, 248, 0.1);
}

.file-upload.series-1 span { border-color: var(--series-1); color: var(--series-1); }
.file-upload.series-1 span:hover { background: rgba(144, 229, 140, 0.1); }
.file-upload.series-2 span { border-color: var(--series-2); color: var(--series-2); }
.file-upload.series-2 span:hover { background: rgba(138, 180, 248, 0.1); }
.file-upload.series-3 span { border-color: var(--series-3); color: var(--series-3); }
.file-upload.series-3 span:hover { background: rgba(199, 146, 234, 0.1); }

/* Once a file's been chosen for that slot, fill the button so it reads as
   "loaded" at a glance — the label text itself stays fixed ("Load series N")
   per spec, so this is the only in-button confirmation a file was picked. */
.file-upload.series-1 span.loaded { background: rgba(144, 229, 140, 0.18); }
.file-upload.series-2 span.loaded { background: rgba(138, 180, 248, 0.18); }
.file-upload.series-3 span.loaded { background: rgba(199, 146, 234, 0.18); }

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.toggle input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}

.toggle-track {
  width: 34px;
  height: 14px;
  border-radius: 999px;
  background: #3c3f4a;
  position: relative;
  transition: background 0.15s ease;
  flex-shrink: 0;
}

.toggle-thumb {
  position: absolute;
  top: -3px;
  left: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #8b8d97;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  transition: transform 0.15s ease, background 0.15s ease;
}

.toggle input:checked + .toggle-track {
  background: rgba(138, 180, 248, 0.35);
}

.toggle input:checked + .toggle-track .toggle-thumb {
  transform: translateX(14px);
  background: var(--accent);
}

.toggle-text {
  font-size: 14px;
  color: var(--text-primary);
}

.date-field {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: default;
}

.date-field-label {
  font-size: 14px;
  color: var(--text-secondary);
}

.date-field input[type="date"] {
  color-scheme: dark;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  border-radius: 4px;
  padding: 6px 8px;
}

.date-field input[type="date"]:focus {
  outline: 1px solid var(--accent);
}

.chart-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 16px 8px 8px;
  position: relative;
  /* overflow: hidden makes this a scroll container so overscroll-behavior
     actually applies — otherwise Chrome ignores it and still treats a
     horizontal swipe here as a back/forward navigation gesture. */
  overflow: hidden;
  overscroll-behavior-x: none;
  /* pan-y (not auto) so pinch-zoom is disallowed across the whole card, not
     just the narrow plot-area overlay inside it — a trackpad-driven pinch
     on iPadOS is cursor-positioned rather than finger-on-glass, and might
     land in the axis-label margins rather than precisely on the overlay.
     Vertical panning stays allowed, so a one-finger flick over the margins
     still scrolls the page normally. */
  touch-action: pan-y;
}

.chart-empty {
  height: 600px; /* fallback only — script.js sets the real responsive height inline */
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 14px;
}

.hidden {
  display: none !important;
}

.invisible {
  visibility: hidden;
}

.readouts {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 0 12px 12px;
  min-height: 52px;
}

.readout-card {
  flex: 1 1 200px;
  min-width: 180px;
  padding: 8px 12px;
  border-radius: 6px;
  border-left: 3px solid var(--card-color, var(--text-secondary));
  background: rgba(255, 255, 255, 0.03);
}

.readout-card.series-1 { --card-color: var(--series-1); }
.readout-card.series-2 { --card-color: var(--series-2); }
.readout-card.series-3 { --card-color: var(--series-3); }

.readout-card-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.readout-swatch {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--card-color, var(--text-secondary));
  flex-shrink: 0;
}

.readout-filename {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.readout-top {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.readout-price {
  font-size: 24px;
  font-weight: 500;
  color: var(--text-primary);
}

.readout-change {
  font-size: 15px;
  font-weight: 500;
}

.readout-change.up {
  color: var(--up);
}

.readout-change.down {
  color: var(--down);
}

.readout-cagr {
  font-size: 14px;
  color: var(--text-secondary);
}

.readout-date {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.chart {
  display: block;
  width: 100%;
}

.axis text {
  fill: var(--text-secondary);
  font-size: 11px;
}

.axis .domain {
  stroke: var(--border);
}

.axis .tick line {
  stroke: var(--border);
}

.grid .tick line {
  stroke: rgba(255, 255, 255, 0.06);
}

.grid .domain {
  display: none;
}

.reference-line {
  stroke: var(--text-secondary);
  stroke-dasharray: 2, 2;
  stroke-opacity: 0.6;
}

.reference-label {
  fill: var(--text-secondary);
  font-size: 11px;
}

/* Neutral (not up/down tinted) — a drag selection now spans every loaded
   series at once, and they can disagree on direction, so the shared
   region/boundary visuals stay neutral. Each series' own direction still
   shows via its metadata card's colored change arrow. */
.selection-region {
  fill: rgba(255, 255, 255, 0.06);
}

.selection-line {
  stroke: var(--text-secondary);
  stroke-dasharray: 3, 3;
}

.overlay {
  cursor: crosshair;
  /* Stops iPadOS/mobile Safari from handling pinch and horizontal pan
     natively (which would zoom or scroll the whole page) so our touch
     handlers get those gestures instead. pan-y (not none) leaves vertical
     panning available in principle — script.js decides per one-finger
     gesture, based on its angle, whether to actually let a near-vertical
     swipe fall through to native page scroll or keep it as a drag-select.
     Scoped to just the plot area (not the whole chart card) so a flick over
     the margins — e.g. the Y-axis labels — always scrolls normally. */
  touch-action: pan-y;
}
