/* ===========================================
   FONTS (self-hosted, faster than Google CDN)
   =========================================== */
@font-face {
  font-family: 'Oswald';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../assets/fonts/oswald-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Oswald';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../assets/fonts/oswald-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Oswald';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../assets/fonts/oswald-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Oswald';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../assets/fonts/oswald-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ===========================================
   DESIGN TOKENS
   =========================================== */

/* Register --header-bg-color as a typed <color> property.
   This lets CSS interpolate its value inside linear-gradient(),
   so header and canvas gradient transition in perfect sync. */
@property --header-bg-color {
  syntax: '<color>';
  inherits: true;
  initial-value: #000000;
}

:root {
  /* -----------------------------------------
     AIR QUALITY (header background)
     ----------------------------------------- */
  --aq-v-bad: #7058E3;      /* Bardzo zły */
  --aq-bad: #F93822;        /* Zły */
  --aq-moderate: #F98122;   /* Dostateczny */
  --aq-sufficient: #F9C822; /* Umiarkowany */
  --aq-good: #3E9F4D;       /* Dobry */
  --aq-v-good: #3E9F97;     /* Bardzo dobry */
  --header-bg-color: #000000;    /* Start black; JS updates, CSS transitions via @property */
  transition: --header-bg-color 0.4s ease;
  --header-text-color: #ffffff; /* Header elements (logo, borders, text) always white */

  --font-primary: 'Oswald', sans-serif;
  --font-secondary: 'Editorial New', 'Times New Roman', Times, serif;
  
  /* -----------------------------------------
     TEMPERATURE (concentric circles)
     Scale: <-25°C to >38°C (Warsaw extremes)
     Non-linear mapping: tanh-based, centered on 10°C
     ----------------------------------------- */
  
  /* Gradient colors (cold → hot) */
  --temp-gradient-0: #001f3f;   /* 0% - extreme cold (-25°C) */
  --temp-gradient-15: #0074D9;  /* 15% - cold */
  --temp-gradient-35: #7FDBFF;  /* 35% - cool */
  --temp-gradient-50: #2ECC40;  /* 50% - mild (10°C center) */
  --temp-gradient-70: #FFDC00;  /* 70% - warm */
  --temp-gradient-85: #FF851B;  /* 85% - hot */
  --temp-gradient-100: #FF4136; /* 100% - extreme hot (+38°C) */
  
  /* Legacy discrete colors (kept for compatibility) */
  --temp-freezing: #001f3f;    /* < -10°C */
  --temp-cold: #0074D9;        /* -10°C to 0°C */
  --temp-cool: #7FDBFF;        /* 0°C to 10°C */
  --temp-mild: #2ECC40;        /* 10°C to 20°C */
  --temp-warm: #FFDC00;        /* 20°C to 30°C */
  --temp-hot: #FF4136;         /* > 30°C */
  
  /* Circle styling */
  --temp-circle-opacity: 0.85;
  --temp-center-glow: #FF0000;
  
  /* -----------------------------------------
     TEMPERATURE RING GEOMETRY (11 rings + center)
     Values in rem, ready for SVG rendering
     Based on specification scaled to canvas
     ----------------------------------------- */
  --temp-ring-count: 11;
  
  /* Center (filled circle) */
  --temp-center-radius: 2.12rem;
  
  /* Ring 1-11: radius (r) and stroke-width */
  --temp-ring-1-radius: 2.90rem;
  --temp-ring-1-stroke: 0.68rem;
  
  --temp-ring-2-radius: 4.03rem;
  --temp-ring-2-stroke: 0.61rem;
  
  --temp-ring-3-radius: 5.19rem;
  --temp-ring-3-stroke: 0.53rem;
  
  --temp-ring-4-radius: 6.35rem;
  --temp-ring-4-stroke: 0.53rem;
  
  --temp-ring-5-radius: 7.49rem;
  --temp-ring-5-stroke: 0.43rem;
  
  --temp-ring-6-radius: 8.63rem;
  --temp-ring-6-stroke: 0.40rem;
  
  --temp-ring-7-radius: 9.79rem;
  --temp-ring-7-stroke: 0.33rem;
  
  --temp-ring-8-radius: 10.94rem;
  --temp-ring-8-stroke: 0.26rem;
  
  --temp-ring-9-radius: 12.08rem;
  --temp-ring-9-stroke: 0.23rem;
  
  --temp-ring-10-radius: 13.23rem;
  --temp-ring-10-stroke: 0.13rem;
  
  --temp-ring-11-radius: 14.40rem;
  --temp-ring-11-stroke: 0.10rem;
  
  /* Mapping parameters (Warsaw):
     - Range: -25°C to +38°C (historic extremes)
     - High sensitivity zone: -5°C to +25°C (typical)
     - Center: 10°C (middle of typical range)
     - 2°C change in typical range = visible color shift */
  
  /* -----------------------------------------
     WATER LEVEL (Vistula river line)
     Fixed height bar, position reflects water level
     Non-linear mapping: tanh-based, centered on typical level
     Gradient: stan rzeki (designer) — dark red → red → magenta → violet → blue
     ----------------------------------------- */
  --water-bar-height: 20px;       /* Fixed bar height */
  --water-color-top: #1B0B0D;     /* Gradient start (dark red-black) */
  --water-color-bottom: #5300FF;   /* Gradient end (electric blue-violet) */
  /* Full 7-stop gradient (stan rzeki) — use when bar shows full spectrum */
  --water-gradient-to-bottom: linear-gradient(
    to bottom,
    #1B0B0D 0%,
    #4F0E10 15%,
    #FF0000 35%,
    #FF0055 50%,
    #FF00AA 60%,
    #AA00FF 75%,
    #5300FF 100%
  );
  --water-gradient-to-top: linear-gradient(
    to top,
    #1B0B0D 0%,
    #4F0E10 15%,
    #FF0000 35%,
    #FF0055 50%,
    #FF00AA 60%,
    #AA00FF 75%,
    #5300FF 100%
  );
  --water-min-position: 10%;      /* Min Y position (extreme low) */
  --water-max-position: 90%;      /* Max Y position (flood level) */
  /* Mapping parameters (Vistula Warsaw):
     - Range: 0-800 cm (record low ~15cm, flood ~800cm)
     - High sensitivity zone: 100-250 cm
     - Center: 175 cm (middle of typical range)
     - 5 cm difference should be clearly visible */
  
  /* -----------------------------------------
     PRECIPITATION (bottom gradients)
     ----------------------------------------- */
  --precip-snow: #FFFFFF;
  --precip-rain: #4169E1;         /* Royal blue */
  --precip-heavy: #8A2BE2;        /* Blue violet for heavy */
  --precip-gradient-end: transparent;
  
  /* -----------------------------------------
     SKY / DAY-NIGHT (column backgrounds)
     ----------------------------------------- */
  --sky-dawn: #87CEEB;            /* Light sky blue */
  --sky-day-clear: #00CED1;       /* Turquoise - clear day */
  --sky-day-cloudy: #B0C4DE;      /* Light steel blue */
  --sky-dusk: #DDA0DD;            /* Plum - sunset tones */
  --sky-dusk-red: #CD5C5C;        /* Indian red - red sunset */
  --sky-night: transparent;        /* Show stripes */
  --sky-overcast: #708090;        /* Slate gray */
  
  /* -----------------------------------------
     STRIPES (base pattern)
     Count is fixed, height scales with canvas
     ----------------------------------------- */
  --stripe-light: #FFFFFF;
  --stripe-dark: #000000;
  --stripe-count: 54;           /* 1080/20=54 single stripes (27 white + 27 black) */
  --stripe-opacity: 1;
  --grid-overlay-opacity: 0.8;  /* Black overlay on grid area */
  
  /* -----------------------------------------
     NEWS LABELS (keywords overlay)
     ----------------------------------------- */
  --news-label-bg: #FF0000;
  --news-label-text: #000000;
  --news-label-font: 'Oswald', sans-serif;
  
  /* -----------------------------------------
     LAYOUT & TIMING
     ----------------------------------------- */
  --header-padding: 0 34px;
  --transition-fast: 0.3s;
  --transition-normal: 0.5s;
  --grid-gap: 2px;
  
  /* -----------------------------------------
     CANVAS (timeline board)
     Fixed 16:9 aspect ratio (Full HD base)
     ----------------------------------------- */
  --canvas-max-width: 1920px;
  --canvas-max-height: 1080px;
  --canvas-aspect-ratio: 16 / 9;
  --canvas-margin: 20px;        /* Left/right margin inside canvas */
  --grid-columns: 24;           /* Hour columns (00:00 - 23:00) */
}

/* ===========================================
   BASE STYLES
   =========================================== */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scrollbar-gutter: stable;
}

body {
  font-family: 'Oswald', sans-serif;
  background-color: #000;
  color: #fff;
  overflow-x: hidden;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  z-index: 2;
  max-width: var(--canvas-max-width);  /* TEST: constrain entire page to canvas width */
  margin-left: auto;
  margin-right: auto;
  /* Slajd w górę: zwija się bardzo wolno na początku, potem szybko przyspiesza (ease-in-quart) */
  transition: transform 0.6s cubic-bezier(0.5, 0, 0.75, 0);
}

body.kpo-pushed #app {
  /* Slajd w dół: mocno zwalnia w ostatniej fazie rozwijania, miękko osiadając na celu (ease-out-quint) */
  transition: transform 0.8s cubic-bezier(0.22, 1, 0.36, 1);
  transform: translateY(90px);
}

/* Brak paska przewijania podczas animacji KPO – unikamy przeskoku layoutu */
html.kpo-pushed,
body.kpo-pushed,
html.kpo-closing,
body.kpo-closing {
  overflow-y: hidden;
}

/* KPO banner strip – fixed at top, revealed when #app slides down */
.kpo-banner-strip {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--canvas-max-width);  /* TEST: match #app constraint */
  height: 90px;
  background: #fff;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.kpo-banner-img {
  height: 90px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  opacity: 0;
  /* Elegancki fade-in zwalniający pod koniec */
  transition: opacity 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

.kpo-banner-strip.kpo-banner-visible .kpo-banner-img {
  opacity: 1;
}

/* KPO footer – black spacer + footer with banner, fade-in after top-banner closes */
.kpo-footer-spacer {
  width: 100%;
  height: 120px;
  background: #000;
  flex-shrink: 0;
}

.kpo-footer {
  width: 100%;
  min-height: 240px;
  flex-grow: 1;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  flex-shrink: 0;
  opacity: 0;
  /* Wydłużony, bardzo powolny fade-in dla majestatycznego pojawienia się */
  transition: opacity 2.5s ease-in-out;
}

.kpo-footer.kpo-footer-visible {
  opacity: 1;
}

.kpo-footer-text {
  font-size: 0.6rem;
  color: #333;
  text-align: center;
  line-height: 1.6;
  letter-spacing: 0.05em;
  margin: 0;
}

.kpo-footer-img {
  height: 120px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
}

/* Header - full-width bg, content limited to canvas width */
#header {
  width: 100%;
  min-height: 100px;
  height: 100px;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: var(--header-bg-color);
  position: relative;
  z-index: 10;
}

.header-inner {
  width: 100%;
  max-width: var(--canvas-max-width);
  padding: var(--header-padding);
  display: flex;
  align-items: center;
  gap: 34px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-logo {
  height: 41px;
  width: auto;
  display: block;
  flex-shrink: 0;
}

.header-logo-fallback {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--header-text-color);
}

.header-outer-pill {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  height: 34px;
  border: 1px solid var(--header-text-color);
  border-radius: 44px;
  padding: 0 10px 0 15px;
}

/* Hidden for now – may be re-enabled later */
.header-lang {
  visibility: hidden;
  color: var(--header-text-color);
  font-size: 22px;
  font-weight: 400;
  line-height: 1;
  transform: translateY(-0.07em);
}

.header-center {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.date-navigation {
  display: flex;
  align-items: center;
  gap: 14px;
}

.date-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  height: 20px;
  padding: 0 9px;
  color: var(--header-text-color);
  background: transparent;
  border: 1px solid currentColor;
  border-radius: 44px;
  font-size: 12px;
  font-weight: 400;
  line-height: 1;
  cursor: pointer;
  transition: opacity var(--transition-fast);
}

.date-pill:hover:not(:disabled) {
  opacity: 0.9;
}

.date-pill:active:not(:disabled) {
  opacity: 0.7;
}

.date-pill:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.date-pill-icon {
  width: 28px;
  height: 6px;
  flex-shrink: 0;
}

.date-pill-label {
  min-width: 5.5ch;
  text-align: center;
}

.date-arrow {
  line-height: 1;
}

.date {
  font-size: 22px;
  font-weight: 400;
  color: var(--header-text-color);
  min-width: 10ch;
  text-align: center;
  line-height: 1;
  transform: translateY(-0.07em);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 15px;
  flex-shrink: 0;
}

.header-about {
  color: var(--header-text-color);
  font-weight: 400;
  text-decoration: none;
  font-size: 22px;
  line-height: 1;
  transform: translateY(-0.07em);
}

.header-about:hover {
  text-decoration: underline;
}

/* ===========================================
   HEADER RWD (desktop → 480px)
   3 breakpoints: comfort → tablet → compact
   Key paddings protected for clickability
   =========================================== */

@media (max-width: 1200px) {
  #header {
    height: 80px;
    min-height: 80px;
  }
  .header-inner {
    padding: 0 20px;
    gap: 16px;
  }
  .header-logo { height: 34px; }
  .header-outer-pill {
    height: 28px;
    padding: 0 8px 0 13px;
    border-radius: 38px;
    gap: 12px;
  }
  .header-lang,
  .date,
  .header-about { font-size: 18px; }
  .date-navigation { gap: 11px; }
  .date-pill {
    height: 18px;
    padding: 0 7px;
    font-size: 10px;
  }
  .date-pill-icon { width: 16px; }
  .header-right { gap: 11px; }
}

@media (max-width: 860px) {
  #header {
    height: 64px;
    min-height: 64px;
  }
  .header-inner {
    padding: 0 12px;
    gap: 10px;
  }
  .header-logo { height: 28px; }
  .header-outer-pill {
    height: 23px;
    padding: 0 7px 0 10px;
    border-radius: 32px;
    gap: 9px;
  }
  .header-lang,
  .date,
  .header-about {
    font-size: 14px;
    transform: none;
  }
  .date-navigation { gap: 8px; }
  .date-pill {
    height: 15px;
    padding: 0 6px;
    font-size: 9px;
  }
  .date-pill-icon {
    width: 12px;
    height: 4px;
  }
  .date { min-width: 8ch; }
  .header-right { gap: 8px; }
}

@media (max-width: 600px) {
  #header {
    height: 44px;
    min-height: 44px;
  }
  .header-inner {
    padding: 0 8px;
    gap: 8px;
  }
  .header-logo { height: 22px; }
  .header-outer-pill {
    height: 20px;
    padding: 0 6px 0 8px;
    border-radius: 26px;
    gap: 6px;
  }
  .header-lang,
  .header-about {
    font-size: 12px;
    transform: none;
  }
  .date { font-size: 12px; min-width: auto; transform: none; }
  .date-navigation { gap: 5px; }
  .date-pill {
    height: 14px;
    padding: 0 5px;
    font-size: 8px;
  }
  .date-pill-label { display: none; }
  .date-pill-icon {
    width: 10px;
    height: 3px;
  }
  .header-outer-pill {
    overflow: hidden;
  }
  .header-right {
    flex-shrink: 1;
    gap: 6px;
  }
}

/* Viewport for timeline — on narrow screens it clips the rotated canvas */
.timeline-viewport {
  width: 100%;
  position: relative;
  background-color: #000;  /* Gaps between canvas and edge stripes */
  margin-top: -2px;       /* Remove subpixel gap between header and canvas at intermediate widths (~1050px) */
}

/* Timeline Canvas - 16:9 aspect ratio, centered on desktop when viewport > max-width */
#timeline {
  position: relative;
  width: 100%;
  max-width: var(--canvas-max-width);
  margin-left: auto;
  margin-right: auto;
  aspect-ratio: var(--canvas-aspect-ratio);
  max-height: var(--canvas-max-height);
  overflow: hidden;
  container-type: inline-size;  /* Enable container queries for child scaling */
}

/* RWD: below this width rotate canvas 90° left so 16:9 lays vertically */
@media (max-width: 480px) {
  html {
    overflow-x: hidden;
    width: 100%;
  }

  body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100%;
  }

  #app {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .timeline-viewport {
    width: 100%;
    min-width: 0;
    flex: 0 0 auto;
    align-self: stretch;
    height: calc(100vw * 16 / 9);
    overflow: hidden;
    position: relative;
  }

  #timeline {
    position: absolute;
    width: calc(100vw * 16 / 9);
    height: 100vw;
    max-width: none;
    max-height: none;
    aspect-ratio: auto;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) rotate(-90deg);
  }

  /* Keep data glitch text readable: rotate 90° right so it stays horizontal on portrait screen */
  .data-glitch-layer .data-glitch {
    transform: rotate(90deg);
    transform-origin: left center;
  }
}

/* Visualization layers: fade-in when first painted (reduces jarring load) */
.viz-layer-fade {
  opacity: 0;
  transition: opacity 0.4s ease;
}
.viz-layer-fade.ready {
  opacity: 1;
}

/* Data glitches: RWD font size (scales with canvas), optional random scale via --glitch-scale */
.data-glitch-layer .data-glitch {
  font-size: calc(var(--glitch-scale, 1) * clamp(0.75rem, 0.6cqi, 0.8rem)); /* min 12px, scales with canvas, max 0.8rem */
}

/* Stripes - canvas area only (inside #timeline) */
.stripes-background {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  background: linear-gradient(
    to bottom,
    var(--stripe-light) 50%,
    var(--stripe-dark) 50%
  );
  background-size: 100% calc(100% / 27);
}


/* Dark overlay on grid area only (dims the stripes in grid, not margins) */
/* Layer 2: Mask overlay */
.grid-overlay {
  position: absolute;
  top: 0;
  left: var(--canvas-margin);
  right: var(--canvas-margin);
  bottom: 0;
  z-index: 2;
  background-color: #000;
  opacity: var(--grid-overlay-opacity);
  pointer-events: none;
}

/* Day/Night background layer - shows daylight hours */
/* Layer 3: Day/Night */
.day-night-layer {
  position: absolute;
  top: 0;
  left: var(--canvas-margin);
  right: var(--canvas-margin);
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  gap: 0;  /* No gap - white separators come from hour-column borders */
  pointer-events: none;
  z-index: 3;
  opacity: 0.8;
}

/* Gwiazdy nocne – overlay wewnątrz każdej kolumny day-night (ta sama warstwa co niebo) */
.day-night-stars {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.day-night-star {
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.95);
}

/* Air quality gradient - inside .timeline-grid: above viz (6), below hour labels (8) */
/* @property --header-bg-color allows CSS to interpolate the color inside the gradient,
   so header and canvas gradient transition in perfect sync without mask workarounds. */
.air-quality-gradient {
  position: absolute;
  top: 0;
  left: var(--canvas-margin);
  right: var(--canvas-margin);
  height: calc(100% * 8 / 27);  /* 8 stripes: opacity drops ~25% every 2 stripes */
  z-index: 7;
  background: linear-gradient(
    to bottom,
    var(--header-bg-color) 0%,
    rgba(0, 0, 0, 0) 100%
  );
  pointer-events: none;
}

.timeline-grid .air-quality-gradient {
  left: 0;
  right: 0;
}

/* Grid sits on top with margins */
/* Layer 5: Grid container */
.timeline-grid {
  position: absolute;
  top: 0;
  left: var(--canvas-margin);
  right: var(--canvas-margin);
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(var(--grid-columns), 1fr);
  gap: 0;  /* No gap - separators come from border-left on hour-column */
  z-index: 5;
}

.hour-column {
  position: relative;
  border-left: 1px solid rgba(255, 255, 255, var(--grid-opacity, 1));
  background: none !important;  /* No background - overlay on gradient */
  background-color: transparent !important;
  z-index: 8;  /* Above visualizations (7), below news keywords (9) */
  transition: background-color var(--transition-normal) ease, border-color 0.2s ease;
}

/* Layer 8: Hour labels (inside hour-column, same stacking context) */
/* RWD: scale down on narrow canvas so labels don’t overlap */
.hour-label {
  text-align: center;
  font-size: clamp(0.4rem, 0.6cqi, 0.66rem);
  font-family: 'Oswald', sans-serif;
  padding: 0.25rem 0;
  background: none !important;  /* No background - overlay on gradient */
  background-color: transparent !important;
  color: rgba(255, 255, 255, var(--hour-labels-opacity, 1));
  position: relative;
  z-index: 8;
  transition: color 0.2s ease, opacity 0.2s ease;
}

/* Hide hour labels when toggled off */
.hour-label.hidden {
  opacity: 0 !important;
}

/* ===========================================
   NEWS KEYWORDS (vertical labels)
   =========================================== */

/* Per-hour cell inside .news-keywords-layer grid */
.news-keywords-container {
  position: relative;
  pointer-events: none;
  overflow: hidden;
}

/* Individual keyword label */
.news-keyword {
  position: absolute;
  background-color: #FF0000;
  color: var(--news-label-text);
  font-family: var(--news-label-font);
  font-size: clamp(0.4rem, 0.8cqi + 1px, 0.85rem + 1px);  /* Scales with canvas width */
  font-weight: bold;
  text-transform: uppercase;
  padding: 0.1em 0.2em;  /* em = relative to own font-size */
  white-space: nowrap;
  transform: rotate(-90deg);
  transform-origin: left top;
  letter-spacing: 0.05em;
  line-height: 1;
  pointer-events: auto;
}

/* Loading state */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  font-size: 1.5rem;
}

/* ===================== */
/* Tuning Panel Styles   */
/* ===================== */
#tuning-container {
  width: 100%;
  max-width: var(--canvas-max-width);
  margin-left: auto;
  margin-right: auto;
  align-self: stretch; /* flex: take full width so panel is visible below canvas */
}

.tuning-panel {
  background: #1a1a2e;
  color: #e0e0e0;
  padding: 1rem;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.85rem;
  border-top: 2px solid #3a3a5e;
}

.tuning-panel-header {
  display: flex;
  align-items: center;
  margin-bottom: 1rem;
}

.tuning-panel-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: #00ff88;
}

.tuning-panel-content {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
}

.tuning-section {
  background: #252540;
  border-radius: 8px;
  padding: 1rem;
  min-width: 0;
  overflow: hidden;
}

.tuning-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #3a3a5e;
}

.tuning-section-header h3 {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 500;
  color: #90CAE5;
}

.tuning-reset-btn {
  background: transparent;
  border: 1px solid #3a3a5e;
  color: #888;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
}

.tuning-reset-btn:hover {
  background: #3a3a5e;
  color: #e0e0e0;
}

.tuning-controls {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
}

.tuning-control {
  display: grid;
  grid-template-columns: minmax(100px, auto) 1fr;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.tuning-label {
  font-size: 0.75rem;
  color: #aaa;
  cursor: help;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  min-width: 0;
}

.tuning-number-container,
.tuning-color-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.tuning-slider {
  flex: 1;
  min-width: 0;
  height: 4px;
  -webkit-appearance: none;
  background: #3a3a5e;
  border-radius: 2px;
  outline: none;
}

.tuning-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: #00ff88;
  border-radius: 50%;
  cursor: pointer;
}

.tuning-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: #00ff88;
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

.tuning-value {
  min-width: 0;
  flex-shrink: 0;
  text-align: right;
  font-family: monospace;
  font-size: 0.75rem;
  color: #00ff88;
  white-space: nowrap;
}

.tuning-color-picker {
  width: 32px;
  height: 24px;
  padding: 0;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.tuning-hex {
  font-family: monospace;
  font-size: 0.75rem;
  color: #888;
}

.tuning-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #3a3a5e;
}

.tuning-btn {
  background: #3a3a5e;
  border: none;
  color: #e0e0e0;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
}

.tuning-btn:hover {
  background: #4a4a6e;
}

/* Checkbox control */
.tuning-control-checkbox {
  grid-template-columns: 1fr auto;
}

.tuning-checkbox-container {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.tuning-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: #00ff88;
}

/* Select control */
.tuning-control-select {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.tuning-select-container {
  display: flex;
  align-items: center;
}

.tuning-select {
  background: rgba(255, 255, 255, 0.08);
  color: #ccc;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 0.75rem;
  font-family: inherit;
  cursor: pointer;
  max-width: 200px;
}

.tuning-select:focus {
  outline: 1px solid #00ff88;
  border-color: #00ff88;
}

.tuning-select option {
  background: #1a1a2e;
  color: #ccc;
}

/* Gradient control */
.tuning-control-gradient {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
}

.tuning-control-gradient .tuning-label {
  margin-bottom: 0.25rem;
}

.tuning-gradient-container {
  width: 100%;
  min-width: 0;
  overflow: hidden;
}

.tuning-gradient-picker {
  width: 100%;
  min-width: 0;
  min-height: 40px;
}

/* Grapick overrides for dark theme */
.tuning-panel .grp-wrapper {
  background: #252540;
  border: 1px solid #3a3a5e;
  border-radius: 4px;
}

.tuning-panel .grp-handler {
  width: 12px;
  height: 28px;
  margin-top: -4px;
  border: 2px solid #fff;
  border-radius: 3px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.tuning-panel .grp-handler-selected {
  border-color: #00ff88;
  box-shadow: 0 0 0 2px rgba(0,255,136,0.3);
}

.tuning-panel .grp-handler-close {
  display: none; /* Hide delete button, double-click to delete */
}

.tuning-panel .grp-preview {
  height: 30px;
  border-radius: 3px;
}

/* ===========================================
   DAY STORY SECTION
   
   AI-generated narrative about the day in Warsaw.
   The AI observes the city only through data streams.
   =========================================== */

.day-story-section {
  display: none; /* Hidden by default, shown via ?narrative=1 */
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  background: transparent;
}

.day-story-text {
  font-family: var(--font-secondary);
  font-size: clamp(1rem, 1.4vw, 1.5rem);
  font-weight: 400;
  font-style: normal;
  color: rgba(255, 255, 255, 0.85);
  line-height: 1.6;
  text-align: center;
  margin: 0;
  opacity: 0;
  transition: opacity 0.8s ease;
}

.day-story-text.loaded {
  opacity: 1;
}

.day-story-text:empty {
  display: none;
}

/* Hide when About is active */
body.about-active .day-story-section {
  display: none;
}

@media (max-width: 768px) {
  .day-story-section {
    padding: 1.5rem 1rem;
  }
  
  .day-story-text {
    text-align: left;
  }
}

/* ===========================================
   ABOUT SECTION
   
   Spacing system: ONE unit (--u) used everywhere.
   Derived from Figma: viewport-top → pill-top ≈ 48px.
   
   Layout (top → bottom):
     header (--about-header)
     3 × u  gap
     ┊─── u ───┊─────────────────────────┊─── u ───┊
     ┊  vertical lines start              ┊
     ┊  ┊── u ── TEXT COL ── u ──┊── u ── TEXT COL ── u ──┊
     ┊  text top-aligned                    ┊
     ┊  ...flexible space...                ┊
     ┊  ≥ u  min gap text → h-line         ┊
     ┊  ──── horizontal closing line ─────  ┊
     ┊  u   vertical lines breathe          ┊
     u  gap to viewport bottom              u
   =========================================== */

.about-section {
  --u: 64px;
  --about-header: 100px;
  width: 100%;
  background: #161616;
  opacity: 0;
  visibility: hidden;
  max-height: 0;
  overflow: hidden;
  transition: opacity 0.5s ease, visibility 0.5s ease, max-height 0s 0.5s;
}

body.about-active #app {
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

body.about-active .about-section {
  opacity: 1;
  visibility: visible;
  max-height: none;
  overflow: visible;
  height: calc(100vh - var(--about-header));
  transition: opacity 0.5s ease 0.15s, visibility 0s 0s, max-height 0s 0s;
}

.timeline-viewport,
.kpo-footer-spacer,
.kpo-footer,
#tuning-container {
  transition: opacity 0.35s ease, visibility 0.35s ease, max-height 0s 0.35s;
}

body.about-active .timeline-viewport,
body.about-active .kpo-footer-spacer,
body.about-active .kpo-footer,
body.about-active #tuning-container {
  opacity: 0;
  visibility: hidden;
  max-height: 0;
  overflow: hidden;
  margin: 0;
  padding: 0;
  border: none;
  flex: 0 0 0px;
  transition: opacity 0.35s ease, visibility 0.35s ease, max-height 0s 0.35s;
}

.about-inner {
  width: 100%;
  max-width: calc(var(--canvas-max-width) - 2 * var(--u));
  margin: calc(3 * var(--u)) auto 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: calc(100vh - var(--about-header) - 3 * var(--u));
  padding-bottom: calc(2 * var(--u));
}

/* Text columns: top-aligned, 64px horizontal padding */
.about-col {
  padding: 0 var(--u);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

.about-col-left {
  font-family: var(--font-primary);
  font-size: clamp(1.1rem, 1.6vw, 1.75rem);
  font-weight: 400;
  color: #fff;
  text-align: center;
  line-height: 1.35;
}

.about-col-right {
  font-family: var(--font-secondary);
  font-size: clamp(1rem, 1.5vw, 1.75rem);
  font-weight: 400;
  font-style: normal;
  color: #fff;
  text-align: center;
  line-height: 1.35;
}

.about-col p {
  margin: 0;
}

.about-col p + p {
  margin-top: 1.5em;
}

.about-col a {
  color: #fff;
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

.about-col a:hover {
  opacity: 0.8;
}

/* -------------------------------------------
   HEADER MORPHING (About active state)
   Both header bg and canvas gradient read --header-bg-color;
   JS morphs the variable on open/close, @property transition
   on :root keeps them in perfect sync — one timing source.
   ------------------------------------------- */

body.about-active .date-navigation {
  max-width: 0;
  opacity: 0;
  overflow: hidden;
  padding: 0;
  margin: 0;
  pointer-events: none;
  transition: max-width 0.4s ease, opacity 0.3s ease;
}

.date-navigation {
  transition: max-width 0.4s ease, opacity 0.3s ease;
}

body.about-active .header-outer-pill {
  border-color: var(--header-text-color);
  position: relative;
}

body.about-active .header-about {
  display: none;
}

/* Close button pill - overlaps right end of outer pill (91×53 horizontal capsule per Figma) */
.header-close-pill {
  display: none;
  position: absolute;
  right: -1px;
  top: 50%;
  transform: translateY(-50%);
  width: 91px;
  height: 53px;
  background: #161616;
  border: 1px solid var(--header-text-color);
  border-radius: 44px;
  cursor: pointer;
  z-index: 20;
  align-items: center;
  justify-content: center;
  padding: 0;
}

body.about-active .header-close-pill {
  display: flex;
}

.header-close-pill:hover {
  background: #2a2a2a;
}

.header-close-pill svg {
  width: 16px;
  height: 16px;
  stroke: var(--header-text-color);
  stroke-width: 1.5;
}

/* -------------------------------------------
   ABOUT RWD
   ------------------------------------------- */

@media (max-width: 1200px) {
  .about-section {
    --u: 38px;
    --about-header: 80px;
  }
  body.about-active .header-close-pill {
    width: 75px;
    height: 44px;
  }
  body.about-active .header-close-pill svg {
    width: 14px;
    height: 14px;
  }
}

@media (max-width: 860px) {
  .about-section {
    --u: 28px;
    --about-header: 64px;
  }
  .about-inner {
    grid-template-columns: 1fr;
    height: auto;
    gap: calc(2 * var(--u));
  }
  body.about-active .header-close-pill {
    width: 62px;
    height: 38px;
  }
  body.about-active .header-close-pill svg {
    width: 12px;
    height: 12px;
  }
}

@media (max-width: 600px) {
  .about-section {
    --u: 18px;
    --about-header: 44px;
  }
  .about-col-left,
  .about-col-right {
    font-size: 1rem;
  }
  body.about-active .header-close-pill {
    width: 52px;
    height: 32px;
  }
  body.about-active .header-close-pill svg {
    width: 10px;
    height: 10px;
  }
}
