#chart-wrap  { position: relative; width: 100%; overflow: hidden; min-height: 440px; }
#brush-wrap  { width: 100%; overflow: hidden; margin-top: 16px; cursor: col-resize; min-height: 100px; }
#chart-wrap svg, #brush-wrap svg { display: block; width: 100%; height: auto; }

#loading {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(44,40,37,0.7); z-index: 20; border-radius: 4px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
#loading.visible { opacity: 1; pointer-events: all; }
#rate-limit-msg {
  position: absolute; inset: 0; display: none; flex-direction: column; gap: 6px;
  align-items: center; justify-content: center; text-align: center;
  background: rgba(44,40,37,0.82); z-index: 21; border-radius: 4px;
  font-family: var(--serif); padding: 20px;
}
#rate-limit-msg.visible { display: flex; }
#rate-limit-msg .rl-title { font-size: 1.05rem; color: var(--ochre); font-style: italic; letter-spacing: 0.01em; }
#rate-limit-msg .rl-sub   { font-size: 0.8rem; color: var(--muted); max-width: 320px; line-height: 1.5; }
#loading-text {
  font-family: var(--serif); font-style: italic; font-size: 1.05rem;
  color: var(--sage); letter-spacing: 0.01em;
}
#loading-cursor {
  font-family: var(--serif); font-style: normal; font-weight: 300;
  color: var(--sage); opacity: 0;
}

#tooltip {
  position: absolute; pointer-events: none; opacity: 0; z-index: 50;
  background: #1c1916; border: 1px solid var(--text-13);
  border-radius: 10px; padding: 12px 16px; min-width: 180px;
  transition: opacity 0.11s ease;
}
.tip-date { font-size: 0.71rem; color: var(--muted); font-style: italic; margin-bottom: 9px; }
.tip-row { display: flex; align-items: baseline; gap: 7px; margin-bottom: 6px; }
.tip-row:last-child { margin-bottom: 0; }
.tip-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; position: relative; top: 1px; }
.tip-ticker { font-size: 0.68rem; color: var(--muted); min-width: 32px; }
.tip-val { font-size: 1.18rem; font-weight: 700; line-height: 1; }
.tip-sub { font-size: 0.68rem; font-style: italic; margin-left: 2px; }
.tip-sub.up   { color: var(--sage); }
.tip-sub.down { color: var(--rust); }
.tip-total { padding-top: 8px; margin-top: 2px; border-top: 1px solid var(--text-13); }
.tip-total .tip-ticker { color: var(--text); font-weight: 600; }
.tip-total .tip-val { color: var(--text); margin-left: auto; }

.brush .selection { fill: rgba(217,119,87,0.12); stroke: rgba(217,119,87,0.40); stroke-width: 1; }
.brush .overlay   { cursor: crosshair; }
.brush .handle    { fill: transparent !important; }

footer { display: flex; justify-content: space-between; align-items: center; margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--text-07); flex-wrap: wrap; gap: 12px; }
.footer-note { font-size: 0.72rem; color: var(--faint); font-style: italic; }
.sparkle { color: var(--faint); font-size: 1.1rem; }
.footer-disclaimer { width: 100%; text-align: center; margin-top: 4px; display: flex; flex-direction: column; gap: 4px; }
.footer-d1 { font-size: 0.72rem; color: var(--text-42); letter-spacing: 0.03em; }
.footer-d2 { font-size: 0.62rem; font-style: italic; color: var(--text-24); letter-spacing: 0.01em; line-height: 1.5; }

.chart-header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
}
.chart-header > div { flex: 1; min-width: 0; }

.share-btn {
  display: flex; align-items: center; gap: 6px;
  background: rgba(217,119,87,0.12); border: 1.5px solid var(--rust);
  color: var(--rust); font-family: var(--serif); font-size: 0.76rem; font-weight: 700;
  padding: 6px 16px; border-radius: 20px; cursor: pointer;
  letter-spacing: 0.04em; white-space: nowrap; flex-shrink: 0; margin-top: 3px;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s, transform 0.15s;
}
.share-btn.pulse { animation: share-pulse 3.2s ease-in-out 0.3s 1; }
.share-btn:hover {
  background: var(--rust); color: #fff;
  box-shadow: 0 0 16px rgba(217,119,87,0.34); transform: scale(1.04);
  animation: none;
}
.share-btn:active { transform: scale(0.97); }
.share-btn svg { transition: transform 0.2s; }
.share-btn:hover svg { transform: translateY(-1px); }
@keyframes share-pulse {
  0%        { transform: scale(1);    box-shadow: 0 0 0px rgba(217,119,87,0);    background: rgba(217,119,87,0.12); color: var(--rust); }
  9%, 18%   { transform: scale(1.07); box-shadow: 0 0 22px rgba(217,119,87,0.5); background: var(--rust); color: #fff; }
  27%       { transform: scale(1);    box-shadow: 0 0 0px rgba(217,119,87,0);    background: rgba(217,119,87,0.12); color: var(--rust); }
  40%, 62%  { transform: scale(1.07); box-shadow: 0 0 22px rgba(217,119,87,0.5); background: var(--rust); color: #fff; }
  100%      { transform: scale(1);    box-shadow: 0 0 0px rgba(217,119,87,0);    background: rgba(217,119,87,0.12); color: var(--rust); }
}
@media (max-width: 640px) {
  .share-btn { padding: 6px 11px; margin-top: 2px; }
  .share-btn svg { width: 14px; height: 14px; }
  #share-label { display: none; }
}

/* ── Short viewports (Desktop) ────────────────────────────────────────── */
@media (min-width: 641px) and (max-height: 820px) {
  .page { padding-top: 16px; padding-bottom: 20px; }
  nav { margin-bottom: 12px; }
  .ticker-nav-wrap { margin-bottom: 16px; padding-bottom: 12px; }
  .company-header { margin-bottom: 12px; }
  .company-name { font-size: 1.8rem; }
  .category-nav, .metric-nav { margin-bottom: 12px; }
  #brush-wrap { margin-top: 12px; }
  footer { margin-top: 16px; }
}

/* ── Mobile portrait ≤ 640 px ────────────────────────────────────────────── */
@media (max-width: 640px) {
  [data-view="qoq"] { display: none; }
  [data-range="10"] { display: none; }
  .range-gear { display: inline-flex; }
  .page { padding: 14px 13px 44px; }

  nav { margin-bottom: 18px; gap: 8px; }
  .logo { font-size: 1.72rem; }
  .tagline { font-size: 0.76rem; }

  /* Ticker rail on mobile: original horizontal scroll, no collapse/expand */
  .ticker-nav-wrap {
    margin-bottom: 18px; padding-bottom: 14px;
    align-items: center;
  }
  .ticker-nav {
    max-height: none !important; height: auto !important;
    overflow-x: auto; overflow-y: hidden; flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
    gap: 5px;
  }
  .ticker-nav-wrap.collapsed .ticker-nav { -webkit-mask-image: none; mask-image: none; }
  .ticker-nav.opening .ticker-btn { animation: none; }
  .ticker-nav::-webkit-scrollbar { display: none; }
  .ticker-btn { font-size: 0.84rem; padding: 6px 13px; flex-shrink: 0; }
  .ticker-search-wrap input { font-size: 16px; }
  .ticker-search-wrap input::placeholder { font-size: 0.72rem; }

  /* Company header */
  .company-header { margin-bottom: 14px; }
  .company-name { font-size: 1.55rem; margin-bottom: 6px; }
  #badges-container { display: none; }
  #chart-legend { display: none; }
  .company-name .vs-sep { font-size: 1.2rem; margin: 0 6px; }
  .ticker-label { font-size: 0.76rem; }
  .ticker-badge { font-size: 0.74rem; padding: 2px 10px; }

  /* Category nav: horizontal scroll */
  .category-nav {
    width: 100%; overflow-x: auto; flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
    margin-bottom: 6px;
  }
  .category-nav::-webkit-scrollbar { display: none; }
  .category-btn { font-size: 0.78rem; padding: 5px 13px; flex-shrink: 0; }

  /* Metric nav: horizontal scroll */
  .metric-nav {
    width: 100%; overflow-x: auto; flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
    margin-bottom: 14px;
  }
  .metric-nav::-webkit-scrollbar { display: none; }
  .metric-btn { font-size: 0.82rem; padding: 6px 13px; flex-shrink: 0; }

  .chart-title { font-size: 1.3rem; }
  .chart-subtitle { font-size: 0.70rem; margin-bottom: 8px; }
  .metric-def { font-size: 0.68rem; }
  .chart-legend { gap: 12px; margin-bottom: 8px; }
  .legend-item { font-size: 0.70rem; }

  /* Controls: two rows */
  .controls { flex-direction: column; align-items: flex-start; gap: 8px; margin-bottom: 10px; }
  .controls > div:first-child { display: flex; gap: 8px; flex-wrap: nowrap; width: 100%; }
  #mode-toggle { display: none; } /* bar/combo not useful on touch */
  .toggle-btn { font-size: 0.82rem; padding: 6px 14px; }
  .range-group { display: flex; gap: 3px; flex-wrap: nowrap; overflow-x: auto; width: 100%; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .range-group::-webkit-scrollbar { display: none; }
  .range-btn { font-size: 0.80rem; padding: 5px 12px; flex-shrink: 0; }

  #chart-wrap { min-height: 260px; }
  #brush-wrap { display: none; }  /* reclaim space on portrait */

  footer { margin-top: 18px; padding-top: 14px; }
  .footer-note { font-size: 0.64rem; }
  .sparkle { display: none; }
  .footer-d2 { font-size: 0.68rem; color: var(--text-38); }
}

/* ── Mobile landscape: short viewport ────────────────────────────────────── */
@media (max-height: 520px) and (orientation: landscape) {
  .page { padding: 8px 16px 20px; }
  nav { margin-bottom: 8px; }
  .tagline { display: none; }
  .company-header { margin-bottom: 8px; }
  .company-name { font-size: 1.2rem; margin-bottom: 4px; }
  .ticker-badge { font-size: 0.70rem; padding: 2px 8px; }

  .category-nav { margin-bottom: 4px; }
  .category-btn { font-size: 0.68rem; padding: 3px 10px; }
  .metric-nav { margin-bottom: 10px; }
  .metric-btn { font-size: 0.72rem; padding: 4px 11px; }

  .chart-title { font-size: 0.92rem; }
  .chart-subtitle { display: none; }
  .metric-def     { display: none; }
  .chart-legend { margin-bottom: 6px; }

  .controls { margin-bottom: 6px; gap: 6px; flex-wrap: nowrap; }
  .toggle-btn { font-size: 0.74rem; padding: 4px 12px; }
  .range-btn { font-size: 0.72rem; padding: 3px 10px; }

  #chart-wrap { min-height: 200px; }
  #brush-wrap { margin-top: 8px; min-height: 50px; }

  footer { margin-top: 12px; padding-top: 10px; }
  .footer-note { font-size: 0.62rem; }
}

/* ── Touch tooltip ─────────────────────────────────────────────────────── */
@media (hover: none) {
  #tooltip { padding: 14px 18px; min-width: 0; max-width: calc(100% - 16px); }
  .tip-val { font-size: 1.28rem; }
}
