@layer base, components, utilities;

:root {
  --bg-light: #ffffff;
  --bg-dark: #141416;
  --surface-light: #ffffff;
  --surface-dark: #1c1c1e;
  --toolbar-light: #f5f5f7;
  --toolbar-dark: #262629;
  --gutter-light: #fbfbfd;
  --gutter-dark: #18181a;
  --raised-light: #f2f2f7;
  --raised-dark: #2c2c2e;
  --seg-active-light: #ffffff;
  --seg-active-dark: #48484a;
  --border-light: #d1d1d6;
  --border-dark: #38383a;
  --grid-light: #efeff4;
  --grid-dark: #2c2c2e;
  --control-border-light: #8e8e93;
  --control-border-dark: #636366;
  --text-light: #1d1d1f;
  --text-dark: #f5f5f7;
  --text-sec-light: #515154;
  --text-sec-dark: #aeaeb2;
  --text-muted-light: #6e6e73;
  --text-muted-dark: #98989d;
  --apple-red-light: #d70015;
  --apple-red-dark: #ff453a;
  --apple-red-dot-light: #ff3b30;
  --apple-red-dot-dark: #ff453a;
  --apple-blue-light: #0066cc;
  --apple-blue-dark: #0a84ff;
  --primary-btn-light: #1c1c1e;
  --primary-btn-dark: #f5f5f7;
  --primary-btn-text-light: #ffffff;
  --primary-btn-text-dark: #1c1c1e;
  --primary-btn-hover-light: #333336;
  --primary-btn-hover-dark: #e5e5ea;

  --ev-blue-bg-light: rgba(0, 122, 255, 0.12);
  --ev-blue-bg-dark: rgba(10, 132, 255, 0.22);
  --ev-blue-text-light: #004999;
  --ev-blue-text-dark: #a6d1ff;
  --ev-green-bg-light: rgba(52, 199, 89, 0.14);
  --ev-green-bg-dark: rgba(48, 209, 88, 0.22);
  --ev-green-text-light: #145e2b;
  --ev-green-text-dark: #a5f3b8;
  --ev-purple-bg-light: rgba(175, 82, 222, 0.13);
  --ev-purple-bg-dark: rgba(191, 90, 242, 0.22);
  --ev-purple-text-light: #651d8a;
  --ev-purple-text-dark: #e6bdfb;
  --ev-amber-bg-light: rgba(255, 149, 0, 0.16);
  --ev-amber-bg-dark: rgba(255, 159, 10, 0.22);
  --ev-amber-text-light: #7a4100;
  --ev-amber-text-dark: #ffd699;
  --ev-sky-bg-light: rgba(14, 165, 233, 0.14);
  --ev-sky-bg-dark: rgba(56, 189, 248, 0.22);
  --ev-sky-text-light: #07517a;
  --ev-sky-text-dark: #bae6fd;
  --ev-now-bg-light: rgba(88, 86, 214, 0.13);
  --ev-now-bg-dark: rgba(94, 92, 230, 0.24);
  --ev-now-text-light: #363487;
  --ev-now-text-dark: #cbcaff;
  --ev-rain-bg-light: rgba(0, 113, 164, 0.15);
  --ev-rain-bg-dark: rgba(50, 173, 230, 0.24);
  --ev-rain-text-light: #004e73;
  --ev-rain-text-dark: #b3e5fc;
  --ev-teal-bg-light: rgba(13, 148, 136, 0.14);
  --ev-teal-bg-dark: rgba(45, 212, 191, 0.2);
  --ev-teal-text-light: #0f524c;
  --ev-teal-text-dark: #99f6e4;
  --ev-coral-bg-light: rgba(224, 90, 43, 0.14);
  --ev-coral-bg-dark: rgba(251, 146, 60, 0.22);
  --ev-coral-text-light: #7c2d12;
  --ev-coral-text-dark: #fed7aa;

  /* Active semantic tokens (fallback for browsers without light-dark()) */
  --bg: var(--bg-light);
  --surface: var(--surface-light);
  --toolbar: var(--toolbar-light);
  --gutter: var(--gutter-light);
  --raised: var(--raised-light);
  --seg-active: var(--seg-active-light);
  --border: var(--border-light);
  --grid: var(--grid-light);
  --control-border: var(--control-border-light);
  --text: var(--text-light);
  --text-sec: var(--text-sec-light);
  --text-muted: var(--text-muted-light);
  --apple-red: var(--apple-red-light);
  --apple-red-dot: var(--apple-red-dot-light);
  --apple-blue: var(--apple-blue-light);
  --primary-btn: var(--primary-btn-light);
  --primary-btn-text: var(--primary-btn-text-light);
  --primary-btn-hover: var(--primary-btn-hover-light);
  --ev-blue-bg: var(--ev-blue-bg-light);
  --ev-blue-text: var(--ev-blue-text-light);
  --ev-green-bg: var(--ev-green-bg-light);
  --ev-green-text: var(--ev-green-text-light);
  --ev-purple-bg: var(--ev-purple-bg-light);
  --ev-purple-text: var(--ev-purple-text-light);
  --ev-amber-bg: var(--ev-amber-bg-light);
  --ev-amber-text: var(--ev-amber-text-light);
  --ev-sky-bg: var(--ev-sky-bg-light);
  --ev-sky-text: var(--ev-sky-text-light);
  --ev-now-bg: var(--ev-now-bg-light);
  --ev-now-text: var(--ev-now-text-light);
  --ev-rain-bg: var(--ev-rain-bg-light);
  --ev-rain-text: var(--ev-rain-text-light);
  --ev-teal-bg: var(--ev-teal-bg-light);
  --ev-teal-text: var(--ev-teal-text-light);
  --ev-coral-bg: var(--ev-coral-bg-light);
  --ev-coral-text: var(--ev-coral-text-light);
  --shadow-window: 0 6px 24px rgba(0, 0, 0, 0.07), 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-popover: 0 12px 32px rgba(0, 0, 0, 0.14), 0 2px 6px rgba(0, 0, 0, 0.06);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --font-sans: -apple-system, BlinkMacSystemFont, Helvetica, Geneva, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  color-scheme: light dark;
  accent-color: var(--apple-blue);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--bg-dark);
    --surface: var(--surface-dark);
    --toolbar: var(--toolbar-dark);
    --gutter: var(--gutter-dark);
    --raised: var(--raised-dark);
    --seg-active: var(--seg-active-dark);
    --border: var(--border-dark);
    --grid: var(--grid-dark);
    --control-border: var(--control-border-dark);
    --text: var(--text-dark);
    --text-sec: var(--text-sec-dark);
    --text-muted: var(--text-muted-dark);
    --apple-red: var(--apple-red-dark);
    --apple-red-dot: var(--apple-red-dot-dark);
    --apple-blue: var(--apple-blue-dark);
    --primary-btn: var(--primary-btn-dark);
    --primary-btn-text: var(--primary-btn-text-dark);
    --primary-btn-hover: var(--primary-btn-hover-dark);
    --ev-blue-bg: var(--ev-blue-bg-dark);
    --ev-blue-text: var(--ev-blue-text-dark);
    --ev-green-bg: var(--ev-green-bg-dark);
    --ev-green-text: var(--ev-green-text-dark);
    --ev-purple-bg: var(--ev-purple-bg-dark);
    --ev-purple-text: var(--ev-purple-text-dark);
    --ev-amber-bg: var(--ev-amber-bg-dark);
    --ev-amber-text: var(--ev-amber-text-dark);
    --ev-sky-bg: var(--ev-sky-bg-dark);
    --ev-sky-text: var(--ev-sky-text-dark);
    --ev-now-bg: var(--ev-now-bg-dark);
    --ev-now-text: var(--ev-now-text-dark);
    --ev-rain-bg: var(--ev-rain-bg-dark);
    --ev-rain-text: var(--ev-rain-text-dark);
    --ev-teal-bg: var(--ev-teal-bg-dark);
    --ev-teal-text: var(--ev-teal-text-dark);
    --ev-coral-bg: var(--ev-coral-bg-dark);
    --ev-coral-text: var(--ev-coral-text-dark);
    --shadow-window: none;
    --shadow-popover: 0 14px 36px rgba(0, 0, 0, 0.55);
  }
}

@supports (color: light-dark(white, black)) {
  :root {
    --bg: light-dark(var(--bg-light), var(--bg-dark));
    --surface: light-dark(var(--surface-light), var(--surface-dark));
    --toolbar: light-dark(var(--toolbar-light), var(--toolbar-dark));
    --gutter: light-dark(var(--gutter-light), var(--gutter-dark));
    --raised: light-dark(var(--raised-light), var(--raised-dark));
    --seg-active: light-dark(var(--seg-active-light), var(--seg-active-dark));
    --border: light-dark(var(--border-light), var(--border-dark));
    --grid: light-dark(var(--grid-light), var(--grid-dark));
    --control-border: light-dark(var(--control-border-light), var(--control-border-dark));
    --text: light-dark(var(--text-light), var(--text-dark));
    --text-sec: light-dark(var(--text-sec-light), var(--text-sec-dark));
    --text-muted: light-dark(var(--text-muted-light), var(--text-muted-dark));
    --apple-red: light-dark(var(--apple-red-light), var(--apple-red-dark));
    --apple-red-dot: light-dark(var(--apple-red-dot-light), var(--apple-red-dot-dark));
    --apple-blue: light-dark(var(--apple-blue-light), var(--apple-blue-dark));
    --primary-btn: light-dark(var(--primary-btn-light), var(--primary-btn-dark));
    --primary-btn-text: light-dark(var(--primary-btn-text-light), var(--primary-btn-text-dark));
    --primary-btn-hover: light-dark(var(--primary-btn-hover-light), var(--primary-btn-hover-dark));
    --ev-blue-bg: light-dark(var(--ev-blue-bg-light), var(--ev-blue-bg-dark));
    --ev-blue-text: light-dark(var(--ev-blue-text-light), var(--ev-blue-text-dark));
    --ev-green-bg: light-dark(var(--ev-green-bg-light), var(--ev-green-bg-dark));
    --ev-green-text: light-dark(var(--ev-green-text-light), var(--ev-green-text-dark));
    --ev-purple-bg: light-dark(var(--ev-purple-bg-light), var(--ev-purple-bg-dark));
    --ev-purple-text: light-dark(var(--ev-purple-text-light), var(--ev-purple-text-dark));
    --ev-amber-bg: light-dark(var(--ev-amber-bg-light), var(--ev-amber-bg-dark));
    --ev-amber-text: light-dark(var(--ev-amber-text-light), var(--ev-amber-text-dark));
    --ev-sky-bg: light-dark(var(--ev-sky-bg-light), var(--ev-sky-bg-dark));
    --ev-sky-text: light-dark(var(--ev-sky-text-light), var(--ev-sky-text-dark));
    --ev-now-bg: light-dark(var(--ev-now-bg-light), var(--ev-now-bg-dark));
    --ev-now-text: light-dark(var(--ev-now-text-light), var(--ev-now-text-dark));
    --ev-rain-bg: light-dark(var(--ev-rain-bg-light), var(--ev-rain-bg-dark));
    --ev-rain-text: light-dark(var(--ev-rain-text-light), var(--ev-rain-text-dark));
    --ev-teal-bg: light-dark(var(--ev-teal-bg-light), var(--ev-teal-bg-dark));
    --ev-teal-text: light-dark(var(--ev-teal-text-light), var(--ev-teal-text-dark));
    --ev-coral-bg: light-dark(var(--ev-coral-bg-light), var(--ev-coral-bg-dark));
    --ev-coral-text: light-dark(var(--ev-coral-text-light), var(--ev-coral-text-dark));
  }
}

@layer base {
  body, div, main, section, header, footer, input, select, button, a, fieldset, ul, li, search {
    box-sizing: border-box;
  }

  body {
    font-family: var(--font-sans);
    margin: 0;
    padding: 0;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
  }

  a {
    color: var(--text);
  }

  :focus-visible {
    outline: 2px solid var(--apple-blue);
    outline-offset: 2px;
  }
}

@layer utilities {
  .visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }
}

@layer components {
  .centered {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: 94%;
    max-width: 48rem;
    margin: 0 auto;
    padding-block: clamp(1.75rem, 4.5vh, 3.5rem) clamp(2.5rem, 5.5vh, 4rem);
    text-align: center;
  }

  /* Header faithful to cwmoriarty.com restraint */
  .site-header {
    margin-bottom: clamp(1.25rem, 2.5vh, 1.75rem);
  }

  .site-header h1 {
    font-size: clamp(1.75rem, 1.45rem + 1.4vw, 2.25rem);
    font-weight: 500;
    margin: 0 0 0.375rem;
    letter-spacing: -0.02em;
    line-height: 1.15;
    text-wrap: balance;
  }

  .sun-toggle {
    background: none;
    border: none;
    font-size: inherit;
    line-height: 1;
    min-inline-size: 2rem;
    min-block-size: 2rem;
    padding: 0.125rem 0.25rem;
    border-radius: 0.375rem;
    cursor: pointer;
    vertical-align: baseline;
    transition: opacity 150ms var(--ease);
  }

  .sun-toggle:hover {
    opacity: 0.72;
  }

  .location-bar {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    font-size: 0.9375rem;
    color: var(--text-sec);
    margin: 0;
    position: relative;
  }

  .city-trigger {
    font-family: inherit;
    font-size: inherit;
    font-weight: 500;
    color: var(--text);
    background: transparent;
    border: none;
    border-bottom: 1.5px dashed var(--control-border);
    padding: 0.125rem 0.25rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    border-radius: 0.25rem 0.25rem 0 0;
    transition: background-color 140ms var(--ease), border-color 140ms var(--ease);
  }

  .city-trigger:hover {
    background: var(--raised);
    border-bottom-color: var(--apple-blue);
  }

  .city-trigger svg {
    color: var(--text-muted);
    flex-shrink: 0;
  }

  .locate-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-inline-size: 2rem;
    min-block-size: 2rem;
    padding: 0.25rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 0.375rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: background-color 140ms var(--ease), color 140ms var(--ease);
  }

  .locate-btn:hover {
    background: var(--raised);
    color: var(--text);
  }

  .station-subline {
    margin: 0.25rem 0 0;
    font-size: 0.8125rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
  }

  /* Inline Location / Station Search Combobox */
  .location-search-wrap {
    position: relative;
    width: 100%;
    max-width: 24rem;
    margin: 0.625rem auto 0;
    text-align: left;
  }

  .location-search-wrap[hidden] {
    display: none;
  }

  .search-input-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .search-input {
    flex: 1;
    min-width: 0;
    font: inherit;
    font-size: 1rem;
    min-block-size: 2.5rem;
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--control-border);
    border-radius: 0.5rem;
    background: var(--surface);
    color: var(--text);
  }

  .search-cancel-btn {
    font: inherit;
    font-size: 0.875rem;
    min-block-size: 2.5rem;
    padding: 0.375rem 0.75rem;
    background: var(--raised);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    cursor: pointer;
  }

  .search-cancel-btn:hover {
    background: var(--toolbar);
  }

  .search-results {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    z-index: 30;
    margin: 0;
    padding: 0.25rem;
    list-style: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.625rem;
    box-shadow: var(--shadow-popover);
    max-height: 16rem;
    overflow-y: auto;
  }

  .search-results[hidden] {
    display: none;
  }

  .search-option {
    padding: 0.5rem 0.625rem;
    border-radius: 0.375rem;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
  }

  .search-option:hover,
  .search-option[aria-selected="true"] {
    background: var(--raised);
  }

  .search-option-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
  }

  .search-option-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
  }

  .search-empty {
    padding: 0.625rem 0.75rem;
    font-size: 0.8125rem;
    color: var(--text-muted);
  }

  /* Direct webcal URL disclosure (toggled by Sun / Wave button) */
  .url-disclosure {
    max-width: 36rem;
    margin: 0.625rem auto 0.875rem;
    padding: 0.5rem;
    background: var(--toolbar);
    border: 1px solid var(--border);
    border-radius: 0.625rem;
  }

  .url-disclosure[hidden] {
    display: none;
  }

  .url-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  #webCal {
    flex: 1;
    min-width: 0;
    min-block-size: 2.25rem;
    padding: 0.375rem 0.625rem;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--control-border);
    border-radius: 0.375rem;
  }

  .copy-wrap {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
  }

  .copy-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    min-inline-size: 4.5rem;
    min-block-size: 2.25rem;
    padding: 0.375rem 0.75rem;
    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--control-border);
    border-radius: 0.375rem;
    cursor: pointer;
    transition: background-color 140ms var(--ease);
  }

  .copy-btn:hover {
    background: var(--raised);
  }

  .copy-btn .icon-check {
    display: none;
  }

  .copy-btn[data-copied] .icon-copy {
    display: none;
  }

  .copy-btn[data-copied] .icon-check {
    display: inline-block;
    color: var(--apple-blue);
  }

  .copy-status {
    font-size: 0.75rem;
    color: var(--text-muted);
    opacity: 0;
    transition: opacity 150ms var(--ease);
  }

  .copy-status:not(:empty) {
    opacity: 1;
  }

  .copy-status:empty {
    display: inline-block;
    width: 0;
    overflow: hidden;
  }

  /* Apple Calendar (macOS / iOS) Window */
  .apple-cal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    overflow: hidden;
    box-shadow: var(--shadow-window);
    text-align: left;
  }

  .cal-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background: var(--toolbar);
    border-bottom: 1px solid var(--border);
    gap: 0.5rem 0.75rem;
    flex-wrap: wrap;
  }

  .cal-toolbar-left {
    display: flex;
    align-items: center;
    gap: 0.625rem;
  }

  .traffic-lights {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
  }

  .tl {
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 50%;
  }

  .tl-red { background: #ff5f57; border: 0.5px solid rgba(0, 0, 0, 0.15); }
  .tl-yellow { background: #febc2e; border: 0.5px solid rgba(0, 0, 0, 0.15); }
  .tl-green { background: #28c840; border: 0.5px solid rgba(0, 0, 0, 0.15); }

  .cal-month-title {
    font-size: 0.9375rem;
    font-weight: 600;
    letter-spacing: 0;
    color: var(--text);
  }

  .cal-toolbar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
  }

  /* macOS Apple Calendar < Today > pager */
  .cal-nav-group {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    background: var(--surface);
    overflow: hidden;
  }

  .cal-nav-btn {
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 500;
    min-inline-size: 1.75rem;
    min-block-size: 1.625rem;
    padding: 0.125rem 0.5rem;
    background: transparent;
    color: var(--text);
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background-color 120ms var(--ease);
  }

  .cal-nav-btn:not(:last-child) {
    border-inline-end: 1px solid var(--border);
  }

  .cal-nav-btn:hover:not(:disabled) {
    background: var(--raised);
  }

  .cal-nav-btn:disabled {
    opacity: 0.38;
    cursor: default;
  }

  /* Native radio segmented control styled via :has(:checked) */
  .unit-segment {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    background: var(--raised);
    padding: 2px;
    margin: 0;
    gap: 2px;
  }

  .unit-segment label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-inline-size: 1.875rem;
    min-block-size: 1.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    padding: 0.125rem 0.5rem;
    border-radius: 0.25rem;
    color: var(--text-sec);
    cursor: pointer;
    user-select: none;
    transition: background-color 140ms var(--ease), color 140ms var(--ease);
  }

  .unit-segment label:has(input:checked) {
    background: var(--seg-active);
    color: var(--text);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
  }

  .unit-segment label:has(input:focus-visible) {
    outline: 2px solid var(--apple-blue);
    outline-offset: 1px;
  }

  .cal-sync-status {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.75rem;
    color: var(--apple-red);
    font-variant-numeric: tabular-nums;
  }

  .cal-sync-status:not([data-state="offline"]) {
    display: none;
  }

  .sync-dot {
    width: 0.4375rem;
    height: 0.4375rem;
    border-radius: 50%;
    background: var(--apple-red-dot);
    flex-shrink: 0;
  }

  /* Day Header Row */
  .cal-header-row {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
  }

  .cal-gutter-col {
    width: 3.5rem;
    flex-shrink: 0;
    border-inline-end: 1px solid var(--grid);
    background: var(--gutter);
  }

  .cal-day-header {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.5rem 0.25rem;
  }

  .cal-day-header:not(:last-child) {
    border-inline-end: 1px solid var(--grid);
  }

  .day-name {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-muted);
  }

  .day-header-today .day-name {
    color: var(--apple-red);
    font-weight: 600;
  }

  .day-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.625rem;
    height: 1.625rem;
    font-size: 0.8125rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    border-radius: 50%;
  }

  .day-number.active-day {
    background: var(--apple-red-dot);
    color: #ffffff;
    font-weight: 600;
  }

  /* Apple Calendar All-Day Strip */
  .cal-allday-row {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    min-block-size: 1.875rem;
  }

  .allday-gutter {
    width: 3.5rem;
    flex-shrink: 0;
    border-inline-end: 1px solid var(--grid);
    background: var(--gutter);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-inline-end: 0.375rem;
    font-size: 0.6875rem;
    color: var(--text-muted);
  }

  .allday-cell {
    flex: 1;
    min-width: 0;
    padding: 0.25rem 0.375rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .allday-cell:not(:last-child) {
    border-inline-end: 1px solid var(--grid);
  }

  /* Hourly Grid Body */
  .cal-body {
    display: flex;
    height: 20.5rem;
    position: relative;
  }

  .cal-time-gutter {
    width: 3.5rem;
    flex-shrink: 0;
    border-inline-end: 1px solid var(--grid);
    background: var(--gutter);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 0.5rem 0.5rem 0.5rem 0;
    user-select: none;
  }

  .time-slot-label {
    font-size: 0.6875rem;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
    text-align: right;
    line-height: 1;
  }

  .cal-days-grid {
    display: flex;
    flex: 1;
    position: relative;
  }

  .cal-day-col {
    flex: 1;
    position: relative;
    overflow: hidden;
  }

  .cal-day-col:not(:last-child) {
    border-inline-end: 1px solid var(--grid);
  }

  .grid-lines {
    position: absolute;
    inset: 0.875rem 0;
    pointer-events: none;
  }

  .grid-line {
    position: absolute;
    left: 0;
    right: 0;
    border-top: 1px solid var(--grid);
  }

  .now-line {
    position: absolute;
    left: 0;
    right: 0;
    border-top: 1.5px solid var(--apple-red-dot);
    z-index: 6;
    pointer-events: none;
  }

  .now-line::before {
    content: "";
    position: absolute;
    left: -3px;
    top: -4px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--apple-red-dot);
  }

  .events-layer {
    position: absolute;
    inset: 0.875rem 0.25rem;
  }

  .cal-event {
    position: absolute;
    border-radius: 0.25rem;
    padding: 0.25rem 0.375rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    line-height: 1.25;
    text-align: left;
    font-family: inherit;
    overflow: hidden;
  }

  .cal-event-lunch {
    background: var(--ev-blue-bg);
    border-inline-start: 3px solid #007aff;
    color: var(--ev-blue-text);
  }

  .cal-event-meeting {
    background: var(--ev-green-bg);
    border-inline-start: 3px solid #34c759;
    color: var(--ev-green-text);
  }

  .cal-event-dinner {
    background: var(--ev-purple-bg);
    border-inline-start: 3px solid #af52de;
    color: var(--ev-purple-text);
  }

  .cal-event-sunblock {
    border: none;
    border-inline-start: 3px solid #ff9500;
    background: var(--ev-amber-bg);
    color: var(--ev-amber-text);
    cursor: pointer;
    z-index: 2;
    transition: filter 120ms var(--ease);
  }

  .cal-event-sunblock:hover {
    filter: brightness(0.95);
  }

  .cal-event-sunblock[data-kind="cold"] {
    border-inline-start-color: #0284c7;
    background: var(--ev-sky-bg);
    color: var(--ev-sky-text);
  }

  .cal-event-sunblock[data-kind="now"] {
    border-inline-start-color: #5856d6;
    background: var(--ev-now-bg);
    color: var(--ev-now-text);
  }

  .cal-event-sunblock[data-kind="precip"] {
    border-inline-start-color: #0071a4;
    background: var(--ev-rain-bg);
    color: var(--ev-rain-text);
  }

  .cal-event-sunblock[data-kind="wind"] {
    border-inline-start-color: #0d9488;
    background: var(--ev-teal-bg);
    color: var(--ev-teal-text);
  }

  .cal-event-sunblock[data-kind="sun"] {
    border-inline-start-color: #e05a2b;
    background: var(--ev-coral-bg);
    color: var(--ev-coral-text);
  }

  .cal-event-sunblock[data-kind="high"] {
    border-inline-start-color: #007aff;
    background: var(--ev-blue-bg);
    color: var(--ev-blue-text);
  }

  .cal-event-sunblock[data-kind="low"] {
    border-inline-start-color: #0284c7;
    background: var(--ev-sky-bg);
    color: var(--ev-sky-text);
  }

  .event-time {
    font-size: 0.6875rem;
    font-variant-numeric: tabular-nums;
    opacity: 0.85;
    white-space: nowrap;
  }

  .event-title {
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .event-sunblock-text {
    font-size: 0.75rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Calendar Footer Options Strip */
  .cal-options-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background: var(--toolbar);
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
    font-size: 0.75rem;
    color: var(--text-sec);
  }

  .cal-toggles {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem 0.875rem;
  }

  .toggle-check {
    display: inline-flex;
    align-items: center;
    gap: 0.3125rem;
    min-block-size: 1.5rem;
    cursor: pointer;
    user-select: none;
  }

  .toggle-check input {
    width: 0.875rem;
    height: 0.875rem;
    margin: 0;
    cursor: pointer;
  }

  .cal-select-wrap {
    display: inline-flex;
    align-items: center;
    gap: 0.3125rem;
  }

  .cal-select {
    font-family: inherit;
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
    min-block-size: 1.5rem;
    padding: 0.125rem 0.375rem;
    border: 1px solid var(--control-border);
    border-radius: 0.3125rem;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
  }

  .free-badge {
    font-size: 0.75rem;
    color: var(--text-muted);
  }

  /* Nearby Harbor Quick Switcher (Tide page — 6px control radius, quiet raised selection) */
  .nearby-stations {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    flex-wrap: wrap;
    margin-top: 0.5rem;
    justify-content: center;
  }

  .nearby-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-inline-end: 0.125rem;
  }

  .station-pill {
    font-family: inherit;
    font-size: 0.75rem;
    min-block-size: 1.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-sec);
    cursor: pointer;
    transition: background-color 140ms var(--ease), border-color 140ms var(--ease), color 140ms var(--ease);
  }

  .station-pill:hover {
    background: var(--raised);
    color: var(--text);
  }

  .station-pill[aria-pressed="true"] {
    background: var(--raised);
    border-color: var(--control-border);
    color: var(--text);
    font-weight: 500;
  }

  /* Event Detail Inspector Popover */
  .event-inspector {
    margin: auto;
    max-width: 21rem;
    width: calc(100vw - 2rem);
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-popover);
    text-align: left;
    opacity: 0;
    transition: opacity 0.16s var(--ease), display 0.16s, overlay 0.16s;
    transition-behavior: allow-discrete;
  }

  .event-inspector:where(:popover-open, .is-open) {
    opacity: 1;
  }

  @starting-style {
    .event-inspector:popover-open {
      opacity: 0;
    }
  }

  @supports not selector(:popover-open) {
    .event-inspector:not(.is-open) {
      display: none;
    }

    .event-inspector.is-open {
      position: fixed;
      inset: 0;
      height: fit-content;
      z-index: 100;
    }
  }

  .event-inspector::backdrop {
    background: rgba(0, 0, 0, 0.2);
  }

  .inspector-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
  }

  .inspector-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
  }

  .inspector-close {
    background: var(--raised);
    border: none;
    border-radius: 0.375rem;
    min-inline-size: 1.75rem;
    min-block-size: 1.75rem;
    font-size: 1rem;
    line-height: 1;
    color: var(--text-sec);
    cursor: pointer;
    flex-shrink: 0;
  }

  .inspector-close:hover {
    background: var(--border);
  }

  .inspector-time {
    font-size: 0.8125rem;
    color: var(--text-sec);
    margin: 0 0 0.625rem;
    font-variant-numeric: tabular-nums;
  }

  .inspector-desc {
    font-size: 0.875rem;
    color: var(--text);
    margin: 0 0 0.75rem;
    line-height: 1.45;
  }

  .inspector-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    border-top: 1px solid var(--grid);
    padding-top: 0.5rem;
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
  }

  /* Subscribe Actions: 1 solid primary + 1 quiet bordered secondary */
  .subscribe-buttons {
    margin-top: clamp(1.75rem, 3.75vh, 2.5rem);
    display: flex;
    gap: 0.625rem;
    flex-wrap: wrap;
    justify-content: center;
  }

  .btn-apple,
  .btn-google {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-block-size: 2.75rem;
    padding: 0.5rem 1.25rem;
    border-radius: 0.5rem;
    text-decoration: none;
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 140ms var(--ease), border-color 140ms var(--ease);
  }

  .btn-apple {
    background: var(--primary-btn);
    color: var(--primary-btn-text);
    border: 1px solid transparent;
  }

  .btn-apple:hover {
    background: var(--primary-btn-hover);
  }

  .btn-google {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--control-border);
  }

  .btn-google:hover {
    background: var(--raised);
  }

  .secondary-links {
    margin-top: 0.625rem;
    font-size: 0.8125rem;
    color: var(--text-muted);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
  }

  .text-action {
    background: none;
    border: none;
    padding: 0.25rem 0;
    font: inherit;
    color: var(--text-sec);
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
  }

  .text-action:hover,
  .secondary-links a:hover {
    color: var(--text);
  }

  .secondary-links a {
    color: var(--text-sec);
    text-underline-offset: 2px;
  }

  /* Footer matching cwmoriarty.com — always bottom-left */
  .libleft {
    font-size: 0.9375rem;
    position: fixed;
    left: 12px;
    bottom: 10px;
    text-align: left;
  }

  .libleft a {
    color: var(--text);
  }

  .build-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    margin-top: 0.125rem;
  }

  @media (prefers-reduced-motion: no-preference) {
    .btn-apple:active,
    .btn-google:active,
    .copy-btn:active,
    .cal-nav-btn:active:not(:disabled),
    .station-pill:active {
      transform: scale(0.98);
    }
  }

  @media (max-width: 640px) {
    .centered {
      width: 96%;
      justify-content: flex-start;
      padding-block: 1.25rem 4.5rem;
    }

    .cal-gutter-col,
    .allday-gutter,
    .cal-time-gutter {
      width: 2.875rem;
    }

    .cal-body {
      height: 19.5rem;
    }
  }

  @media (pointer: coarse) {
    .locate-btn,
    .unit-segment label,
    .cal-nav-btn,
    .station-pill,
    .inspector-close {
      min-block-size: 2.25rem;
      min-inline-size: 2.25rem;
    }
  }

  @media (forced-colors: active) {
    .apple-cal,
    .cal-event,
    .btn-apple,
    .btn-google,
    .copy-btn,
    .unit-segment,
    .cal-nav-group,
    .station-pill,
    .event-inspector {
      border: 1px solid ButtonText;
    }
  }
}
