/* ============ DESIGN TOKENS ============ */
:root, [data-theme='light'] {
  /* Surfaces — white / black, Carolina blue undertone */
  --color-bg: #f5f7fa;
  --color-surface: #ffffff;
  --color-surface-2: #fbfcfe;
  --color-surface-offset: #eef2f7;
  --color-surface-offset-2: #e2e9f1;
  --color-border: #d7e0ea;
  --color-divider: #e4eaf1;

  /* Text */
  --color-text: #0b1220;
  --color-text-muted: #47566a;
  --color-text-faint: #647287;
  --color-text-inverse: #f7f9fc;

  /* Primary accent — Carolina blue (core / stability) */
  --color-primary: #4b9cd3;
  --color-primary-hover: #1b3a63;
  --color-primary-active: #142c4c;
  --color-primary-highlight: #dbecf9;

  /* Satellite accent — small purple touch */
  --color-satellite: #7c5cbf;
  --color-satellite-hover: #5f429c;
  --color-satellite-highlight: #e7e0f5;

  /* Flyers accent — peach (USAR + RIOT only) */
  --color-flyers: #d97a4d;
  --color-flyers-hover: #b8613a;
  --color-flyers-highlight: #fbe6d8;

  --color-success: #3f8055;
  --color-success-highlight: #d7e8dc;
  --color-error: #b3453f;
  --color-error-highlight: #ecd6d3;
  --color-warning: #b9871f;
  --color-warning-highlight: #ede0c3;

  /* Logo-only wood tones (Dryftwood's little log) — not used elsewhere in the UI */
  --brand-log-color: #a9713f;
  --brand-log-end-color: #d9a066;

  --radius-sm: 0.375rem;
  --radius-md: 0.625rem;
  --radius-lg: 0.875rem;
  --radius-xl: 1.25rem;
  --radius-full: 9999px;

  --transition-interactive: 160ms cubic-bezier(0.16, 1, 0.3, 1);

  --shadow-sm: 0 1px 2px oklch(0.2 0.02 200 / 0.06);
  --shadow-md: 0 4px 14px oklch(0.2 0.02 200 / 0.08);
  --shadow-lg: 0 16px 36px oklch(0.2 0.02 200 / 0.14);

  --font-display: 'Cabinet Grotesk', 'Satoshi', sans-serif;
  --font-body: 'Satoshi', 'Inter', sans-serif;
  --font-mono: 'SF Mono', 'JetBrains Mono', ui-monospace, monospace;
}

[data-theme='dark'] {
  --color-bg: #070c14;
  --color-surface: #0e1626;
  --color-surface-2: #111b2d;
  --color-surface-offset: #142138;
  --color-surface-offset-2: #1a2b46;
  --color-border: #24354f;
  --color-divider: #1c2b42;

  --color-text: #eef2f8;
  --color-text-muted: #aab8ce;
  --color-text-faint: #8494ab;
  --color-text-inverse: #0b1220;

  --color-primary: #7bb8e8;
  --color-primary-hover: #9fcdf0;
  --color-primary-active: #bfdff7;
  --color-primary-highlight: #1c3554;

  --color-satellite: #a488d9;
  --color-satellite-hover: #bba5e5;
  --color-satellite-highlight: #2c2347;

  --color-flyers: #e8925f;
  --color-flyers-hover: #f0ac81;
  --color-flyers-highlight: #3d2a1c;

  --color-success: #79b98d;
  --color-success-highlight: #223327;
  --color-error: #d18179;
  --color-error-highlight: #3a2523;
  --color-warning: #d6ac5c;
  --color-warning-highlight: #382f1e;

  --brand-log-color: #c48f5a;
  --brand-log-end-color: #e6b988;

  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.3);
  --shadow-md: 0 4px 14px oklch(0 0 0 / 0.35);
  --shadow-lg: 0 16px 36px oklch(0 0 0 / 0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --color-bg: #070c14;
    --color-surface: #0e1626;
    --color-surface-2: #111b2d;
    --color-surface-offset: #142138;
    --color-surface-offset-2: #1a2b46;
    --color-border: #24354f;
    --color-divider: #1c2b42;
    --color-text: #eef2f8;
    --color-text-muted: #aab8ce;
    --color-text-faint: #8494ab;
    --color-text-inverse: #0b1220;
    --color-primary: #7bb8e8;
    --color-primary-hover: #9fcdf0;
    --color-primary-active: #bfdff7;
    --color-primary-highlight: #1c3554;
    --color-satellite: #a488d9;
    --color-satellite-hover: #bba5e5;
    --color-satellite-highlight: #2c2347;
    --color-flyers: #e8925f;
    --color-flyers-hover: #f0ac81;
    --color-flyers-highlight: #3d2a1c;
    --color-success: #79b98d;
    --color-success-highlight: #223327;
    --color-error: #d18179;
    --color-error-highlight: #3a2523;
    --color-warning: #d6ac5c;
    --color-warning-highlight: #382f1e;
    --brand-log-color: #c48f5a;
    --brand-log-end-color: #e6b988;
    --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.3);
    --shadow-md: 0 4px 14px oklch(0 0 0 / 0.35);
    --shadow-lg: 0 16px 36px oklch(0 0 0 / 0.5);
  }
}

:root {
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.8125rem);
  --text-sm: clamp(0.8125rem, 0.78rem + 0.2vw, 0.9375rem);
  --text-base: clamp(0.9375rem, 0.9rem + 0.2vw, 1rem);
  --text-lg: clamp(1.0625rem, 1rem + 0.4vw, 1.25rem);
  --text-xl: clamp(1.375rem, 1.15rem + 0.9vw, 1.75rem);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
}

/* ============ BASE ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

body {
  min-height: 100dvh;
  line-height: 1.55;
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--color-text);
  background-color: var(--color-bg);
  position: relative;
}

/* Ambient background: soft, slow-drifting blobs in blue/purple/green — a subtle
   lava-lamp feel behind the content. Fixed + very low opacity so it never competes
   with readability or the red/green money-meaning guardrail colors. Purely
   decorative: sits behind everything via z-index and ignores pointer events. */
body::before {
  content: '';
  position: fixed;
  /* V2.7 background pass: overscan so the slow drift/scale never exposes a bare
     edge, and keep the blurred layer on its own GPU layer for smooth scrolling. */
  inset: -8%;
  will-change: transform;
  z-index: 0;
  pointer-events: none;
  opacity: var(--ambient-bg-opacity, 0.85);
  background:
    radial-gradient(42% 36% at 12% 16%, color-mix(in oklab, var(--color-primary) 75%, transparent), transparent 72%),
    radial-gradient(38% 34% at 88% 10%, color-mix(in oklab, var(--color-satellite) 68%, transparent), transparent 72%),
    radial-gradient(40% 38% at 80% 85%, color-mix(in oklab, #3fae7a 62%, transparent), transparent 72%),
    radial-gradient(34% 32% at 10% 90%, color-mix(in oklab, var(--color-primary) 55%, transparent), transparent 72%),
    radial-gradient(30% 30% at 50% 50%, color-mix(in oklab, var(--color-satellite) 30%, transparent), transparent 75%);
  filter: blur(50px);
  animation: ambient-drift 32s ease-in-out infinite alternate;
}

@keyframes ambient-drift {
  0% { transform: translate3d(0, 0, 0) scale(1); }
  50% { transform: translate3d(1.5%, -2%, 0) scale(1.06); }
  100% { transform: translate3d(-1.5%, 2%, 0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  body::before { animation: none; }
}

.app { position: relative; z-index: 1; }

img, svg { display: block; max-width: 100%; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; border-radius: var(--radius-sm); }
button { cursor: pointer; background: none; border: none; }
table { border-collapse: collapse; width: 100%; }

a, button, [role='button'], input, select {
  transition: color var(--transition-interactive), background var(--transition-interactive),
    border-color var(--transition-interactive), box-shadow var(--transition-interactive), transform var(--transition-interactive);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

.tabular { font-variant-numeric: tabular-nums lining-nums; }

/* ============ LAYOUT ============ */
.app { min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in oklab, var(--color-bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--color-border);
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: var(--space-4) var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand { display: flex; align-items: center; gap: var(--space-3); }
.brand-mark { color: var(--color-primary); width: 34px; height: 34px; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-title { font-family: var(--font-display); font-weight: 700; font-size: var(--text-lg); }
h1.brand-title { margin: 0; line-height: inherit; letter-spacing: inherit; }
.brand-version { font-family: var(--font-body); font-weight: 600; font-size: var(--text-xs); color: var(--color-primary); background: color-mix(in oklab, var(--color-primary) 12%, transparent); padding: 2px 7px; border-radius: 999px; margin-left: var(--space-2); vertical-align: middle; letter-spacing: 0.01em; }
.brand-sub { font-size: var(--text-xs); color: var(--color-text-muted); }

.topbar-actions { display: flex; align-items: center; gap: var(--space-3); }
.snapshot-link {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-primary);
  background: color-mix(in oklab, var(--color-primary) 10%, transparent);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  text-decoration: none;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
[data-theme='dark'] .snapshot-link { color: var(--color-primary-hover); }
@media (hover: hover) { .snapshot-link:hover { background: color-mix(in oklab, var(--color-primary) 18%, transparent); } }

.theme-toggle {
  width: 36px; height: 36px;
  position: relative;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-full);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.theme-toggle::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 44px; height: 44px;
  transform: translate(-50%, -50%);
}
@media (hover: hover) { .theme-toggle:hover { color: var(--color-text); background: var(--color-surface-offset); } }
.theme-toggle:active { background: var(--color-surface-offset); }

.main { flex: 1; }
.main-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: var(--space-8) var(--space-6) var(--space-16);
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
}

/* ============ INTRO PANEL (collapsible "How this works") ============ */
.intro-panel {
  background: color-mix(in oklab, var(--color-primary) 5%, var(--color-surface));
  border: 1px solid color-mix(in oklab, var(--color-primary) 20%, var(--color-border));
  border-radius: var(--radius-xl);
  overflow: hidden;
}
.intro-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--text-base);
  color: var(--color-text);
  text-align: left;
}
@media (hover: hover) { .intro-toggle:hover { background: color-mix(in oklab, var(--color-primary) 6%, transparent); } }
.intro-chevron { flex-shrink: 0; transition: transform 0.2s ease; color: var(--color-primary); }
.intro-panel.is-collapsed .intro-chevron { transform: rotate(-90deg); }
.intro-body {
  padding: 0 var(--space-6) var(--space-6);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  max-width: 68ch;
}
.intro-body strong { color: var(--color-text); font-weight: 600; }
.intro-panel.is-collapsed .intro-body { display: none; }

/* ============ STEP 2 COLLAPSE ============ */
#btn-targets-toggle { display: flex; align-items: center; gap: var(--space-2); }
#btn-targets-toggle .intro-chevron { transition: transform 0.2s ease; }
#btn-targets-toggle[aria-expanded="true"] .intro-chevron { transform: rotate(180deg); }
.targets-body { display: none; margin-top: var(--space-6); }
#panel-targets.is-expanded .targets-body { display: block; }
.targets-collapsed-summary {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-top: var(--space-2);
}
#panel-targets.is-expanded .targets-collapsed-summary { display: none; }

/* ============ PANELS ============ */
.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-6) var(--space-6) var(--space-8);
  box-shadow: var(--shadow-sm);
}
.panel-highlight {
  border-color: color-mix(in oklab, var(--color-primary) 35%, var(--color-border));
  background: linear-gradient(180deg, color-mix(in oklab, var(--color-primary) 4%, var(--color-surface)), var(--color-surface) 40%);
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-6);
}
.step-tag {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-primary);
  margin-bottom: var(--space-1);
}
.panel-title { font-family: var(--font-display); font-weight: 700; font-size: var(--text-xl); margin-bottom: var(--space-1); }
.panel-desc { font-size: var(--text-sm); color: var(--color-text-muted); max-width: 62ch; }
.panel-head-actions { display: flex; align-items: center; gap: var(--space-3); flex-shrink: 0; }
.horizon-label { margin-bottom: 0; }

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm); font-weight: 500;
  border: 1px solid var(--color-border);
}
.btn-ghost { background: var(--color-surface-offset); color: var(--color-text-muted); }
@media (hover: hover) { .btn-ghost:hover { color: var(--color-text); background: var(--color-surface-offset-2); } }

/* ============ HOLDINGS TABLE ============ */
.table-scroll-hint {
  display: none;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  margin-bottom: var(--space-2);
}
.table-scroll-hint svg { flex-shrink: 0; animation: table-scroll-nudge 1.6s ease-in-out infinite; }
@keyframes table-scroll-nudge {
  0%, 100% { transform: translateX(0); opacity: 0.55; }
  50% { transform: translateX(4px); opacity: 1; }
}
.table-wrap-outer { position: relative; }
.table-wrap { overflow-x: auto; border-radius: var(--radius-md); border: 1px solid var(--color-divider); -webkit-overflow-scrolling: touch; }
.table-wrap-outer::after {
  content: '';
  position: absolute; top: 1px; right: 1px; bottom: 1px; width: 36px;
  background: linear-gradient(to right, transparent, color-mix(in oklab, var(--color-text) 22%, transparent));
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  pointer-events: none;
  opacity: 0; transition: opacity 0.2s ease;
}
.table-wrap-outer.can-scroll-more::after { opacity: 1; }
.holdings-table { min-width: 640px; font-size: var(--text-sm); }
.holdings-table th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-offset);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  position: sticky; top: 0;
}
.holdings-table td {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-divider);
  vertical-align: middle;
}
@media (hover: hover) { .holdings-table tbody tr:hover { background: color-mix(in oklab, var(--color-primary) 4%, transparent); } }
.col-price, .col-shares, .col-value, .col-weight, .col-tranche, .col-target, .col-drift { text-align: right; font-variant-numeric: tabular-nums lining-nums; }
.col-shares input {
  width: 88px;
  text-align: right;
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums lining-nums;
}
.col-shares input:focus { border-color: var(--color-primary); }

.ticker-cell { display: flex; align-items: center; gap: var(--space-3); }
.ticker-dot { width: 10px; height: 10px; border-radius: var(--radius-full); flex-shrink: 0; }
.ticker-name-block { display: flex; flex-direction: column; line-height: 1.3; }
.ticker-symbol { font-weight: 700; font-size: var(--text-sm); }
.ticker-full-name { font-size: var(--text-xs); color: var(--color-text-faint); }

.role-badge {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.role-badge.core { background: var(--color-primary-highlight); color: var(--color-primary); }
[data-theme='dark'] .role-badge.core { color: var(--color-primary-hover); }
.role-badge.satellite { background: var(--color-satellite-highlight); color: var(--color-satellite); }
.role-badge.flyers { background: var(--color-flyers-highlight); color: var(--color-flyers); }
[data-theme='dark'] .role-badge.flyers { color: var(--color-flyers-hover); }

.totals-row td { font-weight: 700; border-top: 2px solid var(--color-border); padding-top: var(--space-3); }

.weight-cell-wrap { display: flex; align-items: center; justify-content: flex-end; gap: var(--space-2); }
.weight-bar-track { width: 56px; height: 6px; border-radius: var(--radius-full); background: var(--color-surface-offset-2); overflow: hidden; }
.weight-bar-fill { height: 100%; border-radius: var(--radius-full); }

/* ============ CORE/SAT SUMMARY STRIP ============ */
.core-sat-summary { display: flex; gap: var(--space-4); margin-top: var(--space-5); flex-wrap: wrap; }
.summary-chip {
  flex: 1; min-width: 200px;
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-divider);
  background: var(--color-surface-2);
}
.summary-chip-label { display: flex; flex-direction: column; gap: 2px; }
.summary-chip-tag { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.03em; color: var(--color-text-muted); font-weight: 600; }
.summary-chip-value { font-family: var(--font-display); font-size: var(--text-xl); font-weight: 700; font-variant-numeric: tabular-nums lining-nums; }
.summary-chip.core .summary-chip-value { color: var(--color-primary); }
.summary-chip.satellite .summary-chip-value { color: var(--color-satellite); }
.summary-chip.flyers .summary-chip-value { color: var(--color-flyers); }

/* ============ TARGETS PANEL ============ */
input[type='range'] {
  flex: 1;
  height: 6px;
  border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--color-primary) 0%, var(--color-primary) var(--fill, 75%), var(--color-satellite-highlight) var(--fill, 75%), var(--color-satellite) 100%);
  appearance: none;
  cursor: pointer;
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
}
input[type='range']::-webkit-slider-thumb {
  appearance: none;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--color-surface);
  border: 3px solid var(--color-primary);
  box-shadow: var(--shadow-md);
  cursor: pointer;
}
input[type='range']::-moz-range-thumb {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--color-surface);
  border: 3px solid var(--color-primary);
  box-shadow: var(--shadow-md);
  cursor: pointer;
}

.target-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--space-4); }
.target-item {
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  background: var(--color-surface-2);
}
/* Per-holding drift guardrail: ring color shows how far current weight has
   drifted from its target (green within 3pp, orange 3-5pp, red beyond 5pp). */
.target-item.drift-guardrail {
  border: 2px solid var(--drift-color, var(--color-divider));
  box-shadow: 0 0 0 1px var(--drift-color, transparent) inset;
  transition: border-color var(--transition-interactive), box-shadow var(--transition-interactive);
}
.target-item-drift-note {
  margin-top: var(--space-2);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--drift-color, var(--color-text-muted));
}
.target-item-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-3); }
.target-item-ticker { display: flex; align-items: center; gap: var(--space-2); font-weight: 700; font-size: var(--text-sm); }
.target-item-pct { font-size: var(--text-sm); font-weight: 700; font-variant-numeric: tabular-nums lining-nums; }
.target-item input[type='range'] { height: 4px; }
.slider-guardrail {
  background: linear-gradient(90deg, var(--guardrail-color, var(--color-success)) 0%, var(--guardrail-color, var(--color-success)) var(--fill, 50%), var(--color-surface-offset) var(--fill, 50%), var(--color-surface-offset) 100%) !important;
  transition: background var(--transition-interactive);
}
.slider-guardrail::-webkit-slider-thumb { border-color: var(--guardrail-color, var(--color-success)); }
.slider-guardrail::-moz-range-thumb { border-color: var(--guardrail-color, var(--color-success)); }
.target-item-sub { font-size: var(--text-xs); color: var(--color-text-faint); margin-top: var(--space-1); }

/* ============ DEPLOYMENT PANEL ============ */
.field-label { font-size: var(--text-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; color: var(--color-text-muted); }
.amount-prefix { padding: 0 0 0 var(--space-3); color: var(--color-text-muted); font-weight: 600; }

/* ============ TARGET SUBGROUPS (Step 2) ============ */
.target-subgroup { margin-bottom: var(--space-6); }
.target-subgroup:last-child { margin-bottom: 0; }
.target-subgroup-title {
  display: flex; align-items: baseline; gap: var(--space-2); flex-wrap: wrap;
  font-size: var(--text-sm); font-weight: 700; margin-bottom: var(--space-3);
}
.target-subgroup-note { font-size: var(--text-xs); font-weight: 500; color: var(--color-text-faint); text-transform: none; letter-spacing: 0; }
.guardrail-readout {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: var(--space-2);
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px dashed var(--color-divider);
  font-size: var(--text-sm); color: var(--color-text-muted);
}
.target-sum-readout { font-size: var(--text-xs); font-weight: 600; }
.target-sum-readout.ok { color: var(--color-success); }
.target-sum-readout.warn { color: var(--color-warning); }
.spec-band-note { margin-top: var(--space-2); font-size: var(--text-xs); font-weight: 600; padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); transition: background var(--transition-interactive), color var(--transition-interactive); }
.spec-band-note.ok { background: var(--color-success-highlight); color: var(--color-success); }
.spec-band-note.caution { background: var(--color-warning-highlight); color: var(--color-warning); }
.spec-band-note.danger { background: var(--color-error-highlight); color: var(--color-error); }

/* ============ DRY POWDER (Step 3) ============ */
.dry-powder-block { margin-bottom: var(--space-5); }
.dry-powder-slider-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-2); }
.dry-powder-value { font-family: var(--font-display); font-size: var(--text-lg); font-weight: 700; color: var(--color-primary); }
[data-theme='dark'] .dry-powder-value { color: var(--color-primary-hover); }
#dry-powder-slider {
  background: linear-gradient(90deg, var(--color-primary) 0%, var(--color-primary) var(--fill, 66%), var(--color-surface-2) var(--fill, 66%), var(--color-surface-2) 100%);
}
.window-amount-readout { font-size: var(--text-xs); color: var(--color-text-faint); margin-top: var(--space-2); }
.window-section-label { font-size: var(--text-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; color: var(--color-text-faint); margin-bottom: var(--space-3); }

/* ============ PER-WINDOW TICKER SLOTS (Step 3) ============ */
.window-auto-tag {
  font-size: var(--text-xs); font-weight: 600; color: var(--color-text-faint);
  margin-bottom: var(--space-3); padding: 3px 0;
}
.window-auto-tag.custom { color: var(--color-primary); }
[data-theme='dark'] .window-auto-tag.custom { color: var(--color-primary-hover); }

.window-slots { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-3); }

.window-slot-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: var(--space-2);
  position: relative;
  z-index: 1;
}
.window-slot-row:has(.slot-ticker-menu:not([hidden])) { z-index: 50; }
.window-slot-row .ticker-dot { flex-shrink: 0; }
.window-slot-row .ticker-dot.empty { background: var(--color-divider); }

.slot-ticker-dropdown { position: relative; min-width: 0; }

.slot-ticker-trigger {
  width: 100%; min-width: 0;
  min-height: 44px;
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  font-size: var(--text-xs);
  font-weight: 600;
  font-family: inherit;
  color: var(--color-text);
  cursor: pointer;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.slot-ticker-trigger:active { background: var(--color-surface-offset); }
.slot-ticker-trigger[aria-expanded='true'] { border-color: var(--color-primary); }
.slot-ticker-trigger-label {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.slot-ticker-chevron { flex-shrink: 0; color: var(--color-text-faint); transition: transform var(--transition-fast); }
.slot-ticker-trigger[aria-expanded='true'] .slot-ticker-chevron { transform: rotate(180deg); }

.slot-ticker-menu {
  position: absolute;
  top: calc(100% + 4px); left: 0; right: 0;
  z-index: 60;
  max-height: 260px;
  overflow-y: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-1);
  display: flex; flex-direction: column; gap: 1px;
  overflow-x: hidden;
  will-change: transform;
  transform: translateZ(0);
  isolation: isolate;
  contain: layout style paint;
}
.slot-ticker-menu[hidden] { display: none; }
.slot-ticker-menu.menu-flip-up { top: auto; bottom: calc(100% + 4px); }

.slot-ticker-option {
  display: flex; align-items: center; gap: var(--space-2);
  width: 100%;
  min-height: 44px;
  padding: var(--space-2) var(--space-2);
  border: none; border-radius: var(--radius-sm);
  background: transparent;
  font-family: inherit;
  font-size: var(--text-xs); font-weight: 600;
  color: var(--color-text);
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.slot-ticker-option:active { background: var(--color-surface-offset); }
.slot-ticker-option.is-selected { background: var(--color-primary-highlight); color: var(--color-primary); }
.slot-ticker-option-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot-ticker-option-tag { flex: 0 1 auto; min-width: 0; max-width: 40%; font-size: 10px; font-weight: 500; color: var(--color-text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot-ticker-option.is-disabled { color: var(--color-text-faint); cursor: not-allowed; }
.slot-ticker-option.is-disabled:active { background: transparent; }
.slot-ticker-option.is-disabled .ticker-dot { opacity: 0.4; }

@media (hover: hover) {
  .slot-ticker-trigger:hover { border-color: var(--color-text-muted); }
  .slot-ticker-option:not(.is-disabled):hover { background: var(--color-surface-2); }
}

.slot-amount-wrap {
  display: flex; align-items: center;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  width: 92px;
  flex-shrink: 0;
}
.slot-amount-prefix { padding-left: var(--space-2); font-size: var(--text-xs); color: var(--color-text-faint); }
.slot-amount-input {
  width: 100%; min-width: 0;
  padding: var(--space-2) var(--space-2) var(--space-2) 2px;
  font-size: var(--text-xs); font-weight: 700;
  font-variant-numeric: tabular-nums lining-nums;
  background: transparent; border: none;
}

.btn-remove-slot {
  width: 22px; height: 22px; flex-shrink: 0;
  position: relative;
  display: flex; align-items: center; justify-content: center;
  border: none; border-radius: var(--radius-full);
  background: var(--color-surface-2);
  color: var(--color-text-faint);
  font-size: var(--text-sm); line-height: 1; cursor: pointer;
}
.btn-remove-slot::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 40px; height: 44px;
  transform: translate(-45%, -50%);
}
@media (hover: hover) { .btn-remove-slot:hover { background: var(--color-error-highlight); color: var(--color-error); } }

.window-slot-actions { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); margin-bottom: var(--space-3); }
.btn-add-slot, .btn-reset-window {
  font-size: var(--text-xs); font-weight: 600;
  padding: var(--space-1) var(--space-3);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
}
@media (hover: hover) { .btn-add-slot:hover { border-color: var(--color-primary); color: var(--color-primary); } }
@media (hover: hover) { .btn-reset-window:hover { border-color: var(--color-text-muted); color: var(--color-text); } }

.window-total-row { display: flex; align-items: center; justify-content: space-between; padding-top: var(--space-3); border-top: 1px dashed var(--color-divider); position: relative; z-index: 0; }
.window-total-label { font-size: var(--text-xs); font-weight: 600; color: var(--color-text-faint); text-transform: uppercase; letter-spacing: 0.03em; }
.window-total-value { font-family: var(--font-display); font-size: var(--text-base); font-weight: 700; }
.window-total-diff { position: relative; z-index: 0; font-size: var(--text-xs); margin-top: 2px; font-weight: 600; }
.window-total-diff.match { color: var(--color-success); }
.window-total-diff.over { color: var(--color-warning); }
.window-total-diff.under { color: var(--color-text-faint); }
.window-total-row.match .window-total-value { color: var(--color-success); }
.window-total-row.over .window-total-value { color: var(--color-warning); }


.horizon-note { margin-top: var(--space-4); padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); font-size: var(--text-sm); line-height: 1.6; }
.horizon-note.ok { background: var(--color-success-highlight); color: var(--color-success); }
.horizon-note.warn { background: var(--color-warning-highlight); color: var(--color-warning); }
.horizon-note:empty { display: none; }
/* ============ RESULTS ============ */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--space-4); margin-bottom: var(--space-8); }
.kpi-card { padding: var(--space-4); border: 1px solid var(--color-divider); border-radius: var(--radius-md); background: var(--color-surface-2); }
.kpi-card-label { font-size: var(--text-xs); color: var(--color-text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: var(--space-2); }
.kpi-card-value { font-family: var(--font-display); font-size: var(--text-xl); font-weight: 700; font-variant-numeric: tabular-nums lining-nums; margin-bottom: var(--space-1); }
.kpi-card-delta { font-size: var(--text-sm); font-weight: 600; display: flex; align-items: center; gap: var(--space-1); }
.kpi-card-delta.up { color: var(--color-success); }
.kpi-card-delta.down { color: var(--color-error); }
.kpi-card-delta.flat { color: var(--color-text-faint); }

.results-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-5); margin-bottom: var(--space-6); }
.chart-card-wide { grid-column: 1 / -1; }
.chart-card { border: 1px solid var(--color-divider); border-radius: var(--radius-md); padding: var(--space-5); background: var(--color-surface-2); }
.chart-card-title { font-size: var(--text-base); font-weight: 700; margin-bottom: var(--space-1); }
.chart-card-sub { font-size: var(--text-xs); color: var(--color-text-muted); margin-bottom: var(--space-4); max-width: 60ch; }
.chart-canvas-wrap { position: relative; height: 260px; margin-top: var(--space-4); max-width: 100%; overflow: hidden; }
.chart-canvas-wrap canvas { max-width: 100%; }
.chart-canvas-wrap-sm { height: 220px; }
.chart-canvas-wrap-drift { height: 300px; }
.chart-canvas-wrap-horizon { height: 320px; margin-top: var(--space-4); }

.chart-legend { display: flex; justify-content: center; gap: var(--space-5); margin-top: var(--space-3); }
.chart-legend-item { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); font-weight: 600; }
.chart-legend-dot { width: 10px; height: 10px; border-radius: 50%; }

.verdict-card {
  display: flex; align-items: flex-start; gap: var(--space-4);
  padding: var(--space-5);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-6);
  border: 1.5px solid transparent;
}
.verdict-card.improves { background: var(--color-success-highlight); border-color: color-mix(in oklab, var(--color-success) 35%, transparent); }
.verdict-card.worsens { background: var(--color-error-highlight); border-color: color-mix(in oklab, var(--color-error) 35%, transparent); }
.verdict-card.neutral { background: var(--color-warning-highlight); border-color: color-mix(in oklab, var(--color-warning) 35%, transparent); }
.verdict-icon { flex-shrink: 0; width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.verdict-card.improves .verdict-icon { background: var(--color-success); color: white; }
.verdict-card.worsens .verdict-icon { background: var(--color-error); color: white; }
.verdict-card.neutral .verdict-icon { background: var(--color-warning); color: white; }
.verdict-title { font-weight: 700; font-size: var(--text-base); margin-bottom: var(--space-1); }
.verdict-body { font-size: var(--text-sm); color: var(--color-text-muted); }

.col-drift.positive { color: var(--color-success); }
.col-drift.negative { color: var(--color-error); }

/* Step 6: plain-language summary card. Intentionally neutral (wood tones instead of
   green/orange/red) since red/green are reserved for money-meaning guardrail states
   elsewhere — this card is informational/educational, not a verdict. The wood-grain
   look ties back to "Dryftwood" and the little log in the logo: layered CSS gradients
   only (no image asset), kept stylized rather than photoreal, and light enough that
   the white text on top stays fully legible. Sits on a light-blue "water" bed with
   subtle ripples, as if the wood plank were floating. Water tone flips with theme:
   deeper blue in light mode (contrast against the pale page), soft pale blue in dark
   mode (so it still reads against the dark page). */
.summary-water {
  position: relative;
  padding: var(--space-5) var(--space-4);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background-color: #bcdcef;
  background-image:
    repeating-radial-gradient(ellipse 220px 14px at 20% 85%, rgba(255,255,255,0.35) 0px, transparent 3px, transparent 22px),
    repeating-radial-gradient(ellipse 260px 16px at 75% 15%, rgba(255,255,255,0.3) 0px, transparent 3px, transparent 26px),
    linear-gradient(160deg, #d3ecf9, #a8d3ea 55%, #8ec2de);
}
[data-theme='dark'] .summary-water {
  background-color: #16324a;
  background-image:
    repeating-radial-gradient(ellipse 220px 14px at 20% 85%, rgba(255,255,255,0.09) 0px, transparent 3px, transparent 22px),
    repeating-radial-gradient(ellipse 260px 16px at 75% 15%, rgba(255,255,255,0.07) 0px, transparent 3px, transparent 26px),
    linear-gradient(160deg, #6bb0da, #3a7ba8 55%, #235376);
}
.summary-card {
  position: relative;
  padding: var(--space-5);
  border-radius: var(--radius-lg);
  border: 1.5px solid color-mix(in oklab, var(--brand-log-color, #a9713f) 45%, var(--color-border));
  overflow: hidden;
  box-shadow: 0 10px 22px -8px rgba(10, 30, 45, 0.35), inset 0 0 0 1px rgba(255,236,205,0.18), inset 0 -10px 18px -10px rgba(40,20,5,0.45), inset 0 8px 14px -10px rgba(255,240,215,0.35);
  background-color: #9c7850;
  background-image: url("assets/driftwood-main.jpg");
  background-size: cover;
  background-position: center;
}
.summary-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(40,22,8,0.34), rgba(30,16,5,0.50));
  pointer-events: none;
}
.summary-card > * { position: relative; z-index: 1; }
.summary-card p { font-size: var(--text-sm); line-height: 1.65; color: #fffaf2; max-width: 68ch; text-shadow: 0 1px 2px rgba(0,0,0,0.6), 0 0 8px rgba(30,15,5,0.45); }
.summary-card p + p { margin-top: var(--space-3); }
.summary-card p:first-child { font-weight: 700; }
.summary-card p.summary-yogi {
  font-style: italic;
  padding-top: var(--space-3);
  margin-top: var(--space-4) !important;
  border-top: 1px dashed color-mix(in oklab, var(--brand-log-end-color, #d9a066) 50%, transparent);
}
.summary-card .summary-yogi-attr {
  display: block;
  font-style: normal;
  font-size: var(--text-xs);
  opacity: 0.8;
  margin-top: var(--space-1);
}

/* ============ FOOTER ============ */
.closing-bookend {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) 0 var(--space-2);
  color: var(--color-text-faint);
}
.closing-bookend-text {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-style: italic;
  color: var(--color-text-faint);
  margin: 0;
}
.app-footer { padding: var(--space-6) 0 var(--space-4); text-align: center; }
.app-footer p { font-size: var(--text-xs); color: var(--color-text-faint); max-width: 70ch; margin: 0 auto; }
.app-footer a { color: var(--color-text-muted); text-decoration: underline; }
.app-footer .footer-credit { margin-top: var(--space-2); font-size: var(--text-xs); color: var(--color-text-faint); opacity: 0.7; }

/* ============ SELECT ============ */

.horizon-dropdown { position: relative; flex-shrink: 0; }
.horizon-trigger {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
  font-size: var(--text-sm); font-weight: 600;
  font-family: inherit;
  color: var(--color-text);
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.horizon-trigger:active { background: var(--color-surface-offset); }
.horizon-trigger[aria-expanded='true'] { border-color: var(--color-primary); }
.horizon-trigger .slot-ticker-chevron { color: var(--color-text-faint); transition: transform var(--transition-fast); }
.horizon-trigger[aria-expanded='true'] .slot-ticker-chevron { transform: rotate(180deg); }
.horizon-menu {
  position: absolute;
  top: calc(100% + 4px); right: 0;
  z-index: 60;
  min-width: 180px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-1);
  display: flex; flex-direction: column; gap: 1px;
  will-change: transform;
  transform: translateZ(0);
  isolation: isolate;
  contain: layout style paint;
}
.horizon-menu[hidden] { display: none; }
.horizon-menu.menu-flip-up { top: auto; bottom: calc(100% + 4px); }
.horizon-menu .slot-ticker-option { padding: var(--space-2) var(--space-3); white-space: nowrap; }
@media (hover: hover) {
  .horizon-trigger:hover { border-color: var(--color-text-muted); }
}

/* ============ RESPONSIVE ============ */
@media (max-width: 860px) {
  .results-grid { grid-template-columns: 1fr; }
  .chart-card-wide { grid-column: auto; }
  .topbar-inner { padding: var(--space-3) var(--space-4); }
  .main-inner { padding: var(--space-6) var(--space-4) var(--space-12); gap: var(--space-6); }
  .panel { padding: var(--space-5) var(--space-4) var(--space-6); }
  .panel-title { font-size: var(--text-lg); }
  .table-scroll-hint { display: flex; }
}

@media (max-width: 520px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
}

/* Prevent mobile browsers (notably Android Chrome/Samsung Internet) from auto-zooming
   the page on focus, which can make selects/inputs feel broken or unresponsive to taps.
   Any form control under 16px triggers this, so floor these to 16px on touch-sized viewports. */
@media (max-width: 640px) {
  .slot-ticker-trigger, .slot-amount-input, input[type='number'], select {
    font-size: 16px;
  }
  .slot-ticker-trigger { padding: 10px var(--space-2); }
  .slot-amount-input { padding: 12px var(--space-2) 12px 2px; min-height: 44px; }
  .horizon-trigger { font-size: 16px; padding: 10px var(--space-3); }

  /* Direct-entry numeric fields only (share counts, dollar amounts) — no increment/decrement
     use case, so the native up/down spinner arrows just shrink the tappable text area and
     invite accidental +/-1 taps right next to where a thumb naturally lands. Hide them and
     give the field itself a comfortable touch height instead. */
  input[type='number']::-webkit-outer-spin-button,
  input[type='number']::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
  }
  input[type='number'] {
    -moz-appearance: textfield;
    min-height: 44px;
  }

  /* Slightly larger touch surface for range sliders on small screens —
     easier to grab the thumb precisely and less likely to feel unresponsive. */
  input[type='range'] { height: 8px; }
  .target-item input[type='range'] { height: 6px; }
  input[type='range']::-webkit-slider-thumb { width: 24px; height: 24px; }
  input[type='range']::-moz-range-thumb { width: 24px; height: 24px; }
}

/* V2.7: two snapshot pills (30-Day + 60-Day) in the topbar — keep them tight on phones */
@media (max-width: 560px) {
  .topbar-inner { flex-wrap: wrap; row-gap: var(--space-2); }
  .topbar-actions { width: 100%; justify-content: flex-start; gap: var(--space-2); }
  .topbar-actions { flex-wrap: wrap; row-gap: var(--space-2); }
  /* Theme toggle sits first, left of the 30-Day pill, so it's always on screen */
  .topbar-actions .theme-toggle { width: 30px; height: 30px; flex-shrink: 0; }
  .topbar-actions .theme-toggle svg { width: 15px; height: 15px; }
  .snapshot-link { padding: var(--space-1) var(--space-3); }
}


/* V2.7 touch pass: comfortable tap targets on phones (coarse pointers) */
@media (pointer: coarse) {
  .snapshot-link { display: inline-flex; align-items: center; min-height: 36px; position: relative; }
  .snapshot-link::after { content: ''; position: absolute; inset: -4px -2px; }
  .btn-add-slot, .btn-reset-window { min-height: 40px; padding: var(--space-2) var(--space-4); }
  .back-link { min-height: 40px; display: inline-flex; align-items: center; }
}

/* V2.7 background pass: native controls (number fields, scrollbars, dropdown
   option lists) follow the in-app theme instead of the phone's system theme. */
[data-theme='light'] { color-scheme: light; }
[data-theme='dark'] { color-scheme: dark; }
html { background-color: var(--color-bg); }

/* V2.7 gut pass: target + dry-powder sliders span their card (they were ~130px
   wide on phones, which made half-point adjustments fiddly). */
.target-item input[type='range'], #dry-powder-slider { display: block; width: 100%; }
