:root {
  /* The site's shared palette (/_assets/theme.css) in both themes, plus the charts' own colours */
  --font-ui: var(--at-font);
  --font-mono: var(--at-mono);

  --bg: var(--at-bg);
  --surface: var(--at-surface);
  --surface-2: var(--at-surface-2);
  --border: var(--at-border);
  --text-1: var(--at-text);
  --text-2: var(--at-text-2);
  --text-3: var(--at-text-3);
  --accent: var(--at-accent);
  --accent-text: var(--at-accent-ink);
  --up: var(--at-up);
  --down: var(--at-down);
  --warn: var(--at-warn);
  --x: var(--at-up);
  --o: var(--at-down);
  --vwap: #c9a400;
  --vwap-text: #15181d;
  --vwma: #4b4f57; /* light black */
  --vwma-text: #ffffff;

  --plot-bg: var(--at-surface);
  --plot-strip: #f7f8fa;
  --plot-grid: rgba(20, 30, 50, 0.05);
  --plot-grid-major: rgba(20, 30, 50, 0.12);
  --plot-separator: rgba(20, 30, 50, 0.35);
  --plot-hover: var(--at-accent-soft);
  --plot-last-col: var(--at-accent-softer);
}

:root[data-theme="dark"] {
  --vwap: #ffdd00;
  --vwap-text: #0d1014;
  --vwma: #aab0ba; /* a near-black line would vanish on the dark background */
  --vwma-text: #0d1014;

  --plot-strip: #1a1c33;
  --plot-grid: rgba(255, 255, 255, 0.035);
  --plot-grid-major: rgba(255, 255, 255, 0.09);
  --plot-separator: rgba(255, 255, 255, 0.28);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text-1);
  font: 13px/1.4 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, select { font: inherit; color: inherit; }

/* ---------------- Top bar ---------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px 16px;
  flex-wrap: wrap; /* height, colour, border and padding: the site's bar (site-nav.css) */
}

/* The page's name is in the site's bar (site-nav.css); the heading stays for screen readers. */
.brand {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Index menu: names the charts on screen, so it reads like a title */
.index-select {
  height: 30px;
  padding: 0 4px 0 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 650;
  letter-spacing: 0.02em;
  outline: none;
  cursor: pointer;
}

.index-select:hover { border-color: var(--text-3); }
.index-select:focus-visible { border-color: var(--accent); }
.index-select option { color: var(--text-1); font-weight: 500; }

/* Locked controls (e.g. the charts' index, expiry, ATM and days while the algo trades them). */
.index-select:disabled, .field:has(:disabled), .chip:disabled, .view-select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.field:has(:disabled) :disabled { cursor: not-allowed; }
.index-select:disabled:hover, .chip:disabled:hover, .view-select:disabled:hover { border-color: var(--border); }

/* Segmented switch (the simulator's speeds) */
.segmented {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-2);
}

.segmented button {
  height: 26px;
  padding: 0 12px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
}

.segmented button:hover { color: var(--text-1); }

.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
}

/* Spot and near-month future, stacked so they share one slot in the top bar */
.stats {
  display: grid;
  grid-template-columns: auto auto auto;
  align-items: baseline;
  gap: 1px 8px;
}

.stat {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: subgrid;
  align-items: baseline;
}
.stats .label { font-size: 10px; }
.stats .value { font-size: 13px; text-align: right; }
.stats .chg { font-size: 11.5px; }

.label {
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.value {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.chg {
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.up { color: var(--up); }
.down { color: var(--down); }

.controls { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.field {
  display: flex;
  align-items: center;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  overflow: hidden;
}

.field span {
  padding: 0 8px;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-right: 1px solid var(--border);
  line-height: 28px;
}

.field input, .field select {
  height: 28px;
  border: 0;
  background: transparent;
  padding: 0 8px;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  outline: none;
}

.field input { width: 84px; }
.field select { padding-right: 4px; }
.field:focus-within { border-color: var(--accent); }

.btn, .chip, .icon-btn {
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover, .chip:hover, .icon-btn:hover { border-color: var(--text-3); }
.btn:disabled { opacity: 0.55; cursor: default; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.chip { color: var(--text-2); font-size: 12px; }

.chip[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.zoom { display: flex; }
.icon-btn { width: 30px; padding: 0; font-size: 15px; border-radius: 0; margin-left: -1px; }
.icon-btn:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.icon-btn:last-child { border-radius: 0 6px 6px 0; }
.icon-btn.fit { width: auto; padding: 0 9px; font-size: 12px; }
.icon-btn.fit[aria-pressed="true"] { color: var(--accent); }

/* View menu: overlays, box size and days behind one button */
.view-menu { position: relative; }

.view-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 9px 0 10px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
}

.view-btn:hover, .view-btn[aria-expanded="true"] { color: var(--text-1); }
.view-btn[aria-expanded="true"] { border-color: var(--accent); }
.view-btn .caret { color: var(--text-3); transition: transform 0.15s; }
.view-btn[aria-expanded="true"] .caret { transform: rotate(180deg); }

.view-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: max-content; /* as wide as the longest overlay name, on one line */
  min-width: 210px;
  padding: 10px 12px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.32);
}

.view-panel[hidden] { display: none; }
.view-panel.align-end { left: auto; right: 0; }

.view-overlays {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.view-check {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 28px;
  padding: 0 4px;
  margin: 0 -4px;
  border-radius: 5px;
  font-size: 12.5px;
  font-weight: 550;
  cursor: pointer;
}

.view-check:hover { background: var(--surface-2); }
.view-check input { width: 15px; height: 15px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.view-check span { flex: 1; white-space: nowrap; }

/* A sample of the line each overlay draws */
.swatch { width: 18px; height: 3px; border-radius: 2px; }
.swatch.vwap { background: var(--vwap); }
.swatch.vwma { background: var(--vwma); }
.view-check input:not(:checked) ~ .swatch { opacity: 0.35; }

.view-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.view-label {
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.view-select {
  height: 30px;
  min-width: 64px;
  padding: 0 4px 0 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  outline: none;
  cursor: pointer;
}

.view-select:hover { border-color: var(--text-3); }
.view-select:focus-visible { border-color: var(--accent); }

.alert-tools .icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
}

.icon-btn.sound[aria-pressed="true"] { color: var(--accent); }
.icon-btn.sound .mute-slash { display: none; }
.icon-btn.sound[aria-pressed="false"] .mute-slash { display: inline; }
.icon-btn.log[aria-expanded="true"] { color: var(--accent); }

/* Unseen-alert count on the log button */
.badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--down);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

.feed { display: flex; align-items: center; gap: 8px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 10px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 550;
  white-space: nowrap;
}

.pill i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-3);
}

.pill.live { color: var(--up); }
.pill.live i { background: var(--up); box-shadow: 0 0 0 3px color-mix(in srgb, var(--up) 25%, transparent); }
.pill.pending { color: var(--warn); }
.pill.pending i { background: var(--warn); }

/* ---------------- Banner ---------------- */

.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  border-bottom: 1px solid var(--border);
  color: var(--text-1);
}

.banner.error { background: color-mix(in srgb, var(--down) 12%, var(--surface)); }
.banner.warn { background: color-mix(in srgb, var(--warn) 14%, var(--surface)); }
.banner .btn { height: 26px; }

/* ---------------- Charts ---------------- */

.charts {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 10px;
}

.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.panel.atm { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 12px 4px;
}

.ph-title { display: flex; align-items: baseline; gap: 8px; }

.ph-offset {
  font-size: 13px;
  font-weight: 650;
}

.panel.atm .ph-offset { color: var(--accent); }

.ph-strike {
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: 12px;
}

.ph-legs {
  margin-top: 2px;
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ph-vwap { color: var(--vwap); }
.ph-vwma { color: var(--vwma); }

/* Keep "+12.30 (+1.25%) vs open" on one line; the CE/PE/VWAP/VWMA line gives way with an ellipsis. */
.panel-head .ph-main { flex: 1; min-width: 0; }
.panel-head .ph-chg { white-space: nowrap; }

.ph-quote { text-align: right; }

/* Expand / restore, at the right of the price */
.ph-expand {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  margin: -1px -6px 0 -6px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
}

.ph-expand:hover { background: var(--surface-2); color: var(--text-1); }
.ph-expand[aria-pressed="true"] { color: var(--accent); }

/* Every panel has a grid cell of its own, so an expanded chart spans the row over the
   other two without moving them: they keep their size and keep drawing behind it. */
.charts > .panel:nth-child(1) { grid-area: 1 / 1; }
.charts > .panel:nth-child(2) { grid-area: 1 / 2; }
.charts > .panel:nth-child(3) { grid-area: 1 / 3; }
.charts > .panel.expanded { grid-area: 1 / 1 / 2 / -1; z-index: 5; }

.ph-price {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.ph-chg {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

.ph-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 29px;
  padding: 0 12px 8px;
  color: var(--text-3);
  font-size: 11.5px;
  border-bottom: 1px solid var(--border);
}

.ph-meta-text {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ph-signal {
  flex: none;
  padding: 1px 7px;
  border-radius: 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.ph-signal.buy { color: var(--x); background: color-mix(in srgb, var(--x) 14%, transparent); }
.ph-signal.sell { color: var(--o); background: color-mix(in srgb, var(--o) 14%, transparent); }

/* A fresh signal pulses the panel border for a few seconds. */
@keyframes flash-buy {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  50% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--x) 70%, transparent); }
}

@keyframes flash-sell {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  50% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--o) 70%, transparent); }
}

.panel.flash-buy { border-color: var(--x); animation: flash-buy 1s ease-in-out 8; }
.panel.flash-sell { border-color: var(--o); animation: flash-sell 1s ease-in-out 8; }

.plot {
  position: relative;
  flex: 1;
  min-height: 0;
}

.plot canvas {
  position: absolute;
  inset: 0;
  display: block;
}

.scroller {
  position: absolute;
  inset: 0;
  overflow: auto;
  cursor: crosshair;
}

.spacer { width: 1px; height: 1px; }

.plot-msg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  color: var(--text-2);
  background: color-mix(in srgb, var(--plot-bg) 82%, transparent);
  pointer-events: none;
}

.plot-msg.error { color: var(--down); }

/* ---------------- Tooltip ---------------- */

.tooltip {
  position: fixed;
  z-index: 10;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  white-space: nowrap;
}

.tooltip .tip-signal { margin-bottom: 3px; font-family: var(--font-ui); font-weight: 650; }
.tooltip .tip-signal.buy { color: var(--x); }
.tooltip .tip-signal.sell { color: var(--o); }
.tooltip .tip-vwap { margin-top: 2px; color: var(--vwap); }
.tooltip .tip-vwma { margin-top: 2px; color: var(--vwma); }
.tooltip b.x { color: var(--x); }
.tooltip b.o { color: var(--o); }
.tooltip .muted { color: var(--text-3); }

/* ---------------- Alerts ---------------- */

/* Bottom-left: over the oldest history, never the latest columns or the panel headers. */
.toasts {
  position: fixed;
  bottom: 22px;
  left: 22px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 10px 10px 12px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
  pointer-events: auto;
  animation: toast-in 0.18s ease-out;
  position: relative;
  overflow: hidden;
}

/* Time left before the toast closes itself; paused while hovered. */
.toast-timer {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  width: 100%;
  background: currentColor;
  opacity: 0.35;
  transform-origin: left;
  animation: toast-countdown linear forwards;
}

.toast.buy .toast-timer { color: var(--x); }
.toast.sell .toast-timer { color: var(--o); }
.toast.paused .toast-timer { animation-play-state: paused; }

@keyframes toast-countdown {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

.toast.buy { border-left-color: var(--x); }
.toast.sell { border-left-color: var(--o); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.toast-icon { font-size: 15px; line-height: 20px; }
.toast.buy .toast-icon { color: var(--x); }
.toast.sell .toast-icon { color: var(--o); }

.toast-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.toast-body b { font-size: 13px; font-weight: 650; }
.toast-detail { color: var(--text-2); font-family: var(--font-mono); font-size: 12px; }
.toast-hint { color: var(--warn); font-size: 11.5px; }

.toast-close {
  flex: none;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-3);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.toast-close:hover { background: var(--surface-2); color: var(--text-1); }

/* ---------------- Alert log ---------------- */

.alert-log {
  position: fixed;
  top: 60px;
  right: 16px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  width: min(480px, calc(100vw - 32px));
  max-height: min(70vh, 640px);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.32);
}

.alert-log-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 12px 12px 10px 16px;
  border-bottom: 1px solid var(--border);
}

.alert-log-head h2 { margin: 0; font-size: 14px; font-weight: 650; }
.alert-log-sub { flex: 1; color: var(--text-3); font-size: 12px; }

.alert-log-list {
  margin: 0;
  padding: 4px 0;
  overflow-y: auto;
  list-style: none;
}

.alert-log-list li {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 2px 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
}

.alert-log-list li:last-child { border-bottom: 0; }
.alert-log-list li.unseen { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.alert-log-list .icon { grid-row: span 2; font-size: 13px; line-height: 18px; }
.alert-log-list .buy .icon, .alert-log-list .buy b { color: var(--x); }
.alert-log-list .sell .icon, .alert-log-list .sell b { color: var(--o); }
.alert-log-list .error .icon, .alert-log-list .error b { color: var(--warn); }
.alert-log-list .error .icon { font-weight: 800; text-align: center; }
.alert-log-list b { font-size: 13px; font-weight: 650; }
.alert-log-list time { color: var(--text-3); font-family: var(--font-mono); font-size: 11.5px; white-space: nowrap; }
.alert-log-list .detail { grid-column: 2 / 4; color: var(--text-2); font-family: var(--font-mono); font-size: 12px; }

.alert-log-empty { margin: 0; padding: 20px 16px; color: var(--text-3); font-size: 12.5px; }

[hidden] { display: none !important; }

@media (max-width: 1440px) {
  .topbar { column-gap: 14px; }
}

@media (max-width: 1366px) {
  .topbar { column-gap: 12px; }
  .segmented button { padding: 0 9px; }
  .controls { gap: 6px; }
  .expiry-field span { display: none; } /* "13 Oct · weekly" speaks for itself */
}

@media (max-width: 1180px) {
  .stats .chg .abs { display: none; } /* keep just the % change */
}

@media (max-width: 1100px) {
  body { overflow: auto; }
  .charts { grid-template-columns: 1fr; grid-auto-rows: minmax(420px, 70vh); }
  /* Stacked full-width charts: nothing to expand. */
  .charts > .panel:nth-child(n), .charts > .panel.expanded { grid-area: auto; }
  .ph-expand { display: none; }
  .controls { margin-left: 0; }
}

/* Phones: the panel header keeps one line per item (the original was desktop-only). */
@media (max-width: 520px) {
  .topbar { padding: 10px 12px; gap: 10px 12px; }
  .charts { padding: 8px; gap: 8px; }
  .controls { flex-wrap: wrap; } /* the simulator's setup row: Expiry, From, To, ATM, Load */
  .ph-title { white-space: nowrap; }
  .panel-head .ph-chg .abs { display: none; } /* "(-3.56%) vs open" */
  .toasts { left: 12px; bottom: 12px; width: calc(100vw - 24px); }
  .toast:nth-child(n + 3) { display: none; } /* two at a time on a phone; the alert log has them all */
}
