/* ---------------------------------------------------------------------------
   CS2 Market Cap — styles
   Material 3 "Expressive" inspired: tonal surfaces, generous rounding,
   segmented controls, tonal state layers, springy motion.
--------------------------------------------------------------------------- */
:root {
  color-scheme: light;

  /* ---- Material tonal roles (light) ---- */
  --primary:                #6750A4;
  --on-primary:             #ffffff;
  --primary-container:      #EADDFF;
  --on-primary-container:   #21005D;
  --secondary-container:    #E8DEF8;
  --on-secondary-container: #1D192B;
  --tertiary-container:     #FFD8E4;
  --on-tertiary-container:  #31111D;

  /* ---- surfaces ---- */
  --plane:        #F5EEF9;   /* page background */
  --surface:      #FFFFFF;   /* cards / chart / sticky header */
  --surface-2:    #ECE4F1;   /* chips / inputs / hover fill */
  --surface-3:    #F5EFF8;   /* subtle raised */

  --text-primary:  #1D1B20;  /* on-surface */
  --text-secondary:#49454F;  /* on-surface-variant */
  --muted:         #79747E;  /* outline / muted text */
  --grid:          #E7E0EC;
  --baseline:      #CAC4D0;
  --border:        rgba(29, 27, 32, 0.10);
  --outline:       #CAC4D0;

  /* ---- dataviz + semantic ---- */
  --series-1:  var(--primary);
  --up:            #146C2E;   /* delta up = good */
  --down:          #B3261E;   /* delta down = critical */
  --up-wash:       rgba(20, 108, 46, 0.13);
  --down-wash:     rgba(179, 38, 30, 0.11);
  --up-container:    #C4F0CD;
  --on-up-container: #04390F;
  --down-container:    #F9DEDC;
  --on-down-container: #8C1D18;

  /* ---- elevation ---- */
  --shadow:   0 1px 2px rgba(0,0,0,.05), 0 4px 12px rgba(29,27,32,.06);
  --shadow-2: 0 2px 4px rgba(0,0,0,.06), 0 10px 28px rgba(29,27,32,.10);

  /* ---- shape (expressive = generous) ---- */
  --radius:      24px;
  --radius-lg:   28px;
  --radius-md:   16px;
  --radius-sm:   12px;
  --radius-full: 999px;

  --spring: 260ms cubic-bezier(.2, .8, .2, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --primary:                #D0BCFF;
    --on-primary:             #381E72;
    --primary-container:      #4F378B;
    --on-primary-container:   #EADDFF;
    --secondary-container:    #4A4458;
    --on-secondary-container: #E8DEF8;
    --tertiary-container:     #633B48;
    --on-tertiary-container:  #FFD8E4;

    --plane:        #141218;
    --surface:      #211F26;
    --surface-2:    #2B2930;
    --surface-3:    #1D1B20;

    --text-primary:  #E6E0E9;
    --text-secondary:#CAC4D0;
    --muted:         #938F99;
    --grid:          #322F37;
    --baseline:      #49454F;
    --border:        rgba(230, 224, 233, 0.12);
    --outline:       #49454F;

    --up:            #7CE38B;
    --down:          #F2B8B5;
    --up-wash:       rgba(124, 227, 139, 0.16);
    --down-wash:     rgba(242, 184, 181, 0.16);
    --up-container:    #0C3A19;
    --on-up-container: #B6F2C0;
    --down-container:    #601410;
    --on-down-container: #F9DEDC;

    --shadow:   0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.35);
    --shadow-2: 0 2px 6px rgba(0,0,0,.5), 0 14px 34px rgba(0,0,0,.45);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --primary:                #D0BCFF;
  --on-primary:             #381E72;
  --primary-container:      #4F378B;
  --on-primary-container:   #EADDFF;
  --secondary-container:    #4A4458;
  --on-secondary-container: #E8DEF8;
  --tertiary-container:     #633B48;
  --on-tertiary-container:  #FFD8E4;

  --plane:        #141218;
  --surface:      #211F26;
  --surface-2:    #2B2930;
  --surface-3:    #1D1B20;

  --text-primary:  #E6E0E9;
  --text-secondary:#CAC4D0;
  --muted:         #938F99;
  --grid:          #322F37;
  --baseline:      #49454F;
  --border:        rgba(230, 224, 233, 0.12);
  --outline:       #49454F;

  --up:            #7CE38B;
  --down:          #F2B8B5;
  --up-wash:       rgba(124, 227, 139, 0.16);
  --down-wash:     rgba(242, 184, 181, 0.16);
  --up-container:    #0C3A19;
  --on-up-container: #B6F2C0;
  --down-container:    #601410;
  --on-down-container: #F9DEDC;

  --shadow:   0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.35);
  --shadow-2: 0 2px 6px rgba(0,0,0,.5), 0 14px 34px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--plane);
  color: var(--text-primary);
  font-family: "Google Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
.tabnum { font-variant-numeric: tabular-nums; }

/* -------------------------------------------------- top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(16px, 4vw, 40px);
  position: sticky;
  top: 0;
  background: color-mix(in srgb, var(--plane) 82%, transparent);
  backdrop-filter: blur(14px) saturate(1.4);
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 46px; height: 46px;
  border-radius: 16px 16px 16px 28px;   /* expressive squircle */
  background: linear-gradient(135deg, var(--primary), color-mix(in srgb, var(--primary) 70%, var(--tertiary-container)));
  color: var(--on-primary);
  font-weight: 700;
  font-size: 24px;
  line-height: 1;
  box-shadow: var(--shadow);
}
.brand-text h1 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -0.01em; }
.tagline { margin: 1px 0 0; font-size: 12.5px; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.generated { font-size: 12px; color: var(--muted); }

.theme-toggle {
  display: grid; place-items: center;
  width: 46px; height: 46px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--spring), transform var(--spring);
}
.theme-toggle:hover { background: var(--secondary-container); color: var(--on-secondary-container); }
.theme-toggle:active { transform: scale(.92); }
.theme-toggle .ti { display: none; width: 20px; height: 20px; }
.theme-toggle .ti svg { width: 100%; height: 100%; display: block; }
/* show the icon for the theme you'll switch TO: light shows moon, dark shows sun.
   (selectors kept at matching specificity so source order decides) */
.theme-toggle .ti-moon { display: inline-flex; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .ti-moon { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .ti-sun  { display: inline-flex; }
}
:root[data-theme="dark"] .theme-toggle .ti-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .ti-sun  { display: inline-flex; }
:root[data-theme="light"] .theme-toggle .ti-moon { display: inline-flex; }
:root[data-theme="light"] .theme-toggle .ti-sun  { display: none; }

/* -------------------------------------------------- layout */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: clamp(14px, 3vw, 26px) clamp(14px, 4vw, 40px) 64px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px clamp(16px, 2.5vw, 26px);
}
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.card h2 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.card-sub { margin: 4px 0 0; font-size: 12.5px; color: var(--muted); }

/* -------------------------------------------------- filters (segmented) */
.filters { display: flex; align-items: center; gap: 12px; }
.filters-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.range-group {
  display: inline-flex;
  gap: 4px;
  background: var(--surface);
  padding: 4px;
  border-radius: var(--radius-full);
  border: 1px solid var(--outline);
}
.range-btn {
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 16px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background var(--spring), color var(--spring);
}
.range-btn:hover { background: var(--surface-2); color: var(--text-primary); }
.range-btn[aria-pressed="true"] {
  background: var(--secondary-container);
  color: var(--on-secondary-container);
}

/* -------------------------------------------------- hero + tiles */
.hero-grid {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 1.7fr;
  gap: 16px;
}
.hero-card {
  position: relative;
  overflow: hidden;
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 28px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 20px;
  color: var(--on-primary-container);
  background:
    radial-gradient(120% 140% at 100% 0%, color-mix(in srgb, var(--tertiary-container) 70%, transparent), transparent 60%),
    linear-gradient(150deg, var(--primary-container), color-mix(in srgb, var(--primary-container) 80%, var(--surface)));
}
/* two balanced blocks (headline / period chips), vertically centred as a group */
.hero-top { display: flex; flex-direction: column; gap: 8px; }
.hero-bottom { display: flex; flex-direction: column; gap: 12px; }
.stat-label {
  margin: 0; font-size: 12.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em;
  color: color-mix(in srgb, var(--on-primary-container) 72%, transparent);
}
.hero-figure {
  margin: 0;
  font-size: clamp(38px, 6vw, 54px);
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.0;
}
.hero-note {
  margin: 0; font-size: 12px;
  color: color-mix(in srgb, var(--on-primary-container) 72%, transparent);
}
.hero-card .hero-note { max-width: 42ch; }

.tiles {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  min-height: 104px;
  transition: transform var(--spring), box-shadow var(--spring);
}
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
.tile-value { font-size: 23px; font-weight: 650; letter-spacing: -0.01em; line-height: 1.1; }
.tile-value.small { font-size: 17px; font-weight: 600; }
.tile-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-sub:first-child { color: var(--text-secondary); font-weight: 600; }

/* -------------------------------------------------- window chips (hero/modal) */
.window-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.wchip {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 10px 6px;
  min-width: 0;
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--surface) 62%, transparent);
  border: 1px solid color-mix(in srgb, var(--on-primary-container) 12%, transparent);
}
.wchip-label {
  font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: color-mix(in srgb, var(--on-primary-container) 66%, transparent);
}
.wchip-val {
  font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
}
.wchip .arrow { font-size: 10px; }
.wchip.up .wchip-val   { color: var(--up); }
.wchip.down .wchip-val { color: var(--down); }
.wchip.flat .wchip-val { color: color-mix(in srgb, var(--on-primary-container) 70%, transparent); }

/* chips outside the coloured hero (e.g. modal) use neutral surface tokens */
.modal .wchip {
  background: var(--surface-2);
  border-color: var(--border);
}
.modal .wchip-label { color: var(--muted); }
.modal .wchip.flat .wchip-val { color: var(--muted); }

/* -------------------------------------------------- delta */
.delta { margin: 0; font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }
.delta.flat { color: var(--muted); }
.delta .arrow { font-size: 11px; }
.delta-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: var(--radius-full);
  font-weight: 650; font-size: 12.5px; font-variant-numeric: tabular-nums;
}
.delta-pill .arrow { font-size: 9px; }
.delta-pill.up   { color: var(--on-up-container); background: var(--up-container); }
.delta-pill.down { color: var(--on-down-container); background: var(--down-container); }
.delta-pill.flat { color: var(--muted); background: var(--surface-2); }

/* -------------------------------------------------- charts */
.chart { margin: 0; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-card { position: relative; }

.axis-label { fill: var(--muted); font-size: 11px; }
.axis-label.tabnum { font-variant-numeric: tabular-nums; }
.gridline { stroke: var(--grid); stroke-width: 1; }
.baseline { stroke: var(--baseline); stroke-width: 1; }
.series-line { fill: none; stroke: var(--series-1); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.series-area { fill: var(--series-1); opacity: 0.12; }
.end-dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2.5; }
.crosshair { stroke: var(--primary); stroke-width: 1; stroke-dasharray: 3 3; }
.focus-dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2.5; }

/* tooltip */
.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-2);
  padding: 9px 12px;
  font-size: 12.5px;
  min-width: 122px;
  transform: translate(-50%, -120%);
  z-index: 5;
  opacity: 0;
  transition: opacity .12s ease;
}
.chart-tooltip.visible { opacity: 1; }
.chart-tooltip .tt-date { color: var(--muted); font-size: 11.5px; margin-bottom: 3px; }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 7px; }
.chart-tooltip .tt-key { width: 14px; height: 3px; border-radius: 2px; background: var(--series-1); flex: none; }
.chart-tooltip .tt-val { font-weight: 650; font-variant-numeric: tabular-nums; }

/* -------------------------------------------------- table */
.table-head { align-items: center; }
.search { position: relative; display: inline-flex; align-items: center; }
.search-icon { position: absolute; left: 14px; color: var(--muted); font-size: 15px; pointer-events: none; }
.search input {
  font: inherit; font-size: 14px;
  padding: 10px 14px 10px 36px;
  border-radius: var(--radius-full);
  border: 1px solid var(--outline);
  background: var(--surface-2);
  color: var(--text-primary);
  width: 230px;
  max-width: 46vw;
  transition: border-color var(--spring), background var(--spring);
}
.search input::placeholder { color: var(--muted); }
.search input:focus { outline: none; border-color: var(--primary); border-width: 2px; padding-left: 35px; }

.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  text-align: right;
  font-weight: 600;
  font-size: 11.5px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  position: sticky; top: 0;
  background: var(--surface);
  transition: color var(--spring);
}
thead th:hover { color: var(--primary); }
thead th.col-rank, thead th.col-name { text-align: left; }
thead th.col-spark { text-align: right; cursor: default; }
thead th.col-spark:hover { color: var(--text-secondary); }
thead th[aria-sort] { color: var(--primary); }
thead th .sort-caret { font-size: 9px; margin-left: 3px; }

tbody td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
tbody td.col-rank { color: var(--muted); text-align: left; width: 40px; font-variant-numeric: tabular-nums; }
tbody td.col-name { text-align: left; font-variant-numeric: normal; max-width: 300px; }
tbody tr { cursor: pointer; transition: background var(--spring); }
tbody tr:hover { background: color-mix(in srgb, var(--primary) 8%, var(--surface)); }
tbody tr:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
tbody tr:last-child td { border-bottom: 0; }

.item-name { font-weight: 600; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub { display: block; font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.spark { width: 112px; height: 30px; display: block; margin-left: auto; }
.spark path.spark-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark path.spark-area { stroke: none; opacity: .14; }
.spark path.up { stroke: var(--up); }
.spark path.down { stroke: var(--down); }
.spark path.spark-area.up { fill: var(--up); }
.spark path.spark-area.down { fill: var(--down); }

.no-results { text-align: center; color: var(--muted); padding: 36px 12px; }

/* -------------------------------------------------- loading / error */
.loading, .error {
  max-width: 1200px;
  margin: 40px auto;
  padding: 24px clamp(16px, 4vw, 40px);
  color: var(--muted);
  text-align: center;
}
.error {
  color: var(--on-down-container);
  background: var(--down-container);
  border-radius: var(--radius-md);
  max-width: 720px;
}

/* -------------------------------------------------- footer */
.footer {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px clamp(16px, 4vw, 40px) 48px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-secondary);
}
.footer p { margin: 4px 0; }
.footer-muted { color: var(--muted); }
.footer code { background: var(--surface-2); padding: 2px 7px; border-radius: 6px; font-size: 12px; }

/* -------------------------------------------------- modal */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: color-mix(in srgb, #000 42%, transparent); backdrop-filter: blur(2px); }
.modal-panel {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  width: min(700px, 96vw);
  max-height: 90vh;
  overflow-y: auto;
  padding: 26px clamp(18px, 3vw, 30px) 30px;
  animation: modal-in var(--spring);
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
  to   { opacity: 1; transform: none; }
}
.modal-close {
  position: absolute; top: 14px; right: 14px;
  width: 40px; height: 40px;
  border: 0; border-radius: var(--radius-full);
  background: var(--surface-2); color: var(--text-secondary);
  font-size: 22px; line-height: 1; cursor: pointer;
  transition: background var(--spring);
}
.modal-close:hover { background: var(--secondary-container); color: var(--on-secondary-container); }
#modal-title { margin: 4px 48px 4px 0; font-size: 21px; font-weight: 700; letter-spacing: -.01em; }
.modal-stats { display: flex; flex-wrap: wrap; gap: 16px 28px; margin: 16px 0 22px; }
.modal-stats .ms { display: flex; flex-direction: column; gap: 3px; }
.modal-stats .ms.ms-wide { flex-basis: 100%; gap: 8px; }
.modal-stats .ms-label { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.modal-stats .ms-value { font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; }
.modal-charts { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.mini-chart figcaption { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.mini-chart .chart { width: 100%; }

/* -------------------------------------------------- responsive */
@media (max-width: 860px) {
  .hero-grid { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .modal-charts { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
  .tagline { display: none; }
  .generated { display: none; }
  .tiles { grid-template-columns: 1fr 1fr; }
  /* let the table scroll, but drop the least-critical columns first */
  .col-spark { display: none; }
  .col-supply { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
