:root {
  color-scheme: light;
  --navy: #0b2447;
  --purple: #47348a;
  --magenta: #c3368b;
  --blue: #05477f;
  --cyan: #68c5de;
  --bg: #ffffff;
  --bg-soft: #f4f5fa;
  --card-border: #e6e8f2;
  --text-muted: #6b7280;
  --up: #16a34a;
  --down: #dc2626;
  --brand-gradient: linear-gradient(90deg, var(--blue), var(--purple), var(--magenta));
}

* {
  box-sizing: border-box;
  min-width: 0;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--navy);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

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

/* All sizes below use clamp(min, preferred, max) with the preferred value
   in vmin (the smaller of viewport width/height) rather than vh alone, so
   text scales with whichever dimension is actually tight — a narrow phone
   in portrait and a short-but-wide browser window both stay legible and
   never overflow their card. */

/* Header */

.board-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1vh 3vw;
  padding: clamp(8px, 1.6vmin, 20px) clamp(12px, 3vmin, 32px);
  border-bottom: 1px solid var(--card-border);
  flex: 0 0 auto;
}

.brand-logo {
  height: clamp(24px, 4.5vmin, 48px);
  width: auto;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 2.5vw;
}

.status {
  display: flex;
  align-items: center;
  gap: 0.6em;
  color: var(--text-muted);
  font-size: clamp(11px, 1.8vmin, 18px);
  white-space: nowrap;
}

.dot {
  width: 0.8em;
  height: 0.8em;
  border-radius: 50%;
  background: var(--down);
  display: inline-block;
  flex: 0 0 auto;
}

.dot.connected {
  background: var(--up);
}

/* Ticker */

.ticker-wrap {
  flex: 0 0 auto;
  overflow: hidden;
  background: var(--brand-gradient);
}

.ticker {
  display: inline-flex;
  white-space: nowrap;
  padding: clamp(6px, 1.2vmin, 14px) 0;
  animation: scroll-ticker 100s linear infinite;
  will-change: transform;
}

@keyframes scroll-ticker {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

.ticker-item {
  display: inline-flex;
  align-items: baseline;
  gap: 0.5em;
  color: #fff;
  font-size: clamp(12px, 2vmin, 20px);
  font-weight: 600;
  padding: 0 clamp(10px, 2.2vw, 32px);
  border-right: 1px solid rgba(255, 255, 255, 0.25);
  white-space: nowrap;
}

.ticker-item .rate {
  font-variant-numeric: tabular-nums;
  color: #c9cee0;
  font-size: 1.1em;
  font-weight: 700;
}

.ticker-item .pair-arrow {
  color: rgba(255, 255, 255, 0.6);
  font-weight: 400;
}

.ticker-item .trend {
  font-size: 0.85em;
}

.ticker-item .trend.up { color: #7bffb0; }
.ticker-item .trend.down { color: #ffb3b3; }
.ticker-item .trend.flat { color: rgba(255, 255, 255, 0.6); }

/* Grid */

.grid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  align-content: start;
  gap: clamp(10px, 2vmin, 24px) clamp(8px, 1.6vw, 20px);
  padding: clamp(10px, 2.2vmin, 28px) clamp(12px, 3vw, 32px);
  background: var(--bg-soft);
  /* If a longer PAIRS list ever needs more rows than fit, scroll rather
     than clip/compress cards into an unreadable mess. */
  overflow-y: auto;
  overflow-x: hidden;
}

/* At/above LARGE_SCREEN_MIN_WIDTH (board.js), JS takes over: it computes
   the row/column split that fits every card in one view — no scrollbar,
   since a TV can't scroll — and sets --cell-h plus an explicit row/column
   template here. Below that width we keep the auto-fill + scroll behavior
   above, since a phone can't shrink text indefinitely and stay legible. */
.grid.grid-fit {
  overflow: hidden;
  align-content: stretch;
}

.grid.grid-fit .card {
  min-height: 0;
}

.grid.grid-fit .pair-codes {
  font-size: clamp(9px, calc(var(--cell-h, 120px) * 0.15), 30px);
}

.grid.grid-fit .pair-names {
  font-size: clamp(8px, calc(var(--cell-h, 120px) * 0.1), 18px);
}

.grid.grid-fit .rate {
  font-size: clamp(11px, calc(var(--cell-h, 120px) * 0.3), 56px);
}

.grid.grid-fit .trend {
  font-size: clamp(8px, calc(var(--cell-h, 120px) * 0.14), 22px);
}

.card {
  background: var(--bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: clamp(10px, 1.8vmin, 22px) clamp(10px, 1.6vw, 20px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.5em;
  box-shadow: 0 4px 14px rgba(11, 36, 71, 0.06);
  position: relative;
  overflow: hidden;
  /* The pair name/code lines use overflow:hidden for text-ellipsis, which
     lets the browser treat their automatic min-height as 0 and collapse
     the whole grid row to just the rate line. An explicit min-height keeps
     the row tall enough for all three lines regardless of column width. */
  min-height: clamp(96px, 22vmin, 160px);
}

.card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--brand-gradient);
}

.pair-codes {
  font-size: clamp(13px, 2.2vmin, 22px);
  color: var(--navy);
  letter-spacing: 0.02em;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pair-codes .pair-arrow {
  color: var(--text-muted);
  font-weight: 400;
  margin: 0 0.25em;
}

.pair-names {
  font-size: clamp(10px, 1.5vmin, 15px);
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rate-row {
  display: flex;
  align-items: baseline;
  gap: 0.4em;
  min-width: 0;
}

.rate {
  font-size: clamp(16px, 3.6vmin, 38px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--navy);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.trend {
  font-size: clamp(11px, 1.8vmin, 18px);
  font-weight: 700;
  flex: 0 0 auto;
}

.trend.up { color: var(--up); }
.trend.down { color: var(--down); }
.trend.flat { color: var(--text-muted); }

/* Keeps the arrow's space reserved so the row doesn't reflow when a rate
   is unchanged and reappears once it actually moves. */
.trend-hidden {
  visibility: hidden;
}

.empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
  font-size: clamp(16px, 3vmin, 28px);
  padding-top: 10vh;
}

/* Footer */

.board-footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2vh 3vw;
  padding: clamp(8px, 1.4vmin, 18px) clamp(12px, 3vw, 32px);
  background: var(--navy);
  color: #e7ebf5;
  font-size: clamp(10px, 1.6vmin, 16px);
  flex-wrap: wrap;
  text-align: center;
}

.footer-item {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  color: #e7ebf5;
  text-decoration: none;
}

.footer-icon {
  width: 1.1em;
  height: 1.1em;
  fill: var(--cyan);
  flex: 0 0 auto;
}
