*, *::before, *::after { box-sizing: border-box; }

.viz-root {
  color-scheme: light;
  --surface-1:      #fcfcfb;
  --page:           #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --grid:           #e1e0d9;
  --axis:           #c3c2b7;
  --border:         rgba(11,11,11,0.10);
  --series-1:       #2a78d6;
  --up:             #006300;
  --down:           #d03b3b;
  --ind-blue:       #2a78d6;
  --ind-orange:     #eb6834;
  --ind-violet:     #4a3aa7;
  --ind-aqua:       #1baf7a;
  --status-good:    #0ca30c;
  --status-warn:    #fab219;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .viz-root {
    color-scheme: dark;
    --surface-1:      #1a1a19;
    --page:           #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --grid:           #2c2c2a;
    --axis:           #383835;
    --border:         rgba(255,255,255,0.10);
    --series-1:       #3987e5;
    --up:             #0ca30c;
    --down:           #e34948;
    --ind-blue:       #3987e5;
    --ind-orange:     #d95926;
    --ind-violet:     #9085e9;
    --ind-aqua:       #199e70;
    --status-good:    #0ca30c;
    --status-warn:    #fab219;
  }
}
:root[data-theme="dark"] .viz-root {
  color-scheme: dark;
  --surface-1:      #1a1a19;
  --page:           #0d0d0d;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --grid:           #2c2c2a;
  --axis:           #383835;
  --border:         rgba(255,255,255,0.10);
  --series-1:       #3987e5;
  --up:             #0ca30c;
  --down:           #e34948;
  --ind-blue:       #3987e5;
  --ind-orange:     #d95926;
  --ind-violet:     #9085e9;
  --ind-aqua:       #199e70;
  --status-good:    #0ca30c;
  --status-warn:    #fab219;
}

html, body { margin: 0; }
body {
  background: var(--page, #f9f9f7);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
/* Body backdrop mirrors the theme resolution above: OS preference unless the
   toggle has stamped an explicit theme on the root. */
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) body { background: #0d0d0d; }
}
:root[data-theme="dark"] body { background: #0d0d0d; }
:root[data-theme="light"] body { background: #f9f9f7; }

.viz-root {
  max-width: 940px;
  margin: 0 auto;
  padding: 40px 20px 56px;
  background: var(--page);
  color: var(--text-primary);
}

/* ---------- header ---------- */
.head {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 28px;
}
h1 { font-size: 22px; font-weight: 600; margin: 0 0 8px; letter-spacing: -0.01em; }
.ticker {
  font-size: 13px; font-weight: 600; color: var(--text-secondary);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 2px 6px; margin-left: 6px; vertical-align: 3px;
}
.sub { margin: 0; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.chip, .ca {
  font-size: 12px; color: var(--text-secondary);
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 10px; text-decoration: none;
}
.ca { font-variant-numeric: tabular-nums; }
.ca:hover { color: var(--text-primary); }
.byline { text-decoration: none; }
.byline:hover { color: var(--text-primary); }

.hero { text-align: right; }
.hero-top { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-bottom: 2px; }
.hero-label { font-size: 12px; color: var(--text-muted); }
.theme-btn {
  width: 24px; height: 24px; padding: 0; cursor: pointer;
  display: grid; place-items: center;
  font-size: 13px; line-height: 1; color: var(--text-secondary);
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 999px;
}
.theme-btn:hover { color: var(--text-primary); border-color: var(--axis); }
/* The glyph rotates to read as sun (light) vs moon (dark). */
.theme-icon { transition: transform 0.25s ease; }
:root[data-theme="dark"] .theme-icon { transform: rotate(180deg); }
.hero-value { font-size: 48px; font-weight: 600; line-height: 1.05; letter-spacing: -0.02em; }
.hero-delta { font-size: 13px; color: var(--text-secondary); margin-top: 4px; min-height: 18px; }
.hero-delta.up { color: var(--up); }
.hero-delta.down { color: var(--down); }

.avatar {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px; border-radius: 999px;
  background: var(--ind-blue); color: #fff;
  font-size: 14px; font-weight: 700; vertical-align: -6px; margin-right: 8px;
  overflow: hidden;
}
/* The lettermark sits underneath and only shows if logo.png fails to load. */
.avatar > * { grid-area: 1 / 1; }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.no-logo img { display: none; }
.avatar:not(.no-logo) .avatar-fallback { visibility: hidden; }

.pair-quote { color: var(--text-muted); font-weight: 500; margin-left: 4px; }

/* ---------- contract address: the whole chip is the copy target ---------- */
.ca-row { margin-top: 8px; }
.ca-chip {
  display: inline-flex; align-items: center; gap: 8px;
  font: inherit; cursor: pointer; text-align: left;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 12px;
  color: var(--text-secondary);
}
.ca-chip code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; letter-spacing: -0.01em;
}
.ca-chip:hover { color: var(--text-primary); border-color: var(--axis); }
.ca-chip:focus-visible { outline: 2px solid var(--ind-blue); outline-offset: 2px; }
.ca-chip.copied { color: var(--up); border-color: var(--up); }
.ca-icon { font-size: 12px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ---------- stat tiles ---------- */
.stats {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px;
  margin-bottom: 12px;
}
.tile-sub { font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.tile-sub .buy { color: var(--up); }
.tile-sub .sell { color: var(--down); }

/* ---------- rolling windows ---------- */
.windows {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
  margin-bottom: 20px;
}
.win {
  display: flex; flex-direction: column; gap: 3px;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px;
}
.win-label { font-size: 11px; font-weight: 600; letter-spacing: 0.06em; color: var(--text-muted); }
.win-change { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.win-change.up { color: var(--up); }
.win-change.down { color: var(--down); }
.win-vol, .win-txns { font-size: 11.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
/* A window longer than the token's life is flagged, not silently wrong. */
.win.partial .win-txns { font-style: italic; }
.tile {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 6px;
}
.tile-label { font-size: 12px; color: var(--text-muted); }
.tile-value { font-size: 18px; font-weight: 600; }

/* ---------- chart card ---------- */
.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px 20px 12px;
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 4px; }
.card-sub { font-size: 12px; color: var(--text-muted); margin: 0; }
.controls { display: flex; gap: 8px; align-items: center; }
.segmented {
  display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
.segmented button {
  font: inherit; font-size: 12px; color: var(--text-secondary);
  background: transparent; border: 0; padding: 6px 12px; cursor: pointer;
}
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button.on { background: var(--page); color: var(--text-primary); font-weight: 600; }

.select {
  font: inherit; font-size: 12px; color: var(--text-secondary);
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 8px; cursor: pointer;
}
.toggle {
  font: inherit; font-size: 12px; color: var(--text-secondary);
  background: transparent; border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; cursor: pointer;
}
.toggle.on { background: var(--page); color: var(--text-primary); font-weight: 600; border-color: var(--axis); }

.toggle.live { display: inline-flex; align-items: center; gap: 6px; }
.toggle.live .dot {
  width: 7px; height: 7px; border-radius: 999px;
  background: var(--text-muted);
}
.toggle.live.on .dot { background: var(--status-good); animation: pulse 2s ease-in-out infinite; }
.toggle.live.stalled .dot { background: var(--status-warn); animation: none; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) { .toggle.live.on .dot { animation: none; } }

.menu { position: relative; }
.menu summary {
  list-style: none; cursor: pointer; user-select: none;
  font-size: 12px; color: var(--text-secondary);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px;
}
.menu summary::-webkit-details-marker { display: none; }
.menu[open] summary { color: var(--text-primary); border-color: var(--axis); }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  min-width: 190px; padding: 8px;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  display: flex; flex-direction: column; gap: 2px;
}
.menu-panel label {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--text-secondary);
  padding: 6px 8px; border-radius: 6px; cursor: pointer;
}
.menu-panel label:hover { background: var(--page); color: var(--text-primary); }
.menu-panel .param { margin-left: auto; color: var(--text-muted); font-size: 11px; }
.menu-panel input { accent-color: var(--ind-blue); }

.refresh {
  font: inherit; font-size: 12px; color: var(--text-secondary);
  background: transparent; border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 12px; cursor: pointer;
}
.refresh:hover { color: var(--text-primary); border-color: var(--axis); }
.refresh[disabled] { opacity: 0.5; cursor: default; }

/* min-height reserves room for the loading/error overlay before the chart exists */
.chart-wrap { display: flex; gap: 8px; margin: 16px 0 0; min-height: 380px; }
.chart-area { position: relative; flex: 1; min-width: 0; }
.chart { width: 100%; height: 380px; }

.toolrail {
  display: flex; flex-direction: column; gap: 4px;
  padding-top: 2px; flex: 0 0 auto;
}
.tool {
  width: 30px; height: 30px; font-size: 13px; line-height: 1;
  color: var(--text-secondary); background: transparent;
  border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
}
.tool:hover { color: var(--text-primary); border-color: var(--axis); }
.tool.on { background: var(--page); color: var(--text-primary); border-color: var(--axis); }

/* Drawing overlay sits above the chart canvases; it only takes pointer events
   while a drawing tool is armed. */
#overlay {
  position: absolute; inset: 0; z-index: 4;
  pointer-events: none;
}
#overlay.armed { pointer-events: auto; cursor: crosshair; }

.legend {
  position: absolute; top: 8px; left: 8px; z-index: 3; pointer-events: none;
  display: flex; gap: 12px; flex-wrap: wrap; align-items: baseline;
  font-size: 11px; font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  background: color-mix(in srgb, var(--surface-1) 82%, transparent);
  border-radius: 6px; padding: 4px 8px;
}
.legend[hidden] { display: none; }
.leg-time { color: var(--text-muted); }
.leg-vol { color: var(--text-muted); }

.state {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 13px; color: var(--text-muted);
  background: var(--surface-1);
}
.state[hidden] { display: none; }
.state.error { color: var(--down); }

/* ---------- table view ---------- */
.table-view { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 10px; }
summary { font-size: 12px; color: var(--text-secondary); cursor: pointer; }
.table-scroll { max-height: 260px; overflow: auto; margin-top: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 12px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--grid); }
th { color: var(--text-muted); font-weight: 500; position: sticky; top: 0; background: var(--surface-1); }
td { color: var(--text-secondary); }

/* ---------- trades feed (inside the chart panel, under the chart) ---------- */
.trades-block { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 16px; }
.trades-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
}
.trades-scroll { max-height: 320px; margin-top: 12px; }
#tradesTable td, #tradesTable th { white-space: nowrap; }
#tradesTable .num { text-align: right; }
#tradesTable .muted { color: var(--text-muted); }
#tradesTable .muted a { color: inherit; text-decoration: none; }
#tradesTable .muted a:hover { color: var(--text-primary); text-decoration: underline; }
#tradesTable a { color: var(--text-secondary); text-decoration: none; }
.side { font-weight: 600; }
.side.buy { color: var(--up); }
.side.sell { color: var(--down); }

.foot { font-size: 12px; color: var(--text-muted); margin-top: 20px; line-height: 1.6; }
.foot a { color: var(--text-secondary); }
code { font-size: 11px; }

@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 720px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .windows { grid-template-columns: repeat(2, 1fr); }
  .controls { flex-wrap: wrap; }
  /* Keep the full address readable rather than truncating what people copy. */
  .ca-chip code { font-size: 10.5px; }
  .head { align-items: flex-start; }
  .hero { text-align: left; }
  .hero-value { font-size: 38px; }
}
