/* S&Poké 500 — Google Finance–style theme.
   Light is the canonical look; dark mirrors it (OS preference by default,
   toggle stamps data-theme on <html> and wins both ways). */

:root {
  color-scheme: light;
  --bg: #ffffff;
  --bg-soft: #f8f9fa;
  --ink: #202124;
  --ink-2: #444746;
  --muted: #5f6368;
  --faint: #80868b;
  --hairline: #e8eaed;
  --border: #dadce0;
  --blue: #1a73e8;
  --blue-soft: #e8f0fe;
  --up: #137333;
  --up-soft: #e6f4ea;
  --down: #a50e0e;
  --down-soft: #fce8e6;
  --chip: #f1f3f4;
  --banner-bg: #fef7e0;
  --banner-ink: #3c4043;
  --tooltip-bg: #ffffff;
  --spark: #d93a2b;
  --wrap: 1040px;
  --font: Roboto, system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #131314;
    --bg-soft: #1e1f20;
    --ink: #e3e3e3;
    --ink-2: #c4c7c5;
    --muted: #9aa0a6;
    --faint: #80868b;
    --hairline: #2d2f31;
    --border: #444746;
    --blue: #8ab4f8;
    --blue-soft: #1f3760;
    --up: #81c995;
    --up-soft: #14261a;
    --down: #f28b82;
    --down-soft: #331512;
    --chip: #2d2f31;
    --banner-bg: #3a3222;
    --banner-ink: #e8eaed;
    --tooltip-bg: #1e1f20;
    --spark: #e05a4b;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #131314;
  --bg-soft: #1e1f20;
  --ink: #e3e3e3;
  --ink-2: #c4c7c5;
  --muted: #9aa0a6;
  --faint: #80868b;
  --hairline: #2d2f31;
  --border: #444746;
  --blue: #8ab4f8;
  --blue-soft: #1f3760;
  --up: #81c995;
  --up-soft: #14261a;
  --down: #f28b82;
  --down-soft: #331512;
  --chip: #2d2f31;
  --banner-bg: #3a3222;
  --banner-ink: #e8eaed;
  --tooltip-bg: #1e1f20;
  --spark: #e05a4b;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  font-size: 14px;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { width: 100%; max-width: var(--wrap); margin: 0 auto; padding-inline: 20px; }

/* --- Sample banner --- */
.banner {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 8px 16px; font-size: 13px; color: var(--banner-ink);
  background: var(--banner-bg); text-align: center;
}
.banner-ic {
  width: 16px; height: 16px; flex: none; border-radius: 50%;
  border: 1.5px solid currentColor; font: italic 700 10px/13px Georgia, serif;
  text-align: center;
}

/* --- Header --- */
.site-header { border-bottom: 1px solid var(--hairline); background: var(--bg); }
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; }
.brand { display: flex; align-items: center; gap: 8px; color: inherit; }
.brand:hover { text-decoration: none; }
.brand-mark { display: grid; place-items: center; }
.brand-name { font-size: 21px; font-weight: 500; letter-spacing: -0.01em; }
.brand-sub { font-size: 21px; font-weight: 400; color: var(--muted); }
.brand-chip {
  font-size: 11px; font-weight: 500; color: var(--muted);
  border: 1px solid var(--border); border-radius: 6px; padding: 1px 7px; margin-left: 4px;
}
.theme-toggle {
  width: 40px; height: 40px; border-radius: 50%; border: 0; cursor: pointer;
  background: transparent; color: var(--muted); display: grid; place-items: center;
}
.theme-toggle:hover { background: var(--chip); color: var(--ink); }
.ic-sun { display: none; }
:root[data-theme="dark"] .ic-moon { display: none; }
:root[data-theme="dark"] .ic-sun { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ic-moon { display: none; }
  :root:not([data-theme="light"]) .ic-sun { display: block; }
}

main { padding-block: 22px 8px; }

/* --- Quote header --- */
.crumb { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.ticker { font-family: "Roboto Mono", ui-monospace, monospace; font-size: 12px; letter-spacing: 0.02em; }
.crumb-sep { color: var(--faint); }
.quote-name { font-size: 24px; font-weight: 400; margin: 4px 0 2px; letter-spacing: -0.01em; }
.quote-line { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.quote-price {
  font-size: clamp(34px, 7vw, 44px); font-weight: 400; letter-spacing: -0.01em;
  line-height: 1.15; font-variant-numeric: tabular-nums;
}
.quote-change { display: inline-flex; align-items: baseline; gap: 6px; font-size: 16px;
  font-variant-numeric: tabular-nums; }
.quote-change .chg-ic { font-size: 11px; line-height: 1; flex: none; align-self: center; }
.quote-change.up .chg-ic { color: var(--up); }
.quote-change.down .chg-ic { color: var(--down); }
.quote-change .chg-pct { font-weight: 500; }
.quote-change.up .chg-pct { color: var(--up); }
.quote-change.down .chg-pct { color: var(--down); }
.quote-change .chg-abs { color: var(--muted); font-size: 14px; }
.quote-change.flat { color: var(--muted); font-size: 13.5px; }
.quote-asof { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }

/* --- Chart --- */
.chart-section { margin-top: 10px; }
.chart {
  position: relative; margin: 0; width: 100%; height: 340px;
  /* Scrubbing = press-and-drag; without these, iOS long-press pops the
     text-selection / copy callout over the chart labels. */
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
#chart-svg { width: 100%; height: 100%; display: block; touch-action: none; overflow: visible; }
.chart-empty {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 6px; text-align: center;
  color: var(--muted); z-index: 2;
}
.chart-empty strong { color: var(--ink); font-size: 15px; font-weight: 500; }
.chart-tooltip {
  position: absolute; z-index: 5; pointer-events: none; transform: translate(-50%, -100%);
  background: var(--tooltip-bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: 12.5px; white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2), 0 4px 12px rgba(0,0,0,0.12);
}
.chart-tooltip .tt-value { font-weight: 500; font-size: 14px; font-variant-numeric: tabular-nums; }
.chart-tooltip .tt-date { color: var(--muted); font-size: 11.5px; }
.chart-tooltip .tt-delta { font-variant-numeric: tabular-nums; font-weight: 500; font-size: 12px; }
.chart-caption { color: var(--muted); font-size: 12.5px; margin-top: 10px; }

/* Range tabs — Google-style pills */
.range-toggle { display: flex; gap: 4px; margin-top: 12px; border-bottom: 1px solid var(--hairline);
  padding-bottom: 14px; overflow-x: auto;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.range-btn {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  font: 500 13px var(--font); padding: 7px 14px; border-radius: 18px;
  font-variant-numeric: tabular-nums; flex: none;
}
.range-btn:hover { background: var(--chip); color: var(--ink); }
.range-btn.is-active { background: var(--blue-soft); color: var(--blue); }
.range-btn:disabled { opacity: 0.4; cursor: default; background: transparent; }

/* --- Overview --- */
.overview { margin-top: 26px; }
.tabbar { border-bottom: 1px solid var(--hairline); }
.tab {
  display: inline-block; font-size: 14px; font-weight: 500; color: var(--blue);
  padding: 10px 4px; position: relative;
}
.tab.is-active::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 3px;
  background: var(--blue); border-radius: 3px 3px 0 0;
}
.ov-grid { display: grid; grid-template-columns: 1fr 1fr; column-gap: 48px; margin: 0; }
.ov-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 13px 4px; border-bottom: 1px solid var(--hairline); min-height: 24px;
}
.ov-row dt { color: var(--muted); font-size: 13.5px; }
.ov-row dd { margin: 0; font-size: 13.5px; font-weight: 500; font-variant-numeric: tabular-nums; }

/* --- Change values (Google Finance dense-list style: plain colored text
   with a small solid triangle, no filled chip) --- */
.delta {
  display: inline-flex; align-items: baseline; gap: 4px;
  font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.delta .tri { font-size: 0.72em; line-height: 1; }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }
.delta.flat { color: var(--muted); }

/* --- Pill (reserved for the single market-mood accent) --- */
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12.5px; font-weight: 500; font-variant-numeric: tabular-nums;
  border-radius: 8px; padding: 3px 8px; white-space: nowrap;
}
.pill.up { background: var(--up-soft); color: var(--up); }
.pill.down { background: var(--down-soft); color: var(--down); }
.pill.flat { background: var(--chip); color: var(--muted); }
.up-ink { color: var(--up); }
.down-ink { color: var(--down); }

/* --- Movers --- */
.movers { margin-top: 30px; }
.section-title { font-size: 20px; font-weight: 400; margin: 0 0 6px; letter-spacing: -0.01em; }
.mover-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 48px; }
.mover-title { font-size: 13px; font-weight: 500; color: var(--muted); margin: 14px 0 4px; }
.mover-list { list-style: none; margin: 0; padding: 0; }
.mover-item {
  display: flex; align-items: center; gap: 12px; padding: 9px 4px;
  border-bottom: 1px solid var(--hairline);
}
.mover-thumb { width: 32px; height: 44px; border-radius: 4px; flex: none;
  object-fit: cover; background: var(--bg-soft); border: 1px solid var(--hairline); }
.mover-body { min-width: 0; }
.mover-name { font-size: 13.5px; font-weight: 500; line-height: 1.25;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mover-set { font-size: 12px; color: var(--muted); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.mover-meta { margin-left: auto; text-align: right; flex: none;
  display: flex; align-items: center; gap: 12px; }
.mover-price { font-size: 13.5px; font-variant-numeric: tabular-nums; }
.mover-note { color: var(--muted); font-size: 12.5px; padding: 10px 4px; }

/* --- Constituents table --- */
.constituents { margin-top: 34px; }
.constituents-head { display: flex; align-items: center; justify-content: space-between;
  gap: 14px; margin-bottom: 6px; flex-wrap: wrap; }
.search {
  flex: 1; min-width: 180px; max-width: 300px;
  background: var(--bg-soft); border: 1px solid transparent; border-radius: 20px;
  color: var(--ink); padding: 9px 16px; font: 400 13.5px var(--font); outline: none;
}
.search:focus { background: var(--bg); border-color: var(--blue); }
.search::placeholder { color: var(--muted); }
.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table thead th {
  text-align: left; color: var(--muted); font-weight: 500; font-size: 12.5px;
  padding: 10px; border-bottom: 1px solid var(--hairline); position: sticky; top: 0;
  background: var(--bg); white-space: nowrap; z-index: 1;
}
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--ink); }
.table th.sorted-asc::after { content: " ↑"; color: var(--blue); }
.table th.sorted-desc::after { content: " ↓"; color: var(--blue); }
.col-price, .col-change { text-align: right; }
.table tbody td { padding: 8px 10px; border-bottom: 1px solid var(--hairline); vertical-align: middle; }
.table tbody tr:hover td { background: var(--bg-soft); }
.td-rank { color: var(--muted); font-variant-numeric: tabular-nums; width: 40px; }
.td-card { display: flex; align-items: center; gap: 10px; }
.td-thumb { width: 28px; height: 39px; border-radius: 3px; flex: none;
  object-fit: cover; background: var(--bg-soft); border: 1px solid var(--hairline); }
.td-name { font-weight: 500; }
.td-num { color: var(--muted); font-size: 11.5px; }
.td-set { color: var(--ink-2); }
.td-price { text-align: right; font-variant-numeric: tabular-nums; }
.td-change { text-align: right; white-space: nowrap; }
.badge-new {
  font-size: 11px; font-weight: 500; color: var(--blue); background: var(--blue-soft);
  border-radius: 8px; padding: 3px 8px;
}
.thumb-ph { display: grid; place-items: center; color: var(--faint); font-size: 8px; }
.table-count { color: var(--muted); font-size: 12.5px; margin: 12px 0 0; }
.table-note { color: var(--muted); font-size: 12px; margin: 6px 0 0; max-width: 760px; }
.stale-mark { color: var(--muted); font-size: 0.75em; margin-left: 2px; cursor: help; }

/* --- Methodology --- */
.methodology { margin-top: 36px; padding-top: 8px; border-top: 1px solid var(--hairline); }
.method-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.method-block h3 { margin: 0 0 6px; font-size: 14px; font-weight: 600; color: var(--ink); }
.method-block p { margin: 0; color: var(--ink-2); font-size: 13px; line-height: 1.55; }
.method-block a { color: var(--blue); text-decoration: none; }
.method-block a:hover { text-decoration: underline; }
@media (max-width: 720px) { .method-grid { grid-template-columns: 1fr; gap: 16px; } }
.asof-link { color: var(--blue); text-decoration: none; }
.asof-link:hover { text-decoration: underline; }

/* --- Footer --- */
.site-footer { border-top: 1px solid var(--hairline); margin-top: 36px;
  padding-block: 22px 44px; color: var(--ink-2); font-size: 13px; }
.site-footer p { margin: 0 0 8px; max-width: 760px; }
.site-footer .muted { color: var(--muted); font-size: 12px; }

/* --- Loading --- */
[aria-busy="true"] .quote-price { opacity: 0.4; }

/* --- Responsive --- */
@media (max-width: 720px) {
  .ov-grid { grid-template-columns: 1fr; column-gap: 0; }
  .mover-cols { grid-template-columns: 1fr; }
  .col-set { display: none; }
  .brand-chip { display: none; }
}

/* ---- card lightbox ------------------------------------------------------ */
.card-modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 18px; }
.card-modal[hidden] { display: none; }
.card-modal-backdrop {
  position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  opacity: 0; transition: opacity 0.22s ease;
}
.card-modal-panel {
  position: relative; width: 100%; max-width: 400px; max-height: calc(100vh - 36px);
  overflow-y: auto; background: var(--bg); border: 1px solid var(--hairline);
  border-radius: 20px; padding: 18px 18px 20px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35);
  opacity: 0; transform: translateY(14px) scale(0.97);
  transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.card-modal.is-open .card-modal-backdrop { opacity: 1; }
.card-modal.is-open .card-modal-panel { opacity: 1; transform: none; }
.card-modal-close {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  width: 34px; height: 34px; border: 0; border-radius: 50%;
  background: var(--chip); color: var(--ink-2); font-size: 15px; line-height: 1;
  cursor: pointer; display: grid; place-items: center;
}
.card-modal-close:hover { background: var(--border); }
/* Reserve the image's final display size up front so the panel doesn't jump
   when the card loads. #cm-img settles at min(78%, 252px) wide; Pokemon cards
   are 63:88, so its height is min(44vh, 352px). +8px is the wrap's padding
   (border-box), keeping the image from overflowing the reserved box. */
.card-modal-imgwrap { display: grid; place-items: center; padding: 6px 0 2px; height: calc(min(44vh, 352px) + 8px); }
.card-modal-imgwrap > * { grid-area: 1 / 1; }
#cm-img {
  max-width: min(78%, 252px); max-height: 44vh; width: auto; height: auto;
  border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  background: var(--bg-soft);
  opacity: 0; transition: opacity 0.25s ease;
}
#cm-img.is-loaded { opacity: 1; }
.cm-spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--hairline); border-top-color: var(--blue);
  animation: cm-spin 0.7s linear infinite;
}
@keyframes cm-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .cm-spinner { animation-duration: 1.6s; } }
.card-modal-body { padding-top: 14px; text-align: center; }
.cm-name { font-size: 1.15rem; font-weight: 500; color: var(--ink); margin: 0; }
.cm-set { margin: 2px 0 10px; color: var(--muted); font-size: 0.85rem; }
.cm-quote { display: flex; justify-content: center; align-items: baseline; gap: 10px; }
.cm-price { font-size: 1.7rem; font-weight: 400; color: var(--ink); letter-spacing: -0.5px; }
.cm-quote .delta { font-size: 0.95rem; }
.cm-facts {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
  margin: 16px 0 0; padding: 12px 4px 0; border-top: 1px solid var(--hairline);
}
.cm-facts div { display: grid; gap: 2px; }
.cm-facts dt { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--faint); }
.cm-facts dd { margin: 0; font-size: 0.9rem; color: var(--ink-2); }
.cm-stale { margin: 12px 0 0; padding: 8px 10px; border-radius: 8px; background: var(--hairline);
  color: var(--ink-2); font-size: 0.78rem; line-height: 1.45; text-align: left; }
.cm-links { display: flex; justify-content: center; gap: 16px; flex-wrap: wrap; }
.cm-link {
  display: inline-block; margin-top: 14px; font-size: 0.85rem;
  color: var(--blue); text-decoration: none;
}
.cm-link:hover { text-decoration: underline; }
.cm-note { margin: 10px 0 0; color: var(--muted); font-size: 0.75rem; }
.cm-note a { color: var(--muted); text-decoration: underline; }
body.modal-open { overflow: hidden; }
.table tbody tr { cursor: pointer; }
.mover-item { cursor: pointer; }
@media (max-width: 480px) {
  .card-modal { padding: 12px; }
  .card-modal-panel { padding: 14px 14px 18px; }
}

/* ---- brand logo image ---------------------------------------------------- */
.brand-mark img { display: block; width: 28px; height: 28px; border-radius: 8px; }
.crumb { white-space: nowrap; }
.crumb .ticker { color: var(--faint); }
