:root {
  --bg: #ffffff;
  --surface: #f5f5f5;
  --ink: #111111;
  --muted: #666666;
  --border: #e0e0e0;
  --accent: #f7931a;
  --ath: #111111;
  --bottom: #a63d2f;
  --halving: #f7931a;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  color: var(--ink);
  background: var(--bg);
  font-family: "General Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.page-shell {
  width: min(1100px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 48px 0 48px;
}

/* Header */

.header {
  margin-bottom: 32px;
}

h1 {
  margin: 0;
  font-family: "General Sans", sans-serif;
  font-size: clamp(3rem, 7vw, 5.5rem);
  font-weight: 700;
  line-height: 0.92;
  letter-spacing: -0.03em;
}

.accent {
  color: var(--accent);
}

.lede {
  max-width: 520px;
  margin: 12px 0 0;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--muted);
}

/* Metrics (ruled row) */

.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 32px;
}

.metric {
  padding: 20px 0;
  border-right: 1px solid var(--border);
}

.metric:last-child {
  border-right: none;
}

.metric:not(:first-child) {
  padding-left: 20px;
}

.metric-label {
  display: block;
  margin-bottom: 6px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.metric-value {
  font-family: "JetBrains Mono", monospace;
  font-size: clamp(0.95rem, 2vw, 1.3rem);
  font-weight: 500;
  line-height: 1.2;
}

/* View tabs */

.view-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 24px;
  margin-bottom: 24px;
}

.view-tab {
  padding: 0 0 6px;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 100ms ease;
}

.view-tab:hover {
  color: var(--ink);
}

.view-tab.is-active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

/* Chart section */

.chart-section {
  position: relative;
  border: 1px solid var(--border);
  overflow: hidden;
}

.legend {
  position: absolute;
  left: 20px;
  top: 20px;
  z-index: 2;
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-family: "JetBrains Mono", monospace;
}

.chart-controls {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 2;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.control {
  display: grid;
  gap: 8px;
  min-width: 138px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.control-label {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.control select,
.control input {
  accent-color: var(--accent);
}

.control select {
  padding: 6px 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.78rem;
}

.toggle-control {
  min-width: unset;
}

.toggle-control input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.legend h2 {
  margin: 0 0 12px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.legend ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
}

.legend-swatch {
  width: 24px;
  height: 4px;
  display: inline-block;
}

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

.legend-swatch.ath {
  background: var(--ath);
}

.legend-swatch.bottom {
  background: var(--bottom);
}

.legend-swatch.drawdown {
  background: transparent;
  border: 1.5px solid var(--ath);
  height: 2px;
}

.legend-swatch.halving {
  background: var(--halving);
}

/* Timeline legend extras */

.halving-gradient-label {
  margin-top: 12px;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.halving-gradient-bar {
  margin-top: 6px;
  height: 6px;
  background: linear-gradient(to right,
    hsl(0, 85%, 55%),
    hsl(45, 90%, 50%),
    hsl(90, 80%, 45%),
    hsl(135, 75%, 42%),
    hsl(180, 80%, 45%),
    hsl(225, 75%, 55%),
    hsl(270, 70%, 55%)
  );
}

.halving-gradient-ticks {
  display: flex;
  justify-content: space-between;
  margin-top: 3px;
  font-size: 0.62rem;
  color: var(--muted);
}

/* Chart stage */

.chart-stage {
  position: relative;
  padding: 32px 20px 18px;
}

#spiral-chart {
  display: block;
  width: 100%;
  height: auto;
}

#timeline-chart {
  display: block;
  width: 100%;
  height: auto;
}

#cycles-chart {
  display: block;
  width: 100%;
  height: auto;
}

.view-hidden {
  display: none !important;
}

/* Yearly lows table */

#lows-view {
  max-width: 560px;
  margin: 0 auto;
}

.lows-title,
.drawdowns-title {
  margin: 0 0 16px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.lows-table {
  width: 100%;
  border-collapse: collapse;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.85rem;
}

.lows-table th {
  padding: 8px 12px;
  border-bottom: 2px solid var(--ink);
  text-align: left;
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.lows-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.lows-table td:nth-child(2) {
  font-weight: 500;
}

.lows-table tbody tr:hover {
  background: var(--surface);
}

.low-up {
  color: #2bb673;
}

.low-down {
  color: var(--bottom);
}

.low-flat {
  color: var(--muted);
}

/* Major drawdowns table */

#drawdowns-view {
  width: 100%;
}

.drawdowns-table-scroll {
  width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
}

.drawdowns-table-scroll:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.drawdowns-table {
  width: 100%;
  min-width: 1000px;
  border-collapse: collapse;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.drawdowns-table th,
.drawdowns-table td {
  padding: 16px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.drawdowns-table thead th {
  padding-top: 8px;
  border-bottom: 1px solid var(--ink);
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.drawdowns-table tbody th {
  font-weight: 600;
}

.drawdown-date,
.drawdown-halving-offset {
  display: block;
}

.drawdown-halving-offset {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 400;
}

.drawdowns-table tbody td:nth-child(6),
.drawdowns-table tbody td:last-child {
  font-weight: 600;
}

.drawdowns-table tbody tr:hover {
  background: var(--surface);
}

/* Tooltip */

.chart-tooltip {
  position: absolute;
  z-index: 3;
  min-width: 140px;
  max-width: 220px;
  padding: 10px 12px;
  background: rgba(17, 17, 17, 0.94);
  color: #e8e8e8;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  line-height: 1.5;
  pointer-events: none;
  opacity: 0;
  transform: translate3d(0, 4px, 0);
  transition: opacity 120ms ease, transform 120ms ease;
}

.chart-tooltip.is-visible {
  opacity: 1;
  transform: translate3d(0, 0, 0);
}

.tooltip-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.tooltip-key {
  color: rgba(232, 232, 232, 0.5);
}

/* Status bar */

.status-bar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  margin-top: 8px;
  padding: 0 0 8px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.footnote {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

/* SVG elements */

.grid-line {
  stroke: var(--border);
  stroke-width: 1;
}

.grid-ring {
  fill: none;
  stroke: var(--border);
  stroke-width: 1;
}

.price-path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.marker {
  opacity: 0;
  cursor: pointer;
  animation: marker-fade 0.55s ease forwards;
}

.ath-marker {
  fill: var(--ath);
}

.bottom-marker {
  fill: var(--bottom);
}

.bottom-marker.provisional {
  fill: var(--bg);
  stroke: var(--bottom);
  stroke-width: 2.5;
}

/* Descending mirror of the solid-black ATH markers: hollow black. */
.drawdown-marker {
  fill: var(--bg);
  stroke: var(--ath);
  stroke-width: 2;
}

.halving-marker {
  fill: var(--halving);
}

.current-marker {
  fill: var(--accent);
  stroke: var(--bg);
  stroke-width: 3;
}

.hit-path {
  fill: none;
  stroke: rgba(0, 0, 0, 0.001);
  stroke-width: 24;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: stroke;
}

.axis-label {
  fill: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.04em;
}

.price-label {
  fill: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
}

.live-label {
  fill: var(--ink);
  font-family: "JetBrains Mono", monospace;
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Timeline SVG */

.tl-grid-line {
  stroke: var(--border);
  stroke-width: 1;
}

.tl-halving-line {
  stroke: var(--accent);
  stroke-width: 1;
  stroke-dasharray: 6, 4;
  opacity: 0.5;
}

.tl-halving-label {
  fill: var(--accent);
  font-family: "JetBrains Mono", monospace;
  font-size: 9px;
  letter-spacing: 0.04em;
}

.tl-axis-label {
  fill: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.04em;
}

.tl-price-label {
  fill: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
}

.tl-segment {
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tl-hit-path {
  fill: none;
  stroke: rgba(0, 0, 0, 0.001);
  stroke-width: 20;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: stroke;
}

/* Halving progress chart */

.progress-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px 24px;
  margin-bottom: 16px;
}

.progress-header h2 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
}

.progress-header p {
  margin: 0;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.78rem;
  color: var(--muted);
}

.progress-legend {
  margin-bottom: 16px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
}

.progress-legend ul {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  list-style: none;
  margin: 0;
  padding: 0;
}

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

.legend-swatch.progress-band {
  height: 12px;
  background: var(--accent);
  opacity: 0.18;
}

.legend-swatch.estimated-halving {
  height: 0;
  border-top: 1px dashed var(--muted);
}

.progress-scroll-hint {
  display: none;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.78rem;
}

.progress-chart-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
}

.progress-chart-scroll:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#halving-progress-chart {
  display: block;
  width: 100%;
  min-width: 1000px;
  height: auto;
}

.hp-progress-band {
  fill: var(--accent);
  opacity: 0.18;
}

.hp-band-end {
  stroke: var(--accent);
  stroke-width: 1;
}

.hp-halving-line {
  stroke: var(--muted);
  stroke-width: 1;
}

.hp-estimated-line {
  stroke: var(--muted);
  stroke-width: 1;
  stroke-dasharray: 6, 4;
}

.hp-price-path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.hp-axis-label,
.hp-halving-label,
.hp-halving-date,
.hp-progress-label {
  font-family: "JetBrains Mono", monospace;
}

.hp-axis-label,
.hp-halving-label {
  fill: var(--muted);
  font-size: 14px;
}

.hp-halving-date {
  fill: var(--muted);
  font-size: 12px;
}

.hp-progress-label {
  fill: var(--ink);
  font-size: 20px;
  font-weight: 500;
}

@media (max-width: 1100px) {
  .progress-scroll-hint {
    display: block;
  }
}

/* Mean reversion chart */

#mean-reversion-chart,
#wma200-chart {
  display: block;
  width: 100%;
  min-width: 1000px;
  height: auto;
}

/* Flat quantile zones: green below Q25, no fill in the middle, red above Q75. */
.mr-zone {
  fill: none;
  stroke: none;
}

.mr-zone-0,
.legend-swatch.mr-cheap {
  fill: #2bb673;
  background: #2bb673;
  opacity: 0.3;
}

.mr-zone-1 {
  fill: #2bb673;
  opacity: 0.14;
}

.mr-zone-3 {
  fill: #d64545;
  opacity: 0.12;
}

.mr-zone-4,
.legend-swatch.mr-expensive {
  fill: #d64545;
  background: #d64545;
  opacity: 0.26;
}

.legend-swatch.mr-cheap,
.legend-swatch.mr-expensive {
  height: 12px;
}

.legend-swatch.mr-index,
.legend-swatch.wma-line {
  height: 2px;
  background: var(--ink);
}

.wma-path {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2;
  stroke-linejoin: round;
}

.wma-below-band {
  fill: #2bb673;
  opacity: 0.22;
}

/* Annualized return grid */

#returns-chart {
  display: block;
  width: 100%;
  max-width: 900px;
  min-width: 760px;
  height: auto;
  margin: 0 auto;
}

.ar-cell-rect {
  stroke: var(--bg);
  stroke-width: 1;
}

.ar-cell:hover .ar-cell-rect {
  stroke: var(--ink);
  stroke-width: 2;
}

.ar-cell-text {
  font-family: "JetBrains Mono", monospace;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  fill: #111111;
  pointer-events: none;
}

.ar-cell-text.is-light {
  fill: #ffffff;
}

.ar-frame {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1;
  pointer-events: none;
}

.ar-axis-title {
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  fill: var(--muted);
}

.legend-swatch.ar-swatch {
  width: 16px;
  height: 12px;
}

/* The same hues as returnColor() in app.js, at the middle of each range. */
.legend-swatch.ar-loss { background: hsl(345, 100%, 50%); }
.legend-swatch.ar-25 { background: hsl(45, 100%, 50%); }
.legend-swatch.ar-50 { background: hsl(95, 100%, 50%); }
.legend-swatch.ar-75 { background: hsl(145, 100%, 50%); }
.legend-swatch.ar-100 { background: hsl(195, 100%, 50%); }
.legend-swatch.ar-over { background: hsl(220, 100%, 50%); }

.mr-price-path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linejoin: round;
}

.mr-index-path {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.25;
  stroke-linejoin: round;
}

.mr-quantile-label,
.mr-current-label {
  font-family: "JetBrains Mono", monospace;
}

.mr-quantile-label {
  fill: var(--muted);
  font-size: 14px;
}

.mr-current-label {
  fill: var(--ink);
  font-size: 18px;
  font-weight: 500;
  stroke: var(--bg);
  stroke-width: 5px;
  paint-order: stroke;
}

.mr-cursor {
  stroke: var(--muted);
  stroke-width: 1;
  stroke-dasharray: 4, 4;
  pointer-events: none;
}

.mr-hit-area {
  fill: transparent;
  pointer-events: all;
}

/* Cycles SVG */

.cy-grid-line {
  stroke: var(--border);
  stroke-width: 1;
}

.cy-axis-label {
  fill: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.04em;
}

.cy-price-label {
  fill: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
}

.cy-line {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cy-hit-path {
  fill: none;
  stroke: rgba(0, 0, 0, 0.001);
  stroke-width: 20;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: stroke;
}

@keyframes marker-fade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 900px) {
  .metrics {
    grid-template-columns: repeat(2, 1fr);
  }

  .metric {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .metric:nth-child(odd) {
    border-right: 1px solid var(--border);
  }

  .metric:nth-child(n+3) {
    border-bottom: none;
  }

  .legend {
    position: static;
    margin: 16px 16px 0;
  }

  .chart-controls {
    position: static;
    margin: 14px 16px 0;
    justify-content: flex-start;
  }

  .chart-stage {
    padding-top: 12px;
  }
}

@media (max-width: 640px) {
  .page-shell {
    width: min(100vw - 20px, 1100px);
    padding-top: 24px;
  }

  .metrics {
    grid-template-columns: 1fr;
  }

  .metric,
  .metric:nth-child(odd) {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .metric:last-child {
    border-bottom: none;
  }

  .metric:not(:first-child) {
    padding-left: 0;
  }

  .chart-stage {
    padding: 8px 6px 10px;
  }

  .axis-label {
    font-size: 9px;
  }

  .price-label {
    font-size: 8px;
  }

  .chart-tooltip {
    max-width: 180px;
  }
}
