:root {
  --bg: #07090c;
  --bg-2: #0a0e14;
  --panel: #0d1219;
  --panel-hover: #111821;
  --line: #1c2733;
  --line-hi: #2a3644;
  --text: #d6dde6;
  --muted: #6b7a8c;
  --cyan: #5eead4;
  --cyan-dim: rgba(94, 234, 212, 0.18);
  --magenta: #e879f9;
  --magenta-dim: rgba(232, 121, 249, 0.16);
  --up: #34d399;
  --dn: #f87171;
  --led: #c8f5e8;
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --bar-h: 52px;
  --foot-h: 36px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.4;
  overflow: hidden;
}
a { color: var(--cyan); text-decoration: none; }
a:hover { text-decoration: underline; }
button, select, input { font: inherit; color: inherit; }

#bg-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

.shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  max-height: 100dvh;
  min-height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px 18px;
  flex-wrap: wrap;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 9, 12, 0.82);
  backdrop-filter: blur(8px);
  min-height: var(--bar-h);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  flex-shrink: 0;
}
.brand img { display: block; border: 1px solid var(--line); border-radius: 3px; }
.brand-text { display: flex; flex-direction: column; gap: 1px; }
.brand-text strong {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--led);
}
.brand-text .sub {
  font-size: 0.68rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.controls {
  display: flex;
  align-items: center;
  gap: 10px 14px;
  flex-wrap: wrap;
  margin-left: auto;
}
.ctrl {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.ctrl .lbl {
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.ctrl select {
  background: var(--panel);
  border: 1px solid var(--line-hi);
  border-radius: 2px;
  padding: 5px 8px;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--cyan);
  outline: none;
  cursor: pointer;
}
.ctrl select:focus { border-color: var(--cyan); box-shadow: 0 0 0 1px var(--cyan-dim); }

.btn-row { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.btn {
  background: var(--panel);
  border: 1px solid var(--line-hi);
  border-radius: 2px;
  padding: 5px 10px;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.btn:hover { border-color: var(--cyan); color: var(--cyan); background: var(--panel-hover); }
.btn.ghost { color: var(--muted); }
.btn.ghost:hover { color: var(--magenta); border-color: var(--magenta); }
.btn.flash { border-color: var(--cyan); color: var(--cyan); }

.grid-wrap {
  min-height: 0;
  overflow: hidden;
  padding: 0;
}
.grid {
  display: grid;
  width: 100%;
  height: 100%;
  gap: 0;
  background: var(--line);
  border: none;
}
.grid[data-cols="1"] { grid-template-columns: 1fr; }
.grid[data-cols="2"] { grid-template-columns: repeat(2, 1fr); }
.grid[data-cols="3"] { grid-template-columns: repeat(3, 1fr); }
.grid[data-cols="4"] { grid-template-columns: repeat(4, 1fr); }

.cell {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
  min-width: 0;
  background: var(--panel);
  border: 0.5px solid var(--line);
  position: relative;
}
.cell.empty { background: var(--bg-2); }
.cell-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 8px 4px;
  border-bottom: 1px solid var(--line);
  background: rgba(10, 14, 20, 0.9);
  min-height: 34px;
}
.sym-input {
  width: 7.5ch;
  min-width: 5.5ch;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 2px;
  padding: 2px 4px;
  font-family: var(--mono);
  font-weight: 600;
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--led);
  outline: none;
}
.sym-input:hover, .sym-input:focus {
  border-color: var(--line-hi);
  background: rgba(94, 234, 212, 0.06);
}
.sym-input:focus { border-color: var(--cyan); }
.meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-left: auto;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}
.price {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--led);
  letter-spacing: 0.02em;
  text-shadow: 0 0 12px rgba(94, 234, 212, 0.25);
}
.chg {
  font-size: 0.72rem;
  font-weight: 500;
}
.chg.up { color: var(--up); }
.chg.dn { color: var(--dn); }
.chg.flat { color: var(--muted); }
.status {
  font-family: var(--mono);
  font-size: 0.62rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}
.status.warn { color: var(--magenta); }

.chart-host {
  position: relative;
  min-height: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.chart-host .tv-lightweight-charts { width: 100% !important; height: 100% !important; }
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px;
  text-align: center;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  pointer-events: none;
}
.empty-state strong {
  color: var(--magenta);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.foot {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 4px 12px;
  border-top: 1px solid var(--line);
  background: rgba(7, 9, 12, 0.9);
  min-height: var(--foot-h);
  font-size: 0.7rem;
}
.note {
  flex: 1;
  min-width: 180px;
  color: var(--muted);
}
.note summary {
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  list-style: none;
}
.note summary::-webkit-details-marker { display: none; }
.note summary::before {
  content: "▸ ";
  color: var(--cyan);
}
.note[open] summary::before { content: "▾ "; }
.note-body {
  margin-top: 6px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  max-width: 62ch;
  color: var(--muted);
}
.note-body p { margin: 0 0 6px; }
.note-body p:last-child { margin-bottom: 0; }
.err-log {
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--dn);
  white-space: pre-wrap;
  word-break: break-word;
}
.foot-right {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-left: auto;
  flex-wrap: wrap;
}
.legend {
  font-family: var(--mono);
  font-size: 0.62rem;
  color: var(--muted);
  letter-spacing: 0.03em;
}
.legend i {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 1px;
  margin: 0 3px 0 2px;
  vertical-align: middle;
}
.legend i.up { background: var(--up); box-shadow: 0 0 6px var(--up); }
.legend i.dn { background: var(--dn); box-shadow: 0 0 6px var(--dn); }
.co {
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.co:hover { color: var(--cyan); text-decoration: none; }

@media (max-width: 720px) {
  body { overflow: auto; }
  .shell { height: auto; min-height: 100dvh; max-height: none; }
  .grid-wrap { min-height: 70dvh; }
  .grid[data-cols="3"],
  .grid[data-cols="4"] { grid-template-columns: repeat(2, 1fr); }
  .grid[data-cols="2"] { grid-template-columns: 1fr; }
  .cell { min-height: 180px; }
  .brand-text .sub { display: none; }
  .controls { margin-left: 0; width: 100%; }
}

.refresh-stamp {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  color: #6b7a8c;
  align-self: center;
  white-space: nowrap;
  min-width: 7.5rem;
}
