@font-face { font-family: 'GW Plex'; src: url('../resources/fonts/ibm-plex-sans.woff2') format('woff2'); font-weight: 100 700; font-display: block; }
@font-face { font-family: 'GW Mono'; src: url('../resources/fonts/ibm-plex-mono-500.woff2') format('woff2'); font-weight: 500; font-display: block; }
@font-face { font-family: 'GW Mono'; src: url('../resources/fonts/ibm-plex-mono-600.woff2') format('woff2'); font-weight: 600; font-display: block; }

:root {
  --ink: #e9ecef;
  --gold: #f0c24b;
  --paper: #101214;
  --paper-alpha: 1;
  --rise: #5fd38d;
  --fall: #ef6b6b;

  --unit: 1vmin;              /* the single size baseline */
  --s-pad: calc(var(--unit) * 3.6);
  --s-gap: calc(var(--unit) * 2.4);
  --t-label: calc(var(--unit) * 2.5);
  --t-body: calc(var(--unit) * 3.0);
  --t-small: calc(var(--unit) * 2.35);
  --t-hero: calc(var(--unit) * 11);
  --t-big: calc(var(--unit) * 5.6);
  --line: calc(var(--unit) * 0.16);
  --round: calc(var(--unit) * 1.6);
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; background: transparent; }
body { color: var(--ink); font: 400 var(--t-body)/1.2 'GW Plex', 'Segoe UI', system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }

.gw-root { position: relative; width: 100%; height: 100%; overflow: hidden; }
.gw-bg { position: absolute; inset: 0; background: var(--paper); opacity: var(--paper-alpha); }

.gw-grid {
  position: relative;
  display: flex;
  gap: var(--s-gap);
  width: 100%;
  height: 100%;
  padding: var(--s-pad) var(--s-pad) calc(var(--s-pad) * 1.3);
}

.gw-card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: calc(var(--s-pad) * 0.8);
  border-radius: var(--round);
  background: color-mix(in srgb, var(--ink) 4.5%, transparent);
  border: var(--line) solid color-mix(in srgb, var(--ink) 8%, transparent);
}

.gw-lead { flex: 0.85 1 0; }
.gw-board { flex: 2 1 0; container-type: inline-size; }
.gw-player { flex: 0.8 1 0; }

.gw-label {
  font-size: var(--t-label);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- the lead item (hero) ---- */
.gw-lead-price {
  font-family: 'GW Mono', monospace;
  font-weight: 600;
  font-size: var(--t-hero);
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  margin-top: calc(var(--s-gap) * 0.4);
}
.gw-lead-move { font-family: 'GW Mono', monospace; font-size: var(--t-body); opacity: 0.85; }
.gw-spark-lead { flex: 1 1 0; min-height: calc(var(--unit) * 6); width: 100%; margin: calc(var(--s-gap) * 0.6) 0; }
.gw-facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: calc(var(--s-gap) * 0.6) var(--s-gap); margin: 0; }
.gw-fact { min-width: 0; }
.gw-fact dt { font-size: var(--t-small); opacity: 0.55; white-space: nowrap; }
.gw-fact dd { margin: 0; font-family: 'GW Mono', monospace; font-weight: 600; font-size: var(--t-body); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.gw-spark path { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.gw-spark path.up { stroke: var(--rise); }
.gw-spark path.down { stroke: var(--fall); }

.is-up { color: var(--rise); }
.is-down { color: var(--fall); }
.gw-lead-move.is-up, .gw-lead-move.is-down { opacity: 1; }

/* ---- the watch board ---- */
.gw-row {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) repeat(4, minmax(0, 1fr)) minmax(0, 1.25fr);
  align-items: center;
  column-gap: var(--s-gap);
  padding: calc(var(--s-gap) * 0.42) 0;
  border-bottom: var(--line) solid color-mix(in srgb, var(--ink) 7%, transparent);
  white-space: nowrap;
}
.gw-row-head { font-size: var(--t-small); opacity: 0.55; padding-top: 0; flex: 0 0 auto; }
.gw-row-head .c-name { text-transform: uppercase; letter-spacing: 0.06em; }
.gw-rows { flex: 1 1 0; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
/* rows share the board height up to a comfortable maximum, so short lists don't leave a void */
.gw-rows .gw-row { flex: 1 1 0; min-height: calc(var(--t-body) * 2.1); max-height: calc(var(--unit) * 11); }
@media (min-height: 500px) and (min-aspect-ratio: 2/1) { .gw-rows .gw-row { font-size: calc(var(--t-body) * 1.12); } }
.gw-row.is-cut { display: none; }
.gw-row.is-quiet .c-name::after { content: ' \00b7  quiet'; font-size: var(--t-small); opacity: 0.45; }
.c-name { overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.c-num { text-align: right; font-family: 'GW Mono', monospace; font-variant-numeric: tabular-nums; overflow: hidden; }
.gw-row-head .c-num { font-family: inherit; }
.c-trend { display: flex; align-items: center; justify-content: flex-end; gap: calc(var(--s-gap) * 0.5); min-width: 0; }
.c-trend .gw-spark { flex: 1 1 auto; height: calc(var(--t-body) * 1.25); min-width: 0; }
.gw-pct { font-family: 'GW Mono', monospace; font-size: var(--t-small); flex: 0 0 auto; min-width: 4.4em; text-align: right; }
.gw-note { flex: 0 0 auto; font-size: var(--t-small); opacity: 0.6; padding-top: calc(var(--s-gap) * 0.4); }
.gw-note:empty { display: none; }

@container (max-width: 700px) {
  .gw-row { grid-template-columns: minmax(0, 1.5fr) repeat(3, minmax(0, 1fr)) minmax(0, 0.9fr); }
  .c-vol { display: none; }
  .c-trend .gw-spark { display: none; }
}
@container (max-width: 470px) {
  .gw-row { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 0.8fr); }
  .gw-row > :nth-child(2), .gw-row > :nth-child(4) { display: none; }
}

/* ---- player ---- */
.gw-player-big { display: flex; gap: calc(var(--s-gap) * 1.6); margin-top: calc(var(--s-gap) * 0.6); }
.gw-player-big > div { display: flex; flex-direction: column; }
.gw-k { font-size: var(--t-small); opacity: 0.55; }
.gw-v { font-family: 'GW Mono', monospace; font-weight: 600; font-size: var(--t-big); line-height: 1.05; }
.gw-player-xp { font-family: 'GW Mono', monospace; font-size: var(--t-small); opacity: 0.75; margin-top: calc(var(--s-gap) * 0.4); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gw-sub { font-size: var(--t-small); color: var(--gold); margin-top: calc(var(--s-gap) * 0.9); }
.gw-gains { list-style: none; margin: calc(var(--s-gap) * 0.4) 0 0; padding: 0; display: flex; flex-direction: column; gap: calc(var(--s-gap) * 0.3); min-height: 0; overflow: hidden; }
.gw-gains li { display: grid; grid-template-columns: 1fr auto calc(var(--unit) * 7); gap: var(--s-gap); white-space: nowrap; font-size: var(--t-small); }
.gw-gain { font-family: 'GW Mono', monospace; color: var(--rise); text-align: right; }
.gw-lv { font-family: 'GW Mono', monospace; opacity: 0.7; text-align: right; }

/* ---- footer + messages ---- */
.gw-foot { position: absolute; right: var(--s-pad); bottom: calc(var(--s-pad) * 0.3); font-size: calc(var(--t-small) * 0.85); opacity: 0.4; white-space: nowrap; }
.gw-foot.is-stale { opacity: 0.95; color: var(--gold); }
.gw-msg {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); max-width: 72%;
  display: flex; flex-direction: column; gap: 0.35em; text-align: center;
  padding: calc(var(--s-pad) * 0.8) var(--s-pad); border-radius: var(--round);
  background: color-mix(in srgb, var(--paper) 88%, var(--ink)); border: var(--line) solid color-mix(in srgb, var(--gold) 50%, transparent);
}
.gw-msg b { color: var(--gold); font-weight: 600; letter-spacing: 0.04em; }
.gw-msg span { font-size: var(--t-small); opacity: 0.85; }
.gw-root[data-state='loading'] .gw-grid, .gw-root[data-state='error'] .gw-grid, .gw-root[data-state='empty'] .gw-grid { opacity: 0.25; }

/* =================== layouts per slot =================== */

/* Medium horizontal 840x696: lead on top, board under it */
@media (max-aspect-ratio: 2/1) and (min-aspect-ratio: 1/1) and (min-height: 500px) {
  .gw-grid { flex-direction: column; }
  .gw-lead { flex: 0 0 auto; }
  .gw-spark-lead { min-height: calc(var(--unit) * 7); max-height: calc(var(--unit) * 9); }
  .gw-player { display: none !important; }
  .gw-facts { grid-template-columns: repeat(6, auto); }
}

/* Small 840x344 and 696x416: the lead tile plus a short list */
@media (max-height: 499px) {
  :root { --unit: 5px; }
  .gw-player { display: none !important; }
  .gw-facts { grid-template-columns: repeat(3, auto); }
}
@media (max-height: 499px) and (max-aspect-ratio: 2/1) {
  :root { --unit: 4.6px; }
  .gw-board { display: none !important; }
  .gw-lead { flex: 1 1 0; }
}

/* Vertical slots: everything stacks */
@media (max-aspect-ratio: 1/1) {
  .gw-grid { flex-direction: column; }
  .gw-lead { flex: 0 0 auto; }
  .gw-spark-lead { flex: 0 0 auto; height: calc(var(--unit) * 12); }
  .gw-board { flex: 1 1 0; }
  .gw-player { flex: 0 0 auto; }
}
@media (max-aspect-ratio: 1/1) and (max-height: 1000px) {
  .gw-player { display: none !important; }
}

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Tall vertical slots: give the spare height to the lead chart, keep the board to its content */
@media (max-aspect-ratio: 1/1) and (min-height: 1001px) {
  .gw-spark-lead { height: calc(var(--unit) * 34); }
  .gw-board { flex: 0 1 auto; }
  .gw-rows { flex: 0 1 auto; }
  .gw-rows .gw-row { flex: 0 0 auto; height: calc(var(--unit) * 10); }
  .gw-grid { justify-content: flex-start; }
}

/* =================== 1.1: alerts, tabs, Movers, the touch sheet =================== */

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }

/* tabs live in the board's header row */
.gw-row-head { min-height: calc(var(--unit) * 7.2); padding-bottom: calc(var(--s-gap) * 0.3); opacity: 1; }
.gw-row-head > :not(.gw-tabs) { opacity: 0.55; }
.gw-tabs { display: flex; gap: calc(var(--s-gap) * 0.4); align-items: stretch; overflow: visible; }
.gw-tab {
  flex: 0 0 auto;
  min-height: calc(var(--unit) * 6.4);
  padding: 0 calc(var(--s-gap) * 0.7);
  border-radius: calc(var(--round) * 0.7);
  font-size: var(--t-small);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--ink) 60%, transparent);
  border: var(--line) solid color-mix(in srgb, var(--ink) 14%, transparent);
}
.gw-tab.is-on { color: var(--paper); background: var(--gold); border-color: var(--gold); }

.c-name { display: flex; align-items: center; gap: calc(var(--s-gap) * 0.45); min-width: 0; }
.gw-nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.gw-row.is-quiet .c-name::after { flex: 0 0 auto; }

/* an alert is set on this item: a small ring before the name */
.gw-row.has-alert .gw-nm::before, .gw-lead.has-alert .gw-label::before {
  content: ''; display: inline-block; width: 0.55em; height: 0.55em; margin-right: 0.4em; vertical-align: 0.06em;
  border-radius: 50%; border: calc(var(--line) * 1.6) solid var(--gold);
}

/* lit: filled label + thick frame + tinted tile, so it reads without colour too */
.gw-chip {
  flex: 0 0 auto;
  font-family: 'GW Mono', monospace;
  font-size: var(--t-small);
  font-weight: 600;
  padding: 0.12em 0.5em;
  border-radius: calc(var(--round) * 0.5);
  color: var(--paper);
  background: var(--gold);
  white-space: nowrap;
}
.gw-row.is-lit {
  background: color-mix(in srgb, var(--gold) 16%, transparent);
  box-shadow: inset calc(var(--unit) * 0.9) 0 0 var(--gold);
  padding-left: calc(var(--unit) * 1.8);
  border-radius: calc(var(--round) * 0.5);
}
.gw-lead.is-lit {
  border: calc(var(--line) * 4) solid var(--gold);
  background: color-mix(in srgb, var(--gold) 13%, transparent);
}
.gw-alert { flex: 0 0 auto; margin-bottom: calc(var(--s-gap) * 0.5); min-width: 0; }
.gw-alert-top { display: flex; align-items: center; gap: calc(var(--s-gap) * 0.5); min-width: 0; }
.gw-alert-top b {
  flex: 0 0 auto;
  font-size: var(--t-label); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 0.12em 0.55em; border-radius: calc(var(--round) * 0.5); color: var(--paper); background: var(--gold);
}
.gw-alert-more { flex: 1 1 auto; min-width: 0; text-align: right; font-size: var(--t-small); opacity: 0.8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gw-alert-line { margin-top: calc(var(--s-gap) * 0.3); font-size: var(--t-small); font-family: 'GW Mono', monospace; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gw-bell { flex: 0 0 auto; width: calc(var(--t-label) * 1.05); height: calc(var(--t-label) * 1.05); background: var(--gold);
  -webkit-mask: radial-gradient(circle at 50% 92%, #000 14%, transparent 15%), linear-gradient(#000, #000) 50% 74% / 100% 10% no-repeat, radial-gradient(ellipse 36% 58% at 50% 62%, #000 98%, transparent 100%);
  mask: radial-gradient(circle at 50% 92%, #000 14%, transparent 15%), linear-gradient(#000, #000) 50% 74% / 100% 10% no-repeat, radial-gradient(ellipse 36% 58% at 50% 62%, #000 98%, transparent 100%); }
@media (prefers-reduced-motion: no-preference) {
  .gw-lead.is-lit, .gw-row.is-lit { animation: gw-pulse 2.4s ease-in-out infinite; }
}
@keyframes gw-pulse { 50% { border-color: color-mix(in srgb, var(--gold) 55%, transparent); } }

/* Movers rows */
.gw-add {
  flex: 0 0 auto; display: inline-grid; place-items: center;
  width: 1.5em; height: 1.5em; border-radius: 50%;
  font-family: 'GW Mono', monospace; font-weight: 600; line-height: 1;
  color: var(--paper); background: var(--gold);
}
.gw-mover.is-have .gw-add { background: transparent; color: var(--gold); border: calc(var(--line) * 1.4) solid var(--gold); }
.gw-empty { font-size: var(--t-small); opacity: 0.65; padding-top: var(--s-gap); white-space: normal; }

/* the touch sheet covers the whole widget */
.gw-sheet {
  position: absolute; inset: 0; z-index: 5;
  display: flex; flex-direction: column; justify-content: center; gap: calc(var(--s-gap) * 0.9);
  padding: var(--s-pad) calc(var(--s-pad) * 1.4);
  background: color-mix(in srgb, var(--paper) 97%, var(--ink));
}
.gw-sheet-head { display: flex; align-items: baseline; gap: var(--s-gap); min-width: 0; white-space: nowrap; }
.gw-sheet-head b { font-size: var(--t-big); color: var(--gold); overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 0 1 auto; }
.gw-sheet-head span { font-family: 'GW Mono', monospace; font-size: var(--t-small); opacity: 0.75; flex: 0 0 auto; }
.gw-sheet-line { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(6.5em, auto) auto auto; align-items: center; gap: calc(var(--s-gap) * 0.7); }
.gw-sheet-line.is-off .gw-sheet-at { opacity: 0.4; }
.gw-sheet-what { font-size: var(--t-body); min-width: 0; }
.gw-sheet-at { font-family: 'GW Mono', monospace; font-weight: 600; font-size: var(--t-big); text-align: center; white-space: nowrap; }
.gw-step, .gw-toggle, .gw-btn {
  min-width: calc(var(--unit) * 9.5); min-height: calc(var(--unit) * 8.5);
  border-radius: var(--round); font-weight: 600; font-size: var(--t-body);
  border: calc(var(--line) * 1.4) solid color-mix(in srgb, var(--ink) 25%, transparent);
}
.gw-step { font-family: 'GW Mono', monospace; font-size: var(--t-big); line-height: 1; }
.gw-toggle.is-on { color: var(--paper); background: var(--gold); border-color: var(--gold); }
.gw-sheet-foot { display: flex; justify-content: flex-end; gap: var(--s-gap); }
.gw-btn { padding: 0 calc(var(--s-gap) * 1.2); color: var(--paper); background: var(--gold); border-color: var(--gold); }
.gw-btn-quiet { color: var(--ink); background: transparent; border-color: color-mix(in srgb, var(--ink) 25%, transparent); }
.gw-toast {
  position: absolute; left: 50%; bottom: calc(var(--s-pad) * 1.4); transform: translateX(-50%); z-index: 6;
  padding: 0.45em 1em; border-radius: var(--round); font-size: var(--t-small); white-space: nowrap;
  color: var(--paper); background: var(--gold);
}

/* Small slots: a lit item replaces the list, so the alert is the whole widget */
@media (max-height: 499px) {
  .gw-root[data-lit]:not([data-lit='0']):not([data-page='movers']) .gw-board { display: none !important; }
  .gw-root[data-lit]:not([data-lit='0']) .gw-lead { flex: 1 1 0; }
  .gw-sheet { gap: calc(var(--s-gap) * 0.6); padding: calc(var(--s-pad) * 0.7) var(--s-pad); }
  .gw-sheet-what { font-size: var(--t-small); }
}
/* the narrow small slot has no board: Movers is on the bigger sizes */
@media (max-height: 499px) and (max-aspect-ratio: 2/1) {
  .gw-sheet-line { grid-template-columns: minmax(0, 1fr) auto auto auto auto; }
  .gw-sheet-at { min-width: 4.6em; }
}
/* vertical slots: the sheet's label goes above its buttons */
@media (max-aspect-ratio: 1/1) {
  .gw-sheet-line { grid-template-columns: auto minmax(0, 1fr) auto auto; }
  .gw-sheet-what { grid-column: 1 / -1; }
}
.gw-chip-short { display: none; }
@container (max-width: 820px) {
  .gw-chip-full { display: none; }
  .gw-chip-short { display: inline; }
}
@container (max-width: 820px) {
  .gw-row.is-lit .c-name { flex-direction: column; align-items: flex-start; justify-content: center; gap: 0.15em; }
  .gw-row.is-lit .gw-chip { font-size: calc(var(--t-small) * 0.85); padding: 0.05em 0.45em; }
  .gw-row.is-lit .gw-nm { max-width: 100%; }
}
@container (max-width: 820px) {
  .gw-rows .gw-row.is-lit { min-height: calc(var(--t-body) * 2.75); flex-shrink: 0; }
}
.gw-sheet { align-items: center; }
.gw-sheet > * { width: min(100%, calc(var(--unit) * 150)); }
@media (max-height: 499px) { .gw-sheet-what { font-size: var(--t-body); } }
