/* ============================================================
   Here2Retire — Stylesheet
   Font-size scales, 8 themes via CSS custom properties,
   layout, components, modals, tour, and responsive rules.
   ============================================================ */

  /* ============================================
     FONT SIZE SCALE — controlled by data-size on <html>
     S = 1x (default), M = 1.2x, L = 1.45x
     All font sizes reference --fs-* variables.
     ============================================ */

  :root, [data-size="s"] {
    --scale: 1;
    /* Base sizes */
    --fs-xxs:  8px;   /* micro labels */
    --fs-xs:   9px;   /* badge, section labels */
    --fs-sm:  10px;   /* legend, chips */
    --fs-base: 11px;  /* body text, event names */
    --fs-md:  12px;   /* input labels */
    --fs-lg:  13px;   /* card titles, chart title */
    --fs-xl:  20px;   /* stat values */
    --fs-2xl: 24px;   /* big-num */
    --fs-3xl: 28px;   /* h1 logo (desktop) */
    --fs-h1-mobile: 20px;
    /* Spacing that grows with font */
    --sp-pad-panel: 20px;
    --sp-pad-viz:   20px;
    --sp-pad-header: 14px 24px;
    --sp-gap-main:  14px;
    --sp-gap-events: 6px;
    --chart-h:      280px;
  }

  [data-size="m"] {
    --scale: 1.2;
    --fs-xxs:  9px;
    --fs-xs:  11px;
    --fs-sm:  12px;
    --fs-base: 13px;
    --fs-md:  14px;
    --fs-lg:  15px;
    --fs-xl:  24px;
    --fs-2xl: 28px;
    --fs-3xl: 32px;
    --fs-h1-mobile: 24px;
    --sp-pad-panel: 24px;
    --sp-pad-viz:   24px;
    --sp-pad-header: 16px 28px;
    --sp-gap-main:  16px;
    --sp-gap-events: 8px;
    --chart-h:      320px;
  }

  [data-size="l"] {
    --scale: 1.45;
    --fs-xxs: 11px;
    --fs-xs:  13px;
    --fs-sm:  14px;
    --fs-base: 15px;
    --fs-md:  16px;
    --fs-lg:  18px;
    --fs-xl:  28px;
    --fs-2xl: 34px;
    --fs-3xl: 38px;
    --fs-h1-mobile: 28px;
    --sp-pad-panel: 28px;
    --sp-pad-viz:   28px;
    --sp-pad-header: 18px 32px;
    --sp-gap-main:  20px;
    --sp-gap-events: 10px;
    --chart-h:      360px;
  }

  /* DEFAULT: Dark Terminal */
  :root, [data-theme="dark"] {
    --bg: #0a0c0f;
    --surface: #111417;
    --border: #2a3040;
    --accent: #e8ff57;
    --accent2: #ff6b35;
    --danger: #ff3b55;
    --safe: #39d98a;
    --text: #f4f6ff;
    --muted: #8a95aa;
    --card: #13161b;
    --font-head: 'Syne', sans-serif;
    --font-body: 'DM Mono', monospace;
    --radius: 2px;
    --theme-btn-active: rgba(232,255,87,0.15);
    --theme-btn-border: rgba(232,255,87,0.5);
    --slider-track: var(--border);
    --shadow: none;
    --event-hover-bg: #1a1d22;
  }

  /* MINIMAL */
  [data-theme="minimal"] {
    --bg: #fafaf8;
    --surface: #f2f2ee;
    --border: #d0ccc6;
    --accent: #111;
    --accent2: #444;
    --danger: #b52a1c;
    --safe: #1a7a45;
    --text: #0d0d0d;
    --muted: #555;
    --card: #fff;
    --font-head: 'Georgia', serif;
    --font-body: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    --radius: 0px;
    --theme-btn-active: rgba(0,0,0,0.08);
    --theme-btn-border: rgba(0,0,0,0.4);
    --slider-track: #ccc;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --event-hover-bg: #f0ede8;
  }

  /* WES ANDERSON */
  [data-theme="wes"] {
    --bg: #f5efe6;
    --surface: #ede4d4;
    --border: #c9b99a;
    --accent: #c0392b;
    --accent2: #e67e22;
    --danger: #922b21;
    --safe: #1a6b3c;
    --text: #1a0c06;
    --muted: #5c4535;
    --card: #fdf6ec;
    --font-head: 'Playfair Display', 'Georgia', serif;
    --font-body: 'Courier New', Courier, monospace;
    --radius: 3px;
    --theme-btn-active: rgba(192,57,43,0.12);
    --theme-btn-border: rgba(192,57,43,0.6);
    --slider-track: #c9b99a;
    --shadow: 2px 2px 0px rgba(139,115,85,0.3);
    --event-hover-bg: #ede4d4;
  }

  /* GEN Z */
  [data-theme="genz"] {
    --bg: #0d0d0d;
    --surface: #141414;
    --border: #303030;
    --accent: #00ff88;
    --accent2: #ff2d78;
    --danger: #ff2d78;
    --safe: #00ff88;
    --text: #f8f8f8;
    --muted: #888;
    --card: #111;
    --font-head: 'Syne', sans-serif;
    --font-body: 'DM Mono', monospace;
    --radius: 12px;
    --theme-btn-active: rgba(0,255,136,0.1);
    --theme-btn-border: rgba(0,255,136,0.5);
    --slider-track: #2a2a2a;
    --shadow: 0 0 20px rgba(0,255,136,0.15);
    --event-hover-bg: #1a1a1a;
  }

  /* UNICORN */
  [data-theme="unicorn"] {
    --bg: #fef0ff;
    --surface: #f5d8ff;
    --border: #cc88ee;
    --accent: #6a0faa;
    --accent2: #e0157e;
    --danger: #d01070;
    --safe: #0a9a72;
    --text: #1a0030;
    --muted: #6b3d8a;
    --card: #fff8ff;
    --font-head: 'Syne', sans-serif;
    --font-body: 'DM Mono', monospace;
    --radius: 16px;
    --theme-btn-active: rgba(106,15,170,0.12);
    --theme-btn-border: rgba(106,15,170,0.5);
    --slider-track: #cc88ee;
    --shadow: 0 4px 20px rgba(106,15,170,0.12);
    --event-hover-bg: #f0d0ff;
  }

  /* SOFT — Minimal palette + rounded corners + layered shadows + system fonts */
  [data-theme="soft"] {
    --bg: #fafaf8;
    --surface: #f2f2ee;
    --border: #d0ccc6;
    --accent: #111;
    --accent2: #444;
    --danger: #b52a1c;
    --safe: #1a7a45;
    --text: #0d0d0d;
    --muted: #555;
    --card: #fff;
    --font-head: 'DM Serif Display', Georgia, serif;
    --font-body: system-ui, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
    --radius: 16px;
    --theme-btn-active: rgba(0,0,0,0.08);
    --theme-btn-border: rgba(0,0,0,0.4);
    --slider-track: #ccc;
    --shadow: 0 1px 8px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.05);
    --event-hover-bg: #f0ede8;
  }

  /* AIR — Airbnb-inspired clean minimal */
  [data-theme="air"] {
    --bg: #ffffff;
    --surface: #ffffff;
    --border: #e0e0e0;
    --accent: #1cb554;
    --accent2: #444444;
    --danger: #c13515;
    --safe: #1cb554;
    --text: #222222;
    --muted: #717171;
    --card: #ffffff;
    --font-head: system-ui, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
    --font-body: system-ui, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
    --radius: 12px;
    --theme-btn-active: rgba(28,181,84,0.07);
    --theme-btn-border: rgba(28,181,84,0.4);
    --slider-track: #e0e0e0;
    --shadow: none;
    --event-hover-bg: #f5fdf8;
  }

  /* AIRY — Air colors, generous whitespace, simplified type scale */
  html[data-theme="airy"] {
    --bg: #ffffff;
    --surface: #ffffff;
    --border: #e0e0e0;
    --accent: #222222;
    --accent2: #444444;
    --danger: #c13515;
    --safe: #1cb554;
    --text: #222222;
    --muted: #717171;
    --card: #ffffff;
    --font-head: system-ui, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
    --font-body: system-ui, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
    --radius: 12px;
    --theme-btn-active: rgba(0,0,0,0.05);
    --theme-btn-border: rgba(0,0,0,0.4);
    --slider-track: #d0d0d0;
    --shadow: none;
    --event-hover-bg: #f5f5f5;
    /* More generous spacing */
    --sp-pad-panel: 28px;
    --sp-pad-viz:   28px;
    --sp-gap-main:  24px;
    --sp-gap-events: 10px;
    /* Simplified type scale — floor at 11px, no micro text */
    --fs-xxs:  11px;
    --fs-xs:   12px;
    --fs-sm:   13px;
    --fs-base: 14px;
    --fs-md:   15px;
    --fs-lg:   16px;
    --fs-xl:   26px;
  }

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

  html { height: 100%; }

  body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background 0.3s, color 0.3s;
  }

  /* Noise texture overlay */
  body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.035'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 999;
    opacity: 0.4;
  }

  /* ---- MAIN LAYOUT ---- */
  main {
    display: grid;
    grid-template-columns: 380px 1fr;
    flex: 1;
  }

  /* ---- LEFT PANEL ---- */
  .panel {
    border-right: 1px solid var(--border);
    padding: var(--sp-pad-panel);
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    max-height: calc(100vh - 122px);
    position: sticky;
    top: 0;
  }

  .section-label {
    font-size: var(--fs-sm);
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--text);
    margin-bottom: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .section-label::before {
    content: '';
    display: inline-block;
    width: 3px;
    height: 13px;
    background: var(--accent);
    border-radius: 2px;
    flex-shrink: 0;
  }
  /* Collapsible section label */
  .section-collapse-btn { cursor: pointer; user-select: none; }
  .section-label-text { flex: 1; }
  .section-caret {
    font-size: 3em;
    font-style: normal;
    color: var(--accent);
    transition: transform 0.25s ease;
    line-height: 1;
  }
  .section-caret.collapsed { transform: rotate(-90deg); }
  #profileSliders {
    overflow: hidden;
    max-height: 900px;
    opacity: 1;
    transition: max-height 0.35s cubic-bezier(0.4,0,0.2,1), opacity 0.25s ease;
  }
  #profileSliders.collapsed { max-height: 0; opacity: 0; }

  .input-group { margin-bottom: 10px; }

  /* Label with hover tooltip */
  .input-group label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    font-size: var(--fs-md);
    color: var(--muted);
    position: relative;
  }

  .label-text {
    flex: 1;
    min-width: 0;
    cursor: help;
  }

  .label-name {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .label-text:hover .label-tip {
    display: block;
    animation: fadeSlide 0.15s ease forwards;
  }

  .label-tip {
    display: none;
    position: fixed;
    /* top/left set by JS on hover so the tip escapes any overflow:auto parent */
    width: 280px;
    max-width: calc(100vw - 32px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    z-index: 9999;
    box-shadow: 0 8px 24px rgba(0,0,0,0.18);
    pointer-events: none;
    font-weight: 400;
    white-space: normal;
    box-sizing: border-box;
  }

  /* Wider tip for SWR and other rich explainers */
  .label-tip.label-tip-wide {
    width: 320px;
  }

  /* No longer need the ancestor-relative anchoring — tooltips are position:fixed
     and positioned by JS (see js/tour.js, label tooltip positioner). */
  .input-group { position: relative; }

  /* Direction/positioning handled by JS for position:fixed tooltips. */

  .input-group label .label-val {
    color: var(--accent);
    font-size: var(--fs-lg);
    font-weight: 500;
    flex-shrink: 0;
    margin-left: 8px;
  }

  input[type="range"] {
    width: 100%;
    -webkit-appearance: none;
    height: 2px;
    background: var(--slider-track);
    outline: none;
    cursor: pointer;
  }

  input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 13px;
    height: 13px;
    background: var(--accent);
    border-radius: 50%;
    border: none;
    box-shadow: none;
    cursor: pointer;
    transition: transform 0.15s;
  }

  input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.3); }

  input[type="range"]::-moz-range-thumb {
    width: 13px;
    height: 13px;
    background: var(--accent);
    border-radius: 50%;
    border: none;
    box-shadow: none;
    cursor: pointer;
  }

  /* ---- EVENTS LIST ---- */
  .events-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .event-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    width: 100%;
    color: var(--text);
    font-family: var(--font-body);
    font-size: var(--fs-base);
    box-shadow: var(--shadow);
  }

  .event-btn:hover { border-color: var(--accent); background: var(--event-hover-bg); }
  .event-btn.active { border-color: var(--accent); background: var(--theme-btn-active); }

  .event-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
  .event-info { flex: 1; min-width: 0; }
  .event-name { font-size: var(--fs-base); font-weight: 500; color: var(--text); margin-bottom: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .event-year { font-size: var(--fs-xxs); color: var(--muted); letter-spacing: 1px; }
  .event-drop { font-size: var(--fs-base); color: var(--danger); font-weight: 500; flex-shrink: 0; }
  .event-drop.pos { color: var(--safe); }

  /* ---- RIGHT VIZ PANEL ---- */
  .viz {
    padding: var(--sp-pad-viz);
    display: flex;
    flex-direction: column;
    gap: var(--sp-gap-main);
    overflow-y: auto;
  }

  /* ---- STATS ROW ---- */
  .stats-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    flex-shrink: 0;
  }

  .scenarios-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    flex-shrink: 0;
  }

  .stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    box-shadow: var(--shadow);
    transition: background 0.3s, transform 0.18s ease, box-shadow 0.18s ease;
    display: flex;
    flex-direction: column;
    position: relative;
  }

  /* Hover lift: slight scale + deeper shadow, card pops above neighbours */
  .stat-card:hover {
    transform: scale(1.025);
    box-shadow: 0 10px 36px rgba(0,0,0,0.13);
    z-index: 10;
  }


  .stat-card .stat-label {
    font-size: var(--fs-xxs);
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 5px;
    min-height: 2.6em;
  }

  .stat-card .stat-value {
    font-family: var(--font-head);
    font-size: var(--fs-xl);
    line-height: 1;
    margin-top: 8px;
  }

  .stat-card .stat-value.danger { color: var(--danger); }
  .stat-card .stat-value.safe { color: var(--safe); }
  .stat-card .stat-value.accent { color: var(--accent); }
  .stat-card .stat-sub { font-size: var(--fs-xxs); color: var(--muted); margin-top: 3px; }

  /* ---- CHART ---- */
  /* The chart-container has a fixed height so it's always fully visible */
  .chart-container {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    flex-shrink: 0;
    height: var(--chart-h);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
    transition: height 0.3s;
  }

  .chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    flex-shrink: 0;
  }

  .chart-title {
    font-family: var(--font-head);
    font-size: var(--fs-lg);
    font-weight: 700;
    letter-spacing: -0.3px;
  }

  .legend {
    display: flex;
    gap: 14px;
    font-size: var(--fs-xxs);
    color: var(--muted);
    letter-spacing: 1px;
  }

  .legend-item { display: flex; align-items: center; gap: 5px; }
  .legend-line { width: 16px; height: 2px; }

  /* Canvas fills the remaining space in chart-container */
  #mainChart {
    display: block;
    width: 100% !important;
    flex: 1;
    min-height: 0;
  }

  /* ---- EVENT INFO ---- */
  .timeline-event {
    background: rgba(232,255,87,0.05);
    border: 1px solid rgba(232,255,87,0.2);
    border-radius: var(--radius);
    padding: 12px 16px;
    flex-shrink: 0;
    transition: background 0.3s, border-color 0.3s;
  }

  [data-theme="minimal"] .timeline-event { background: var(--surface); border-color: var(--border); }
  [data-theme="wes"] .timeline-event { background: #fdf0dc; border-color: #c9b99a; }
  [data-theme="genz"] .timeline-event { background: rgba(0,255,136,0.04); border-color: rgba(0,255,136,0.2); }
  [data-theme="unicorn"] .timeline-event { background: rgba(139,47,201,0.06); border-color: rgba(139,47,201,0.25); }
  [data-theme="soft"] .timeline-event { background: var(--card); border-color: var(--border); }
  [data-theme="air"] .timeline-event { background: var(--card); border-color: var(--border); }

  .timeline-event h4 {
    font-family: var(--font-head);
    font-size: var(--fs-lg);
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 4px;
  }

  .timeline-event p { font-size: var(--fs-base); color: var(--muted); line-height: 1.6; }

  /* ---- COMPARISON GRID ---- */
  .all-events-summary {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    flex-shrink: 0;
    box-shadow: var(--shadow);
  }

  .all-events-summary h3 {
    font-family: var(--font-head);
    font-size: var(--fs-lg);
    font-weight: 700;
    margin-bottom: 10px;
  }

  .comparison-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
  }

  .compare-cell {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 6px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
  }

  .compare-cell:hover { border-color: var(--accent); background: var(--event-hover-bg); }
  .compare-cell.active { border-color: var(--accent); background: var(--theme-btn-active); }
  .compare-cell .cc-year { font-size: var(--fs-xxs); color: var(--muted); letter-spacing: 1px; margin-bottom: 3px; }
  .compare-cell .cc-name { font-size: var(--fs-xs); font-weight: 500; color: var(--text); margin-bottom: 5px; line-height: 1.3; }
  .compare-cell .cc-drop { font-size: var(--fs-md); font-weight: 500; }

  /* ---- FIRE STATUS CARDS ---- */
  .fire-status {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    flex-shrink: 0;
  }

  .status-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow);
  }

  .status-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
  }

  .status-card.good::before { background: var(--safe); }
  .status-card.bad::before { background: var(--danger); }
  .status-card.warn::before { background: var(--accent2); }

  .status-card p { font-size: var(--fs-xs); color: var(--muted); line-height: 1.5; }

  .status-card .big-num {
    font-family: var(--font-head);
    font-size: var(--fs-2xl);
    line-height: 1;
    margin: 5px 0 4px;
  }

  .stat-label { font-size: var(--fs-xxs); letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); margin-bottom: 5px; }

  .recovery-bar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 14px;
    margin-bottom: 5px;
  }

  .recovery-bar-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--muted);
  }

  .recovery-bar-pct {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
  }

  .recovery-bar {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
  }

  .recovery-bar-hint {
    font-size: 11px;
    color: var(--muted);
    margin-top: 5px;
    line-height: 1.4;
  }

  .recovery-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.8s ease;
  }

  /* Panel inner is always shown on desktop; toggle only on mobile */
  .panel-inner {
    display: flex;
    flex-direction: column;
    gap: 0;
  }

  /* ---- MOBILE EVENTS PICKER (horizontal scroll strip) ---- */
  /* Wrapper section — hidden on desktop, shown on mobile inside panel-inner */
  .mobile-crisis-section {
    display: none;
  }
  .mobile-crisis-divider {
    font-size: var(--fs-sm);
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--text);
    padding: 16px 0 0;
    border-top: 1px solid var(--border);
    margin-top: 16px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .mobile-crisis-divider::before {
    content: '';
    display: inline-block;
    width: 3px;
    height: 13px;
    background: var(--accent);
    border-radius: 2px;
    flex-shrink: 0;
  }

  .mobile-events-strip {
    display: none;
    overflow-x: auto;
    gap: 8px;
    padding: 4px 0 10px;
    flex-shrink: 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .mobile-events-strip::-webkit-scrollbar { display: none; }

  .mobile-event-chip {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 10px 16px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 24px;
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 14px;
    color: var(--text);
    white-space: nowrap;
    transition: all 0.2s;
    font-weight: 500;
  }
  .mobile-event-chip:hover, .mobile-event-chip.active {
    border-color: var(--accent);
    background: rgba(232,255,87,0.06);
  }
  .mobile-event-chip .chip-dot { width: 8px; height: 8px; border-radius: 50%; }
  .mobile-event-chip .chip-drop { color: var(--danger); font-size: 13px; font-weight: 600; }

  /* ---- ANIMATIONS ---- */
  @keyframes fadeSlide {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
  }

  .animate-in { animation: fadeSlide 0.35s ease forwards; }

  /* ============================
     RESPONSIVE BREAKPOINTS
     ============================ */

  /* Tablet — contain nav + right panel */
  @media (max-width: 900px) {
    main { grid-template-columns: 300px 1fr; }
    .stats-row     { grid-template-columns: repeat(3, 1fr); }
    .scenarios-row { grid-template-columns: repeat(3, 1fr); }
    .comparison-grid { grid-template-columns: repeat(4, 1fr); }

    /* Nav: dropdown replaced the scrolling pill-row, no overflow needed */
    .app-nav { max-width: 100vw; }
    .nav-controls {
      flex: 1;
      min-width: 0;
      overflow-x: auto;
      scrollbar-width: none;
    }
    .nav-controls::-webkit-scrollbar { display: none; }

    /* Viz: no horizontal bleed */
    .viz { overflow-x: hidden; }
  }

  /* Narrow tablet / large phone — cards go 2-col, lone 3rd fills full width */
  @media (max-width: 800px) {
    .stats-row,
    .scenarios-row {
      grid-template-columns: repeat(2, 1fr);
      gap: 10px;
    }
    /* 3rd card (lone on its row) spans full width */
    .stats-row > .stat-card:nth-child(3),
    .scenarios-row > .stat-card:nth-child(3) {
      grid-column: span 2;
    }
  }

  /* Mobile — single column, panel becomes a collapsible section */
  @media (max-width: 640px) {
    /* Let the page scroll vertically; kill all horizontal overflow */
    html { overflow-x: hidden; }
    body { overflow-x: hidden; overflow-y: auto; }

    /* ---- NAV: contain to viewport width ---- */
    .app-nav {
      padding: 0 12px;
      max-width: 100vw;
      box-sizing: border-box;
    }
    .nav-brand { flex-shrink: 0; }
    .nav-brand-tag { display: none; }
    .nav-brand h1 { font-size: var(--fs-h1-mobile); }

    /* Controls: hide S/M/L size buttons + divider (save ~120 px),
       let remaining 5 swatches scroll if needed */
    .size-btn { display: none !important; }
    .nav-divider { display: none !important; }
    .nav-controls {
      flex: 1;
      min-width: 0;
      overflow-x: auto;
      scrollbar-width: none;
      justify-content: flex-end;
    }
    .nav-controls::-webkit-scrollbar { display: none; }

    main {
      grid-template-columns: minmax(0, 1fr);
      grid-template-rows: auto auto;
      max-width: 100vw;
      overflow-x: hidden;
      box-sizing: border-box;
    }

    /* On mobile, left panel becomes an accordion */
    .panel {
      position: static;
      max-height: none;
      border-right: none;
      border-bottom: 1px solid var(--border);
      padding: 0;
      gap: 0;
      overflow: visible;
      min-width: 0;
      width: 100%;
    }

    .panel-inner {
      padding: 16px;
      display: flex;
      flex-direction: column;
      gap: 0;
      width: 100%;
      min-width: 0;
      box-sizing: border-box;
      /* NO overflow-x: hidden here — it was clipping the right-edge value spans */
    }

    /* Input groups: full-width, let flex layout handle the label ↔ value spacing */
    .input-group { width: 100%; box-sizing: border-box; }
    .input-group label { width: 100%; box-sizing: border-box; }
    input[type="range"] { width: 100%; max-width: 100%; box-sizing: border-box; }

    /* Mobile events — show section wrapper + strip inside panel, hide desktop sidebar list */
    .desktop-events { display: none !important; }
    .mobile-crisis-section { display: block; }
    .mobile-events-strip { display: flex !important; }

    /* When FIRE PROFILE is collapsed, close the gap so spacing above = spacing below title */
    #profileSection.collapsed + .mobile-crisis-section .mobile-crisis-divider {
      margin-top: 4px;
    }

    /* Viz: scroll vertically, never horizontally */
    .viz {
      padding: 14px;
      gap: 12px;
      overflow-x: hidden;
      overflow-y: visible;
      min-width: 0;
      width: 100%;
    }

    /* Every direct child of viz must stay within viewport width */
    .viz > * { max-width: 100%; box-sizing: border-box; }

    /* Hide the fixed-width 160 px mini sparkline on mobile —
       it has inline flex-shrink:0;width:160px so we must use !important */
    #miniChart,
    .timeline-event > div > div:nth-child(2) { display: none !important; }

    /* Clamp every full-width row that lives outside <main> */
    .feature-tabs  { max-width: 100vw; box-sizing: border-box; }
    .disclaimer-strip { max-width: 100vw; box-sizing: border-box; overflow: hidden; }

    .stats-row,
    .scenarios-row { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    /* Keep the lone 3rd card full-width on mobile too */
    .stats-row > .stat-card:nth-child(3),
    .scenarios-row > .stat-card:nth-child(3) { grid-column: span 2; }

    .chart-container { height: 55vh; }

    /* 4-column grid on mobile: readable cells without needing to scroll */
    .comparison-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; }
    .compare-cell { padding: 8px 4px; }
    .compare-cell .cc-name { font-size: 10px; line-height: 1.2; }
    .compare-cell .cc-year { font-size: 9px; }
    .compare-cell .cc-drop { font-size: 13px; }

    .fire-status { grid-template-columns: 1fr; }

    /* ---- MOBILE MODAL FIXES ---- */
    /* Prevent horizontal panning on the backdrop */
    .modal-backdrop {
      overflow: hidden;
      touch-action: pan-y;
    }

    .welcome-modal {
      max-width: 100%;
      width: calc(100vw - 16px);
      max-height: min(580px, calc(100dvh - 48px));
      border-radius: 20px;
      margin: 0 8px;
      display: flex;
      flex-direction: column;
      overflow: hidden;
    }

    .modal-header { padding: 12px 16px 0; }

    .modal-body {
      padding: 6px 16px 0;
      flex: 1;
      overflow-y: auto;
      overflow-x: hidden;
      -webkit-overflow-scrolling: touch;
      overscroll-behavior: contain;
      display: flex;
      flex-direction: column;
    }

    .modal-logo { font-size: 26px; }
    .modal-close { width: 28px; height: 28px; font-size: 12px; }

    .modal-tagline { font-size: 15px; margin-bottom: 10px; margin-top: 6px; font-weight: 700; }
    .modal-intro { font-size: 15px; line-height: 1.5; margin-bottom: 12px; }

    /* Three full-width cards stacked vertically — override desktop grid */
    /* max-height clips card 3 completely; gradient fades the bottom of card 2 */
    .modal-concepts {
      display: flex !important;
      flex-direction: column !important;
      gap: 10px;
      margin-bottom: 0;
      max-height: 210px;
      overflow: hidden;
      position: relative;
      flex-shrink: 0;
    }
    /* Gradient hint — lives inside the clipped concepts box so nothing leaks below */
    .modal-concepts::after {
      content: '';
      position: absolute;
      bottom: 0; left: 0; right: 0;
      height: 72px;
      background: linear-gradient(to bottom, transparent, var(--bg));
      pointer-events: none;
    }

    .concept-card {
      /* Horizontal: large emoji on left, title + desc on right */
      display: flex !important;
      flex-direction: row !important;
      align-items: center !important;
      gap: 14px;
      padding: 14px 14px !important;
      box-sizing: border-box;
      width: 100%;
    }

    /* Plain large emoji — no box, no background */
    .concept-card .cc-icon {
      font-size: 36px !important;
      display: block !important;
      flex-shrink: 0;
      line-height: 1;
      width: auto;
      height: auto;
      min-width: unset;
      background: none;
      border: none;
      border-radius: 0;
      margin-bottom: 0;
    }

    .concept-card .cc-body { flex: 1; min-width: 0; }

    .concept-card .cc-title {
      font-size: 15px !important;
      font-weight: 700;
      margin-bottom: 4px;
      line-height: 1.2;
      display: block;
    }

    .concept-card .cc-desc {
      font-size: 13px !important;
      line-height: 1.45;
      display: block;
    }

    /* Page dots — hidden */
    .concept-dots { display: none; }

    /* Footer: always visible, stacked vertically, no overflow tricks needed */
    .modal-footer-row {
      flex-shrink: 0;
      margin-top: auto;
      padding: 12px 0 16px;
      gap: 4px;
      background: var(--bg);
      flex-direction: column;
      align-items: stretch;
    }

    /* Primary CTA: full-width, prominent */
    .btn-primary {
      width: 100%;
      font-size: 15px;
      padding: 14px;
      border-radius: 10px;
    }

    /* Secondary: de-emphasised text link — !important beats the later desktop rule */
    .btn-secondary {
      background: transparent !important;
      border: none !important;
      box-shadow: none !important;
      color: var(--muted);
      font-size: 13px;
      padding: 8px;
      text-align: center;
      width: 100%;
      flex: unset;
    }

    /* ---- MOBILE TOUR: hide desktop tour elements, show carousel ---- */
    /* Hide the desktop overlay entirely */
    .tour-overlay { display: none !important; }

    /* Show carousel instead */
    .tour-carousel.open { display: block; }
  }

  /* ---- THEME BTN (used in nav controls) ---- */
  .theme-bar-label {
    font-size: var(--fs-xxs);
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--muted);
    white-space: nowrap;
    font-family: var(--font-body);
  }

  .theme-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 20px;
    cursor: pointer;
    font-size: var(--fs-xxs);
    font-family: var(--font-body);
    color: var(--muted);
    background: transparent;
    white-space: nowrap;
    transition: all 0.2s;
    letter-spacing: 0.5px;
  }

  .theme-btn:hover { border-color: var(--accent); color: var(--text); }

  .theme-btn.active {
    border-color: var(--theme-btn-border);
    background: var(--theme-btn-active);
    color: var(--text);
    font-weight: 600;
  }

  .theme-swatch {
    width: 8px; height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1px solid rgba(0,0,0,0.1);
  }

  /* ---- THEME DROPDOWN ---- */
  .theme-dropdown {
    position: relative;
  }

  .theme-dropdown-trigger {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 20px;
    cursor: pointer;
    font-size: var(--fs-xxs);
    font-family: var(--font-body);
    color: var(--text);
    background: transparent;
    white-space: nowrap;
    transition: border-color 0.2s, background 0.2s;
    letter-spacing: 0.5px;
    line-height: 1;
  }

  .theme-dropdown-trigger:hover,
  .theme-dropdown.open .theme-dropdown-trigger {
    border-color: var(--accent);
    background: var(--theme-btn-active);
  }

  .theme-name-current {
    font-size: var(--fs-xxs);
    letter-spacing: 0.5px;
  }

  .theme-dropdown-arrow {
    font-size: 10px;
    color: var(--muted);
    transition: transform 0.2s;
    line-height: 1;
  }

  .theme-dropdown.open .theme-dropdown-arrow {
    transform: rotate(180deg);
  }

  .theme-dropdown-menu {
    display: none;
    position: fixed;
    min-width: 130px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 4px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.18);
    z-index: 1800;
    flex-direction: column;
    gap: 1px;
  }

  .theme-dropdown.open .theme-dropdown-menu {
    display: flex;
  }

  .theme-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border: none;
    border-radius: 7px;
    background: transparent;
    cursor: pointer;
    font-size: var(--fs-sm);
    font-family: var(--font-body);
    color: var(--text);
    text-align: left;
    transition: background 0.15s;
    white-space: nowrap;
    width: 100%;
  }

  .theme-option:hover {
    background: var(--event-hover-bg);
  }

  .theme-option.active {
    background: var(--theme-btn-active);
    color: var(--text);
    font-weight: 600;
  }

  /* Active size button highlight */
  .size-btn.active {
    border-color: var(--theme-btn-border);
    background: var(--theme-btn-active);
    color: var(--text) !important;
    font-weight: 700;
    box-shadow: 0 0 0 2px var(--theme-btn-border);
  }

  .size-btn.active span { color: var(--accent) !important; }

  /* ---- Wes Anderson special decorative borders ---- */
  [data-theme="wes"] .app-nav {
    border-bottom: 3px double var(--border);
  }
  [data-theme="wes"] .feature-tabs {
    border-bottom: 3px double var(--border);
  }
  [data-theme="wes"] .panel {
    border-right: 3px double var(--border);
  }

  /* Gen Z glow effects */
  [data-theme="genz"] .stat-card,
  [data-theme="genz"] .chart-container,
  [data-theme="genz"] .all-events-summary {
    box-shadow: 0 0 0 1px rgba(0,255,136,0.05), 0 4px 20px rgba(0,255,136,0.05);
  }
  [data-theme="genz"] .event-btn.active,
  [data-theme="genz"] .compare-cell.active {
    box-shadow: 0 0 12px rgba(0,255,136,0.2);
  }

  /* Unicorn gradient background shimmer */
  [data-theme="unicorn"] body {
    background: linear-gradient(135deg, #fef0ff 0%, #f0e8ff 50%, #ffe8f8 100%);
  }
  [data-theme="unicorn"] .stat-card,
  [data-theme="unicorn"] .chart-container,
  [data-theme="unicorn"] .all-events-summary {
    box-shadow: 0 4px 24px rgba(139,47,201,0.1);
  }

  /* Air layout */
  [data-theme="air"] .app-nav {
    background: #ffffff;
    border-bottom: 1px solid #e8e8e8;
    box-shadow: none;
  }
  /* Stat cards and comparison grid: border only, no shadow */
  [data-theme="air"] .stat-card,
  [data-theme="air"] .all-events-summary,
  [data-theme="air"] .timeline-event {
    box-shadow: none;
    border: 1px solid var(--border);
  }
  /* Chart: shadow + no border stroke */
  [data-theme="air"] .chart-container {
    box-shadow: 0 4px 24px rgba(0,0,0,0.09), 0 2px 8px rgba(0,0,0,0.05);
    border: none;
  }
  /* Crisis event list: unselected = no shadow; selected = shadow + green stroke */
  [data-theme="air"] .event-btn {
    box-shadow: none;
    border: 1px solid var(--border);
    background: #ffffff;
  }
  [data-theme="air"] .event-btn.active {
    border: 1.5px solid var(--accent);
    box-shadow: 0 2px 12px rgba(0,0,0,0.1);
    background: #ffffff;
  }
  [data-theme="air"] .event-btn:hover:not(.active) {
    border-color: #b0b0b0;
    background: #ffffff;
    box-shadow: none;
  }
  /* Compare cell: green border only, white background */
  [data-theme="air"] .compare-cell.active { background: #ffffff; }
  /* Event title: dark text, not accent green */
  [data-theme="air"] .timeline-event h4 { color: var(--text); }
  /* Profile panel text: black */
  [data-theme="air"] .input-group label { color: var(--text); }
  [data-theme="air"] .input-group label .label-val { color: var(--text); }

  /* ---- AIRY overrides ---- */
  [data-theme="airy"] .app-nav {
    background: #ffffff;
    border-bottom: 1px solid #e8e8e8;
    box-shadow: none;
  }
  [data-theme="airy"] .stat-card,
  [data-theme="airy"] .all-events-summary,
  [data-theme="airy"] .timeline-event {
    box-shadow: none;
    border: 1px solid var(--border);
  }
  [data-theme="airy"] .chart-container {
    box-shadow: 0 4px 24px rgba(0,0,0,0.09), 0 2px 8px rgba(0,0,0,0.05);
    border: none;
  }
  /* Spacing: inter-group breathing room */
  [data-theme="airy"] .panel { gap: 24px; }
  [data-theme="airy"] .panel-divider { margin: 8px -28px 4px; }
  [data-theme="airy"] .section-label { font-size: 12px; letter-spacing: 2px; margin-bottom: 14px; }
  [data-theme="airy"] .input-group { margin-bottom: 18px; }
  [data-theme="airy"] .input-group label { font-size: 15px; margin-bottom: 8px; color: var(--text); }
  [data-theme="airy"] .input-group label .label-val { color: var(--text); }
  [data-theme="airy"] .events-grid { gap: 10px; }
  [data-theme="airy"] .event-btn { padding: 13px 16px; }
  [data-theme="airy"] .stats-row,
  [data-theme="airy"] .scenarios-row { gap: 16px; }
  [data-theme="airy"] .stat-card { padding: 14px 16px; }
  [data-theme="airy"] .stat-card .stat-label { font-size: 12px; letter-spacing: 1px; margin-bottom: 6px; min-height: 2.6em; }
  [data-theme="airy"] .scenarios-row .stat-card .stat-label { min-height: auto; margin-bottom: 6px; }
  [data-theme="airy"] .stat-card .stat-sub { font-size: 12px; margin-top: 5px; }
  /* Crisis event list */
  [data-theme="airy"] .event-btn {
    box-shadow: none;
    border: 1px solid var(--border);
    background: #ffffff;
  }
  [data-theme="airy"] .event-btn.active {
    border: 1.5px solid var(--accent);
    box-shadow: 0 2px 12px rgba(0,0,0,0.1);
    background: #ffffff;
  }
  [data-theme="airy"] .event-btn:hover:not(.active) {
    border-color: #b0b0b0;
    background: #ffffff;
    box-shadow: none;
  }
  [data-theme="airy"] .compare-cell.active { background: #ffffff; }
  [data-theme="airy"] .timeline-event h4 { color: var(--text); }

  @media (max-width: 380px) {
    .stats-row,
    .scenarios-row { grid-template-columns: 1fr 1fr; }
    .stat-card .stat-value { font-size: 17px; }
  }

  /* ---- TOOLTIPS ---- */
  .stat-card {
    position: relative; /* needed for tooltip positioning */
  }

  .stat-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 6px;
    margin-bottom: 5px;
  }

  .stat-label {
    flex: 1;
  }

  .tooltip-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid var(--muted);
    color: var(--muted);
    font-size: 11px;
    cursor: help;
    flex-shrink: 0;
    line-height: 1;
    font-style: normal;
    font-family: var(--font-body);
    transition: border-color 0.15s, color 0.15s;
    user-select: none;
  }

  .tooltip-trigger:hover {
    border-color: var(--accent);
    color: var(--accent);
  }

  .tooltip-box {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    width: 260px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    z-index: 100;
    box-shadow: 0 8px 24px rgba(0,0,0,0.18);
    pointer-events: none;
  }

  /* When actively tapped/clicked — allow reading content, and on mobile use
     a fixed bottom sheet so it always stays inside the viewport */
  .tooltip-box.active {
    pointer-events: auto;
  }

  @media (max-width: 640px) {
    /* Block ALL CSS-triggered tooltip display on mobile — handled by body-level overlay */
    .stat-card:hover .tooltip-box,
    .stat-card:focus-within .tooltip-box {
      display: none !important;
      animation: none !important;
    }
    /* ---- Mobile tooltip overlay (lives at body level, escapes card stacking/transform) ---- */
    #mobileTooltipOverlay {
      display: none;
      position: fixed;
      inset: 0;
      z-index: 2000;
    }
    #mobileTooltipOverlay.open { display: block; }
    .mto-backdrop {
      position: absolute;
      inset: 0;
      background: rgba(0,0,0,0.25);
    }
    .mto-sheet {
      position: absolute;
      bottom: 0; left: 0; right: 0;
      background: var(--surface);
      border: 1px solid var(--border);
      border-top: none;
      border-radius: 16px 16px 0 0;
      padding: 12px 20px calc(28px + env(safe-area-inset-bottom));
      box-shadow: 0 -4px 24px rgba(0,0,0,0.14);
    }
    /* Drag-handle pill at top of sheet */
    .mto-sheet::before {
      content: '';
      display: block;
      width: 36px; height: 4px;
      background: var(--border);
      border-radius: 2px;
      margin: 0 auto 14px;
    }
    /* Typography matching desktop .tooltip-box */
    .mto-content .tt-title {
      font-family: var(--font-body);
      font-size: 15px;
      font-weight: 600;
      color: var(--text);
      margin-bottom: 8px;
    }
    .mto-content .tt-body {
      font-size: 14px;
      color: var(--muted);
      line-height: 1.6;
    }
    .mto-content .tt-example {
      margin-top: 10px;
      padding: 8px 12px;
      background: var(--card);
      border-left: 2px solid var(--accent);
      border-radius: 0 var(--radius) var(--radius) 0;
      font-size: 13px;
      color: var(--text);
      line-height: 1.5;
    }
  }

  /* last card in each row: float right so they don't go offscreen */
  .stat-card:nth-child(3) .tooltip-box,
  .stat-card:nth-child(4) .tooltip-box {
    left: auto;
    right: 0;
  }
  /* Scenario row: middle + last card float right */
  .scenarios-row .stat-card:nth-child(2) .tooltip-box,
  .scenarios-row .stat-card:nth-child(3) .tooltip-box {
    left: auto;
    right: 0;
  }

  .stat-card:hover .tooltip-box,
  .stat-card:focus-within .tooltip-box,
  .tooltip-box.active {
    display: block;
    animation: fadeSlide 0.15s ease forwards;
  }

  .tooltip-box .tt-title,
  .label-tip .tt-title {
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
  }

  .tooltip-box .tt-body,
  .label-tip .tt-body {
    font-size: 13px;
    color: var(--muted);
    line-height: 1.6;
  }

  .tooltip-box .tt-example {
    margin-top: 9px;
    padding: 7px 10px;
    background: var(--card);
    border-left: 2px solid var(--accent);
    border-radius: 0 var(--radius) var(--radius) 0;
    font-size: 12px;
    color: var(--text);
    line-height: 1.5;
  }

  /* ---- PRESET MODES ---- */
  .preset-modes {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 16px;
  }

  .preset-btn {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    padding: 8px 12px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-family: var(--font-body);
    color: var(--muted);
    text-align: left;
    transition: all 0.18s;
    width: 100%;
  }

  .preset-btn:hover {
    border-color: var(--accent);
    color: var(--text);
    background: var(--event-hover-bg);
  }

  .preset-btn.active {
    border-color: var(--accent);
    background: var(--theme-btn-active);
    color: var(--text);
  }

  .preset-btn.active .preset-label {
    color: var(--accent);
  }

  .preset-btn .preset-label {
    font-size: var(--fs-base);
    font-weight: 600;
    letter-spacing: 0.3px;
    white-space: nowrap;
    flex: 1;
  }

  .preset-btn .preset-range {
    font-size: var(--fs-xxs);
    color: var(--muted);
    letter-spacing: 0.5px;
    white-space: nowrap;
    margin-left: auto;
  }

  .preset-btn .preset-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--border);
    flex-shrink: 0;
    transition: background 0.18s;
  }

  .preset-btn.active .preset-dot {
    background: var(--accent);
    box-shadow: 0 0 6px var(--accent);
  }

  /* Active size button highlight */
  .size-btn.active {
    border-color: var(--theme-btn-border);
    background: var(--theme-btn-active);
    color: var(--text) !important;
    font-weight: 700;
    box-shadow: 0 0 0 2px var(--theme-btn-border);
  }

  .size-btn.active span {
    color: var(--accent) !important;
  }

  /* ==============================
     APP SHELL — NAV + FEATURE TABS
     ============================== */

  /* Top nav bar — brand + controls */
  .app-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 52px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
    gap: 16px;
    position: relative;
    z-index: 200; /* above page content so dropdown paints on top */
  }

  .nav-brand {
    display: flex;
    align-items: baseline;
    gap: 10px;
    flex-shrink: 0;
  }

  .nav-brand h1 {
    font-family: var(--font-head);
    font-size: var(--fs-2xl);
    font-weight: 800;
    letter-spacing: -1px;
    line-height: 1;
  }

  .nav-brand h1 span { color: var(--accent); }

  .nav-brand-tag {
    font-size: var(--fs-xxs);
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--muted);
    font-family: var(--font-body);
  }

  .nav-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
  }

  .nav-divider {
    width: 1px;
    height: 18px;
    background: var(--border);
    margin: 0 4px;
    flex-shrink: 0;
  }

  /* "How it works" button — in nav */
  .how-btn.tab-how-btn {
    align-self: center;
    flex-shrink: 0;
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 9px 18px;
    font-size: 13px;
    font-weight: 600;
    gap: 6px;
    border-radius: 50px;
    letter-spacing: 0.2px;
    display: flex;
    align-items: center;
    cursor: pointer;
  }
  .how-btn.tab-how-btn span {
    color: #fff;
    font-size: 15px;
    font-weight: 700;
  }
  .how-btn.tab-how-btn:hover {
    opacity: 0.85;
  }

  /* Disclaimer strip */
  .disclaimer-strip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
    opacity: 0.9;
  }

  .disclaimer-strip .ds-icon { font-size: 11px; flex-shrink: 0; }

  .disclaimer-strip .ds-text {
    font-size: var(--fs-xxs);
    color: var(--muted);
    font-family: var(--font-body);
    line-height: 1.3;
  }

  .disclaimer-strip .ds-text strong {
    color: var(--text);
    font-weight: 600;
  }

  [data-theme="dark"] .disclaimer-strip {
    background: rgba(232,255,87,0.02);
    border-bottom-color: rgba(232,255,87,0.06);
  }

  /* ---- HOW IT WORKS BUTTON ---- */
  .how-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: transparent;
    cursor: pointer;
    font-family: var(--font-body);
    font-size: var(--fs-xxs);
    color: var(--muted);
    transition: all 0.2s;
    white-space: nowrap;
    letter-spacing: 0.5px;
  }
  .how-btn span { font-weight: 700; color: var(--accent); font-size: 13px; line-height: 1; }
  .how-btn:hover { border-color: var(--accent); color: var(--text); }

  /* ---- MODAL BACKDROP ---- */
  .modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
  }
  .modal-backdrop.open { display: flex; }

  /* ---- WELCOME MODAL ---- */
  .welcome-modal {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    max-width: 720px;
    width: 100%;
    max-height: 92vh;
    overflow-y: auto;
    box-shadow: 0 24px 80px rgba(0,0,0,0.4);
    animation: modalIn 0.3s cubic-bezier(0.34,1.56,0.64,1) forwards;
    position: relative;
  }

  @keyframes modalIn {
    from { opacity: 0; transform: scale(0.92) translateY(16px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
  }

  .modal-header {
    padding: 32px 36px 0;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
  }

  .modal-logo {
    font-family: var(--font-head);
    font-size: 32px;
    font-weight: 800;
    letter-spacing: -1px;
    line-height: 1;
  }
  .modal-logo span { color: var(--accent); }

  .modal-close {
    background: none;
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    cursor: pointer;
    color: var(--muted);
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
  }
  .modal-close:hover { border-color: var(--text); color: var(--text); }

  .modal-body { padding: 20px 36px 36px; }

  .modal-tagline {
    font-size: 18px;
    color: var(--text);
    font-weight: 700;
    margin-bottom: 12px;
    margin-top: 8px;
    font-family: var(--font-head);
  }

  .modal-intro {
    font-size: 17px;
    color: var(--muted);
    line-height: 1.45;
    margin-bottom: 20px;
  }

  /* Concept cards inside modal */
  .modal-concepts {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 24px;
  }

  .concept-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px 18px;
  }

  .concept-card .cc-icon { font-size: 22px; margin-bottom: 8px; display: block; }
  .concept-card .cc-title {
    font-family: var(--font-head);
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 6px;
  }
  .concept-card .cc-desc {
    font-size: 14px;
    color: var(--muted);
    line-height: 1.6;
  }

  /* Concept card dots — hidden on desktop */
  .concept-dots {
    display: none;
  }
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 24px;
  }

  .modal-step {
    display: flex;
    align-items: flex-start;
    gap: 12px;
  }

  .step-num {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--bg);
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 1px;
    font-family: var(--font-body);
  }

  .step-text {
    font-size: var(--fs-base);
    color: var(--muted);
    line-height: 1.6;
  }
  .step-text strong { color: var(--text); }

  .modal-footer-row {
    display: flex;
    gap: 10px;
    align-items: stretch; /* equal height */
  }

  .btn-primary {
    flex: 1;
    padding: 13px 24px;
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: 8px;
    font-family: var(--font-body);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.15s;
    letter-spacing: 0.3px;
  }
  .btn-primary:hover { opacity: 0.85; }

  .btn-secondary {
    flex: 1;
    padding: 13px 20px;
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: var(--font-body);
    font-size: 15px;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    text-align: center;
  }
  .btn-secondary:hover { color: var(--text); border-color: var(--text); }

  /* ---- TOUR OVERLAY ---- */
  /* Click-anywhere-to-exit: overlay catches pointer events via the highlight shadow area */
  .tour-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1500;
    pointer-events: none;
    cursor: pointer; /* hint that clicking exits */
  }
  .tour-overlay.open { display: block; }

  /* The dark shadow punch-out area is pointer-events enabled for click-to-exit */
  .tour-exit-layer {
    position: fixed;
    inset: 0;
    pointer-events: all;
    cursor: pointer;
    z-index: 1501;
  }

  /* Highlight ring around the target — sits above exit layer */
  .tour-highlight {
    position: fixed;
    border-radius: 8px;
    box-shadow: 0 0 0 9999px rgba(0,0,0,0.52);
    border: 2px solid var(--accent);
    pointer-events: none;
    z-index: 1502;
    transition: top 0.35s cubic-bezier(0.4,0,0.2,1),
                left 0.35s cubic-bezier(0.4,0,0.2,1),
                width 0.35s cubic-bezier(0.4,0,0.2,1),
                height 0.35s cubic-bezier(0.4,0,0.2,1);
  }

  /* Mobile tour spotlight — pulses a green ring around the active section */
  .tour-mobile-spotlight {
    animation: mobileTourPulse 2s ease forwards;
    border-radius: 10px;
    position: relative;
    z-index: 1;
  }
  @keyframes mobileTourPulse {
    0%   { box-shadow: 0 0 0 0px var(--accent); }
    25%  { box-shadow: 0 0 0 4px var(--accent); }
    75%  { box-shadow: 0 0 0 4px var(--accent); }
    100% { box-shadow: 0 0 0 0px var(--accent); }
  }

  /* Tour callout — centered on screen (desktop) */
  .tour-callout {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 340px;
    background: var(--bg);
    border: 2px solid var(--accent);
    border-radius: 14px;
    padding: 22px 22px 18px;
    box-shadow: 0 16px 60px rgba(0,0,0,0.35), 0 0 0 1px var(--accent);
    pointer-events: all;
    z-index: 1600;
  }

  .tc-step {
    font-size: 11px;
    color: var(--accent);
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-bottom: 6px;
    font-family: var(--font-body);
    font-weight: 700;
  }

  .tc-title {
    font-family: var(--font-head);
    font-size: 20px;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 8px;
    line-height: 1.2;
  }

  .tc-body {
    font-size: 14px;
    color: var(--muted);
    line-height: 1.65;
    margin-bottom: 14px;
  }
  .tc-body strong { color: var(--text); }

  .tc-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  /* "End tour" as a subtle text link inside callout */
  .tc-end {
    font-size: 11px;
    color: var(--muted);
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
    background: none;
    border: none;
    font-family: var(--font-body);
    padding: 0;
    transition: color 0.15s;
    flex-shrink: 0;
  }
  .tc-end:hover { color: var(--text); }

  .tc-dots { display: flex; gap: 6px; align-items: center; }

  .tc-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--border);
    transition: background 0.2s, transform 0.2s;
  }
  .tc-dot.active {
    background: var(--accent);
    transform: scale(1.3);
  }

  .tc-btn {
    padding: 8px 16px;
    border-radius: 7px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
  }
  .tc-btn:hover { border-color: var(--accent); color: var(--text); }
  .tc-btn.primary {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
    font-weight: 700;
  }
  .tc-btn.primary:hover { opacity: 0.85; }

  /* =====================
     MOBILE TOUR — card carousel
     ===================== */
  .tour-carousel {
    display: none; /* shown only on mobile when tour is active */
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 1600;
    pointer-events: all;
  }
  .tour-carousel.open { display: block; }

  /* Cards track — horizontally scrollable, snapping */
  .tc-cards-track {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 0;
  }
  .tc-cards-track::-webkit-scrollbar { display: none; }

  .tc-card {
    flex: 0 0 100%;
    scroll-snap-align: center;
    background: var(--bg);
    border-top: 2px solid var(--accent);
    border-radius: 20px 20px 0 0;
    padding: 20px 22px calc(env(safe-area-inset-bottom, 0px) + 16px);
    box-sizing: border-box;
    box-shadow: 0 -8px 32px rgba(0,0,0,0.18);
  }

  .tc-card-step {
    font-size: 10px;
    color: var(--accent);
    letter-spacing: 2px;
    text-transform: uppercase;
    font-weight: 700;
    font-family: var(--font-body);
    margin-bottom: 4px;
  }

  .tc-card-title {
    font-family: var(--font-head);
    font-size: 18px;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 6px;
    line-height: 1.2;
  }

  .tc-card-body {
    font-size: 14px;
    color: var(--muted);
    line-height: 1.55;
    margin-bottom: 14px;
  }
  .tc-card-body strong { color: var(--text); }

  .tc-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  /* Page dots at bottom of carousel */
  .tc-page-dots {
    display: flex;
    gap: 6px;
    align-items: center;
  }

  .tc-page-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--border);
    transition: background 0.2s, transform 0.2s;
    cursor: pointer;
  }
  .tc-page-dot.active {
    background: var(--accent);
    transform: scale(1.3);
  }

  .tc-card-actions {
    display: flex;
    gap: 6px;
    align-items: center;
  }

  .tc-card-end {
    font-size: 11px;
    color: var(--muted);
    text-decoration: underline;
    text-underline-offset: 2px;
    background: none;
    border: none;
    font-family: var(--font-body);
    padding: 0;
    cursor: pointer;
  }
  .tc-card-end:hover { color: var(--text); }


/* ============================================
   BRAND & WIDE-TOOLTIP OVERRIDES
   (previously the inline <style> block in <body>)
   ============================================ */

  /* ---- BRAND: Here2Retire logo — "2Retire" is always green, across all themes ---- */
  .nav-brand h1 span,
  .modal-logo span {
    color: #14c52f !important;
  }

  /* ---- Wider tooltip styling for richer educational content ---- */
  /* Positioning handled by base .label-tip rules; this just styles the body. */
  .label-tip.label-tip-wide .tt-body {
    line-height: 1.55;
    word-wrap: break-word;
    overflow-wrap: break-word;
  }
  .label-tip.label-tip-wide .tt-body em {
    color: var(--text);
    font-style: italic;
  }
  .label-tip.label-tip-wide .tt-example {
    white-space: normal;
    word-wrap: break-word;
  }

  /* ---- Budget explainer block — educational preamble above the list ---- */
  .budget-explainer {
    background: var(--card);
    border: 1px solid var(--border);
    border-left: 3px solid #14c52f;
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 14px;
    font-size: var(--fs-xs);
    color: var(--muted);
    line-height: 1.55;
    font-family: var(--font-body);
  }
  .budget-explainer strong { color: var(--text); font-weight: 600; }
  .budget-explainer .be-accent { color: #14c52f; font-weight: 600; }
  .budget-explainer .be-flow {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
    font-family: var(--font-body);
  }
  .be-pill {
    display: inline-block;
    padding: 4px 9px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    font-size: var(--fs-xxs);
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    letter-spacing: 0.2px;
  }
  .be-pill-goal {
    background: #14c52f;
    color: #fff;
    border-color: #14c52f;
  }
  .be-arrow {
    font-size: var(--fs-xxs);
    color: var(--muted);
    letter-spacing: 0.5px;
    font-weight: 500;
  }

  .panel-divider {
    margin: 4px -20px 16px;
    border: none;
    border-top: 1px solid var(--border);
    position: relative;
  }

  .panel-divider-label {
    position: absolute;
    top: -10px;
    left: 20px;
    background: var(--surface);
    padding: 0 8px;
    font-size: var(--fs-sm);
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--text);
    font-family: var(--font-body);
    font-weight: 700;
  }

  [data-theme="dark"] .panel-divider-label { background: var(--bg); }
  [data-theme="minimal"] .panel-divider-label { background: var(--bg); }
  [data-theme="genz"] .panel-divider-label { background: var(--bg); }
  [data-theme="unicorn"] .panel-divider-label { background: var(--bg); }
  [data-theme="soft"] .panel-divider-label { background: var(--bg); }
  [data-theme="air"] .panel-divider-label { background: var(--surface); }
  [data-theme="airy"] .panel-divider-label { background: var(--surface); }

  /* ========================
     BUDGET CALCULATOR
     ======================== */
  #budgetInner {
    overflow: hidden;
    max-height: 2000px;
    opacity: 1;
    transition: max-height 0.35s cubic-bezier(0.4,0,0.2,1), opacity 0.25s ease;
  }
  #budgetInner.collapsed { max-height: 0; opacity: 0; }

  .budget-summary {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
  }
  .budget-summary-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 4px;
    font-family: var(--font-body);
  }
  .bs-label {
    font-size: var(--fs-xxs);
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--muted);
  }
  .bs-value {
    font-family: var(--font-head);
    font-size: var(--fs-lg);
    font-weight: 700;
    color: var(--text);
  }
  .bs-value.accent { color: var(--accent); font-size: var(--fs-xl); }

  .budget-bar {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    display: flex;
    margin-top: 10px;
  }
  .budget-bar-inner {
    height: 100%;
    display: flex;
    width: 100%;
  }
  .budget-bar-seg {
    height: 100%;
    transition: width 0.3s ease;
  }

  .budget-linked-note {
    font-size: var(--fs-xxs);
    color: var(--muted);
    margin-top: 8px;
    letter-spacing: 0.3px;
    line-height: 1.4;
  }
  .budget-linked-note span { color: var(--accent); font-weight: 600; }

  .budget-items {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .budget-item {
    display: grid;
    grid-template-columns: 20px 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 8px 4px;
    border-bottom: 1px dashed var(--border);
  }
  .budget-item:last-child { border-bottom: none; }

  .bi-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    justify-self: center;
    flex-shrink: 0;
  }
  .bi-label-wrap {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
  }
  .bi-label {
    font-size: var(--fs-base);
    color: var(--text);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .bi-hint {
    font-size: var(--fs-xxs);
    color: var(--muted);
    letter-spacing: 0.3px;
  }
  .bi-input-wrap {
    display: flex;
    align-items: center;
    gap: 2px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 4px 8px;
    transition: border-color 0.15s;
  }
  .bi-input-wrap:focus-within {
    border-color: var(--accent);
  }
  .bi-input-wrap .bi-currency {
    font-size: var(--fs-sm);
    color: var(--muted);
    font-family: var(--font-body);
  }
  .bi-input {
    width: 70px;
    border: none;
    outline: none;
    background: transparent;
    font-family: var(--font-body);
    font-size: var(--fs-base);
    color: var(--text);
    text-align: right;
    padding: 0;
  }
  .bi-input::-webkit-outer-spin-button,
  .bi-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
  .bi-input[type=number] { -moz-appearance: textfield; }

  .budget-reset-btn {
    margin-top: 10px;
    width: 100%;
    padding: 8px;
    background: transparent;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    color: var(--muted);
    font-family: var(--font-body);
    font-size: var(--fs-xxs);
    letter-spacing: 1px;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.15s;
  }
  .budget-reset-btn:hover {
    border-color: var(--accent);
    color: var(--text);
    border-style: solid;
  }

  /* ---- FOOTER DISCLAIMER ---- */
  .page-footer {
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    background: var(--surface);
    padding: 16px 24px 20px;
  }

  .footer-inner { max-width: 960px; }

  .footer-title {
    font-size: var(--fs-xxs);
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 8px;
    font-family: var(--font-body);
  }

  .footer-body {
    font-size: var(--fs-xxs);
    color: var(--muted);
    line-height: 1.7;
    font-family: var(--font-body);
    opacity: 0.85;
  }

  .footer-body p + p { margin-top: 6px; }

