/* Bean to Brew — design tokens */
:root {
  --coffee-900: #2b1810;
  --coffee-800: #3d2418;
  --coffee-700: #5a3924;
  --coffee-600: #7a4f30;
  --coffee-500: #9b6b3f;
  --coffee-400: #b88a5a;
  --coffee-300: #d4a575;
  --coffee-200: #e8c89a;
  --coffee-100: #f4e4c1;
  --cream-50:  #faf6ee;

  --leaf-700: #2d4a2b;
  --leaf-600: #3f6b3a;
  --leaf-500: #5a8a4f;
  --berry-600: #8b1e2e;
  --berry-500: #b03340;

  --bg: var(--cream-50);
  --surface: #ffffff;
  --surface-2: #f7efe2;
  --ink: var(--coffee-900);
  --ink-soft: var(--coffee-700);
  --ink-muted: #6b5848;
  --border: #e6d6bc;
  --accent: var(--coffee-700);
  --accent-2: var(--leaf-600);

  --shadow-sm: 0 1px 2px rgba(43,24,16,0.06), 0 1px 1px rgba(43,24,16,0.04);
  --shadow-md: 0 4px 14px rgba(43,24,16,0.08), 0 2px 4px rgba(43,24,16,0.05);
  --shadow-lg: 0 12px 32px rgba(43,24,16,0.12), 0 4px 8px rgba(43,24,16,0.06);

  --radius: 10px;
  --radius-lg: 16px;

  --font-display: "Fraunces", "Cormorant Garamond", "Playfair Display", Georgia, serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

[data-theme="dark"] {
  --bg: #1a120c;
  --surface: #241810;
  --surface-2: #2e2014;
  --ink: #f4e4c1;
  --ink-soft: #d4a575;
  --ink-muted: #a08b73;
  --border: #3a2a1a;
  --accent: var(--coffee-300);
  --accent-2: #8fb87f;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "kern", "liga", "calt";
}

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; color: var(--ink); margin: 0 0 .4em; }
h1 { font-size: clamp(2rem, 5vw, 3.5rem); line-height: 1.05; letter-spacing: -0.02em; }
h2 { font-size: clamp(1.5rem, 3vw, 2.25rem); line-height: 1.15; }
h3 { font-size: 1.25rem; line-height: 1.25; }
p { margin: 0 0 1em; color: var(--ink-soft); }
a { color: var(--accent); text-decoration: none; border-bottom: 1px solid transparent; transition: border-color .15s; }
a:hover { border-bottom-color: var(--accent); }

.tabular { font-variant-numeric: tabular-nums lining-nums; }
.muted { color: var(--ink-muted); }
.eyebrow { font-size: .78rem; letter-spacing: .14em; text-transform: uppercase; color: var(--accent-2); font-weight: 600; }

/* Nav */
.nav {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.nav-inner {
  max-width: 1400px; margin: 0 auto; padding: 14px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-size: 1.15rem; font-weight: 600; white-space: nowrap; }
.brand svg { width: 28px; height: 28px; }
.nav-links { display: flex; gap: 4px; flex-wrap: wrap; }
.nav-links a {
  padding: 8px 14px; border-radius: 8px; font-size: .92rem; font-weight: 500;
  color: var(--ink-soft); border: 1px solid transparent;
}
.nav-links a:hover { background: var(--surface-2); color: var(--ink); border-color: transparent; }
.nav-links a.active { background: var(--coffee-700); color: var(--cream-50); }
[data-theme="dark"] .nav-links a.active { background: var(--coffee-300); color: var(--coffee-900); }
.nav-actions { display: flex; gap: 8px; align-items: center; }
.btn-icon {
  background: transparent; border: 1px solid var(--border); width: 36px; height: 36px;
  border-radius: 8px; cursor: pointer; color: var(--ink-soft);
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-icon:hover { background: var(--surface-2); color: var(--ink); }

/* Layout */
.page { max-width: 1400px; margin: 0 auto; padding: 32px 24px 64px; }
.hero {
  display: grid; grid-template-columns: 1.05fr .95fr; gap: 48px; align-items: center;
  min-height: 70vh; padding: 24px 0 48px;
}
@media (max-width: 900px) { .hero { grid-template-columns: 1fr; gap: 24px; min-height: auto; } }

.hero-text h1 { margin-bottom: .25em; }
.hero-image { position: relative; border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-lg); aspect-ratio: 4/3; }
.hero-image img { width: 100%; height: 100%; object-fit: cover; display: block; }

.stepper {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 32px;
}
@media (max-width: 720px) { .stepper { grid-template-columns: repeat(2, 1fr); } }
.step {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow-sm); transition: transform .18s, box-shadow .18s, border-color .18s;
  color: var(--ink); display: block;
}
.step:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--coffee-300); }
.step .num { font-family: var(--font-display); font-size: 1.4rem; color: var(--accent); font-weight: 600; }
.step h4 { margin: 6px 0 4px; font-family: var(--font-body); font-size: 1rem; font-weight: 600; }
.step p { font-size: .87rem; color: var(--ink-muted); margin: 0; }

/* Page header */
.page-head { margin-bottom: 28px; display: flex; gap: 18px; align-items: end; justify-content: space-between; flex-wrap: wrap; }
.page-head .lede { max-width: 56ch; }

/* Grid layouts */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 24px; }
.grid-12 { display: grid; grid-template-columns: repeat(12, 1fr); gap: 24px; }
.span-6 { grid-column: span 6; }
.span-7 { grid-column: span 7; }
.span-5 { grid-column: span 5; }
.span-8 { grid-column: span 8; }
.span-4 { grid-column: span 4; }
.span-12 { grid-column: span 12; }
@media (max-width: 1100px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .grid-12 { grid-template-columns: repeat(6, 1fr); }
  .span-7, .span-8, .span-12 { grid-column: span 6; }
  .span-5 { grid-column: span 6; }
  .span-4 { grid-column: span 3; }
  .span-6 { grid-column: span 6; }
}
@media (max-width: 720px) {
  .grid-12 { grid-template-columns: 1fr; }
  [class^="span-"] { grid-column: span 1; }
  .nav-inner { padding: 10px 14px; gap: 8px; }
  .nav-links { gap: 2px; }
  .nav-links a { padding: 6px 8px; font-size: .82rem; }
  .page { padding: 18px 14px 48px; }
  .chart { height: 280px; }
  .chart.tall { height: 320px; }
  .brand span { display: none; }
  .nav-links { flex: 1; justify-content: flex-end; }
}

/* Card */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 20px; box-shadow: var(--shadow-sm);
}
.card-head { display: flex; align-items: start; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.card-title { font-family: var(--font-display); font-size: 1.15rem; font-weight: 600; margin: 0; }
.card-sub { font-size: .85rem; color: var(--ink-muted); margin-top: 2px; }
.card-tools { display: flex; gap: 6px; flex-shrink: 0; }
.icon-btn {
  width: 30px; height: 30px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; color: var(--ink-soft);
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 14px; height: 14px; }

/* Insight callout */
.insight {
  background: var(--surface-2); border-left: 4px solid var(--accent-2); border-radius: 6px;
  padding: 14px 16px; margin-top: 12px; font-size: .92rem; color: var(--ink);
}
.insight strong { color: var(--accent); }

/* Year scrubber */
.scrubber {
  display: flex; align-items: center; gap: 14px; padding: 14px 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm);
  margin-bottom: 24px; flex-wrap: wrap;
}
.scrubber .label { font-weight: 600; font-size: .9rem; }
.scrubber input[type="range"] { flex: 1; min-width: 240px; accent-color: var(--coffee-700); }
.scrubber .year-display {
  font-family: var(--font-display); font-size: 1.5rem; font-weight: 600; color: var(--accent);
  min-width: 80px; text-align: center;
}
.play-btn {
  background: var(--coffee-700); color: var(--cream-50); border: none; border-radius: 999px;
  width: 38px; height: 38px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.play-btn:hover { background: var(--coffee-800); }
[data-theme="dark"] .play-btn { background: var(--coffee-300); color: var(--coffee-900); }

/* KPI */
.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
@media (max-width: 800px) { .kpi-row { grid-template-columns: repeat(2, 1fr); } }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px;
}
.kpi .label { font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-muted); margin-bottom: 6px; }
.kpi .value { font-family: var(--font-display); font-size: 1.7rem; font-weight: 600; color: var(--ink); }
.kpi .sub { font-size: .8rem; color: var(--ink-muted); margin-top: 2px; }

/* Chart container */
.chart { width: 100%; height: 340px; position: relative; }
.chart.tall { height: 440px; }
.chart.short { height: 240px; }
.chart svg { display: block; }

/* Map */
.map-svg { width: 100%; height: 100%; display: block; }
.country { stroke: var(--surface); stroke-width: .5; cursor: pointer; transition: opacity .15s; }
.country:hover { stroke: var(--ink); stroke-width: 1.2; }
.country.dimmed { opacity: .35; }
.country.selected { stroke: var(--berry-600); stroke-width: 1.8; }
.map-bg { cursor: default; }

/* Selection summary — country + scrubber-year climate stats card.
   Lives below the scrubber; collapses to nothing when no country selected. */
.selection-pill-host { margin: 12px 0 0; min-height: 0; }
.selection-pill-host:empty { margin: 0; }
.selection-pill {
  display: block;
  padding: 12px 14px;
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--berry-600);
  border-radius: 12px;
  font-size: .88rem; line-height: 1.3;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.selection-pill-head {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 10px;
}
.selection-pill-label { color: var(--ink-muted); font-weight: 500; }
.selection-pill-name { font-weight: 600; font-size: 1rem; }
.selection-pill-year { color: var(--ink-muted); font-weight: 500; }
.selection-pill-clear {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px;
  margin-left: auto;
  padding: 0; border: 0; border-radius: 999px;
  background: transparent; color: var(--ink-muted);
  cursor: pointer; transition: background .12s, color .12s;
}
.selection-pill-clear:hover { background: var(--berry-600); color: #fff; }
.selection-pill-clear:focus-visible { outline: 2px solid var(--coffee-500); outline-offset: 1px; }

.selection-pill-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
}
.selection-pill-stats .stat { min-width: 0; }
.selection-pill-stats dt {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--ink-muted); font-weight: 600; margin-bottom: 4px;
}
.selection-pill-stats dd {
  margin: 0; font-family: 'Fraunces', serif; font-size: 1.25rem; font-weight: 500;
  color: var(--ink); line-height: 1.15;
}
.selection-pill-stats dd .unit { font-family: 'Inter', sans-serif; font-size: .78rem; font-weight: 500; color: var(--ink-muted); margin-left: 2px; }
.selection-pill-stats .sub { margin-top: 2px; font-size: .76rem; color: var(--ink-muted); }

.zone-chip {
  display: inline-block; padding: 3px 8px; border-radius: 999px;
  font-family: 'Inter', sans-serif; font-size: .78rem; font-weight: 600;
  border: 1px solid transparent;
}
.zone-chip.zone-optimal  { background: rgba(42, 111, 58, .14); color: #2a6f3a; border-color: rgba(42,111,58,.35); }
.zone-chip.zone-marginal { background: rgba(229, 192, 96, .22); color: #8a6a16; border-color: rgba(229,192,96,.55); }
.zone-chip.zone-hot      { background: rgba(193, 67, 43, .14); color: #c1432b; border-color: rgba(193,67,43,.45); }
.zone-chip.zone-cool     { background: rgba(30, 96, 145, .14); color: #1e6091; border-color: rgba(30,96,145,.4); }
.zone-chip.zone-cold     { background: rgba(30, 96, 145, .22); color: #154a72; border-color: rgba(30,96,145,.5); }

@media (max-width: 640px) {
  .selection-pill-stats { grid-template-columns: 1fr; }
}

/* Tooltip */
.tt {
  position: absolute; pointer-events: none; background: var(--coffee-900); color: var(--cream-50);
  border-radius: 6px; padding: 8px 10px; font-size: .82rem; line-height: 1.4; box-shadow: var(--shadow-md);
  z-index: 100; max-width: 240px; opacity: 0; transition: opacity .12s;
}
.tt.on { opacity: 1; }
.tt b { color: #fff; }

/* Legend */
.legend { display: flex; align-items: center; gap: 8px; font-size: .78rem; color: var(--ink-muted); margin-top: 6px; flex-wrap: wrap; }
.legend .swatch { width: 14px; height: 10px; border-radius: 2px; }

/* Filter chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink-soft);
  padding: 5px 10px; border-radius: 999px; font-size: .82rem; cursor: pointer;
}
.chip.active { background: var(--coffee-700); color: var(--cream-50); border-color: var(--coffee-700); }
[data-theme="dark"] .chip.active { background: var(--coffee-300); color: var(--coffee-900); border-color: var(--coffee-300); }

/* Footer */
.footer { border-top: 1px solid var(--border); margin-top: 64px; padding: 32px 0; color: var(--ink-muted); font-size: .85rem; }
.footer .footer-inner { max-width: 1400px; margin: 0 auto; padding: 0 24px; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 16px; }

/* Loading skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--border) 50%, var(--surface-2) 100%);
  background-size: 200% 100%; animation: shimmer 1.4s linear infinite;
  border-radius: 8px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px;
  background: var(--coffee-700); color: var(--cream-50); border: none; border-radius: 8px;
  font-weight: 500; font-size: .92rem; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--coffee-800); border-bottom-color: transparent; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--border); }
.btn.ghost:hover { background: var(--surface-2); }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Print */
@media print {
  .nav, .scrubber, .card-tools, .footer { display: none !important; }
  .card { break-inside: avoid; box-shadow: none; border-color: #ccc; }
  body { background: white; color: black; }
}

/* Focus */
:focus-visible { outline: 2px solid var(--coffee-500); outline-offset: 2px; border-radius: 4px; }
