:root {
  color-scheme: light;
  --ink: #19231f;
  --muted: #607068;
  --paper: #f4f1e8;
  --card: #fbfaf6;
  --line: #d7d8ce;
  --accent: #356859;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 85% 5%, rgba(189, 223, 177, 0.42), transparent 26rem),
    var(--paper);
  font-family: "DM Sans", system-ui, sans-serif;
}

main { position: relative; width: min(1120px, calc(100% - 40px)); margin: 0 auto; }

.project-link {
  position: absolute;
  top: 32px;
  right: 0;
  display: inline-flex;
  gap: 6px;
  align-items: center;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
}
.project-link:hover { text-decoration: underline; text-underline-offset: 3px; }

.hero { padding: 76px 0 48px; max-width: 780px; }

.eyebrow {
  margin: 0 0 12px;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

h1, h2 { font-family: "Newsreader", Georgia, serif; font-weight: 600; }

h1 { margin: 0; font-size: clamp(3.2rem, 8vw, 6.8rem); line-height: 0.88; letter-spacing: -0.045em; }

.intro { max-width: 630px; margin: 32px 0 0; color: var(--muted); font-size: 1.08rem; line-height: 1.65; }

.controls {
  position: relative;
  z-index: 2;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(251, 250, 246, 0.88);
  box-shadow: 0 12px 35px rgba(42, 57, 49, 0.06);
}
.controls + .controls { margin-top: 12px; }
.panel-heading { margin-bottom: 22px; }
.panel-heading .eyebrow { margin-bottom: 5px; }
.panel-heading h2 { margin: 0; font-size: clamp(1.55rem, 3vw, 2rem); }
.panel-heading > p:last-child:not(.eyebrow) { max-width: 620px; margin: 7px 0 0; color: var(--muted); font-size: 0.82rem; line-height: 1.5; }
.display-year-control { margin-top: 0; padding-top: 0; border-top: 0; }

label { display: block; margin-bottom: 9px; font-size: 0.82rem; font-weight: 600; }
.search-row { display: flex; gap: 10px; }

.year-range-control { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.year-range-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 20px; font-size: 0.82rem; font-weight: 600; }
.year-range-heading output { color: var(--accent); }
.year-range-slider { --range-gradient: linear-gradient(to right, #cdd2cd 0%, var(--accent) 0%, var(--accent) 100%, #cdd2cd 100%); position: relative; height: 24px; margin: 1px 8px 0; }
.year-range-slider::before { position: absolute; top: 10px; right: 0; left: 0; height: 4px; border-radius: 4px; background: var(--range-gradient); content: ""; }
.year-range-slider input[type="range"] { position: absolute; inset: 0; z-index: 1; width: 100%; height: 24px; margin: 0; appearance: none; background: transparent; pointer-events: none; }
.year-range-slider input[type="range"]::-webkit-slider-runnable-track { height: 4px; background: transparent; }
.year-range-slider input[type="range"]::-webkit-slider-thumb { width: 18px; height: 18px; margin-top: -7px; appearance: none; border: 2px solid white; border-radius: 50%; background: var(--accent); box-shadow: 0 1px 5px rgba(25, 35, 31, 0.28); cursor: grab; pointer-events: auto; }
.year-range-slider input[type="range"]::-moz-range-track { height: 4px; background: transparent; }
.year-range-slider input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border: 2px solid white; border-radius: 50%; background: var(--accent); box-shadow: 0 1px 5px rgba(25, 35, 31, 0.28); cursor: grab; pointer-events: auto; }
.year-range-slider input[type="range"]:focus-visible::-webkit-slider-thumb { outline: 3px solid rgba(53, 104, 89, 0.25); outline-offset: 2px; }
.year-range-limits { display: flex; justify-content: space-between; margin: 9px 0 0; color: var(--muted); font-size: 0.7rem; }

input, button { min-height: 48px; border-radius: 8px; font: inherit; }

input:not([type="range"]) {
  flex: 1;
  min-width: 0;
  padding: 0 15px;
  border: 1px solid #b8beb8;
  background: white;
  color: var(--ink);
  font-size: 1rem;
}

input:not([type="range"]):focus { outline: 3px solid rgba(53, 104, 89, 0.18); border-color: var(--accent); }

button {
  padding: 0 21px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  font-weight: 600;
  cursor: pointer;
}

button:hover { background: #285448; }
button:disabled { cursor: wait; opacity: 0.65; }

.place-choices { display: grid; gap: 6px; margin-top: 12px; }
.place-choices button { min-height: 42px; text-align: left; background: #edf1eb; color: var(--ink); border-color: transparent; }
.place-choices button:hover { background: #e0e9df; }
.status { min-height: 1.25em; margin: 10px 0 0; color: var(--muted); font-size: 0.82rem; }
.status.error { color: #a23c31; }

.averaging-control { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.averaging-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 20px; }
.averaging-heading label { margin: 0; }
.averaging-heading output { color: var(--accent); font-size: 0.82rem; font-weight: 600; }
.averaging-control input[type="range"] { width: 100%; margin: 14px 0 2px; accent-color: var(--accent); cursor: pointer; }
.averaging-control input[type="range"]:disabled { cursor: wait; opacity: 0.55; }
.range-ticks { position: relative; height: 18px; margin: 0 7px; color: var(--muted); font-size: 0.7rem; }
.range-ticks span { position: absolute; top: 0; display: grid; justify-items: center; transform: translateX(-50%); }
.range-ticks span::before { width: 1px; height: 4px; margin-bottom: 1px; background: #aeb7b0; content: ""; }
.range-ticks span:nth-child(1) { left: 0; }
.range-ticks span:nth-child(2) { left: 20%; }
.range-ticks span:nth-child(3) { left: 40%; }
.range-ticks span:nth-child(4) { left: 60%; }
.range-ticks span:nth-child(5) { left: 80%; }
.range-ticks span:nth-child(6) { left: 100%; }
.range-hint { margin: 5px 0 0; color: var(--muted); font-size: 0.7rem; }

.chart-card {
  position: relative;
  min-height: 680px;
  margin: 24px 0;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
}

.chart-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; }
.chart-heading h2 { margin: 0; font-size: clamp(1.8rem, 4vw, 2.7rem); }
.chart-description { margin: 7px 0 0; color: var(--muted); font-size: 0.88rem; }
.chart { width: 100%; height: 570px; }

.trend-card { min-height: 500px; }
.trend-heading { align-items: flex-start; }
.trend-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-top: 26px; }
.trend-panel { min-width: 0; padding: 16px 12px 8px; border: 1px solid var(--line); border-radius: 12px; background: #f7f7f1; }
.trend-panel label { margin: 0 0 7px 4px; }
.temperature-input { position: relative; width: 124px; }
.temperature-input input:not([type="range"]) { width: 100%; min-height: 42px; padding-right: 40px; }
.temperature-input span { position: absolute; top: 50%; right: 13px; color: var(--muted); font-size: 0.84rem; pointer-events: none; transform: translateY(-50%); }
.trend-chart { width: 100%; height: 330px; }

.legend-key { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 0.74rem; }
.gradient { width: 110px; height: 8px; border-radius: 10px; background: linear-gradient(90deg, #440154, #3b528b, #21918c, #5ec962, #fde725); }

.chart-placeholder {
  position: absolute;
  inset: 110px 30px 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  background: var(--card);
}
.chart-placeholder[hidden] { display: none; }

.spinner { width: 19px; height: 19px; border: 2px solid #ccd2cb; border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.explanation { display: grid; grid-template-columns: 0.7fr 1.4fr 1fr; gap: 42px; padding: 50px 0 72px; border-top: 1px solid var(--line); }
.explanation h2 { margin: 0; font-size: 2rem; }
.explanation p { margin: 0; color: var(--muted); line-height: 1.7; }
.reading-notes { display: grid; gap: 12px; }
.reading-notes strong { color: var(--ink); }
dl { display: grid; gap: 14px; margin: 0; }
dl div { padding-bottom: 12px; border-bottom: 1px solid var(--line); }
dt { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; }
dd { margin: 4px 0 0; font-size: 0.88rem; }

footer { padding: 26px 20px; background: #1d2a25; color: #bfc9c2; text-align: center; font-size: 0.78rem; }
footer a { color: #e6eee8; }

@media (max-width: 720px) {
  main { width: min(100% - 24px, 1120px); }
  .project-link { position: static; margin-top: 24px; }
  .hero { padding-top: 32px; }
  .search-row { flex-direction: column; }
  .chart-card { min-height: 610px; padding: 20px 12px; }
  .chart-heading { align-items: flex-start; flex-direction: column; padding: 0 8px; }
  .chart { height: 480px; }
  .trend-card { min-height: 0; }
  .trend-grid { grid-template-columns: 1fr; }
  .trend-chart { height: 320px; }
  .chart-placeholder { inset: 140px 12px 20px; }
  .explanation { grid-template-columns: 1fr; gap: 20px; }
}

@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
