:root {
  --bg: #05080d;
  --bg-2: #0a1018;
  --panel: #0d1622;
  --grid: #14212f;
  --up: #16d67a;
  --up-glow: rgba(22, 214, 122, 0.55);
  --down: #ff3b52;
  --down-glow: rgba(255, 59, 82, 0.55);
  --flat: #7f8ea3;
  --text: #e8f1ff;
  --dim: #6b7d95;
  --gold: #ffcf4d;
  --font: 'VT323', "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: radial-gradient(circle at 50% -10%, var(--bg-2), var(--bg) 60%);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  letter-spacing: 0.03em;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.4vh 2.2vw;
  background: linear-gradient(180deg, #0c1826, #070d15);
  border-bottom: 2px solid var(--grid);
}
.brand { display: flex; align-items: center; gap: 0.8vw; flex: 1 1 0; min-width: 0; }
.logo { color: var(--up); font-size: 3vh; }
.brand-name { font-size: 2.8vh; font-weight: 700; letter-spacing: 0.12em; }
.market-state {
  display: flex; align-items: center; justify-content: flex-end; gap: 1vw;
  flex: 1 1 0; min-width: 0;
  font-size: 1.8vh; color: var(--dim); letter-spacing: 0.15em;
}
.market-state .dot {
  width: 1.1vh; height: 1.1vh; border-radius: 50%;
  background: var(--up); box-shadow: 0 0 10px var(--up-glow);
  animation: pulse 2s infinite;
}
.clock { color: var(--gold); font-variant-numeric: tabular-nums; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }

/* ---------- screen title (centered in the top header) ---------- */
.screen-title {
  flex: 0 1 auto;
  text-align: center;
  font-size: 5vh;
  font-weight: 700;
  letter-spacing: 0.25em;
  color: var(--gold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- board ---------- */
.board {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0 2.2vw 1vh;
  min-height: 0;
}
.board-head, .row {
  display: grid;
  grid-template-columns: 7% 38% 24% 9% 22%;
  align-items: center;
}
.board-head {
  color: var(--dim);
  font-size: 1.8vh;
  letter-spacing: 0.2em;
  padding: 1vh 1.4vw;
  border-bottom: 1px solid var(--grid);
}
.col-chg, .col-price { text-align: right; }

.rows { flex: 1; overflow: hidden; display: flex; flex-direction: column; }

.row {
  padding: 0 1.4vw;
  height: 0; flex: 1 1 0;
  min-height: 6vh;
  border-bottom: 1px solid rgba(20, 33, 47, 0.6);
  font-size: 4vh;
  transition: background-color 0.6s ease;
}
.row:nth-child(odd) { background: rgba(13, 22, 34, 0.4); }

.sym {
  font-size: 2.8vh; color: var(--dim); letter-spacing: 0.12em;
  border: 1px solid var(--grid); border-radius: 4px;
  padding: 0.3vh 0.6vw; display: inline-block;
}
.col-name { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
/* .name font-size is set per-row by the auto-fit script; this is the fallback. */
.name { font-weight: 600; letter-spacing: 0.02em; line-height: 1; font-size: 4vh;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.name .live-badge {
  font-size: 1.6vh; color: var(--gold); margin-left: 0.6vw;
  letter-spacing: 0.15em; vertical-align: middle; opacity: 0.8;
}
.info {
  font-size: 1.9vh; color: var(--dim); letter-spacing: 0.03em; opacity: 0.85; line-height: 1.15;
  margin-top: 0.4vh; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* 15-minute sparkline */
.col-graph {
  padding: 0.4vh 1.2vw;
  align-self: stretch;               /* fill the full row height */
  display: flex;
  align-items: center;
}
.col-graph .spark { display: block; width: 100%; height: 80%; overflow: visible; }
.col-graph .spark line {
  stroke-width: 2.5;
  stroke-linecap: butt;
  vector-effect: non-scaling-stroke;
}
.col-graph .spark line.up   { stroke: var(--up);   filter: drop-shadow(0 0 3px var(--up-glow)); }
.col-graph .spark line.down { stroke: var(--down); filter: drop-shadow(0 0 3px var(--down-glow)); }
.col-graph .spark line.flat { stroke: var(--flat); }
.col-graph .spark line.base {
  stroke: var(--dim);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  opacity: 0.45;
}

/* ---------- STOCK CRASHED overlay ---------- */
.row.crashed { background: rgba(255, 59, 82, 0.07); }
.row.crashed .col-chg { display: none; }                 /* change column hidden */
.row.crashed .col-graph {
  grid-column: 3 / 5;                                     /* span graph + change */
  justify-content: center;
}
.crash-label {
  width: 100%;
  text-align: center;
  color: var(--down);
  font-weight: 700;
  font-size: 4.4vh;
  letter-spacing: 0.18em;
  animation: crashblink 1.1s steps(1) infinite;
}
@keyframes crashblink { 50% { opacity: 0.3; } }
body.is-crashed .board-head .col-graph,
body.is-crashed .board-head .col-chg { visibility: hidden; }

/* ---------- screen 4: fit all items on one display ---------- */
body.fit-all .row { min-height: 0; }              /* let rows shrink to share height */
body.fit-all .board { padding-bottom: 0.4vh; }

.chg { text-align: right; font-size: 4.5vh; font-variant-numeric: tabular-nums; white-space: nowrap; }
.price {
  text-align: right; font-weight: 700; font-variant-numeric: tabular-nums;
  font-size: 10vh;
}
.cur { font-size: 4vh; color: var(--dim); margin-right: 0.4vw; }

/* movement colouring */
.up   { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--flat); }
.arrow { display: inline-block; margin-right: 0.3vw; }

/* flash animation when a price changes */
@keyframes flashUp   { 0%{background:rgba(22,214,122,.28)} 100%{background:transparent} }
@keyframes flashDown { 0%{background:rgba(255,59,82,.28)}  100%{background:transparent} }
.row.tick-up   { animation: flashUp 0.9s ease-out; }
.row.tick-down { animation: flashDown 0.9s ease-out; }

.loading { padding: 4vh; text-align: center; color: var(--dim); letter-spacing: 0.3em; }

/* ---------- ticker tape ---------- */
.ticker-tape {
  height: 6vh;
  background: #000;
  border-top: 2px solid var(--grid);
  display: flex;
  align-items: center;
  overflow: hidden;
  white-space: nowrap;
}
.tape-track {
  display: inline-block;
  padding-left: 100%;
  animation: scroll 40s linear infinite;
  font-size: 2.4vh;
  letter-spacing: 0.08em;
}
.tape-track .t-item { margin: 0 2vw; }
.tape-track .t-sym { color: var(--dim); }
@keyframes scroll { from { transform: translateX(0); } to { transform: translateX(-100%); } }

/* ---------- connection lost ---------- */
.conn-lost {
  position: fixed; bottom: 8vh; left: 50%; transform: translateX(-50%);
  background: var(--down); color: #fff; padding: 1vh 2vw;
  border-radius: 6px; font-size: 1.8vh; letter-spacing: 0.15em;
  display: none;
}
.conn-lost.show { display: block; animation: pulse 1.2s infinite; }
