@media (max-width: 768px) {
  :root {
    --mobile-gutter: 20px;
    --mobile-tab-height: 68px;
    --mobile-surface: #0b0b0d;
    --mobile-surface-raised: #141417;
    --mobile-hairline: rgba(255, 255, 255, 0.10);
  }

  html, body { background: #000; color: #f7f7f8; }
  body { min-height: 100dvh; }
  .shell, main { background: #000; }
  main { padding: max(18px, env(safe-area-inset-top)) var(--mobile-gutter) calc(var(--mobile-tab-height) + env(safe-area-inset-bottom) + 28px); }
  .bottom-tab-bar {
    position: fixed;
    z-index: 80;
    left: 12px;
    right: 12px;
    bottom: max(4px, calc(env(safe-area-inset-bottom) - 20px));
    min-height: var(--mobile-tab-height);
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    padding: 7px;
    border: 1px solid var(--mobile-hairline);
    border-radius: 24px;
    background: rgba(18, 18, 21, 0.94);
    backdrop-filter: blur(22px) saturate(140%);
  }
  .bottom-tab-bar .tab-btn { min-width: 0; min-height: 54px; color: #a1a1a8; border-radius: 18px; }
  .bottom-tab-bar .tab-btn.active { color: var(--blue); background: rgba(80, 145, 255, 0.12); }
  .bottom-tab-bar .tab-btn svg { width: 23px; height: 23px; }
  .bottom-tab-bar .tab-btn span { font-size: 11px; font-weight: 650; }

  /* iOS gives an overflow:auto element its own scrolling layer only when it is
     not also compositing a backdrop-filter or animating a transform. With both,
     the drag never becomes a scroll and resolves as a tap on whatever option is
     under the finger. Drop both on mobile and let the list scroll. */
  .liquid-select-list {
    backdrop-filter: none;
    transition: opacity .16s ease;
    transform: none;
    overscroll-behavior: contain;
    background: var(--mobile-surface-raised);
  }
  .liquid-select.open .liquid-select-list { transform: none; }
  .liquid-select-option { min-height: 44px; touch-action: pan-y; }

  :focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }
  button, a, input, select { touch-action: manipulation; }
  button, .symbol-link, .sheet-row { min-height: 44px; }

  .mobile-home-only[hidden] { display: block !important; }
  .mobile-home-scope[hidden] { display: flex !important; }
  .mobile-home-shortcuts[hidden] { display: grid !important; }
  #overview.metrics-grid { display: block; }
  #overview .hero-card { padding: 8px 0 0; border: 0; box-shadow: none; background: transparent; }
  .mobile-home-scope { align-items: center; justify-content: space-between; min-height: 44px; margin-bottom: 8px; color: #92929a; font-size: 13px; }
  .mobile-home-scope select { width: auto; min-height: 40px; padding: 0 32px 0 12px; border: 0; border-radius: 999px; background-color: rgba(80,145,255,.10); color: var(--blue); font-weight: 650; }
  #overview .hero-lbl { color: #92929a; font-size: 13px; font-weight: 600; }
  #heroTotalValue { max-inline-size: 100%; margin-top: 6px; font-size: clamp(42px, 12vw, 58px); line-height: .98; letter-spacing: -0.055em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
  #heroChange { margin-top: 12px; font-size: 15px; }
  #heroMeta { min-height: 20px; color: #8d8d94; font-size: 12px; }
  .hero-chart-area { height: 212px; margin: 18px calc(-1 * var(--mobile-gutter)) 0; }
  #heroPeriods { display: grid; grid-template-columns: repeat(6, 1fr); gap: 3px; margin: 4px 0 22px; border-bottom: 1px solid var(--mobile-hairline); }
  #heroPeriods .period-chip { min-width: 0; min-height: 44px; padding: 0; border: 0; border-radius: 0; background: transparent; color: #888890; }
  #heroPeriods .period-chip.active { color: var(--blue); box-shadow: inset 0 -2px var(--blue); }
  .mobile-home-shortcuts { grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 0 0 12px; }
  .mobile-home-shortcuts button { display: grid; justify-items: center; gap: 7px; padding: 10px 4px; border: 0; background: transparent; color: #f5f5f7; }
  .mobile-home-shortcuts button span { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 16px; background: rgba(80, 145, 255, .12); color: var(--blue); font-size: 20px; }
  .mobile-home-shortcuts button strong { font-size: 11px; font-weight: 600; }
  #overview > .metric, #tradeQueueCard { display: none; }
  .mobile-home-freshness { margin: 2px 0 22px; color: #777780; font-size: 12px; }
  .mobile-home-holdings-head { display: flex; align-items: center; justify-content: space-between; }
  .mobile-home-holdings-head button { border: 0; background: transparent; color: var(--blue); font-size: 13px; }

  .mobile-holdings-controls[hidden] { display: grid !important; }
  .mobile-holdings-controls { display: grid; gap: 12px; margin: 16px 0 18px; }
  .mobile-holdings-search { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 14px; border: 1px solid var(--mobile-hairline); border-radius: 16px; background: var(--mobile-surface-raised); color: #a1a1a8; }
  .mobile-holdings-search input { width: 100%; min-height: 46px; border: 0; outline: 0; background: transparent; color: inherit; font-size: 16px; }
  .mobile-holdings-filters { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
  .mobile-holdings-filters button { flex: 0 0 auto; min-height: 40px; padding: 0 16px; border: 1px solid var(--mobile-hairline); border-radius: 999px; background: transparent; color: #a1a1a8; }
  .mobile-holdings-filters button.active { border-color: rgba(80,145,255,.38); background: rgba(80,145,255,.12); color: var(--blue); }
  #netWorthViewToggle, #networthSortChips { display: none; }
  .mobile-inline-state, .mobile-inline-error { padding: 14px 0; color: #a1a1a8; font-size: 14px; }
  .mobile-inline-error { color: #d9c49b; }
  .mobile-inline-loading { display: flex; align-items: center; gap: 8px; padding: 14px 0; color: #a1a1a8; font-size: 14px; }
  .mobile-inline-loading::before { content: ''; width: 12px; height: 12px; border: 2px solid rgba(161,161,168,.32); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
  .mobile-inline-state button { margin: 10px 0 0; padding: 0; border: 0; background: transparent; color: var(--blue); }
  .mobile-holding-list { border-top: 1px solid var(--mobile-hairline); }
  .mobile-holding-row { width: 100%; min-height: 92px; display: grid; grid-template-columns: 44px minmax(0,1fr) auto; gap: 12px; align-items: center; padding: 14px 0; border: 0; border-bottom: 1px solid var(--mobile-hairline); border-radius: 0; background: transparent; color: inherit; text-align: left; }
  .mobile-holding-monogram { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 14px; background: rgba(80,145,255,.12); color: var(--blue); font-size: 13px; font-weight: 800; }
  .mobile-holding-copy, .mobile-holding-value { min-width: 0; display: grid; gap: 2px; }
  .mobile-holding-copy strong { font-size: 16px; }
  .mobile-holding-copy > span, .mobile-holding-copy small { overflow: hidden; color: #a1a1a8; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-holding-copy em { width: max-content; margin-top: 2px; padding: 2px 7px; border-radius: 999px; font-size: 10px; font-style: normal; font-weight: 750; }
  .mobile-holding-eligible { background: rgba(80,145,255,.14); color: var(--blue); }
  .mobile-holding-read-only { background: rgba(255,255,255,.08); color: #b3b3ba; }
  .mobile-holding-value { justify-items: end; text-align: right; }
  .mobile-holding-value strong { font-size: 14px; white-space: nowrap; }
  .mobile-holding-value small { font-size: 11px; white-space: nowrap; }
  .linked-holding-sheet { position: fixed; inset: 0; z-index: 120; }
  .linked-holding-backdrop { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: rgba(0,0,0,.64); }
  .linked-holding-panel { position: absolute; left: 0; right: 0; bottom: 0; padding: 12px var(--mobile-gutter) calc(24px + env(safe-area-inset-bottom)); border-radius: 26px 26px 0 0; background: #151518; }
  .linked-holding-panel > p { margin: 10px 0 4px; color: #a1a1a8; font-size: 12px; }
  .linked-holding-panel h2 { margin: 0 0 18px; font-size: 28px; }
  .linked-holding-close { position: absolute; top: 14px; right: var(--mobile-gutter); min-width: 40px; padding: 0; border: 0; background: transparent; color: #f7f7f8; font-size: 28px; }
  #linkedHoldingBody { display: grid; gap: 12px; }
  #linkedHoldingBody > div { display: flex; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--mobile-hairline); }
  #linkedHoldingBody span, #linkedHoldingBody p { color: #a1a1a8; }
  #linkedHoldingBody p { margin: 6px 0 0; font-size: 13px; line-height: 1.45; }
  body.linked-holding-open { overflow: hidden; }

  #quickMode .quick-grid { display: none; }
  .mobile-trade-landing { display: grid; gap: 28px; }
  .mobile-trade-landing > header p { margin: 0 0 6px; color: #8e8e96; font-size: 13px; }
  .mobile-trade-landing > header h2 { margin: 0; font-size: 34px; line-height: 1.03; letter-spacing: -.045em; }
  .mobile-trade-search { position: relative; display: flex; align-items: center; gap: 10px; min-height: 54px; padding: 0 16px; border: 1px solid var(--mobile-hairline); border-radius: 18px; background: var(--mobile-surface-raised); color: #8e8e96; }
  .mobile-trade-search input { width: 100%; min-height: 52px; border: 0; outline: 0; background: transparent; color: #fff; font-size: 16px; }
  .mobile-trade-search .suggest-dropdown { top: calc(100% + 8px); left: 0; right: 0; }
  .mobile-section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
  .mobile-section-head h3 { margin: 0; font-size: 17px; letter-spacing: -.02em; }
  .mobile-section-head small { color: #8e8e96; font-size: 12px; }
  .mobile-trade-row { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) auto; min-height: 66px; padding: 11px 0; border: 0; border-bottom: 1px solid var(--mobile-hairline); background: transparent; color: inherit; text-align: left; }
  .mobile-trade-copy, .mobile-trade-value { min-width: 0; display: grid; gap: 3px; }
  .mobile-trade-copy strong, .mobile-trade-value strong { font-size: 15px; }
  .mobile-trade-copy small, .mobile-trade-value small { overflow: hidden; color: #a1a1a8; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-trade-value { justify-items: end; text-align: right; }
  .stock-order-overlay { background: #000; }
  .stock-order-amount { font-size: clamp(58px, 18vw, 78px); letter-spacing: -.055em; font-variant-numeric: tabular-nums; }
  .stock-order-review, .stock-order-place { min-height: 54px; border-radius: 18px; background: var(--blue); color: #fff; }
  .stock-order-keypad button { min-height: 58px; border-radius: 16px; font-size: 24px; }
  .stock-order-confirm { border: 1px solid var(--mobile-hairline); border-radius: 22px; background: var(--mobile-surface-raised); }

  @media (display-mode: standalone) {
    main { padding-top: max(22px, env(safe-area-inset-top)); }
  }

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
    .hero-chart-svg path, .perf-chart-svg path { transition: none !important; }
  }

  .dividend-center-panel { padding: 0; border: 0; background: transparent; box-shadow: none; }
  .dividend-heading { display: block; }
  .dividend-heading h2 { font-size: 36px; letter-spacing: -.04em; }
  .dividend-view-toggle.desktop-dividend-view-toggle { display: none; }
  .dividend-view-toggle.mobile-dividend-view-toggle[hidden] { display: grid !important; }
  .dividend-view-toggle { position: sticky; top: env(safe-area-inset-top); z-index: 20; display: grid; grid-template-columns: repeat(4, 1fr); margin: 14px 0 18px; padding: 4px; background: rgba(25,25,28,.94); backdrop-filter: blur(18px); }
  .dividend-view-toggle .chip { min-width: 0; padding: 0 4px; font-size: 12px; }
  .dividend-hero-grid { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 1px; overflow: hidden; border: 1px solid var(--mobile-hairline); border-radius: 22px; background: var(--mobile-hairline); }
  .dividend-hero-card { min-height: 112px; padding: 16px; border: 0; border-radius: 0; background: var(--mobile-surface); }
  .dividend-payer-row, .dividend-agenda-row { grid-template-columns: minmax(0,1fr) auto; min-height: 64px; padding: 12px 0; border: 0; border-bottom: 1px solid var(--mobile-hairline); background: transparent; }
  .dividend-coverage { width: 100%; margin: 12px 0; padding: 12px 14px; border: 0; border-radius: 14px; background: rgba(80,145,255,.09); color: #b8cfff; text-align: left; }

  /* The PWA shell is intentionally dark-first, even when the desktop preference is light. */
  #networth .networth-stat:not(.primary),
  #networth .source-bucket,
  #dividends .dividend-card,
  #dividends .dividend-hero-card:not(.primary) {
    background: linear-gradient(180deg, rgba(255,255,255,.035), rgba(255,255,255,.012)), #0d0e12;
    border-color: var(--mobile-hairline);
    box-shadow: none;
    color: #f5f5f7;
  }
  #networth .networth-stat span,
  #networth .networth-stat small,
  #networth .source-label,
  #networth .source-meta,
  #networth .src-chevron,
  #dividends .dividend-hero-card:not(.primary) span,
  #dividends .dividend-card-head p,
  #dividends .dividend-method,
  #dividends .dividend-month small,
  #dividends .dividend-date-row small,
  #dividends .dividend-payer-row small,
  #dividends .dividend-agenda-row small,
  #dividends .dividend-calendar-number,
  #dividends .dividend-agenda-title {
    color: #98a0ad;
  }
  #networth .networth-stat strong,
  #networth .source-bucket strong,
  #dividends .dividend-card strong,
  #dividends .dividend-card h3,
  #dividends .dividend-hero-card:not(.primary) strong,
  #dividends .dividend-date-row,
  #dividends .dividend-payer-row,
  #dividends .dividend-agenda-row {
    color: #f5f5f7;
  }
  #networth .networth-stat.primary span,
  #networth .networth-stat.primary small { color: rgba(255,255,255,.74); }
  #dividends .dividend-view-toggle { border: 1px solid var(--mobile-hairline); border-radius: 16px; }
  #dividends .dividend-view-toggle .chip { background: #101115; border-color: transparent; color: #aeb5c1; }
  #dividends .dividend-view-toggle .chip.active { background: rgba(80,145,255,.20); color: #dce8ff; }

  @media (max-width: 260px) {
    .mobile-home-scope,
    .mobile-home-scope[hidden] { display: grid !important; grid-template-columns: minmax(0, 1fr); justify-content: stretch; gap: 6px; }
    .mobile-home-scope select { width: 100%; max-width: 100%; }
    #heroTotalValue { font-size: clamp(32px, 18vw, 42px); letter-spacing: -.05em; }
    .bottom-tab-bar { left: 6px; right: 6px; min-height: 62px; padding: 4px; border-radius: 20px; }
    .bottom-tab-bar .tab-btn { min-height: 52px; padding: 4px 1px; }
    .bottom-tab-bar .tab-btn svg { width: 20px; height: 20px; }
    .bottom-tab-bar .tab-btn span { overflow-wrap: anywhere; font-size: 7px; line-height: 1.05; letter-spacing: 0; text-align: center; }
  }
}
