:root {
  --bg: #0f1115;
  --bar: #171a21;
  --line: #262b36;
  --text: #e6e9ef;
  --muted: #9aa3b2;
  --tile-gap: 2px;
}

* { box-sizing: border-box; }

html { height: 100%; }
body {
  margin: 0;
  height: 100dvh; /* dynamic viewport height: fits mobile Safari's changing toolbars */
  background: var(--bg);
  color: var(--text);
  font: 13px/1.3 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  flex: 0 0 auto;
  padding: 0 12px;
  background: var(--bar);
  border-bottom: 1px solid var(--line);
}
#bar .left, #bar .right { display: flex; align-items: center; gap: 10px; }

#theme {
  background: #0f1218;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
}

.agg { font-weight: 600; font-variant-numeric: tabular-nums; }
.agg.up { color: #4ade80; }
.agg.down { color: #f87171; }

.legend { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.legend .bar {
  width: 120px; height: 10px; border-radius: 5px;
  border: 1px solid var(--line);
  background: linear-gradient(to right, rgb(220,38,38), rgb(58,63,75), rgb(22,163,74));
}
@media (max-width: 900px) { .legend { display: none; } }

.status { color: var(--muted); font-size: 12px; }
.status .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.status .dot.open { background: #22c55e; }
.status .dot.closed { background: #6b7280; }
.updated { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }

button {
  background: #0f1218;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 9px;
  cursor: pointer;
  font-size: 12px;
}
button:hover { border-color: #3a424f; }

#stage { position: relative; flex: 1 1 auto; min-height: 0; }
#grid { position: absolute; inset: 0; }

.sector-region {
  position: absolute;
  border: 1px solid #2b3242;
  border-radius: 6px;
  pointer-events: none;
}
.sector-label {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(18, 21, 28, 0.72);
  border-radius: 6px 6px 0 0;
  overflow: hidden;
  white-space: nowrap;
  pointer-events: none;
}
.sector-label .s-name { overflow: hidden; text-overflow: ellipsis; }
.sector-label .s-pct { flex: 0 0 auto; font-variant-numeric: tabular-nums; text-transform: none; letter-spacing: 0; }
.sector-label .s-pct.up { color: #4ade80; }
.sector-label .s-pct.down { color: #f87171; }

.tile {
  position: absolute;
  overflow: hidden;
  border-radius: 3px;
  outline: var(--tile-gap) solid var(--bg);
  outline-offset: calc(var(--tile-gap) * -1);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.45);
  cursor: pointer;
  user-select: none;
  transition: filter 0.08s ease;
}
.tile:hover { filter: brightness(1.12); }
.tile.stale { opacity: 0.55; }
.tile .sym { font-weight: 700; letter-spacing: 0.3px; line-height: 1.1; }
.tile .chg { font-variant-numeric: tabular-nums; opacity: 0.95; line-height: 1.25; }
.tile .price { font-variant-numeric: tabular-nums; opacity: 0.75; line-height: 1.25; }

#refresh.spinning { animation: spin 0.7s linear infinite; }
#refresh:disabled { opacity: 0.6; cursor: default; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .tile { transition: none; }
  #refresh.spinning { animation: none; }
}

.tooltip {
  position: fixed;
  z-index: 10;
  pointer-events: none;
  background: #0b0d11;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 12px;
  white-space: pre;
  box-shadow: 0 6px 18px rgba(0,0,0,0.5);
  font-variant-numeric: tabular-nums;
}

.message {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  padding: 24px;
}
.message .box { max-width: 480px; }
.message a, .message .link { color: #7dd3fc; cursor: pointer; text-decoration: underline; }

.hidden { display: none !important; }
