:root {
  color-scheme: light;
  --bg: #f3efe7;
  --panel: rgba(255, 255, 255, 0.8);
  --panel-strong: #ffffff;
  --text: #1f2328;
  --muted: #5d6670;
  --line: rgba(31, 35, 40, 0.12);
  --accent: #1f6f5b;
  --accent-soft: rgba(31, 111, 91, 0.12);
  --good: #166534;
  --shadow: 0 16px 40px rgba(31, 35, 40, 0.08);
  --radius: 20px;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(31, 111, 91, 0.14), transparent 30%),
    radial-gradient(circle at top right, rgba(31, 35, 40, 0.06), transparent 26%),
    linear-gradient(180deg, #faf7f0 0%, var(--bg) 100%);
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 40px 0 56px;
}

.hero {
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 6px);
  background: var(--panel);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 700;
}

.hero h1 {
  margin: 0;
  max-width: 14ch;
  font-size: clamp(2.2rem, 5vw, 4.6rem);
  line-height: 0.98;
}

.year-form {
  margin-top: 24px;
}

.year-form label,
.metric-label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.year-controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.year-controls input,
.year-controls button {
  height: 48px;
  border-radius: 14px;
  border: 1px solid var(--line);
  font: inherit;
}

.year-controls input {
  width: min(240px, 100%);
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--text);
}

.year-controls button {
  padding: 0 18px;
  background: var(--text);
  color: white;
  cursor: pointer;
  font-weight: 700;
}

.year-controls button:hover {
  background: #111418;
}

#share-button {
  background: rgba(31, 35, 40, 0.06);
  color: var(--text);
}

#share-button:hover {
  background: rgba(31, 35, 40, 0.12);
}

.stat-description,
.stat-source,
#results-count {
  color: var(--muted);
}

.year-form {
  margin-bottom: 0;
}

.results-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin: 30px 4px 16px;
}

.results-header h2 {
  margin: 0;
  font-size: 1.3rem;
}

#results-count {
  margin: 0;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px;
}

.stat-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.stat-card__header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

.stat-title {
  margin: 0;
  font-size: 1.12rem;
}

.stat-description {
  margin: 10px 0 0;
  line-height: 1.55;
  font-size: 0.94rem;
}

.stat-badge {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 8px 12px;
  background: var(--accent-soft);
  color: var(--good);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.stat-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.stat-metrics > div {
  padding: 14px;
  border-radius: 16px;
  background: rgba(31, 35, 40, 0.03);
}

.stat-metrics strong {
  display: block;
  font-size: 1rem;
}

.chart-wrap {
  position: relative;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(31, 111, 91, 0.03), rgba(31, 35, 40, 0.01));
  overflow: hidden;
}

.chart {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 640 / 220;
  max-height: 360px;
}

.chart-grid {
  stroke: rgba(31, 35, 40, 0.08);
  stroke-width: 1;
}

.chart-axis {
  stroke: rgba(31, 35, 40, 0.16);
  stroke-width: 1.2;
}

.chart-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-fill {
  fill: rgba(31, 111, 91, 0.12);
  stroke: none;
}

.chart-dot {
  fill: white;
  stroke: var(--accent);
  stroke-width: 2;
}

.chart-marker-line {
  stroke: rgba(31, 111, 91, 0.45);
  stroke-width: 1.4;
  stroke-dasharray: 4 4;
  pointer-events: none;
}

.chart-hover-line {
  stroke: var(--accent);
  stroke-width: 1.8;
  opacity: 0.35;
  pointer-events: none;
}

/* Responsive adjustments */
@media (max-width: 920px) {
  :root {
    --radius: 16px;
  }

  .app-shell {
    padding: 28px 12px 40px;
  }

  .hero {
    padding: 18px;
  }

  .stat-card {
    padding: 16px;
    border-radius: 14px;
  }

  .chart {
    max-height: 300px;
  }
}

@media (min-width: 921px) {
  /* ensure grid items respect min width but never exceed 3 columns */
  .stats-grid {
    grid-template-columns: repeat(2, minmax(280px, 1fr));
  }
}

@media (max-width: 720px) {
  .year-controls {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .year-controls input,
  .year-controls button {
    width: 100%;
  }

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

  .stat-card__header {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

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

  .chart-wrap {
    border-radius: 12px;
  }

  .chart-tooltip {
    font-size: 0.75rem;
    padding: 6px 8px;
  }
}

@media (max-width: 420px) {
  .hero h1 {
    font-size: 1.8rem;
  }

  .year-controls input {
    height: 44px;
  }

  .chart {
    max-height: 260px;
  }
}


.chart-marker {
  fill: #ffffff;
  stroke: var(--accent);
  stroke-width: 3;
}

.chart-marker-label {
  fill: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.chart-axis-label {
  fill: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.chart-axis-label--selected {
  fill: var(--accent);
  font-weight: 700;
}

.chart-hover-layer {
  cursor: crosshair;
}

.chart-tooltip {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 2;
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(31, 35, 40, 0.9);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 120ms ease, transform 120ms ease;
  max-width: calc(100% - 24px);
  white-space: nowrap;
}

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

.stat-footer {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  font-size: 0.88rem;
}

.stat-source {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  cursor: help;
}

.stat-source__icon {
  width: 20px;
  height: 20px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(31, 35, 40, 0.08);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 700;
  flex: 0 0 auto;
}

.stat-source__text {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.empty-state,
.error-state {
  grid-column: 1 / -1;
  padding: 28px;
  border-radius: var(--radius);
  border: 1px dashed rgba(31, 35, 40, 0.2);
  background: rgba(255, 255, 255, 0.6);
  color: var(--muted);
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 20px;
  }

  .hero {
    padding: 22px;
  }

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

  .stat-card__header,
  .stat-metrics {
    grid-template-columns: 1fr;
    display: grid;
  }
}