/* ═══════════════════════════════════════════
   DESIGN TOKENS — light / dark
═══════════════════════════════════════════ */
:root, [data-theme="light"] {
  --font-display: 'Cabinet Grotesk', 'Helvetica Neue', sans-serif;
  --font-body: 'Satoshi', 'Inter', sans-serif;

  /* Type scale */
  --text-xs:   clamp(0.75rem,  0.7rem  + 0.25vw, 0.875rem);
  --text-sm:   clamp(0.875rem, 0.8rem  + 0.35vw, 1rem);
  --text-base: clamp(1rem,     0.95rem + 0.25vw, 1.125rem);
  --text-lg:   clamp(1.125rem, 1rem    + 0.75vw, 1.5rem);
  --text-xl:   clamp(1.5rem,   1.2rem  + 1.25vw, 2.25rem);

  /* Spacing */
  --sp-1: 0.25rem; --sp-2: 0.5rem; --sp-3: 0.75rem;
  --sp-4: 1rem; --sp-5: 1.25rem; --sp-6: 1.5rem;
  --sp-8: 2rem; --sp-10: 2.5rem; --sp-12: 3rem;

  /* Radii */
  --r-sm: 0.375rem; --r-md: 0.625rem; --r-lg: 1rem; --r-xl: 1.5rem;

  /* Palette — professional navy-indigo */
  --bg:            #eef1fb;
  --surface:       #ffffff;
  --surface-2:     #f5f7ff;
  --surface-3:     #eceffe;
  --border:        #d1d8f0;
  --divider:       #e2e8f8;

  --text:          #1a1e3c;
  --text-muted:    #5a6098;
  --text-faint:    #9ca3bf;

  --accent:        #2a52d6;
  --accent-h:      #1e3ea8;
  --accent-subtle: #eef2ff;
  --accent-tint:   #dde6ff;

  --success:       #126e38;
  --success-bg:    #f0fdf4;
  --success-ring:  #6ee7a0;

  --warn:          #a35a0a;
  --warn-bg:       #fff7ed;
  --warn-ring:     #fdba74;

  --danger:        #991b1b;
  --danger-bg:     #fef2f2;
  --danger-ring:   #fca5a5;

  --shadow-sm: 0 1px 4px rgba(26,30,60,0.07);
  --shadow-md: 0 4px 16px rgba(26,30,60,0.10);
  --shadow-lg: 0 12px 36px rgba(26,30,60,0.13);

  --ease: 220ms cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="dark"] {
  --bg:            #090c1a;
  --surface:       #0f1425;
  --surface-2:     #141932;
  --surface-3:     #1a2040;
  --border:        #232a50;
  --divider:       #1d2440;

  --text:          #dde2ff;
  --text-muted:    #8892c8;
  --text-faint:    #424b7a;

  --accent:        #7c9bff;
  --accent-h:      #9bb3ff;
  --accent-subtle: #141a3e;
  --accent-tint:   #1c2450;

  --success:       #34d279;
  --success-bg:    #082416;
  --success-ring:  #166534;

  --warn:          #fb923c;
  --warn-bg:       #1a0d00;
  --warn-ring:     #92400e;

  --danger:        #f87171;
  --danger-bg:     #1f0505;
  --danger-ring:   #7f1d1d;

  --shadow-sm: 0 1px 4px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg: 0 12px 36px rgba(0,0,0,0.6);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #090c1a; --surface: #0f1425; --surface-2: #141932;
    --surface-3: #1a2040; --border: #232a50; --divider: #1d2440;
    --text: #dde2ff; --text-muted: #8892c8; --text-faint: #424b7a;
    --accent: #7c9bff; --accent-h: #9bb3ff;
    --accent-subtle: #141a3e; --accent-tint: #1c2450;
    --success: #34d279; --success-bg: #082416; --success-ring: #166534;
    --warn: #fb923c; --warn-bg: #1a0d00; --warn-ring: #92400e;
    --danger: #f87171; --danger-bg: #1f0505; --danger-ring: #7f1d1d;
    --shadow-sm: 0 1px 4px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.5);
    --shadow-lg: 0 12px 36px rgba(0,0,0,0.6);
  }
}

/* ═══════════════════════════════════════════
   BASE RESET
═══════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
  line-height: 1.6;
}
h1, h2, h3, h4 {
  font-family: var(--font-display);
  text-wrap: balance;
  line-height: 1.15;
}
p, li { text-wrap: pretty; max-width: 62ch; }
input, button, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
img, svg { display: block; max-width: 100%; }
::selection { background: var(--accent-tint); color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: var(--r-sm); }

/* ═══════════════════════════════════════════
   LAYOUT — TOP BAR
═══════════════════════════════════════════ */
.page-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 200;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: var(--sp-3) clamp(var(--sp-4), 4vw, var(--sp-10));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  box-shadow: var(--shadow-sm);
}

.brand { display: flex; align-items: center; gap: var(--sp-4); }

.brand-mark {
  width: 44px;
  height: 44px;
  color: var(--accent);
  flex-shrink: 0;
}

.brand h1 {
  font-size: var(--text-lg);
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text);
}

.eyebrow {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 2px;
}

.theme-toggle {
  width: 40px;
  height: 40px;
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: background var(--ease), color var(--ease);
  flex-shrink: 0;
}
.theme-toggle:hover { background: var(--surface-3); color: var(--text); }

/* ═══════════════════════════════════════════
   LAYOUT — MAIN GRID
═══════════════════════════════════════════ */
.app-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: var(--sp-6);
  padding: var(--sp-6) clamp(var(--sp-4), 4vw, var(--sp-10));
  max-width: 1280px;
  margin: 0 auto;
  width: 100%;
  align-items: start;
}

.controls-panel {
  position: sticky;
  top: calc(64px + var(--sp-6));
  max-height: calc(100dvh - 64px - var(--sp-12));
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.results-stack {
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
}

/* ═══════════════════════════════════════════
   PANEL
═══════════════════════════════════════════ */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: var(--sp-6);
  box-shadow: var(--shadow-md);
}

/* ═══════════════════════════════════════════
   SECTION HEADS
═══════════════════════════════════════════ */
.section-head {
  margin-bottom: var(--sp-6);
}
.section-head h2 {
  font-size: var(--text-xl);
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text);
  margin-bottom: var(--sp-2);
}
.section-head > p {
  font-size: var(--text-sm);
  color: var(--text-muted);
}
.section-head.compact h2 {
  font-size: var(--text-lg);
}
.section-head.compact { margin-bottom: var(--sp-4); }

/* ═══════════════════════════════════════════
   CONTROLS FORM
═══════════════════════════════════════════ */
.controls {
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
}
.field span { color: var(--text-muted); font-weight: 600; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.07em; }

select, input[type="number"] {
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  font-size: var(--text-sm);
  color: var(--text);
  transition: border-color var(--ease), box-shadow var(--ease);
  appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235a6098' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 2.5rem;
  cursor: pointer;
}
[data-theme="dark"] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238892c8' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}
select:focus, input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

.salary-row {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
input[type="number"] { font-family: var(--font-display); font-weight: 700; font-size: var(--text-base); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 9999px;
  outline: none;
  cursor: pointer;
  border: none;
  padding: 0;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 2.5px solid var(--surface);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform var(--ease);
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }

/* Toggle row */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-4);
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color var(--ease), background var(--ease);
}
.toggle-row:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-subtle);
}
.toggle-row div { display: flex; flex-direction: column; gap: 2px; }
.toggle-row span { font-size: var(--text-sm); font-weight: 700; color: var(--text); }
.toggle-row small { font-size: var(--text-xs); color: var(--text-muted); }
.toggle-row input[type="checkbox"] {
  position: relative;
  width: 44px;
  height: 24px;
  appearance: none;
  background: var(--border);
  border-radius: 9999px;
  cursor: pointer;
  transition: background var(--ease);
  flex-shrink: 0;
  border: none;
  padding: 0;
}
.toggle-row input[type="checkbox"]::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: white;
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  transition: left var(--ease);
}
.toggle-row input[type="checkbox"]:checked { background: var(--accent); }
.toggle-row input[type="checkbox"]:checked::after { left: 23px; }

/* Note card */
.note-card {
  margin-top: var(--sp-5);
  padding: var(--sp-4) var(--sp-5);
  background: var(--accent-subtle);
  border: 1px solid var(--accent-tint);
  border-radius: var(--r-md);
}
.note-card h3 { font-size: var(--text-sm); font-weight: 700; color: var(--accent); margin-bottom: var(--sp-1); }
.note-card p { font-size: var(--text-xs); color: var(--text-muted); max-width: 100%; }

/* ═══════════════════════════════════════════
   HERO STATS
═══════════════════════════════════════════ */
.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-4);
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-5) var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  box-shadow: var(--shadow-sm);
}
.stat-card.accent {
  background: var(--accent);
  border-color: var(--accent-h);
}
.stat-card.accent .stat-label { color: rgba(255,255,255,0.75); }
.stat-card.accent strong { color: white; }
.stat-card.accent small { color: rgba(255,255,255,0.65); }
.stat-label {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.stat-card strong {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 2.5vw, 2.25rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text);
  line-height: 1;
}
.stat-card small { font-size: var(--text-xs); color: var(--text-muted); }

/* ═══════════════════════════════════════════
   OUTPUT GRID
═══════════════════════════════════════════ */
.output-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-8);
}

/* ═══════════════════════════════════════════
   FEE TABLE
═══════════════════════════════════════════ */
.fee-table {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.fee-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--divider);
}
.fee-row:last-child { border-bottom: none; }
.fee-row.subtotal {
  padding-top: var(--sp-4);
  margin-top: var(--sp-2);
  border-top: 2px solid var(--border);
  border-bottom: none;
}
.fee-row.total-row {
  margin-top: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--accent-subtle);
  border: 1px solid var(--accent-tint);
  border-radius: var(--r-md);
}
.fee-name-col { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.fee-name-col .name { font-size: var(--text-sm); font-weight: 600; color: var(--text); }
.fee-name-col .hint { font-size: var(--text-xs); color: var(--text-faint); }
.fee-amt {
  font-family: var(--font-display);
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  text-align: right;
}
.fee-amt.zero { color: var(--success); }
.fee-amt.muted { color: var(--text-muted); }
.fee-amt.big {
  font-size: var(--text-base);
  color: var(--accent);
  font-weight: 800;
}
.fee-note {
  margin-top: var(--sp-3);
  font-size: var(--text-xs);
  color: var(--text-faint);
}

/* ═══════════════════════════════════════════
   ODDS METER
═══════════════════════════════════════════ */
.odds-meter {
  margin-bottom: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.odds-bar-track {
  height: 14px;
  background: var(--surface-3);
  border-radius: 9999px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.odds-bar {
  height: 100%;
  border-radius: 9999px;
  width: 0%;
  background: var(--accent);
  transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1), background 0.4s;
}
#oddsNarrative {
  font-size: var(--text-sm);
  color: var(--text-muted);
  max-width: 100%;
}

/* Insight chips */
.insight-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.insight {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  font-size: var(--text-xs);
  border: 1px solid;
  line-height: 1.5;
}
.insight.info { background: var(--accent-subtle); border-color: var(--accent-tint); color: var(--text); }
.insight.success { background: var(--success-bg); border-color: var(--success-ring); color: var(--success); }
.insight.warn { background: var(--warn-bg); border-color: var(--warn-ring); color: var(--warn); }
.insight.danger { background: var(--danger-bg); border-color: var(--danger-ring); color: var(--danger); }
.insight-icon { font-size: 1rem; flex-shrink: 0; margin-top: 1px; }
.insight-body strong { display: block; font-weight: 700; margin-bottom: 2px; }

/* ═══════════════════════════════════════════
   TIMELINE
═══════════════════════════════════════════ */
.timeline-panel { }

.timeline-steps {
  display: flex;
  gap: 0;
  overflow: visible;
  position: relative;
}

.step {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  position: relative;
}
.step:not(:last-child)::after {
  content: '';
  position: absolute;
  top: 14px;
  left: 50%;
  width: 100%;
  height: 2px;
  background: var(--border);
  z-index: 0;
}
.step-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 800;
  color: var(--text-faint);
  position: relative;
  z-index: 1;
  transition: all var(--ease);
  margin-bottom: var(--sp-3);
  flex-shrink: 0;
}
.step.active .step-dot {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  box-shadow: 0 0 0 4px var(--accent-tint);
}
.step.done .step-dot {
  background: var(--success);
  border-color: var(--success);
  color: white;
}
.step-title {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
}
.step-duration {
  font-size: 0.68rem;
  color: var(--text-muted);
  line-height: 1.3;
}
.step.active .step-title { color: var(--accent); }

/* Timeline connector color for active steps */
.step.done:not(:last-child)::after { background: var(--success); opacity: 0.4; }

/* ═══════════════════════════════════════════
   FOOTER AREA
═══════════════════════════════════════════ */
.disclaimer {
  padding: var(--sp-6) clamp(var(--sp-4), 4vw, var(--sp-10));
  text-align: center;
  max-width: 900px;
  margin: 0 auto;
}
.disclaimer p {
  font-size: var(--text-xs);
  color: var(--text-faint);
  max-width: 100%;
}

/* ═══════════════════════════════════════════
   TRANSITIONS — number updates
═══════════════════════════════════════════ */
.stat-card strong, .fee-amt, #lotteryOdds, #totalCost, #timelineRange {
  transition: color 0.35s;
}

/* ═══════════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════════ */
@media (max-width: 1024px) {
  .app-grid { grid-template-columns: 1fr; }
  .controls-panel { position: static; max-height: none; overflow: visible; }
  .output-grid { grid-template-columns: 1fr; gap: var(--sp-6); }
}

@media (max-width: 700px) {
  .hero-stats { grid-template-columns: 1fr; }
  .topbar { padding: var(--sp-3) var(--sp-4); }
  .brand h1 { font-size: 1rem; }
  .brand-mark { width: 36px; height: 36px; }
  .timeline-steps { flex-direction: column; gap: var(--sp-4); }
  .step { flex-direction: row; text-align: left; align-items: flex-start; gap: var(--sp-3); }
  .step::after { display: none; }
  .step-dot { margin-bottom: 0; flex-shrink: 0; }
}
