@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:wght@400;500;600;700;800&display=swap');

:root {
  --font-sans: 'IBM Plex Sans', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --bg: #f9fafb;
  --surface: #ffffff;
  --surface-soft: #f3f4f6;
  --ink: #111827;
  --muted: #6b7280;
  --faint: #9ca3af;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --accent: #10b981;
  --accent-strong: #059669;
  --accent-soft: #d1fae5;
  --blue: #3b82f6;
  --blue-soft: #dbeafe;
  --cyan: #06b6d4;
  --amber: #f59e0b;
  --amber-soft: #fef3c7;
  --danger: #ef4444;
  --danger-soft: #fee2e2;
  --cash: #9ca3af;
  --shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.05);
  --surface-shadow: 0 2px 12px -2px rgba(0, 0, 0, 0.04);
  --page-start: #ffffff;
  --page-glow: rgba(16, 185, 129, 0.05);
  --brand-ink: #111827;
  --brand-muted: #6b7280;
  --label: #374151;
  --focus-ring: rgba(16, 185, 129, 0.3);
  --accent-border: rgba(16, 185, 129, 0.5);
  --active-tab-bg: #f0fdf4;
  --workspace-bg: rgba(255, 255, 255, 0.6);
  --panel-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.1);
  --tab-hover-bg: #f3f4f6;
  --chart-grid: #f3f4f6;
  --neutral-pill-bg: #f3f4f6;
  --neutral-pill-ink: #4b5563;
  --action-hold-bg: #f3f4f6;
  --action-hold-ink: #4b5563;
  --info-border: #bfdbfe;
  --info-bg: #eff6ff;
  --info-ink: #1e3a8a;
  --good-insight-bg: #f0fdf4;
  --good-insight-ink: #166534;
  --warn-insight-bg: #fffbeb;
  --warn-insight-ink: #92400e;
  --info-insight-bg: #eff6ff;
  --info-insight-ink: #1e40af;
  --gauge-track: #f3f4f6;
  --danger-border: #fca5a5;
  --base-border: #6ee7b7;
  --bull-border: #93c5fd;
  --bear-tile-bg: #fef2f2;
  --base-tile-bg: #f0fdf4;
  --bull-tile-bg: #eff6ff;
  --warning-border: #fcd34d;
  --warning-ink: #92400e;
  --tooltip-bg: rgba(255, 255, 255, 0.95);
  --radius: 12px;
}

html[data-theme="dark"] {
  --bg: #09090b;
  --surface: #18181b;
  --surface-soft: #27272a;
  --ink: #fafafa;
  --muted: #a1a1aa;
  --faint: #71717a;
  --line: #27272a;
  --line-strong: #3f3f46;
  --accent: #10b981;
  --accent-strong: #34d399;
  --accent-soft: rgba(16, 185, 129, 0.15);
  --blue: #60a5fa;
  --blue-soft: rgba(59, 130, 246, 0.15);
  --cyan: #22d3ee;
  --amber: #fbbf24;
  --amber-soft: rgba(245, 158, 11, 0.15);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.15);
  --cash: #71717a;
  --shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.4);
  --surface-shadow: 0 2px 12px -2px rgba(0, 0, 0, 0.3);
  --page-start: #09090b;
  --page-glow: rgba(16, 185, 129, 0.05);
  --brand-ink: #fafafa;
  --brand-muted: #a1a1aa;
  --label: #e4e4e7;
  --focus-ring: rgba(16, 185, 129, 0.3);
  --accent-border: rgba(16, 185, 129, 0.5);
  --active-tab-bg: rgba(16, 185, 129, 0.1);
  --workspace-bg: rgba(24, 24, 27, 0.6);
  --panel-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.6);
  --tab-hover-bg: #27272a;
  --chart-grid: rgba(255, 255, 255, 0.05);
  --neutral-pill-bg: #27272a;
  --neutral-pill-ink: #e4e4e7;
  --action-hold-bg: #27272a;
  --action-hold-ink: #e4e4e7;
  --info-border: rgba(59, 130, 246, 0.3);
  --info-bg: rgba(59, 130, 246, 0.1);
  --info-ink: #bfdbfe;
  --good-insight-bg: rgba(16, 185, 129, 0.1);
  --good-insight-ink: #a7f3d0;
  --warn-insight-bg: rgba(245, 158, 11, 0.1);
  --warn-insight-ink: #fde68a;
  --info-insight-bg: rgba(59, 130, 246, 0.1);
  --info-insight-ink: #bfdbfe;
  --gauge-track: #27272a;
  --danger-border: rgba(248, 113, 113, 0.3);
  --base-border: rgba(16, 185, 129, 0.3);
  --bull-border: rgba(59, 130, 246, 0.3);
  --bear-tile-bg: rgba(248, 113, 113, 0.05);
  --base-tile-bg: rgba(16, 185, 129, 0.05);
  --bull-tile-bg: rgba(59, 130, 246, 0.05);
  --warning-border: rgba(245, 158, 11, 0.3);
  --warning-ink: #fde68a;
  --tooltip-bg: rgba(24, 24, 27, 0.95);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

svg.nav-icon,
svg.mobile-nav-icon,
svg.empty-state-icon,
svg.toast-icon,
svg.cmd-result-icon,
svg.ui-icon {
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
}

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

button,
summary {
  cursor: pointer;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 6px;
  font-size: 1.05rem;
  line-height: 1.3;
  letter-spacing: 0;
  text-transform: uppercase;
}

h2 {
  margin-bottom: 14px;
  font-size: 0.95rem;
  line-height: 1.3;
  letter-spacing: 0;
}

h2 span {
  color: var(--muted);
  font-weight: 500;
}

h3 {
  font-size: 0.88rem;
}

/* ── App Layout ── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.app-shell {
  flex: 1;
  min-width: 0;
  padding: 32px 40px 48px;
  margin-left: 240px;
}

/* ── Sidebar ── */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 240px;
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  z-index: 50;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 4px 8px 20px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 20px;
}

.sidebar-brand .brand-name {
  display: block;
  font-family: var(--font-sans);
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: 0;
  color: var(--brand-ink);
}

.sidebar-brand .brand-kicker {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0;
}

.brand-name {
  font-family: var(--font-sans);
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: 0;
  color: var(--brand-ink);
}

.brand-kicker {
  color: var(--brand-muted);
  font-size: 0.7rem;
  text-transform: uppercase;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 24px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 42px;
  padding: 10px 14px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.9rem;
  text-align: left;
  transition: all 150ms ease;
  cursor: pointer;
}

.nav-item:hover {
  background: var(--tab-hover-bg);
  color: var(--ink);
}

.nav-item.is-active {
  background: var(--active-tab-bg);
  color: var(--accent-strong);
  font-weight: 600;
}

.nav-icon {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

.nav-label { flex: 1; }

.sidebar-search { margin-bottom: 28px; }

.cmd-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 150ms ease;
}

.cmd-trigger:hover {
  border-color: var(--accent);
  background: var(--surface);
}

.cmd-trigger kbd {
  font-size: 0.72rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--faint);
}

.sidebar-bottom {
  margin-top: auto;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.sidebar-toggles {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 8px;
}

.sidebar-toggle-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 6px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: all 150ms ease;
}

.sidebar-toggle-btn:hover {
  background: var(--tab-hover-bg);
  color: var(--ink);
}

.toggle-badge {
  margin-left: auto;
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  color: var(--faint);
}

.sidebar-settings-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  list-style: none;
}

.sidebar-settings-btn::-webkit-details-marker { display: none; }
.sidebar-settings-btn:hover { background: var(--tab-hover-bg); color: var(--ink); }

/* ── Command Palette ── */
.cmd-palette-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
}

.cmd-palette-overlay.is-open {
  display: flex;
  animation: fade-in 120ms ease;
}

.cmd-palette {
  width: min(560px, 90vw);
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--panel-shadow);
  overflow: hidden;
}

.cmd-input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.cmd-icon { color: var(--accent); font-size: 1.1rem; }

.cmd-input-wrap input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--ink);
  font-size: 1rem;
  outline: none;
  padding: 0;
  min-height: auto;
}

.cmd-kbd {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  color: var(--faint);
}

.cmd-results {
  max-height: 340px;
  overflow-y: auto;
  padding: 8px;
}

.cmd-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--ink);
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 100ms ease;
}

.cmd-result-item:hover, .cmd-result-item.is-selected {
  background: var(--active-tab-bg);
}

.cmd-result-icon {
  width: 18px;
  height: 18px;
  color: var(--muted);
  stroke-width: 2;
}

.cmd-result-item .cmd-result-type {
  color: var(--faint);
  font-size: 0.75rem;
  margin-left: auto;
}

/* ── Toast ── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--panel-shadow);
  color: var(--ink);
  font-size: 0.88rem;
  pointer-events: auto;
  animation: toast-in 250ms ease;
  max-width: 380px;
}

.toast.toast-error { border-color: var(--danger-border); }
.toast.toast-success { border-color: var(--base-border); }

.toast-icon {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ── Empty State ── */
.empty-state {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 80px 24px;
  gap: 12px;
}

.empty-state.is-visible { display: flex; }
.empty-state.is-visible ~ * { display: none !important; }

.empty-state-icon {
  width: 48px;
  height: 48px;
  margin-bottom: 8px;
  color: var(--accent);
  stroke-width: 1.8;
}

.empty-state h2 { margin-bottom: 4px; font-size: 1.2rem; }

.empty-state p { color: var(--muted); max-width: 400px; line-height: 1.6; }

.empty-state-btn {
  margin-top: 8px;
  min-height: 40px;
  padding: 8px 20px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: white;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background 150ms ease;
}

.empty-state-btn:hover { background: var(--accent-strong); }

/* ── Sticky Section Headers ── */
.sticky-head {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: 12px 0;
  margin: -12px 0 12px;
  border-bottom: 1px solid transparent;
  transition: border-color 200ms ease;
}

/* ── Keyboard Hint ── */
.keyboard-hint {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  padding: 10px 14px;
  margin-bottom: 28px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--faint);
  font-size: 0.78rem;
}

.keyboard-hint kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 0.72rem;
  font-family: inherit;
}

/* ── Animated Numbers ── */
.animate-number {
  display: inline-block;
  transition: transform 200ms ease;
}

/* ── Mobile Top Bar ── */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 60;
  min-height: 56px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  align-items: center;
  justify-content: space-between;
}

.mobile-menu-btn {
  min-height: 36px;
  min-width: 36px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-size: 1.2rem;
}

/* ── Mobile Bottom Nav ── */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 60;
  min-height: 64px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
  justify-content: space-around;
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 150ms ease;
}

.mobile-nav-item.is-active {
  color: var(--accent-strong);
  background: var(--active-tab-bg);
  border-radius: 12px;
}

.mobile-nav-icon {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

/* ── Why Button ── */
.why-btn {
  min-height: 24px;
  min-width: 24px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 150ms ease;
  margin-left: 6px;
}

.why-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.why-popover {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--info-bg);
  border: 1px solid var(--info-border);
  color: var(--info-ink);
  font-size: 0.85rem;
  line-height: 1.55;
  animation: fade-in 150ms ease;
}

.settings-menu,
.selection-menu {
  justify-self: end;
  position: relative;
}

.sidebar .settings-menu {
  width: 100%;
}

.settings-menu summary,
.selection-menu summary {
  list-style: none;
}

.settings-menu summary::-webkit-details-marker,
.selection-menu summary::-webkit-details-marker {
  display: none;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.icon-button::before {
  content: "\2699";
  font-size: 1.15rem;
}

.icon-button.dots::before {
  content: "\22EE";
}

.settings-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 5;
  display: grid;
  gap: 10px;
  width: min(340px, calc(100vw - 48px));
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--panel-shadow);
}

.sidebar .settings-panel {
  top: auto;
  right: 0;
  bottom: calc(100% + 10px);
  left: 0;
  width: auto;
}

.settings-group {
  display: grid;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.setting-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
}

.setting-row div {
  display: grid;
  gap: 3px;
}

.setting-row strong {
  color: var(--ink);
  font-size: 0.9rem;
}

.setting-row span {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.selection-panel {
  width: 300px;
}

.simulation-settings {
  margin-bottom: 28px;
}

.simulation-settings-head {
  margin-bottom: 20px;
}

.simulation-settings-head h2 {
  margin-bottom: 6px;
}

.simulation-settings-head p {
  margin-bottom: 0;
}

.control-bar {
  display: grid;
  grid-template-columns: minmax(190px, 240px) 1px minmax(240px, 1fr) 1px minmax(190px, 240px) minmax(120px, 150px);
  gap: 24px;
  align-items: center;
}

.control-field {
  display: grid;
  align-items: center;
  gap: 12px;
}

.amount-field,
.horizon-field {
  grid-template-columns: auto minmax(110px, 1fr);
}

.risk-field {
  grid-template-columns: auto minmax(160px, 1fr) 54px;
}

.control-divider {
  width: 1px;
  height: 38px;
  background: var(--line-strong);
}

label {
  color: var(--label);
  font-size: 0.9rem;
  font-weight: 650;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

input:focus,
select:focus,
button:focus-visible,
summary:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
  outline: none;
}

input[type="range"] {
  min-height: 26px;
  padding: 0;
  accent-color: var(--accent);
}

select[multiple] {
  min-height: 190px;
}

button {
  min-height: 42px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 10px 20px;
  background: var(--accent);
  color: white;
  font-weight: 700;
}

button:hover {
  background: var(--accent-strong);
}

.secondary-button {
  border-color: var(--accent-border);
  background: var(--surface);
  color: var(--accent);
}

.secondary-button:hover {
  background: var(--accent-soft);
}

.small-button {
  min-height: 32px;
  padding: 6px 12px;
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.84rem;
}

.small-button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.toggle-button {
  min-width: 76px;
  min-height: 36px;
  padding: 6px 12px;
  border-color: var(--line-strong);
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.86rem;
}

.toggle-button:hover {
  border-color: var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent);
}

.toggle-button.is-active {
  border-color: var(--blue);
  background: var(--blue-soft);
  color: var(--blue);
}

.app-shell {
  padding: 32px 40px 48px;
}

.workspace {
  display: none;
  background: transparent;
  padding: 0;
  border: none;
  box-shadow: none;
}

.workspace.is-active {
  display: block;
  animation: view-enter 220ms ease both;
}

@keyframes view-enter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tab,
  .tab::after,
  .learning-progress.level-up,
  .confetti-piece,
  .workspace.is-active {
    animation: none;
    transition: none;
  }
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
}

.section-head.with-actions {
  align-items: center;
}

.section-head.with-actions > div:first-child {
  min-width: 0;
}

.muted {
  color: var(--muted);
}

.status-good {
  color: var(--accent);
  font-weight: 650;
}

.status-bad {
  color: var(--danger);
  font-weight: 650;
}

.surface,
.metric,
.index-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--surface-shadow);
  transition: box-shadow 200ms ease, border-color 200ms ease;
}

.surface:hover,
.metric:hover,
.index-card:hover {
  box-shadow: var(--shadow);
  border-color: var(--line-strong);
}

.surface {
  padding: 24px;
}

.index-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}

.market-index-layout {
  display: grid;
  grid-template-columns: minmax(230px, 0.75fr) minmax(0, 2.25fr);
  align-items: stretch;
  gap: 20px;
  margin-bottom: 28px;
}

.market-index-layout .index-strip {
  grid-template-columns: 1fr;
  grid-auto-rows: minmax(0, 1fr);
  gap: 20px;
  margin-bottom: 0;
}

.index-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 100px;
  gap: 10px;
  min-height: 150px;
  padding: 22px;
}

.market-index-layout .index-card {
  align-items: center;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 18px;
  min-height: 0;
  padding: 20px;
}

.market-index-layout .index-card > div {
  min-width: 0;
}

.index-card span,
.index-card small {
  color: var(--muted);
}

.index-card strong {
  display: block;
  margin: 12px 0 8px;
  font-size: 1.35rem;
  line-height: 1.1;
}

.market-index-layout .index-card strong {
  margin: 10px 0 6px;
  font-size: 1.18rem;
}

.index-change {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-weight: 700;
}

.index-change span {
  color: inherit;
}

.positive {
  color: var(--accent);
}

.negative {
  color: var(--danger);
}

.pending {
  color: var(--warning-ink);
}

.sparkline {
  align-self: end;
  width: 104px;
  height: 72px;
}

.market-index-layout .sparkline {
  align-self: center;
  justify-self: start;
  width: 84px;
  height: 58px;
}

.sparkline path {
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sparkline .positive-line {
  stroke: var(--accent);
}

.sparkline .negative-line {
  stroke: var(--danger);
}

.market-index-history {
  margin-bottom: 0;
}

.market-index-toolbar {
  align-items: flex-start;
}

.market-index-controls {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 12px;
  margin-left: auto;
}

.market-index-controls select {
  width: 260px;
  max-width: 100%;
}

.market-index-controls .range-tabs {
  width: auto;
}

.market-index-summary.metric-grid.compact {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.market-index-summary .metric {
  min-height: 78px;
  padding: 14px 16px;
}

.market-index-summary .metric h3 {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 8px;
  font-size: 0.76rem;
}

.market-index-summary .metric strong {
  font-size: 1rem;
}

.market-index-summary .why-btn {
  min-width: 18px;
  min-height: 18px;
  margin-left: 2px;
  font-size: 0.62rem;
}

.market-index-chart-frame {
  height: 360px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 20px;
}

.metric-grid.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.metric-grid.highlights {
  margin-bottom: 28px;
}

.metric {
  min-height: 110px;
  padding: 22px;
}

.metric h3 {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.metric h3 .why-btn {
  flex: 0 0 auto;
  min-width: 20px;
  min-height: 20px;
  margin-left: 0;
  font-size: 0.66rem;
}

.metric strong {
  display: block;
  font-size: 1.25rem;
  line-height: 1.15;
}

.metric .metric-subtitle {
  display: block;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.86rem;
}

.market-grid {
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) minmax(440px, 1.6fr) minmax(260px, 1fr);
  gap: 24px;
  align-items: stretch;
}

.lower-grid,
.portfolio-grid,
.forecast-layout,
.diagnostics-grid {
  display: grid;
  gap: 24px;
}

.lower-grid {
  grid-template-columns: minmax(300px, 0.85fr) minmax(440px, 1.2fr);
  margin-top: 28px;
}

.portfolio-grid {
  grid-template-columns: minmax(280px, 0.85fr) minmax(340px, 1fr) minmax(340px, 1fr);
}

.forecast-layout {
  grid-template-columns: minmax(0, 1fr) 360px;
  align-items: start;
}

.forecast-main,
.forecast-side {
  display: grid;
  gap: 24px;
}

.ticker-actions,
.simulator-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 14px;
}

.ticker-actions {
  flex-wrap: nowrap;
  min-width: 0;
}

.ticker-actions select {
  width: 260px;
  min-width: 150px;
}

.forecast-horizon-field {
  display: grid;
  grid-template-columns: auto 84px;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  color: var(--label);
  font-size: 0.9rem;
  font-weight: 650;
}

.forecast-horizon-field input {
  min-height: 42px;
  text-align: right;
}

.chart-surface {
  min-height: 550px;
}

.chart-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.range-tabs {
  display: flex;
  gap: 8px;
}

.range-button {
  min-height: 34px;
  border: 0;
  background: transparent;
  color: var(--label);
  padding: 6px 12px;
  font-size: 0.88rem;
}

.range-button:hover,
.range-button.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 20px;
  margin-bottom: 10px;
  color: var(--label);
  font-size: 0.84rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.legend-item::before {
  content: "";
  width: 22px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.legend-item.historical,
.legend-item.base {
  color: var(--accent);
}

.legend-item.bear {
  color: var(--danger);
}

.legend-item.bull {
  color: var(--blue);
}

.legend-item.moving-average {
  color: var(--blue);
}

.legend-item.moving-average::before,
.legend-item.base::before,
.legend-item.bear::before,
.legend-item.bull::before {
  border-top: 2px dashed currentColor;
  background: transparent;
}

.chart-frame {
  position: relative;
  width: 100%;
  height: 430px;
  margin-top: 10px;
}

#forecastChart,
#marketIndexChart {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.stack,
.data-table,
.insight-list,
.sentiment-list {
  display: grid;
  gap: 0;
}

.stack {
  gap: 8px;
}

.row {
  display: grid;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 11px 4px;
  border-bottom: 1px solid var(--line);
}

.row:last-child {
  border-bottom: 0;
}

.row.two-column {
  grid-template-columns: minmax(0, 1fr) auto;
}

.market-row {
  grid-template-columns: 1.1fr 0.8fr 0.8fr 0.8fr 0.8fr 0.8fr auto;
}

.asset-row,
.trade-row {
  grid-template-columns: 1fr 0.9fr 0.8fr 0.9fr;
}

.top-row {
  grid-template-columns: 1fr 0.8fr 1fr 0.9fr;
}

.table-head {
  min-height: 32px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.wide-table {
  overflow-x: auto;
}

.profile-grid {
  display: grid;
  gap: 0;
}

.profile-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: baseline;
  min-height: 38px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.profile-item:last-child {
  border-bottom: 0;
}

.profile-item span:first-child {
  color: var(--muted);
}

.profile-item strong {
  text-align: right;
}

.narrative {
  color: var(--label);
  line-height: 1.6;
}

.about-summary {
  margin-top: 0;
  color: var(--ink);
  line-height: 1.65;
}

.freshness-list {
  display: grid;
  gap: 6px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 0.92rem;
}

.term {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 800;
}

.pill {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.pill.neutral {
  background: var(--neutral-pill-bg);
  color: var(--neutral-pill-ink);
}

.action-pill {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  min-height: 26px;
  padding: 3px 9px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.action-pill.hold {
  background: var(--action-hold-bg);
  color: var(--action-hold-ink);
}

.info-note {
  display: grid;
  gap: 8px;
  margin-top: 20px;
  padding: 18px;
  border: 1px solid var(--info-border);
  border-radius: 10px;
  background: var(--info-bg);
  color: var(--info-ink);
  font-size: 0.88rem;
  line-height: 1.55;
}

body:not(.learn-mode) .learn-panel {
  display: none;
}

.learn-panel {
  margin-bottom: 28px;
}

.forecast-side .learn-panel {
  margin-bottom: 0;
}

.eyebrow {
  display: block;
  margin-bottom: 8px;
  color: var(--accent-strong);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.lesson-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.lesson-stack {
  display: grid;
  gap: 10px;
}

.lesson-grid > .lesson-card,
.lesson-stack > .lesson-card,
.risk-checklist {
  display: grid;
  gap: 10px;
  min-height: 110px;
  padding: 20px;
  border: 1px solid var(--accent-soft);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 4px 20px -4px var(--page-glow);
  line-height: 1.55;
}

.lesson-grid > .lesson-card strong,
.lesson-stack > .lesson-card strong,
.risk-checklist strong {
  color: var(--ink);
}

.lesson-grid > .lesson-card p,
.lesson-stack > .lesson-card p {
  margin: 0;
  color: var(--label);
}

.lesson-grid > .lesson-card small,
.lesson-stack > .lesson-card small {
  color: var(--muted);
}

.risk-checklist span {
  display: block;
  color: var(--label);
}

.glossary-chip {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.82em;
  font-weight: 800;
}

.compact-note {
  margin-top: 16px;
}

.insight-list {
  gap: 14px;
}

.insight {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  min-height: 60px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  line-height: 1.5;
  font-size: 0.9rem;
}

.insight::before {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.72rem;
}

.insight.good {
  background: var(--good-insight-bg);
  color: var(--good-insight-ink);
}

.insight.good::before {
  content: "\2713";
  border: 1px solid var(--accent);
  color: var(--accent);
}

.insight.warn {
  background: var(--warn-insight-bg);
  color: var(--warn-insight-ink);
}

.insight.warn::before {
  content: "!";
  border: 1px solid var(--amber);
  color: var(--amber);
}

.insight.info {
  background: var(--info-insight-bg);
  color: var(--info-insight-ink);
}

.insight.info::before {
  content: "i";
  border: 1px solid var(--blue);
  color: var(--blue);
}

.sentiment-card {
  display: grid;
  align-content: start;
}

.sentiment-gauge {
  display: grid;
  justify-items: center;
  gap: 0;
  margin-top: 16px;
  margin-bottom: 20px;
}

.gauge-arc {
  --gauge-deg: 108deg;
  position: relative;
  width: 260px;
  height: 130px;
  border-radius: 260px 260px 0 0;
  background: conic-gradient(
    from 270deg at 50% 100%,
    var(--accent) 0deg var(--gauge-deg),
    var(--gauge-track) var(--gauge-deg) 180deg,
    transparent 180deg 360deg
  );
  cursor: pointer;
  transition:
    filter 160ms ease,
    transform 160ms ease;
}

.gauge-arc::after {
  content: "";
  position: absolute;
  left: 32px;
  right: 32px;
  bottom: 0;
  height: 94px;
  border-radius: 196px 196px 0 0;
  background: var(--surface);
}

.sentiment-gauge:hover .gauge-arc {
  filter: saturate(1.08);
  transform: translateY(-2px);
}

.gauge-value {
  margin-top: -50px;
  z-index: 1;
  color: var(--ink);
}

.gauge-value strong {
  font-size: 2rem;
}

.gauge-value span {
  color: var(--muted);
}

#sentimentLabel {
  margin: 4px 0 0;
  color: var(--accent);
  font-weight: 700;
}

.sentiment-list {
  gap: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 18px;
}

.sentiment-list span {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  color: var(--label);
}

.sentiment-list span:last-child {
  border-bottom: 0;
}

.card-title-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.portfolio-summary {
  display: grid;
  grid-template-columns: 1.25fr 1.25fr 1fr 0.7fr;
  gap: 24px;
  margin-bottom: 28px;
}

.scenario-tile {
  min-height: 130px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 22px;
}

.scenario-tile strong {
  display: block;
  margin: 12px 0 10px;
  font-size: 1.6rem;
  line-height: 1.1;
}

.scenario-tile span:first-child {
  display: block;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
  text-transform: uppercase;
}

.scenario-tile.bear {
  border-color: var(--danger-border);
  background: var(--bear-tile-bg);
}

.scenario-tile.base {
  border-color: var(--base-border);
  background: var(--base-tile-bg);
}

.scenario-tile.bull {
  border-color: var(--bull-border);
  background: var(--bull-tile-bg);
}

.scenario-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}

.allocation-card {
  display: grid;
  align-content: start;
}

.allocation-view {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  justify-items: center;
  align-items: center;
  margin: 30px 0;
}

.allocation-donut {
  --stock: 0%;
  --etf: 0%;
  --crypto: 0%;
  --cash-start: 0%;
  width: 178px;
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, var(--surface) 0 48%, transparent 49%),
    conic-gradient(
      var(--accent) 0 var(--stock),
      var(--cyan) var(--stock) var(--etf),
      var(--blue) var(--etf) var(--crypto),
      var(--cash) var(--crypto) 100%
    );
  display: grid;
  place-items: center;
  cursor: pointer;
  transition:
    filter 160ms ease,
    transform 160ms ease;
}

.allocation-donut:hover {
  filter: saturate(1.08);
  transform: translateY(-2px);
}

.allocation-donut strong {
  display: block;
  font-size: 1.5rem;
}

.allocation-donut span {
  color: var(--muted);
}

.allocation-legend {
  display: grid;
  gap: 14px;
  width: min(100%, 230px);
}

.legend-row {
  display: grid;
  grid-template-columns: 14px minmax(70px, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--accent);
}

.legend-dot.etf {
  background: var(--cyan);
}

.legend-dot.crypto {
  background: var(--blue);
}

.legend-dot.cash {
  background: var(--cash);
}

.hover-tooltip {
  position: fixed;
  z-index: 100;
  display: grid;
  gap: 4px;
  min-width: 190px;
  max-width: min(300px, calc(100vw - 32px));
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--tooltip-bg);
  color: var(--ink);
  box-shadow: 0 16px 36px rgba(15, 23, 42, 0.16);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 14px));
  transition: opacity 120ms ease;
}

.hover-tooltip.is-visible {
  opacity: 1;
}

.hover-tooltip strong {
  font-size: 0.9rem;
}

.hover-tooltip span {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.about-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(340px, 0.88fr);
  gap: 24px;
  align-items: stretch;
  margin-bottom: 22px;
}

.about-project-card,
.about-profile-card {
  min-width: 0;
}

.about-project-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 28px;
}

.about-project-card h2 {
  max-width: 760px;
  margin-top: 0;
  font-size: 1.65rem;
  line-height: 1.18;
}

.about-project-card p {
  max-width: 820px;
  color: var(--label);
  line-height: 1.6;
}

.project-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.project-stats article {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.project-stats span,
.project-stats small {
  color: var(--muted);
}

.project-stats strong {
  display: block;
  margin: 8px 0 2px;
  font-size: 1.25rem;
}

.about-profile-card {
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.about-profile-head {
  display: flex;
  align-items: center;
  gap: 18px;
}

.about-avatar {
  display: grid;
  width: 86px;
  height: 86px;
  flex: 0 0 86px;
  place-items: center;
  border: 3px solid color-mix(in srgb, var(--accent) 55%, var(--line));
  border-radius: 24px;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--accent) 28%, transparent), transparent 48%),
    var(--surface-soft);
  color: var(--accent-strong);
  font-size: 1.55rem;
  font-weight: 800;
  overflow: hidden;
}

.about-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.about-profile-head h2 {
  margin-bottom: 8px;
  color: var(--accent-strong);
  font-size: 1.45rem;
  line-height: 1.2;
}

.about-profile-head p {
  margin-bottom: 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.98rem;
  letter-spacing: 0;
  line-height: 1.5;
}

.about-profile-copy {
  margin-bottom: 0;
  color: var(--label);
  font-size: 1.1rem;
  line-height: 1.75;
}

.about-links {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: auto;
}

.about-links a {
  display: flex;
  min-height: 54px;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.94rem;
  letter-spacing: 0;
  text-decoration: none;
  transition:
    border-color 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

.about-links a:hover {
  border-color: var(--accent-border);
  color: var(--accent-strong);
  transform: translateY(-1px);
}

.about-links .ui-icon {
  width: 20px;
  height: 20px;
  color: var(--accent-strong);
  stroke-width: 2;
}

.project-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
  margin-bottom: 22px;
}

.architecture-card {
  grid-column: 1 / -1;
}

.glossary-card {
  grid-column: 1 / -1;
}

.architecture-map {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin: 20px 0;
}

.architecture-node {
  position: relative;
  display: grid;
  align-content: start;
  gap: 12px;
  min-height: 260px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.architecture-node:not(:last-child)::after {
  content: "→";
  position: absolute;
  top: 30px;
  right: -17px;
  z-index: 1;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface);
  color: var(--accent);
  font-weight: 900;
}

.architecture-step {
  width: fit-content;
  padding: 4px 8px;
  border: 1px solid var(--info-border);
  border-radius: 999px;
  color: var(--info-ink);
  background: var(--blue-soft);
  font-size: 0.76rem;
  font-weight: 800;
}

.architecture-node h3 {
  margin: 0;
  font-size: 1rem;
}

.architecture-node ul {
  display: grid;
  gap: 10px;
  margin: 0;
  padding-left: 18px;
  color: var(--label);
  line-height: 1.45;
}

.architecture-node li::marker {
  color: var(--accent);
}

.architecture-node code,
.architecture-details code {
  color: var(--label);
  font-size: 0.86em;
  overflow-wrap: anywhere;
}

.architecture-details {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.architecture-details p {
  margin: 8px 0 0;
  color: var(--label);
  line-height: 1.55;
}

.glossary-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.glossary-item {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.glossary-item span {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.health-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
}

.health-card {
  min-height: 150px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.health-card span {
  color: var(--muted);
  font-size: 0.9rem;
}

.health-card strong {
  display: block;
  margin: 14px 0 4px;
  font-size: 1.25rem;
  line-height: 1.15;
}

.health-card small {
  display: block;
  color: var(--label);
  line-height: 1.45;
}

.diagnostics-card {
  margin-top: 24px;
}

.diagnostics,
.advanced-diagnostics {
  margin-top: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 16px 18px;
}

.diagnostics summary,
.advanced-diagnostics summary {
  cursor: pointer;
  color: var(--label);
  font-weight: 750;
}

.diagnostics-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 18px;
}

.diagnostics .diagnostics-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.json-panel h3 {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0;
}

.json-block {
  max-height: 360px;
  margin: 0;
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--label);
  font-size: 0.8rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.diagnostic-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 18px 0;
}

.warning-banner,
.error-banner {
  padding: 12px 14px;
  border-radius: var(--radius);
}

.warning-banner {
  background: var(--amber-soft);
  border: 1px solid var(--warning-border);
  color: var(--warning-ink);
}

.error-banner {
  background: var(--danger-soft);
  border: 1px solid var(--danger-border);
  color: var(--danger);
}

.app-footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-top: 32px;
  padding: 16px 20px;
  border: 1px solid var(--info-border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.84rem;
}

.learning-progress {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--surface-soft);
  border: 1px solid var(--line);
}

.progress-info {
  display: grid;
  gap: 2px;
  font-size: 0.75rem;
}

.progress-level {
  min-width: 0;
  font-weight: 700;
  color: var(--accent);
}

.progress-text {
  min-width: 0;
  color: var(--muted);
  line-height: 1.25;
}

.progress-track {
  width: 100%;
  height: 8px;
  margin-top: 2px;
  background: var(--line-strong);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
  transition: width 400ms ease;
}

.learning-progress.level-up {
  animation: progress-level-pop 700ms ease;
}

.confetti-burst {
  position: fixed;
  inset: 0;
  z-index: 10000;
  overflow: hidden;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  top: var(--origin-y);
  left: var(--origin-x);
  width: 8px;
  height: 12px;
  border-radius: 2px;
  background: var(--confetti-color);
  opacity: 0;
  animation: confetti-pop 1300ms cubic-bezier(0.16, 0.9, 0.34, 1) forwards;
  animation-delay: var(--delay);
}

.skeleton {
  background: linear-gradient(105deg, var(--surface-soft) 25%, var(--line) 50%, var(--surface-soft) 75%);
  background-size: 200% 100%;
  animation: loading-skeleton 1.5s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  border-radius: var(--radius);
  min-height: 24px;
}

.skeleton-text {
  height: 14px;
  margin-bottom: 8px;
  border-radius: 4px;
}

.skeleton-text:last-child {
  margin-bottom: 0;
  width: 80%;
}

@keyframes loading-skeleton {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@keyframes progress-level-pop {
  0% {
    border-color: var(--line);
    box-shadow: none;
    transform: scale(1);
  }

  45% {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-soft);
    transform: scale(1.015);
  }

  100% {
    border-color: var(--line);
    box-shadow: none;
    transform: scale(1);
  }
}

@keyframes confetti-pop {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(0deg) scale(0.75);
  }

  65% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) rotate(var(--r)) scale(1);
  }
}

@media (max-width: 1100px) {
  .control-bar,
  .market-index-layout,
  .index-strip,
  .market-grid,
  .lower-grid,
  .lesson-grid,
  .portfolio-grid,
  .portfolio-summary,
  .forecast-layout,
  .about-layout,
  .project-grid,
  .health-grid {
    grid-template-columns: 1fr;
  }

  .control-bar { gap: 14px; }
  .control-divider { display: none; }
  .chart-surface { min-height: 500px; }
  .market-index-summary.metric-grid.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  .mobile-topbar { display: flex; }
  .mobile-bottom-nav { display: flex; }
  .keyboard-hint { display: none; }

  .app-shell {
    margin-left: 0;
    position: fixed;
    top: 56px;
    right: 0;
    bottom: calc(64px + env(safe-area-inset-bottom));
    left: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px 16px 32px;
  }

  .sticky-head {
    top: -16px;
    margin: -16px 0 16px;
    padding: 28px 0 12px;
  }

  body.mobile-sidebar-open::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 70;
    background: rgba(0, 0, 0, 0.48);
  }

  .sidebar.is-mobile-open {
    display: flex;
    z-index: 90;
    width: min(320px, calc(100vw - 48px));
    box-shadow: var(--panel-shadow);
  }

  .learning-progress { display: none; }

  .section-head,
  .section-head.with-actions,
  .ticker-actions,
  .simulator-actions,
  .chart-toolbar,
  .app-footer {
    display: grid;
  }

  .section-head,
  .section-head.with-actions {
    gap: 16px;
  }

  .surface,
  .metric,
  .index-card,
  .scenario-tile,
  .health-card,
  .lesson-grid > .lesson-card,
  .lesson-stack > .lesson-card,
  .risk-checklist {
    padding: 18px;
  }

  .ticker-actions,
  .simulator-actions {
    width: 100%;
    justify-content: stretch;
    justify-items: stretch;
  }

  .ticker-actions {
    gap: 12px;
  }

  .ticker-actions select,
  .ticker-actions button,
  .forecast-horizon-field {
    width: 100%;
    min-width: 0;
  }

  .forecast-horizon-field {
    grid-template-columns: minmax(0, 1fr) minmax(74px, 96px);
  }

  .simulator-actions {
    grid-template-columns: minmax(0, 1fr) 48px;
    gap: 12px;
    align-items: stretch;
  }

  .simulator-actions > button,
  .simulator-actions .selection-menu,
  .simulator-actions .icon-button {
    width: 100%;
  }

  .selection-menu .settings-panel {
    position: fixed;
    top: 112px;
    right: 16px;
    left: 16px;
    width: auto;
    max-height: calc(100dvh - 208px);
    overflow-y: auto;
  }

  .market-index-controls {
    width: 100%;
    margin-left: 0;
    align-items: stretch;
  }

  .market-index-controls select,
  .market-index-controls .range-tabs {
    width: 100%;
  }

  .range-tabs {
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .amount-field,
  .horizon-field,
  .risk-field,
  .market-row,
  .asset-row,
  .trade-row,
  .top-row,
  .row.two-column,
  .allocation-view,
  .architecture-map,
  .architecture-details,
  .glossary-list,
  .scenario-grid,
  .metric-grid.compact,
  .diagnostics-grid {
    grid-template-columns: 1fr;
  }

  .data-table {
    gap: 10px;
  }

  .data-table .table-head {
    display: none;
  }

  .data-table .row {
    border-bottom: 0;
  }

  .data-table .asset-row:not(.table-head),
  .data-table .trade-row:not(.table-head),
  .data-table .top-row:not(.table-head),
  .data-table .market-row:not(.table-head) {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px 16px;
    min-height: 0;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface-soft);
  }

  .data-table .asset-row:not(.table-head) > strong,
  .data-table .trade-row:not(.table-head) > strong,
  .data-table .top-row:not(.table-head) > strong,
  .data-table .market-row:not(.table-head) > strong {
    grid-column: 1;
    grid-row: 1;
    align-self: center;
    font-size: 1rem;
  }

  .data-table .asset-row:not(.table-head) > span:nth-child(2),
  .data-table .top-row:not(.table-head) > span:nth-child(2),
  .data-table .market-row:not(.table-head) > span:nth-child(2) {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
    width: fit-content;
    padding: 3px 9px;
    border-radius: 6px;
    background: var(--neutral-pill-bg);
    color: var(--neutral-pill-ink);
    font-size: 0.78rem;
    font-weight: 750;
    text-transform: capitalize;
  }

  .data-table .trade-row:not(.table-head) > .action-pill {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
  }

  .data-table .asset-row:not(.table-head) > span:nth-child(3),
  .data-table .asset-row:not(.table-head) > span:nth-child(4),
  .data-table .trade-row:not(.table-head) > span:nth-child(3),
  .data-table .trade-row:not(.table-head) > span:nth-child(4),
  .data-table .top-row:not(.table-head) > span:nth-child(3),
  .data-table .top-row:not(.table-head) > span:nth-child(4),
  .data-table .market-row:not(.table-head) > span:nth-child(3),
  .data-table .market-row:not(.table-head) > span:nth-child(4),
  .data-table .market-row:not(.table-head) > span:nth-child(5),
  .data-table .market-row:not(.table-head) > span:nth-child(6) {
    display: grid;
    gap: 3px;
    color: var(--ink);
    font-weight: 650;
  }

  .data-table .asset-row:not(.table-head) > span:nth-child(4),
  .data-table .trade-row:not(.table-head) > span:nth-child(4),
  .data-table .top-row:not(.table-head) > span:nth-child(4),
  .data-table .market-row:not(.table-head) > span:nth-child(4),
  .data-table .market-row:not(.table-head) > span:nth-child(6) {
    justify-items: end;
    text-align: right;
  }

  .data-table .asset-row:not(.table-head) > span:nth-child(3)::before,
  .data-table .asset-row:not(.table-head) > span:nth-child(4)::before,
  .data-table .trade-row:not(.table-head) > span:nth-child(3)::before,
  .data-table .trade-row:not(.table-head) > span:nth-child(4)::before,
  .data-table .top-row:not(.table-head) > span:nth-child(3)::before,
  .data-table .top-row:not(.table-head) > span:nth-child(4)::before,
  .data-table .market-row:not(.table-head) > span:nth-child(3)::before,
  .data-table .market-row:not(.table-head) > span:nth-child(4)::before,
  .data-table .market-row:not(.table-head) > span:nth-child(5)::before,
  .data-table .market-row:not(.table-head) > span:nth-child(6)::before {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
  }

  .data-table .asset-row:not(.table-head) > span:nth-child(3)::before,
  .data-table .trade-row:not(.table-head) > span:nth-child(3)::before {
    content: "Weight";
  }

  .data-table .asset-row:not(.table-head) > span:nth-child(4)::before {
    content: "Value";
  }

  .data-table .trade-row:not(.table-head) > span:nth-child(4)::before {
    content: "Amount";
  }

  .data-table .top-row:not(.table-head) > span:nth-child(3)::before {
    content: "Base return";
  }

  .data-table .top-row:not(.table-head) > span:nth-child(4)::before {
    content: "Confidence";
  }

  .data-table .market-row:not(.table-head) > span:nth-child(3)::before {
    content: "Base";
  }

  .data-table .market-row:not(.table-head) > span:nth-child(4)::before {
    content: "Bear";
  }

  .data-table .market-row:not(.table-head) > span:nth-child(5)::before {
    content: "Bull";
  }

  .data-table .market-row:not(.table-head) > span:nth-child(6)::before {
    content: "Confidence";
  }

  .data-table .market-row:not(.table-head) > button {
    grid-column: 1 / -1;
    width: 100%;
  }

  .architecture-node {
    min-height: 0;
  }

  .architecture-node:not(:last-child)::after {
    content: "↓";
    top: auto;
    right: auto;
    bottom: -18px;
    left: 24px;
  }

  .diagnostics .diagnostics-grid { grid-template-columns: 1fr; }
  .index-card { grid-template-columns: 1fr; }
  .sparkline { width: 100%; }
  .chart-frame { height: 330px; }
  .market-index-summary.metric-grid.compact { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: 1fr; }
  .metric strong,
  .scenario-tile strong,
  .health-card strong {
    overflow-wrap: anywhere;
  }

  .mobile-nav-item {
    flex: 1;
    min-width: 0;
    padding-right: 4px;
    padding-left: 4px;
  }

  .project-stats,
  .about-links {
    grid-template-columns: 1fr;
  }

  .about-profile-head {
    align-items: flex-start;
  }

  .about-avatar {
    width: 72px;
    height: 72px;
    flex-basis: 72px;
    border-radius: 20px;
    font-size: 1.25rem;
  }

  .about-project-card h2 {
    font-size: 1.35rem;
  }

  .about-profile-head h2 {
    font-size: 1.25rem;
  }

  .about-profile-head p,
  .about-links a {
    letter-spacing: 0;
  }

  .toast-container { top: auto; bottom: calc(64px + 12px + env(safe-area-inset-bottom)); right: 12px; left: 12px; flex-direction: column; }
  .toast { max-width: 100%; }
}
