/* ============================================================
   UK Grid Live — Styles
   Design tokens follow spec section 5.
   ============================================================ */

:root {
  /* base palette */
  --bg:             #0B0D10;
  --bg-card:        #15181D;
  --bg-elevated:    #1E222A;
  --text-primary:   #F5F7FA;
  --text-secondary: #A8B0BD;
  --text-muted:     #6B7280;
  --border:         #2A2F38;
  --accent:         #5EEAD4;

  /* band colours */
  --band-very-low:   #22C55E;
  --band-low:        #84CC16;
  --band-moderate:   #EAB308;
  --band-high:       #F97316;
  --band-very-high:  #EF4444;

  /* fuel colours */
  --fuel-wind:    #60A5FA;
  --fuel-solar:   #FBBF24;
  --fuel-hydro:   #06B6D4;
  --fuel-nuclear: #A78BFA;
  --fuel-biomass: #84CC16;
  --fuel-gas:     #F97316;
  --fuel-coal:    #4B5563;
  --fuel-imports: #94A3B8;
  --fuel-other:   #6B7280;

  /* spacing */
  --section-gap:   80px;
  --card-padding:  32px;
  --card-radius:   16px;
  --content-max:   1100px;

  /* shadows */
  --shadow-card:  0 4px 16px rgba(0, 0, 0, 0.2);
}

/* -- reset & base --------------------------------------------- */

*,
*::before,
*::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

button { font: inherit; cursor: pointer; }

/* Ensure the [hidden] attribute always wins over display rules. */
[hidden] { display: none !important; }

h1, h2, h3, p, ul { margin: 0; }

ul { list-style: none; padding: 0; }

sub { font-size: 0.65em; }

/* Visually hidden but available to screen readers */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* -- page layout ---------------------------------------------- */

.page {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 64px 24px;
  display: flex;
  flex-direction: column;
  gap: var(--section-gap);
}

.section { position: relative; }

.section__title {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 24px;
  letter-spacing: -0.01em;
}

.card {
  background: var(--bg-card);
  border-radius: var(--card-radius);
  padding: var(--card-padding);
  box-shadow: var(--shadow-card);
}

/* -- hero ----------------------------------------------------- */

.section--hero {
  text-align: center;
  padding: 24px 0 16px;
}

.brand {
  text-align: left;
  margin-bottom: 64px;
}
.brand__title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.brand__subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.hero__body { min-height: 280px; }

.hero__number-wrap {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 12px;
  margin-bottom: 16px;
}
.hero__number {
  font-size: 96px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.hero__unit {
  font-size: 18px;
  color: var(--text-muted);
  font-weight: 400;
}

.hero__interpretation {
  margin-top: 16px;
  font-size: 18px;
  color: var(--text-secondary);
  max-width: 540px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.55;
}

.hero__footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 40px;
  font-size: 13px;
  color: var(--text-muted);
}

.live-indicator {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(94, 234, 212, 0.6);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%   { opacity: 0.4; box-shadow: 0 0 0 0 rgba(94, 234, 212, 0.6); }
  50%  { opacity: 1;   box-shadow: 0 0 0 6px rgba(94, 234, 212, 0); }
  100% { opacity: 0.4; box-shadow: 0 0 0 0 rgba(94, 234, 212, 0); }
}

.hero__error,
.section__error {
  color: var(--text-muted);
  font-size: 14px;
  padding: 24px;
  text-align: center;
}

/* -- band pill ------------------------------------------------ */

.band-pill {
  display: inline-block;
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  background: var(--band-moderate);
  color: var(--bg);
}
.band-pill[data-band="very-low"]  { background: var(--band-very-low);  color: var(--bg); }
.band-pill[data-band="low"]       { background: var(--band-low);       color: var(--bg); }
.band-pill[data-band="moderate"]  { background: var(--band-moderate);  color: var(--bg); }
.band-pill[data-band="high"]      { background: var(--band-high);      color: var(--bg); }
.band-pill[data-band="very-high"] { background: var(--band-very-high); color: var(--text-primary); }

/* -- mix section ---------------------------------------------- */

.mix__headline {
  font-size: 18px;
  color: var(--text-secondary);
  margin-bottom: 24px;
  min-height: 1.5em;
}
.mix__headline strong { color: var(--text-primary); font-weight: 600; }

.mix__layout { min-height: 320px; }

.mix__content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  align-items: center;
}

.mix__chart-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

.mix__chart-wrap canvas {
  max-width: 320px;
  max-height: 320px;
}

.legend {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.legend__item {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}
.legend__dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}
.legend__name { color: var(--text-secondary); }
.legend__perc { color: var(--text-primary); font-variant-numeric: tabular-nums; font-weight: 500; }

.mix__caption {
  margin-top: 24px;
  font-size: 14px;
  color: var(--text-muted);
  min-height: 1.5em;
}

/* -- story section -------------------------------------------- */

.story__chart-wrap {
  position: relative;
  width: 100%;
  height: 320px;
}
.story__content,
.story__skeleton {
  position: absolute;
  inset: 0;
}
.story__content canvas {
  width: 100% !important;
  height: 100% !important;
}

/* -- greenest window callout ---------------------------------- */

.greenest-callout {
  margin-top: 32px;
  background: linear-gradient(
    135deg,
    rgba(94, 234, 212, 0.08) 0%,
    rgba(94, 234, 212, 0.02) 100%
  );
  border: 1px solid rgba(94, 234, 212, 0.25);
  border-radius: 12px;
  padding: 24px 28px;
  position: relative;
  overflow: hidden;
}
.greenest-callout::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--accent);
}
.greenest-callout__label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}
.greenest-callout__time {
  font-size: 32px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  margin-bottom: 8px;
}
.greenest-callout__justification {
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.55;
}

/* -- footer --------------------------------------------------- */

.footer {
  border-top: 1px solid var(--border);
  padding-top: 32px;
  padding-bottom: 16px;
}
.footer__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 32px;
  font-size: 13px;
  color: var(--text-muted);
}
.footer__attrib { text-align: right; }
.footer__byline { grid-column: 1; }
.footer__meta   { grid-column: 2; text-align: right; }
.footer__link {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-size: 13px;
  text-decoration: none;
}
.footer__link:hover { text-decoration: underline; }

/* -- skeleton loaders ----------------------------------------- */

.skeleton {
  background: var(--bg-elevated);
  background-image: linear-gradient(
    90deg,
    var(--bg-elevated) 0%,
    var(--border) 50%,
    var(--bg-elevated) 100%
  );
  background-size: 200% 100%;
  border-radius: 8px;
  animation: shimmer 1.6s ease-in-out infinite;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skeleton--hero-number { width: 280px; height: 96px; margin: 0 auto 16px; }
.skeleton--hero-pill   { width: 120px; height: 28px; margin: 0 auto 16px; border-radius: 999px; }
.skeleton--hero-line   { width: 360px; height: 20px; margin: 16px auto 0; }
.skeleton--headline    { display: inline-block; width: 320px; height: 22px; }
.skeleton--donut       { width: 240px; height: 240px; border-radius: 50%; }
.skeleton--legend      { width: 240px; height: 240px; }
.skeleton--chart       { width: 100%; height: 100%; }

.mix__skeleton {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  align-items: center;
  justify-items: center;
}

/* -- chart fade-in ------------------------------------------- */

.fade-in { animation: fadeIn 400ms ease-out both; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* -- fatal fallback ------------------------------------------- */

.fatal-fallback {
  position: fixed;
  inset: 0;
  background: rgba(11, 13, 16, 0.96);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
}
.fatal-fallback__inner {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  padding: 40px;
  max-width: 440px;
  text-align: center;
  box-shadow: var(--shadow-card);
}
.fatal-fallback h2 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 12px;
}
.fatal-fallback p {
  color: var(--text-secondary);
  margin-bottom: 24px;
}
.btn {
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  padding: 12px 24px;
  font-weight: 600;
  font-size: 14px;
}
.btn:hover { filter: brightness(1.05); }

/* -- modal ---------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(11, 13, 16, 0.7);
  backdrop-filter: blur(4px);
}
.modal__panel {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  padding: 32px 36px;
  max-width: 560px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-card);
}
.modal__close {
  position: absolute;
  top: 12px;
  right: 16px;
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  line-height: 1;
  border-radius: 8px;
}
.modal__close:hover { background: var(--bg-elevated); color: var(--text-primary); }
.modal__title {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 16px;
  letter-spacing: -0.01em;
}
.modal__body p {
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1.6;
  margin-bottom: 14px;
}
.modal__body p:last-child { margin-bottom: 0; }
.modal__body a { color: var(--accent); }
.modal__body strong { color: var(--text-primary); font-weight: 600; }

/* -- regional map --------------------------------------------- */

.region-headline {
  font-size: 18px;
  color: var(--text-secondary);
  margin-bottom: 24px;
  min-height: 1.5em;
}
.region-headline strong { color: var(--text-primary); font-weight: 600; }

.region-map-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  min-height: 380px;
}

.region-map {
  width: 100%;
  max-width: 360px;
  aspect-ratio: 722.8125 / 1185;
}

.region-map__svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* The GB silhouette image — original is black, recolour via filter to match theme */
.region-map__silhouette-img {
  /* The original SVG is solid black. Use a filter to convert black → --bg-elevated (#1E222A).
     CSS filter brightness/invert can't directly hit a specific colour, but we can
     get close by using the image as-is on the dark theme — black on near-black still
     shows as a subtle silhouette via the slight contrast. To make it pop more, we
     add a brightness boost. */
  filter: brightness(0) invert(0.14);
  pointer-events: none;
}

.region-tile {
  cursor: pointer;
  outline: none;
}
.region-tile__shape {
  transition: filter 150ms ease, stroke-width 150ms ease;
  stroke: var(--bg-card);
  stroke-width: 4;
}
.region-tile__label {
  font-family: "Inter", sans-serif;
  font-size: 26px;
  font-weight: 700;
  fill: #0B0D10;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.region-tile:hover .region-tile__shape,
.region-tile:focus-visible .region-tile__shape {
  filter: brightness(1.15);
  stroke: var(--text-primary);
  stroke-width: 5;
}
.region-tile--active .region-tile__shape {
  stroke: var(--text-primary);
  stroke-width: 6;
}

/* Band fills for dots */
.region-tile[data-band="very-low"]  .region-tile__shape { fill: var(--band-very-low); }
.region-tile[data-band="low"]       .region-tile__shape { fill: var(--band-low); }
.region-tile[data-band="moderate"]  .region-tile__shape { fill: var(--band-moderate); }
.region-tile[data-band="high"]      .region-tile__shape { fill: var(--band-high); }
.region-tile[data-band="very-high"] .region-tile__shape { fill: var(--band-very-high); }

/* For "very high" (red), use light text for contrast */
.region-tile[data-band="very-high"] .region-tile__label { fill: var(--text-primary); }

.region-map__hint {
  font-size: 13px;
  color: var(--text-muted);
}

.skeleton--map {
  width: 100%;
  max-width: 360px;
  aspect-ratio: 722.8125 / 1185;
}

/* -- region popup --------------------------------------------- */

.region-popup {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.region-popup__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(11, 13, 16, 0.7);
  backdrop-filter: blur(4px);
}
.region-popup__panel {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  padding: 28px 32px;
  max-width: 420px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-card);
}
.region-popup__close {
  position: absolute;
  top: 10px;
  right: 14px;
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  line-height: 1;
  border-radius: 8px;
}
.region-popup__close:hover { background: var(--bg-elevated); color: var(--text-primary); }

.region-popup__name {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 16px;
  letter-spacing: -0.01em;
}
.region-popup__intensity-wrap {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 12px;
}
.region-popup__intensity {
  font-size: 48px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.region-popup__unit {
  font-size: 14px;
  color: var(--text-muted);
}

.region-popup__mix-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: 24px 0 12px;
}
.region-popup__mix {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.region-popup__mix-item {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}
.region-popup__mix-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}
.region-popup__mix-name { color: var(--text-secondary); }
.region-popup__mix-perc {
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

/* -- responsive: mobile --------------------------------------- */

@media (max-width: 768px) {
  :root {
    --section-gap: 48px;
    --card-padding: 20px;
  }
  .page { padding: 32px 16px; }

  .brand { margin-bottom: 40px; }
  .hero__number { font-size: 64px; }
  .hero__unit { font-size: 16px; }
  .hero__interpretation { font-size: 16px; }

  .mix__content,
  .mix__skeleton {
    grid-template-columns: 1fr;
    gap: 24px;
  }
  .mix__chart-wrap canvas {
    max-width: 240px;
    max-height: 240px;
  }

  .story__chart-wrap { height: 260px; }

  .greenest-callout { padding: 20px 22px; }
  .greenest-callout__time { font-size: 24px; }
  .greenest-callout__justification { font-size: 14px; }

  .footer__grid {
    grid-template-columns: 1fr;
  }
  .footer__attrib,
  .footer__meta { text-align: left; }
  .footer__byline,
  .footer__meta { grid-column: auto; }
}

/* -- reduced motion ------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .live-indicator { animation: none; opacity: 1; }
  .skeleton { animation: none; background: var(--bg-elevated); }
}
