/*
 * Keli - Master Stylesheet
 * Following CSS 2025 Guide Principles
 * Architecture: Cascade Layers for specificity control
 *
 * === RULES ===
 * ✅ DO:
 *   - clamp(), min(), max() for responsive values (gap, font-size, padding)
 *   - @container queries for component-level responsiveness
 *   - OKLCH colors (perceptually uniform)
 *   - Grid: repeat(auto-fit, minmax()) for responsive layouts
 *   - 100dvh (NOT 100vh)
 *   - Logical properties (margin-block, padding-inline)
 *
 * ❌ DON'T:
 *   - Pixel-based @media queries inside components
 *   - Override clamp() with @media - adjust clamp values instead
 *   - RGB/HSL colors - use OKLCH
 *   - Fixed breakpoints (320px, 768px, 1024px) - let content dictate
 *   - position: absolute for stacking - use grid-area: stack
 *
 * 📐 Layout @media OK for: Grid structure changes (bento → stack)
 * 🎨 Component @media OK for: Accessibility (prefers-reduced-motion, prefers-contrast)
 */

/* === LAYER DECLARATION === */
@layer reset, base, layout, components, utilities;

/* ================================================================
   @layer reset - CSS Reset 2025
   ================================================================ */
@layer reset {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  * {
    margin: 0;
  }

  body {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
  }

  img,
  picture,
  video,
  canvas,
  svg {
    display: block;
    max-width: 100%;
  }

  input,
  button,
  textarea,
  select {
    font: inherit;
  }

  p,
  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    overflow-wrap: break-word;
  }

  h1,
  h2,
  h3 {
    text-wrap: balance;
  }

  p {
    text-wrap: pretty;
  }
}

/* ================================================================
   @layer base - Design System Foundation
   ================================================================ */
@layer base {
  /* === CSS VARIABLES (Modern OKLCH Colors) === */
  :root {
    /* Enable light/dark mode support */
    color-scheme: light dark;

    /* Atmospheric color palette */
    --color-primary: oklch(58% 0.18 245);
    --color-primary-bright: oklch(68% 0.2 245);
    --color-primary-dim: oklch(45% 0.15 245);

    --color-accent-warn: oklch(75% 0.18 65);
    --color-accent-danger: oklch(65% 0.22 25);
    --color-accent-safe: oklch(75% 0.15 145);

    /* Surfaces: light (vaalea tausta) / dark (tumma tausta) */
    --color-surface: light-dark(oklch(98% 0.005 245), oklch(22% 0.015 245));
    --color-surface-dim: light-dark(oklch(92% 0.01 245), oklch(18% 0.02 245));

    /* Text colors: light (tumma teksti) / dark (vaalea teksti) */
    --color-text: light-dark(oklch(25% 0.02 245), oklch(90% 0.02 245));
    --color-text-muted: light-dark(oklch(55% 0.03 245), oklch(65% 0.03 245));
    --color-text-dim: light-dark(oklch(70% 0.02 245), oklch(50% 0.02 245));

    /* Atmospheric circular gradient for body background */
    --bg-body-image: radial-gradient(
      circle at center,
      oklch(70% 0.16 240) 0%,
      oklch(58% 0.16 245) 25%,
      oklch(50% 0.15 250) 50%,
      oklch(45% 0.14 255) 75%,
      oklch(40% 0.13 260) 100%
    );

    --radius: 12px;
    --radius-sm: 8px;

    /* Shadow color: light (dark shadows) / dark (darker shadows) */
    --shadow-color: light-dark(
      oklch(25% 0.02 245 / 0.12),
      oklch(5% 0.02 245 / 0.4)
    );
    --shadow: 0 1px 3px var(--shadow-color), 0 8px 24px var(--shadow-color);
    --shadow-lg: 0 4px 6px var(--shadow-color), 0 12px 40px var(--shadow-color);

    /* Typography */
    --font-display: "Rajdhani", -apple-system, sans-serif;
    --font-body: "Manrope", -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: "JetBrains Mono", "Courier New", monospace;
  }

  /* === ANIMATIONS === */
  @keyframes grain {
    0%,
    100% {
      transform: translate(0, 0);
    }
    10% {
      transform: translate(-5%, -10%);
    }
    30% {
      transform: translate(3%, -15%);
    }
    50% {
      transform: translate(12%, 9%);
    }
    70% {
      transform: translate(9%, 4%);
    }
    90% {
      transform: translate(-1%, 7%);
    }
  }

  @keyframes fadeInUp {
    from {
      opacity: 0;
      transform: translateY(24px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  @keyframes cloudPulse {
    0%,
    100% {
      opacity: 1;
    }
    50% {
      opacity: 0.7;
    }
  }

  @keyframes headerPulse {
    0%,
    100% {
      box-shadow:
        0 4px 16px oklch(45% 0.15 245 / 0.35),
        0 0 20px oklch(58% 0.18 245 / 0.3),
        inset 0 1px 0 oklch(85% 0.08 245 / 0.4);
    }
    50% {
      box-shadow:
        0 6px 20px oklch(45% 0.15 245 / 0.4),
        0 0 28px oklch(58% 0.18 245 / 0.4),
        inset 0 1px 0 oklch(85% 0.08 245 / 0.5);
    }
  }

  @keyframes shimmer {
    0%,
    100% {
      opacity: 0.6;
    }
    50% {
      opacity: 1;
    }
  }

  @keyframes livePulse {
    0%,
    100% {
      opacity: 1;
    }
    50% {
      opacity: 0.4;
    }
  }

  @keyframes pulse {
    0%,
    100% {
      opacity: 1;
    }
    50% {
      opacity: 0.6;
    }
  }

  /* Dark mode gradient override (system preference) */
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --bg-body-image: radial-gradient(
        circle at center,
        oklch(28% 0.16 240) 0%,
        oklch(22% 0.16 245) 25%,
        oklch(18% 0.15 250) 50%,
        oklch(14% 0.14 255) 75%,
        oklch(11% 0.13 260) 100%
      );
    }
  }

  /* Manual dark mode override */
  :root[data-theme="dark"] {
    --bg-body-image: radial-gradient(
      circle at center,
      oklch(28% 0.16 240) 0%,
      oklch(22% 0.16 245) 25%,
      oklch(18% 0.15 250) 50%,
      oklch(14% 0.14 255) 75%,
      oklch(11% 0.13 260) 100%
    );
  }

  /* === BODY & EFFECTS === */
  body {
    font-family: var(--font-body);
    background: var(--bg-body-image);
    background-attachment: fixed;
    color: var(--color-text);
    padding: clamp(0.5rem, 1.5vw, 1.5rem);
    position: relative;
    overflow-x: hidden;
  }
}

/* ================================================================
   @layer layout - Grid Structure & Responsive
   ================================================================ */
@layer layout {
  /* === BENTO GRID LAYOUT === */
  #app {
    display: grid;
    gap: clamp(0.5rem, 1.2vw, 1rem);
    width: min(100%, 1400px);
    position: relative;
    z-index: 1;

    /* Desktop: Bento layout */
    grid-template-areas:
      "compass stats"
      "compass table";
    grid-template-columns: minmax(280px, 380px) 1fr;
    grid-template-rows: auto 1fr;

    /* Entrance animation */
    animation: fadeInUp 0.8s cubic-bezier(0.16, 1, 0.3, 1);
  }

  /* Grid Areas */
  .area-compass {
    grid-area: compass;
  }

  .area-stats {
    grid-area: stats;
    animation: fadeInUp 0.8s 0.1s cubic-bezier(0.16, 1, 0.3, 1) backwards;
  }

  .area-table {
    grid-area: table;
    animation: fadeInUp 0.8s 0.2s cubic-bezier(0.16, 1, 0.3, 1) backwards;
  }

  /* === ALOFT-ONLY MODE: Center table when no ground wind data === */
  #app.aloft-only {
    grid-template-areas: "table";
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    place-items: center;
  }

  /* === RESPONSIVE: TABLET & MOBILE === */
  @media (max-width: 900px) {
    #app {
      grid-template-areas:
        "compass"
        "stats"
        "table";
      grid-template-columns: 1fr;
      grid-template-rows: auto auto 1fr;
    }
  }

  @media (max-width: 480px) {
    body {
      padding: 0.75rem;
    }
  }
}

/* ================================================================
   @layer components - UI Components
   ================================================================ */
@layer components {
  /* === APP CONTAINER === */
  .app-container {
    display: contents;
  }

  /* === CARD BASE === */
  .card {
    background: var(--color-surface);
    backdrop-filter: blur(20px);
    border-radius: var(--radius);
    padding: clamp(0.75rem, 1vw, 1.25rem);
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
    border: 1px solid
      light-dark(oklch(95% 0.005 245 / 0.6), oklch(30% 0.02 245 / 0.4));
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  }

  /* Card border gradient removed - unnecessary for info screen/mobile */

  /* === COMPASS PANEL === */
  .area-compass {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(0.75rem, 1.5vw, 1.25rem);
    text-align: center;
    position: relative;
  }

  /* === THEME TOGGLE === */
  .theme-toggle {
    position: absolute;
    bottom: 0.75rem;
    left: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    border: 1px solid light-dark(oklch(80% 0.02 245 / 0.4), oklch(35% 0.02 245 / 0.4));
    border-radius: 50%;
    background: light-dark(oklch(95% 0.005 245 / 0.8), oklch(25% 0.015 245 / 0.8));
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }

  .theme-toggle:hover {
    background: light-dark(oklch(90% 0.01 245 / 0.8), oklch(30% 0.02 245 / 0.8));
    border-color: var(--color-primary);
    transform: scale(1.1);
  }

  .theme-toggle:active {
    transform: scale(0.95);
  }

  .theme-toggle-icon {
    font-size: 1.1rem;
    line-height: 1;
  }

  /* Station header with info and live indicator */
  .station-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    width: 100%;
    gap: 1rem;
  }

  .station-info {
    flex: 1;
    text-align: left;
  }

  .station-info h1 {
    font-family: var(--font-display);
    font-size: clamp(1.5rem, 3vw, 2rem);
    font-weight: 800;
    color: var(--color-primary);
    letter-spacing: 0.02em;
    text-transform: uppercase;
    line-height: 1.2;
    margin: 0;
  }

  .station-details {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-block-start: 0.5rem;
    font-size: 0.875rem;
    flex-wrap: wrap;
  }

  .station-type {
    background: light-dark(oklch(0.5 0.1 240), oklch(0.4 0.12 240));
    color: white;
    padding: 0.125rem 0.5rem;
    border-radius: 0.25rem;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    font-family: var(--font-display);
  }

  .station-distance {
    font-family: var(--font-mono);
    color: light-dark(oklch(0.6 0.05 240), oklch(0.7 0.05 240));
    font-size: 0.875rem;
    font-weight: 500;
  }

  .station-distance.warning {
    color: light-dark(oklch(0.65 0.15 60), oklch(0.75 0.15 60));
    font-weight: 600;
  }

  .distance-warning-icon {
    font-size: 1.125rem;
    animation: pulse 2s ease-in-out infinite;
    cursor: help;
  }

  .area-compass h1 {
    font-family: var(--font-display);
    font-size: clamp(1.5rem, 3vw, 2rem);
    font-weight: 800;
    color: var(--color-primary);
    letter-spacing: 0.02em;
    text-transform: uppercase;
    line-height: 1.2;
    margin-block-end: -0.5rem;
  }

  .compass-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(0.5rem, 2vw, 1rem);
  }

  .area-compass svg {
    width: clamp(240px, 70vw, 380px);
    height: clamp(240px, 70vw, 380px);
    margin-inline: auto;
    filter: drop-shadow(0 4px 12px oklch(45% 0.15 245 / 0.15));
  }

  .compass-direction {
    text-align: center;
    font-weight: 800;
    font-size: clamp(1rem, 3vw, 1.3rem);
    color: var(--color-primary);
    font-family: var(--font-display);
    letter-spacing: 0.1em;
    padding-inline: clamp(0.5rem, 2vw, 1rem);
  }

  /* === WIND DISPLAY (in compass panel) === */
  .wind-display {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: clamp(0.75rem, 2vw, 1rem);
    text-align: center;
  }

  .wind-display > div {
    padding: 1rem;
    background: linear-gradient(
      135deg,
      var(--color-surface-dim),
      var(--color-surface)
    );
    border-radius: var(--radius-sm);
    border: 1px solid
      light-dark(oklch(90% 0.01 245 / 0.3), oklch(30% 0.02 245 / 0.3));
  }

  /* === STAT BOXES === */
  .area-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: clamp(0.5rem, 1.5vw, 0.75rem);
    align-content: start;
  }

  .stat-box {
    background: linear-gradient(
      135deg,
      var(--color-surface-dim) 0%,
      var(--color-surface) 100%
    );
    border-radius: var(--radius-sm);
    padding: clamp(0.6rem, 1.5vw, 0.85rem);
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    border: 1px solid
      light-dark(oklch(90% 0.01 245 / 0.6), oklch(30% 0.02 245 / 0.6));
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    overflow: hidden;
  }

  /* Stat-box hover effects removed - unnecessary for info screen/mobile */

  .label {
    font-size: clamp(0.65rem, 1.2vw, 0.75rem);
    font-weight: 600;
    color: light-dark(oklch(45% 0.03 245), oklch(72% 0.03 245));
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-family: var(--font-display);
    line-height: 1.2;
  }

  .value-big {
    font-size: clamp(1.3rem, 2.5vw, 1.7rem);
    font-weight: 800;
    color: var(--color-text);
    font-family: var(--font-mono);
    letter-spacing: -0.02em;
    line-height: 1;
  }

  .value-huge {
    font-size: clamp(2rem, 7vw, 4.5rem);
    font-weight: 800;
    color: var(--color-text);
    font-family: var(--font-mono);
    line-height: 1;
    letter-spacing: -0.03em;
    background: linear-gradient(
      135deg,
      var(--color-primary-dim),
      var(--color-primary)
    );
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
  }

  /* === TEMPERATURE BOX === */
  .temp-box {
    min-width: 160px;
    container-type: inline-size;
  }

  @container (max-width: 480px) {
    .temp-box {
      grid-column: 1 / -1;
    }
  }

  .temp-values {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
  }

  .temp-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    padding: 0.15rem 0.35rem;
    border-radius: 6px;
    background: light-dark(
      oklch(96% 0.005 245 / 0.5),
      oklch(25% 0.015 245 / 0.5)
    );
  }

  .temp-alt {
    font-size: clamp(0.65rem, 1.2vw, 0.75rem);
    color: var(--color-text-muted);
    font-weight: 600;
    font-family: var(--font-display);
    line-height: 1.2;
  }

  .temp-val {
    font-size: clamp(0.85rem, 1.7vw, 1.05rem);
    font-weight: 800;
    color: var(--color-text);
    font-family: var(--font-mono);
    line-height: 1.2;
  }

  /* === HIGH WINDS TABLE === */
  .area-table {
    overflow: hidden;
    background: light-dark(
      linear-gradient(
        180deg,
        oklch(98% 0.005 245) 0%,
        oklch(96% 0.01 245) 100%
      ),
      linear-gradient(180deg, oklch(22% 0.015 245) 0%, oklch(20% 0.02 245) 100%)
    );
  }

  .wind-table-container {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-sm);
  }

  /* Custom scrollbar */
  .wind-table-container::-webkit-scrollbar {
    height: 10px;
  }

  .wind-table-container::-webkit-scrollbar-track {
    background: linear-gradient(
      90deg,
      var(--color-surface-dim),
      var(--color-surface),
      var(--color-surface-dim)
    );
    border-radius: 5px;
  }

  .wind-table-container::-webkit-scrollbar-thumb {
    background: linear-gradient(
      90deg,
      var(--color-primary-dim),
      var(--color-primary),
      var(--color-primary-bright)
    );
    border-radius: 5px;
    box-shadow: 0 2px 8px
      light-dark(oklch(45% 0.15 245 / 0.3), oklch(15% 0.15 245 / 0.5));
  }

  table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 4px;
    font-size: clamp(0.8rem, 1.5vw, 0.95rem);
    table-layout: auto;
  }

  .high-winds-table th:first-child,
  .high-winds-table td:first-child {
    min-width: 85px;
    max-width: 120px;
  }

  th,
  td {
    padding: clamp(0.5rem, 1.3vw, 0.75rem);
    text-align: center;
  }

  th {
    background: linear-gradient(
      135deg,
      var(--color-primary-dim),
      var(--color-primary),
      var(--color-primary-bright)
    );
    color: white;
    font-weight: 800;
    font-family: var(--font-display);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: clamp(0.7rem, 1.4vw, 0.8rem);
    position: sticky;
    top: 0;
    z-index: 10;
    border-radius: 10px;
    box-shadow:
      0 2px 8px oklch(45% 0.15 245 / 0.2),
      inset 0 1px 0 oklch(85% 0.08 245 / 0.3);
    border: none;
  }

  th:first-child {
    text-align: left;
    padding-left: clamp(0.75rem, 2vw, 1.25rem);
  }

  td:first-child {
    text-align: left;
    padding-left: clamp(0.75rem, 2vw, 1.25rem);
  }

  td {
    background: var(--color-surface);
    border: 1px solid
      light-dark(oklch(92% 0.005 245 / 0.3), oklch(28% 0.015 245 / 0.3));
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  }

  /* Altitude row gradients */
  .high-winds-table tbody tr td:first-child {
    position: relative;
    font-size: clamp(0.85rem, 1.6vw, 1rem);
    font-weight: 800;
    letter-spacing: 0.02em;
  }

  .high-winds-table tbody tr:nth-child(1) td:first-child {
    background: linear-gradient(
      90deg,
      light-dark(oklch(88% 0.1 245 / 0.2), oklch(28% 0.1 245 / 0.3)) 0%,
      light-dark(oklch(92% 0.08 245 / 0.1), oklch(25% 0.08 245 / 0.15)) 40%,
      transparent 70%
    );
    color: light-dark(oklch(35% 0.08 245), oklch(75% 0.08 245));
  }

  .high-winds-table tbody tr:nth-child(2) td:first-child {
    background: linear-gradient(
      90deg,
      light-dark(oklch(90% 0.08 240 / 0.18), oklch(26% 0.08 240 / 0.25)) 0%,
      light-dark(oklch(94% 0.06 240 / 0.09), oklch(24% 0.06 240 / 0.12)) 40%,
      transparent 70%
    );
    color: light-dark(oklch(37% 0.07 240), oklch(73% 0.07 240));
  }

  .high-winds-table tbody tr:nth-child(3) td:first-child {
    background: linear-gradient(
      90deg,
      light-dark(oklch(92% 0.06 235 / 0.15), oklch(24% 0.06 235 / 0.2)) 0%,
      light-dark(oklch(95% 0.04 235 / 0.08), oklch(23% 0.04 235 / 0.1)) 40%,
      transparent 70%
    );
    color: light-dark(oklch(40% 0.06 235), oklch(70% 0.06 235));
  }

  .high-winds-table tbody tr:nth-child(4) td:first-child {
    background: linear-gradient(
      90deg,
      light-dark(oklch(94% 0.04 230 / 0.12), oklch(22% 0.04 230 / 0.15)) 0%,
      light-dark(oklch(96% 0.02 230 / 0.06), oklch(22% 0.02 230 / 0.08)) 40%,
      transparent 70%
    );
    color: light-dark(oklch(42% 0.05 230), oklch(68% 0.05 230));
  }

  .high-winds-table tbody tr:nth-child(5) td:first-child {
    background: linear-gradient(
      90deg,
      light-dark(oklch(96% 0.02 225 / 0.1), oklch(20% 0.02 225 / 0.12)) 0%,
      light-dark(oklch(97% 0.01 225 / 0.05), oklch(21% 0.01 225 / 0.06)) 40%,
      transparent 70%
    );
    color: light-dark(oklch(45% 0.04 225), oklch(65% 0.04 225));
  }

  /* Current hour highlight */
  .current-hour-cell {
    background: light-dark(oklch(96% 0.03 245), oklch(20% 0.03 245)) !important;
    /* box-shadow: 0 2px 8px oklch(45% 0.15 245 / 0.12); */
    /* border: 2px solid oklch(70% 0.12 245 / 0.35) !important; DISABLED: FOR TEST*/
  }

  .current-hour-cell.wind-cell-empty {
    background: none !important;
  }

  /* === WIND SAFETY COLOR SYSTEM === */
  .wind-safe {
    background: light-dark(oklch(93% 0.08 145), oklch(25% 0.1 145));
    border: 1px solid
      light-dark(oklch(80% 0.1 145 / 0.3), oklch(35% 0.12 145 / 0.5));
  }

  .wind-caution {
    background: light-dark(oklch(94% 0.1 90), oklch(28% 0.12 90));
    border: 1px solid
      light-dark(oklch(80% 0.12 90 / 0.3), oklch(38% 0.14 90 / 0.5));
  }

  .wind-warning {
    background: light-dark(oklch(90% 0.14 55), oklch(32% 0.16 55));
    border: 1px solid
      light-dark(oklch(75% 0.16 55 / 0.4), oklch(42% 0.18 55 / 0.6));
  }

  .wind-danger {
    background: light-dark(oklch(87% 0.16 25), oklch(35% 0.18 25));
    border: 1px solid
      light-dark(oklch(70% 0.18 25 / 0.5), oklch(45% 0.2 25 / 0.7));
  }

  /* === WIND CELL STYLING === */
  .wind-cell {
    position: relative;
    padding: clamp(0.6rem, 1.6vw, 1rem);
    border-radius: 12px;
    text-align: center;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    overflow: hidden;
    box-shadow: 0 2px 6px
      light-dark(oklch(25% 0.02 245 / 0.08), oklch(5% 0.02 245 / 0.3));
  }

  .wind-cell-content {
    display: flex;
    flex-direction: column;
    gap: clamp(0.25rem, 0.9vw, 0.4rem);
    align-items: center;
    position: relative;
    z-index: 2;
  }

  .wind-speed-hero {
    font-family: var(--font-mono);
    font-size: clamp(1.4rem, 3.2vw, 1.85rem);
    font-weight: 600;
    line-height: 0.9;
    letter-spacing: -0.03em;
    background: linear-gradient(135deg, var(--color-text), oklch(35% 0.04 245));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 2px 8px oklch(25% 0.02 245 / 0.1);
  }

  .surface-row .wind-speed-hero {
    font-size: clamp(0.8rem, 1.1vw, 0.9rem);
    font-weight: 500;
  }

  .wind-direction-compact {
    font-family: var(--font-mono);
    font-size: clamp(0.7rem, 1.3vw, 0.85rem);
    font-weight: 700;
    color: light-dark(oklch(35% 0.04 245), oklch(75% 0.04 245));
  }

  /* === CLOUD BORDERS === */
  .cloud-frame {
    position: absolute;
    inset: 0;
    border-radius: 10px;
    pointer-events: none;
    z-index: 3;
    animation: cloudPulse 3s ease-in-out infinite;
  }

  .cloud-1 {
    box-shadow:
      inset 0 0 0 2px
        light-dark(oklch(90% 0.01 240 / 0.3), oklch(30% 0.01 240 / 0.4)),
      inset 0 0 10px
        light-dark(oklch(90% 0.01 240 / 0.1), oklch(30% 0.01 240 / 0.2));
  }

  .cloud-2 {
    box-shadow:
      inset 0 0 0 1px light-dark(oklch(50% 0.02 240), oklch(55% 0.02 240)),
      inset 0 0 20px light-dark(oklch(60% 0.02 240), oklch(45% 0.02 240));
  }

  .cloud-3 {
    box-shadow:
      inset 0 0 0 1px light-dark(oklch(10% 0.05 240), oklch(75% 0.05 240)),
      inset 0 0 20px light-dark(oklch(10% 0.05 240), oklch(75% 0.05 240));
  }

  /* === DIRECTIONAL GRADIENT === */
  .dir-indicator {
    position: absolute;
    inset: 0;
    border-radius: 12px;
    z-index: 1;
    pointer-events: none;
    background: conic-gradient(
      from calc(var(--wind-angle, 0deg) - 90deg) at 50% 50%,
      transparent 0deg,
      var(--dir-color) 40deg,
      var(--dir-color-bright) 90deg,
      var(--dir-color) 140deg,
      transparent 180deg,
      transparent 360deg
    );
    opacity: 0.9;
    transition: opacity 0.3s ease;
  }

  .wind-safe .dir-indicator {
    --dir-color: oklch(75% 0.18 145 / 0.3);
    --dir-color-bright: oklch(80% 0.2 145 / 0.4);
  }

  .wind-caution .dir-indicator {
    --dir-color: oklch(80% 0.16 90 / 0.3);
    --dir-color-bright: oklch(85% 0.18 90 / 0.4);
  }

  .wind-warning .dir-indicator {
    --dir-color: oklch(70% 0.22 50 / 0.45);
    --dir-color-bright: oklch(75% 0.24 50 / 0.55);
  }

  .wind-danger .dir-indicator {
    --dir-color: oklch(50% 0.26 25 / 0.55);
    --dir-color-bright: oklch(55% 0.28 25 / 0.65);
  }

  /* Empty cells */
  .wind-cell-empty {
    padding: clamp(0.6rem, 1.6vw, 1rem);
    text-align: center;
    color: var(--color-text-dim);
    font-family: var(--font-mono);
    background: light-dark(
      oklch(96% 0.005 245 / 0.3),
      oklch(24% 0.015 245 / 0.3)
    );
    min-width: 60px;
  }

  .sfc-empty {
    background: light-dark(
      oklch(94% 0.01 245 / 0.2),
      oklch(22% 0.02 245 / 0.2)
    ) !important;
    color: var(--color-text-dim);
    opacity: 0.5;
  }

  /* === TIME-BASED STYLING === */
  .time-current-header {
    background: linear-gradient(
      135deg,
      var(--color-primary),
      var(--color-primary-bright)
    ) !important;
    color: white !important;
    box-shadow:
      0 4px 16px oklch(45% 0.15 245 / 0.35),
      0 0 20px oklch(58% 0.18 245 / 0.3),
      inset 0 1px 0 oklch(85% 0.08 245 / 0.4);
    animation: headerPulse 3s ease-in-out infinite;
  }

  .time-current-cell {
    box-shadow:
      0 0 0 4px var(--color-primary),
      0 6px 16px
        light-dark(oklch(45% 0.15 245 / 0.45), oklch(15% 0.15 245 / 0.6)) !important;
    transform: scale(1.04);
    z-index: 5;
  }

  .time-past-cell {
    opacity: 0.45;
    filter: grayscale(0.4) brightness(0.95);
  }

  /* === LAYOUT: Historia + Now + Forecast === */
  .history-header {
    background: light-dark(
      linear-gradient(135deg, oklch(60% 0.08 245), oklch(65% 0.1 245)),
      linear-gradient(135deg, oklch(35% 0.08 245), oklch(40% 0.1 245))
    ) !important;
    opacity: 0.85;
  }

  .high-winds-table tbody tr td:nth-child(2) {
    opacity: 0.6;
  }

  .now-header {
    background: linear-gradient(
      135deg,
      var(--color-primary),
      var(--color-primary-bright)
    ) !important;
    color: white !important;
    border-left: 3px solid var(--color-primary-dim);
    border-right: 3px solid var(--color-primary-dim);
  }

  .high-winds-table tbody tr.surface-row .sfc-empty {
    visibility: visible !important;
    display: table-cell !important;
  }

  /* === SURFACE FORECAST ROW === */
  .surface-row {
    border-top: 3px solid var(--color-primary);
  }

  .surface-label {
    vertical-align: middle;
    line-height: 1.3;
    background: linear-gradient(
      90deg,
      light-dark(oklch(92% 0.05 200 / 0.15), oklch(25% 0.05 200 / 0.2)) 0%,
      light-dark(oklch(95% 0.03 200 / 0.08), oklch(23% 0.03 200 / 0.12)) 50%,
      transparent 100%
    ) !important;
    color: light-dark(oklch(35% 0.06 200), oklch(70% 0.06 200));
    text-align: left !important;
    width: 85px !important;
    min-width: 85px !important;
    max-width: 85px !important;
    padding-right: 0.5rem !important;
  }

  .surface-label-sub {
    display: block;
    font-size: clamp(0.6rem, 1.1vw, 0.7rem);
    font-weight: 500;
    color: var(--color-text-muted);
    text-transform: none;
    font-family: var(--font-body);
    margin-top: 0.2rem;
    opacity: 0.8;
  }

  .surface-cell {
    background: linear-gradient(
      135deg,
      light-dark(oklch(95% 0.02 245 / 0.6), oklch(23% 0.02 245 / 0.6)),
      light-dark(oklch(97% 0.01 245 / 0.5), oklch(21% 0.01 245 / 0.5))
    );
    position: relative;
  }

  .surface-cell.wind-safe {
    box-shadow:
      inset 0 0 0 2px
        light-dark(oklch(75% 0.18 142 / 0.35), oklch(40% 0.18 142 / 0.5)),
      inset 0 -3px 8px
        light-dark(oklch(75% 0.16 142 / 0.1), oklch(40% 0.16 142 / 0.2));
  }

  .surface-cell.wind-caution {
    box-shadow:
      inset 0 0 0 2px
        light-dark(oklch(75% 0.2 85 / 0.35), oklch(45% 0.2 85 / 0.5)),
      inset 0 -3px 8px
        light-dark(oklch(75% 0.18 85 / 0.1), oklch(45% 0.18 85 / 0.2));
  }

  .surface-cell.wind-warning {
    box-shadow:
      inset 0 0 0 2px
        light-dark(oklch(70% 0.22 50 / 0.35), oklch(50% 0.22 50 / 0.5)),
      inset 0 -3px 8px
        light-dark(oklch(70% 0.2 50 / 0.12), oklch(50% 0.2 50 / 0.2));
  }

  .surface-cell.wind-danger {
    box-shadow:
      inset 0 0 0 2px
        light-dark(oklch(65% 0.24 25 / 0.35), oklch(55% 0.24 25 / 0.5)),
      inset 0 -3px 8px
        light-dark(oklch(65% 0.22 25 / 0.15), oklch(55% 0.22 25 / 0.25));
  }

  /* === LIVE BADGE === */
  .live-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    background: light-dark(oklch(0.5 0.1 25), oklch(0.4 0.12 25));
    color: white;
    padding: 0.125rem 0.5rem;
    border-radius: 0.25rem;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    font-family: var(--font-display);
  }

  .live-dot {
    width: 6px;
    height: 6px;
    background: white;
    border-radius: 50%;
    animation: livePulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  }

  /* === STALE BADGE === */
  .stale-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    background: var(--color-accent-warn);
    color: light-dark(oklch(0.2 0.05 65), oklch(0.95 0.02 65));
    padding: 0.125rem 0.5rem;
    border-radius: 0.25rem;
    font-weight: 600;
    font-size: 0.75rem;
    letter-spacing: 0.02em;
    font-family: var(--font-mono);
    box-shadow: 0 2px 6px oklch(0.5 0.15 65 / 0.3);
  }
}

/* ================================================================
   @layer utilities - Loading, Error, Accessibility
   ================================================================ */
@layer utilities {
  /* === LOADING & ERROR === */
  .loading {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem 2rem;
    color: white;
    font-size: clamp(1rem, 2vw, 1.5rem);
    font-family: var(--font-display);
    font-weight: 600;
    letter-spacing: 0.04em;
    animation: pulse 2s ease-in-out infinite;
  }

  .loading-indicator {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    min-height: 50dvh;
    color: white;
  }

  .loading-indicator p {
    font-size: clamp(1rem, 2vw, 1.5rem);
    font-family: var(--font-display);
    font-weight: 600;
    letter-spacing: 0.04em;
    animation: pulse 2s ease-in-out infinite;
  }

  @keyframes spin {
    from {
      transform: rotate(0deg);
    }
    to {
      transform: rotate(360deg);
    }
  }

  .spinner {
    width: 48px;
    height: 48px;
    border: 4px solid
      light-dark(oklch(75% 0.08 245 / 0.2), oklch(35% 0.08 245 / 0.3));
    border-top-color: var(--color-primary-bright);
    border-radius: 50%;
    animation: spin 1s linear infinite;
  }

  .error {
    background: light-dark(
      linear-gradient(
        135deg,
        oklch(92% 0.1 25 / 0.9),
        oklch(95% 0.08 25 / 0.8)
      ),
      linear-gradient(135deg, oklch(35% 0.12 25 / 0.9), oklch(30% 0.1 25 / 0.8))
    );
    color: light-dark(oklch(35% 0.15 25), oklch(85% 0.15 25));
    padding: 1.25rem;
    border-radius: var(--radius-sm);
    margin-block-end: 1rem;
    border: 1px solid
      light-dark(oklch(75% 0.15 25 / 0.4), oklch(45% 0.18 25 / 0.6));
    font-weight: 500;
  }

  /* === ACCESSIBILITY === */
  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
      scroll-behavior: auto !important;
    }

    .cloud-frame {
      animation: none !important;
    }
  }

  @media (prefers-contrast: high) {
    .wind-cell {
      border: 2px solid currentColor;
    }

    .wind-speed-hero {
      -webkit-text-fill-color: currentColor;
    }
  }
}
