:root {
  --bg: #0e1117;
  --panel: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --green: #00e676;
  --red: #ff5252;
  --blue: #58a6ff;
  --amber: #ffb300;
  --orange: #ff9100;
  --purple: #d500f9;
  --cyan: #00e5ff;
  --shield: #ffd600;
}

* { box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
html, body { max-width: 100%; overflow-x: hidden; }
body { margin: 0; background: var(--bg); color: var(--text); padding: 18px; }
.container { max-width: 1260px; margin: 0 auto; width: 100%; }

/* Top Nav & Share Bar */
.nav-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.nav-bar a { color: var(--muted); text-decoration: none; font-size: 0.85rem; }
.nav-bar a:hover { color: var(--green); }
.share-actions { display: flex; align-items: center; gap: 8px; }
.share-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(0, 229, 255, 0.1);
  border: 1px solid rgba(0, 229, 255, 0.4);
  color: var(--cyan);
  font-size: 0.8rem; font-weight: 700;
  padding: 6px 12px; border-radius: 7px; cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease, transform 0.1s ease;
}
.nav-bar a.kofi-btn {
  display: inline-flex; align-items: center; gap: 5px;
  background: rgba(255, 179, 0, 0.1);
  border: 1px solid rgba(255, 179, 0, 0.4);
  color: var(--amber);
  font-size: 0.8rem; font-weight: 700; white-space: nowrap;
  padding: 6px 12px; border-radius: 7px; text-decoration: none;
  transition: background 0.14s ease, border-color 0.14s ease;
}
.nav-bar a.kofi-btn:hover { background: rgba(255, 179, 0, 0.18); border-color: var(--amber); color: var(--amber); }
.share-btn:hover { background: rgba(0, 229, 255, 0.18); border-color: var(--cyan); }
.share-btn:active { transform: scale(0.98); }
.share-btn.copied {
  background: rgba(0, 230, 118, 0.16);
  border-color: var(--green);
  color: var(--green);
}
.reset-link-btn {
  background: var(--panel); border: 1px solid var(--border); color: var(--muted);
  font-size: 0.78rem; padding: 6px 10px; border-radius: 7px; cursor: pointer;
}
.reset-link-btn:hover { border-color: var(--amber); color: var(--amber); }

h1 { font-size: 1.7rem; line-height: 1.2; margin: 0 0 10px; overflow-wrap: break-word; }  /* 10px above (nav gap) and 10px below: title centred between the nav and the content */
.subtitle { color: var(--muted); font-size: 0.9rem; margin-bottom: 12px; }
#status { font-size: 0.84rem; color: var(--green); margin-bottom: 14px; }
/* Loading/loaded messages stay hidden to reduce clutter; errors (red) are still shown */
#status { display: none; }
#status[style*="255, 82, 82"] { display: block; }

/* Active Signal Banner */
.signal-banner { position: relative; --sig: var(--green); display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; background: var(--panel); background: color-mix(in srgb, var(--sig) 9%, var(--panel)); border: 1px solid var(--border); border-color: color-mix(in srgb, var(--sig) 30%, var(--border)); border-left: 4px solid var(--sig); border-radius: 10px; padding: 9px 14px; margin-bottom: 14px; max-width: 100%; }
.signal-banner.bear, .signal-banner.short { --sig: var(--red); }
.signal-banner.bounce { --sig: var(--blue); }
.signal-banner.alert { --sig: var(--orange); }
.signal-banner.hedged { --sig: var(--shield); }
.signal-main { min-width: 0; flex: 1 1 280px; }
.signal-main .tag { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; }
.signal-main .holding { font-size: 1.05rem; font-weight: 800; margin: 1px 0 2px; color: var(--sig); overflow-wrap: break-word; }
.signal-main .reason { font-size: 0.78rem; color: var(--text); line-height: 1.35; }
.signal-pills { display: flex; flex-wrap: wrap; gap: 10px; max-width: 100%; }
.pill { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; min-width: 105px; flex: 1 1 auto; }
.pill .p-label { font-size: 0.72rem; color: var(--muted); }
.pill .p-val { font-size: 0.98rem; font-weight: 700; margin-top: 2px; }

/* Live Intraday EOD Preview Strip */
.intraday-preview {
  display: none;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 15px;
  margin: -10px 0 16px;
  font-size: 0.83rem;
}
.intraday-preview.is-change {
  display: flex;
  background: rgba(255, 179, 0, 0.08);
  border-color: rgba(255, 179, 0, 0.55);
  border-left: 5px solid var(--amber);
}
.intraday-preview.is-steady {
  display: flex;
  border-left: 5px solid var(--blue);
}
.intraday-preview.to-bull { --c: var(--green); } .intraday-preview.to-bear { --c: var(--red); } .intraday-preview.to-bounce { --c: var(--blue); } .intraday-preview.to-crisis { --c: var(--shield); }
.intraday-preview.is-change[class*="to-"] { background: color-mix(in srgb, var(--c) 9%, var(--panel)); border-color: color-mix(in srgb, var(--c) 55%, var(--border)); border-left-color: var(--c); }
.intraday-preview.is-change[class*="to-"] .ip-badge { background: color-mix(in srgb, var(--c) 18%, transparent); color: var(--c); border-color: color-mix(in srgb, var(--c) 45%, transparent); }
.intraday-preview.is-change[class*="to-"] .ip-main { color: var(--c); }
.ip-left { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; min-width: 0; flex: 1 1 320px; }
.ip-badge {
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.intraday-preview.is-change .ip-badge { background: rgba(255, 179, 0, 0.18); color: var(--amber); border: 1px solid rgba(255, 179, 0, 0.45); }
.intraday-preview.is-steady .ip-badge { background: rgba(88, 166, 255, 0.14); color: var(--blue); border: 1px solid rgba(88, 166, 255, 0.35); }
.ip-main { font-weight: 700; color: var(--text); }
.intraday-preview.is-change .ip-main { color: var(--amber); }
.ip-sub { color: var(--muted); font-size: 0.8rem; }

.signal-main .tag { display: flex; align-items: center; gap: 6px; }
.sig-info { width: 18px; height: 18px; padding: 0; border-radius: 50%; border: 1px solid var(--border); background: var(--bg); color: var(--muted); font: italic 700 0.7rem Georgia, serif; line-height: 1; cursor: pointer; flex: 0 0 auto; }
.sig-fill { text-transform: none; letter-spacing: 0; font-weight: 600; color: var(--muted); }
.sig-fill:empty { display: none; }
.sig-info[aria-expanded="true"] { color: var(--sig); border-color: var(--sig); }
.sig-alloc { font-size: 0.82rem; font-weight: 600; color: var(--text); }
.sig-alloc:empty { display: none; }
.sig-pop { position: absolute; z-index: 20; left: 8px; top: calc(100% - 4px); width: max-content; max-width: min(320px, calc(100vw - 32px)); background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; box-shadow: 0 6px 20px rgba(0,0,0,.35); }
.sig-pop[hidden] { display: none; }
.sig-pop { font-size: 0.85rem; line-height: 1.4; color: var(--text); text-align: left; }
.sig-pop .sig-pop-main { margin: 0; color: var(--text); font-size: inherit; white-space: pre-line; }
.sig-pop-head { font-size: 0.7rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 3px; }
.sig-pop-live { margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--border); }
.sig-pop-live[hidden] { display: none; }
.sig-pop-row { margin-top: 5px; }
.sig-pop-note { margin-top: 7px; font-size: 0.78rem; color: var(--muted); }

/* Signal card with the live line as a footer (banner opts in with data-side):
   date label, one line "symbol state · allocation", divider, one line "LIVE  status". Even padding top and bottom. */
.signal-banner[data-side] { display: block; padding: 10px 14px; }
.signal-banner[data-side] .holding { display: inline; font-size: 0.95rem; margin: 0; }
.signal-banner[data-side] .sig-alloc { display: inline; font-size: 0.95rem; font-weight: 700; }
.signal-banner[data-side] .sig-alloc::before { content: " · "; color: var(--muted); }
.signal-banner[data-side] .sig-alloc:empty { display: none; }
.signal-banner[data-side] .tag { margin-bottom: 3px; }
.signal-banner[data-side] .signal-pills { margin-top: 9px; }
.intraday-preview.is-change:not([class*="to-"]) { --c: var(--amber); }
.signal-banner[data-side] > .intraday-preview.intraday-preview { margin: 9px 0 0; padding: 9px 0 0; background: none; border: 0; border-top: 1px solid color-mix(in srgb, var(--sig) 30%, var(--border)); border-radius: 0; }
.signal-banner[data-side] .ip-left { flex: 1 1 auto; gap: 8px; flex-wrap: nowrap; align-items: baseline; }
.signal-banner[data-side] .ip-badge { background: none !important; border: 0 !important; padding: 0; font-size: 0.95rem; font-weight: 800; letter-spacing: 0.04em; color: var(--text) !important; }
.signal-banner[data-side] .ip-main { font-size: 0.95rem; font-weight: 700; color: var(--c, var(--blue)) !important; }

/* Layout Grid */
.grid { display: grid; grid-template-columns: 345px minmax(0, 1fr); gap: 18px; }
.grid > * { min-width: 0; }
/* Quick zoom eras: one bar above the chart on every screen size */
.mobile-zoom-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.mobile-zoom-bar .zoom-label { min-width: 78px; color: var(--muted); font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; white-space: nowrap; flex: 0 0 auto; }
.mobile-zoom-bar .preset-row { margin-bottom: 0; min-width: 0; }
@media (max-width: 880px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .main-panel { order: 1; }
  .sidebar-panel { order: 2; }
  .desktop-zoom-section { display: none; }
  .mobile-zoom-bar { margin-bottom: 12px; }
  .mobile-zoom-bar .preset-row { margin-bottom: 0; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .mobile-zoom-bar .preset-btn { white-space: nowrap; flex: 0 0 auto; }
}
/* Quick picks (ticker / goal / fill price) above the chart, styled like the zoom bar */
.pick-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
#pickBars { margin-bottom: 2px; }
.pick-row .preset-btn { padding: 7px 13px; font-size: 0.82rem; font-weight: 700; }
.pick-label { color: var(--muted); font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; white-space: nowrap; flex: 0 0 auto; min-width: 78px; }
.pick-row { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.pick-row .preset-btn { white-space: nowrap; }
@media (max-width: 880px) {
  .pick-row { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .pick-row .preset-btn { flex: 0 0 auto; }
}
.pick-row, .mobile-zoom-bar .preset-row { scrollbar-width: none; }
.pick-row::-webkit-scrollbar, .mobile-zoom-bar .preset-row::-webkit-scrollbar { display: none; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 16px; max-width: 100%; overflow: hidden; }
.section-title { font-size: 0.73rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--amber); font-weight: 700; margin: 16px 0 10px; border-top: 1px solid var(--border); padding-top: 12px; }
.section-title:first-child, .sidebar-panel > .section-title:nth-child(1 of .section-title) { margin-top: 0; border-top: none; padding-top: 0; }
.control { margin-bottom: 15px; }
.control label { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; font-size: 0.84rem; margin-bottom: 5px; color: var(--muted); }
.control label span { color: var(--text); font-weight: 600; }
.hint { font-size: 0.76rem; color: var(--muted); margin-top: 4px; line-height: 1.4; }
input[type="range"], input[type="number"], select { width: 100%; max-width: 100%; accent-color: var(--green); }
input[type="number"], select { background: var(--bg); border: 1px solid var(--border); color: var(--text); padding: 8px; border-radius: 6px; font-size: 0.85rem; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 0.83rem; margin-top: 10px; cursor: pointer; }
.preset-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.preset-btn { background: var(--bg); border: 1px solid var(--border); color: var(--text); font-size: 0.76rem; padding: 5px 9px; border-radius: 6px; cursor: pointer; }
.preset-btn:hover { border-color: var(--cyan); color: var(--cyan); }
.preset-btn.active { background: rgba(0, 229, 255, 0.16); border-color: var(--cyan); color: var(--cyan); font-weight: 700; }
.trade-rate { margin-left: 8px; font-size: 0.8rem; font-weight: 400; color: var(--muted); white-space: nowrap; }

/* Unified Summary Comparison Table */
.summary-table-card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; margin-top: 16px; margin-bottom: 0; overflow: hidden; }
table.summary-table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
table.summary-table th { background: rgba(14, 17, 23, 0.75); text-align: right; color: var(--muted); font-weight: 700; font-size: 0.71rem; text-transform: uppercase; letter-spacing: 0.04em; padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.summary-table th:first-child { text-align: left; }
table.summary-table td { padding: 9px 12px; border-bottom: 1px solid rgba(48, 54, 61, 0.45); text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
table.summary-table td:first-child { text-align: left; font-weight: 700; }
table.summary-table tbody tr:last-child td { border-bottom: none; }
table.summary-table tr.row-full td:first-child { color: var(--green); }
table.summary-table tr.row-zoom td:first-child { color: var(--cyan); }
table.summary-table tr.row-pres td:first-child { color: var(--amber); }
.bh-sub { display: block; font-size: 0.72rem; font-weight: 500; color: var(--muted); margin-top: 2px; }
.chart-toolbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px 16px; margin-bottom: 10px; flex-wrap: wrap; }
.chart-toolbar-left { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.chart-toggle-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chart-rebase-toggle { display: inline-flex; align-items: center; gap: 7px; font-size: 0.78rem; color: var(--cyan); font-weight: 600; cursor: pointer; background: rgba(0, 229, 255, 0.08); border: 1px solid rgba(0, 229, 255, 0.3); padding: 5px 10px; border-radius: 6px; white-space: nowrap; }
.chart-rebase-toggle input { margin: 0; accent-color: var(--cyan); cursor: pointer; }
.chart-win-stats { min-width: 480px; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); }
.chart-win-stats:empty { display: none; }
table.cw-table { width: 100%; border-collapse: collapse; font-size: 0.76rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.cw-table th { padding: 3px 10px; font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); text-align: right; border-bottom: 1px solid var(--border); background: rgba(14, 17, 23, 0.75); }
table.cw-table th:first-child { text-align: left; }
table.cw-table td { padding: 3px 10px; text-align: right; font-weight: 700; line-height: 1.25; }
table.cw-table td:first-child { text-align: left; }
.section-title[hidden] { display: none !important; }
.winner-banner.below-chart { margin: 18px 0 0 !important; }
.setup-card #optSummary, .setup-card #vaultPresetHint { margin-bottom: 0 !important; }
.setup-card #vaultPresetHint { margin-bottom: 10px !important; color: var(--text); }
table.cw-table td.cw-fill { text-align: left; font-weight: 500; font-size: 0.7rem; color: var(--muted); white-space: normal; padding-top: 4px; border-top: 1px solid rgba(48, 54, 61, 0.45); }
table.cw-table tr.cw-row-strat td { border-bottom: 1px solid rgba(48, 54, 61, 0.45); }
table.cw-table tr.cw-row-strat td:first-child { color: var(--muted); }
table.cw-table tr.cw-row-bh td { font-weight: 700; }
table.cw-table tr.cw-row-bh td:first-child { color: var(--muted); }
#chart { width: 100%; height: 460px; }
#chart .rangeslider-handle-min,
#chart .rangeslider-handle-max { fill: #00e5ff !important; stroke: #00e5ff !important; stroke-width: 3px !important; }
#chart .rangeslider-mask-min,
#chart .rangeslider-mask-max { fill: rgba(0, 0, 0, 0.58) !important; }
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px 12px;
  position: absolute;
  left: 14px;
  right: 14px;
  top: 0;
  margin: 0;
  padding: 0;
  z-index: 2;
}
.chart-legend:empty { display: none; }
.cl-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: transparent;
  border: none;
  padding: 2px 3px;
  margin: 0;
  color: var(--text);
  font-family: inherit;
  font-size: 0.76rem;
  line-height: 1.25;
  cursor: pointer;
  transition: opacity 0.15s ease;
}
.cl-item:hover { opacity: 0.8; }
.cl-item.is-hidden { opacity: 0.35; text-decoration: line-through; }
.cl-swatch { flex: 0 0 auto; display: block; }
.chart-date-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
  padding-top: 8px;
}
.cdb-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}
.cdb-lbl {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.cdb-field input[type="date"] {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 0.79rem;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  color-scheme: dark;
  min-width: 0;
}
.cdb-field input[type="date"]:focus {
  outline: none;
  border-color: var(--cyan);
}
.cdb-sep { color: var(--muted); font-size: 0.85rem; }
.cdb-reset {
  background: var(--bg);
  border: 1px solid rgba(0, 229, 255, 0.45);
  color: var(--cyan);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}
.cdb-reset:hover:not(:disabled) {
  background: rgba(0, 229, 255, 0.12);
  border-color: var(--cyan);
}
.cdb-reset:disabled {
  opacity: 0.38;
  border-color: var(--border);
  color: var(--muted);
  cursor: default;
}

/* Era Stress-Test Table */
.era-card { margin-top: 18px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 18px; max-width: 100%; }
.era-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.era-header h3 { margin: 0; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--amber); }
.era-header span { font-size: 0.78rem; color: var(--muted); }
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.era-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
table.era-table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.04em; padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.era-table th.num, table.era-table td.num { text-align: right; }
table.era-table td { padding: 10px 12px; border-bottom: 1px solid rgba(48, 54, 61, 0.55); white-space: nowrap; }
table.era-table tbody tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.dd-good { color: var(--cyan); }
.dd-warn { color: var(--amber); }
.dd-bad  { color: var(--red); }

/* Trade Log */
.log-card { margin-top: 22px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 18px; max-width: 100%; }
.main-panel .log-card { margin-top: 18px; }
.log-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.log-header h3 { margin: 0; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--amber); }
.log-filters { display: flex; flex-wrap: wrap; gap: 6px; }
.filter-btn { background: var(--bg); border: 1px solid var(--border); color: var(--muted); font-size: 0.75rem; padding: 4px 10px; border-radius: 6px; cursor: pointer; }
.filter-btn.active { background: rgba(0, 229, 255, 0.16); border-color: var(--cyan); color: var(--cyan); font-weight: 700; }
.log-scroll { max-height: 340px; overflow: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: 8px; }
table.log-table { width: 100%; border-collapse: collapse; font-size: 0.83rem; }
table.log-table th { position: sticky; top: 0; background: #0e1117; text-align: left; color: var(--muted); font-weight: 600; font-size: 0.73rem; text-transform: uppercase; letter-spacing: 0.04em; padding: 9px 12px; border-bottom: 1px solid var(--border); z-index: 1; white-space: nowrap; }
table.log-table td { padding: 8px 12px; border-bottom: 1px solid rgba(48, 54, 61, 0.45); white-space: nowrap; }
.pill-tag { display: inline-block; padding: 2px 7px; border-radius: 4px; font-size: 0.74rem; font-weight: 700; }
.tag-bull { background: rgba(0, 230, 118, 0.14); color: var(--green); }
.tag-bounce { background: rgba(88, 166, 255, 0.14); color: var(--blue); }
.tag-bear, .tag-short { background: rgba(255, 82, 82, 0.14); color: var(--red); }
.tag-tmf { background: rgba(255, 214, 0, 0.14); color: var(--shield); }
.tag-vol { background: rgba(255, 145, 0, 0.14); color: var(--orange); }
.tag-amber { background: rgba(255, 179, 0, 0.14); color: var(--amber); }
.tag-win  { background: rgba(0, 230, 118, 0.16); color: var(--green); }
.tag-roll { background: rgba(0, 229, 255, 0.14); color: var(--cyan); }
.tag-cap  { background: rgba(255, 179, 0, 0.16); color: var(--amber); }

/* Showdown Leaderboard & MA Toggle Chips */
.ma-toggle-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin-top: 6px; }
.ma-chip {
  display: flex; align-items: center; gap: 7px;
  background: var(--bg); border: 1px solid var(--border);
  padding: 6px 9px; border-radius: 6px; font-size: 0.8rem; font-weight: 600;
  cursor: pointer; user-select: none;
}
.ma-chip input { margin: 0; width: auto; accent-color: var(--cyan); }
.swatch { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }

.board-card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 14px; overflow: hidden; }
.board-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--border); background: rgba(14, 17, 23, 0.55); }
.board-header h3 { margin: 0; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--amber); }
.board-header span { font-size: 0.76rem; color: var(--muted); }
table.board-table { width: 100%; border-collapse: collapse; font-size: 0.83rem; }
table.board-table th { background: rgba(14, 17, 23, 0.85); text-align: right; color: var(--muted); font-weight: 700; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; padding: 9px 11px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.board-table th:first-child, table.board-table th:nth-child(2) { text-align: left; }
table.board-table td { padding: 9px 11px; border-bottom: 1px solid rgba(48, 54, 61, 0.45); text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
table.board-table td:first-child, table.board-table td:nth-child(2) { text-align: left; }
table.board-table tbody tr { cursor: pointer; transition: background 0.12s ease; }
table.board-table tbody tr:hover { background: rgba(88, 166, 255, 0.08); }
table.board-table tbody tr.is-focused { background: rgba(0, 229, 255, 0.09); }
table.board-table tbody tr:last-child td { border-bottom: none; }

.rank-badge { display: inline-block; min-width: 20px; text-align: center; padding: 1px 5px; border-radius: 4px; font-size: 0.72rem; font-weight: 800; background: var(--bg); border: 1px solid var(--border); color: var(--muted); }
.rank-1 { border-color: var(--green); color: var(--green); background: rgba(0, 230, 118, 0.12); }
.sig-pill { display: inline-block; padding: 2px 7px; border-radius: 4px; font-size: 0.72rem; font-weight: 700; }
.sig-bull { background: rgba(0, 230, 118, 0.15); color: var(--green); }
.sig-bounce { background: rgba(88, 166, 255, 0.15); color: var(--blue); }
.sig-short { background: rgba(255, 82, 82, 0.15); color: var(--red); }
.sig-tmf { background: rgba(255, 214, 0, 0.15); color: var(--shield); }
.sig-cash { background: rgba(139, 148, 158, 0.18); color: var(--muted); }

/* Sidebar Fixed-Rule Cards (matches Trade Log & Signal Banner palette) */
.rule-list { list-style: none; margin: 4px 0 8px; padding: 0; display: grid; gap: 7px; }
.rule-item {
  --rule-col: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--rule-col);
  border-radius: 7px;
  padding: 7px 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}
.rule-item.rule-bull { --rule-col: var(--green); }
.rule-item.rule-bounce { --rule-col: var(--blue); }
.rule-item.rule-bear { --rule-col: var(--red); }
.rule-item.rule-shield { --rule-col: var(--shield); }
.rule-item.rule-vault { --rule-col: var(--amber); }
.rule-item.rule-neutral { --rule-col: var(--muted); }
.rule-badge {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1.2;
}
.rule-desc { color: var(--text); font-size: 0.78rem; line-height: 1.38; }
.rule-note { font-size: 0.73rem; color: var(--muted); line-height: 1.4; padding-top: 2px; }

.ma-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
@media (max-width: 780px) { .ma-grid { grid-template-columns: minmax(0, 1fr); } }
.ma-doc-card { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 13px 15px; }
.ma-doc-card strong { display: block; font-size: 0.92rem; margin-bottom: 4px; }
.ma-doc-card p { margin: 0; font-size: 0.84rem; color: var(--muted); }

/* Methodology Explainer */
.explainer {
  margin-top: 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px;
  line-height: 1.65;
  max-width: 100%;
}
.explainer h2 { font-size: 1.32rem; margin: 0 0 12px; border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.explainer h3 { font-size: 1.05rem; margin: 24px 0 8px; color: var(--amber); }
.explainer p, .explainer li { color: #c9d1d9; font-size: 0.94rem; overflow-wrap: break-word; }
.explainer code { background: var(--bg); border: 1px solid var(--border); padding: 2px 6px; border-radius: 4px; font-size: 0.86rem; color: var(--cyan); word-break: break-word; }
.explainer ul, .explainer ol { padding-left: 20px; }
.explainer li { margin-bottom: 8px; }
.regime-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin: 16px 0 20px;
}
.two-col-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 14px 0 20px;
}
@media (max-width: 820px) {
  .regime-grid, .two-col-grid { grid-template-columns: minmax(0, 1fr); }
}
.regime-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 15px;
}
.regime-box.bull { border-top: 3px solid var(--green); }
.regime-box.bounce { border-top: 3px solid var(--blue); }
.regime-box.bear { border-top: 3px solid var(--red); }
.regime-box.tmf { border-top: 3px solid var(--cyan); }
.regime-box.fin { border-top: 3px solid var(--amber); }
.regime-box .r-title { font-weight: 700; font-size: 0.93rem; margin-bottom: 6px; }
.regime-box.bull .r-title { color: var(--green); }
.regime-box.bounce .r-title { color: var(--blue); }
.regime-box.bear .r-title { color: var(--red); }
.regime-box.tmf .r-title { color: var(--cyan); }
.regime-box.fin .r-title { color: var(--amber); }
.regime-box p { font-size: 0.85rem; margin: 0; color: var(--muted); }
.formula-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--cyan);
  border-radius: 8px;
  padding: 12px 15px;
  margin: 12px 0;
  font-size: 0.88rem;
  color: var(--text);
}
.disclaimer { margin-top: 24px; padding-top: 14px; border-top: 1px solid var(--border); font-size: 0.8rem; color: var(--muted); }

/* Mobile Specific Tweaks */
@media (max-width: 600px) {
  body { padding: 12px; }
  h1 { font-size: 1.4rem; }
  .signal-banner { padding: 8px 12px; }
  .signal-main .holding { font-size: 0.98rem; }
  .era-card, .log-card { padding: 12px; }
  .card { padding: 10px 9px; }
  .explainer { padding: 18px 14px; }
  table.summary-table th, table.summary-table td { padding: 7px 8px; font-size: 0.76rem; }
  table.board-table th, table.board-table td { padding: 7px 8px; font-size: 0.75rem; }
  .chart-toggle-group { width: 100%; flex-wrap: nowrap; gap: 6px; }
  .chart-rebase-toggle { flex: 1 1 auto; justify-content: center; font-size: 0.70rem; padding: 5px 6px; gap: 5px; min-width: 0; }
  .chart-toolbar-left { width: 100%; }
  .chart-win-stats { width: 100%; min-width: 0; }
  table.cw-table { width: 100%; font-size: 0.70rem; }
  table.cw-table th, table.cw-table td { padding: 3px 5px; }
  #chart { height: 375px; }
  .chart-legend { gap: 3px 9px; left: 10px; right: 10px; }
  .cl-item { font-size: 0.69rem; gap: 4px; padding: 1px 2px; }
  .chart-date-bar { flex-wrap: nowrap; gap: 5px; margin-top: 6px; padding-top: 8px; }
  .cdb-field { flex: 1 1 0; flex-direction: column; align-items: stretch; gap: 2px; min-width: 0; }
  .cdb-lbl { font-size: 0.63rem; padding-left: 2px; }
  .cdb-field input[type="date"] { width: 100%; padding: 6px 5px; font-size: 0.76rem; }
  .cdb-sep { display: none; }
  .cdb-reset { align-self: flex-end; padding: 7px 9px; font-size: 0.72rem; flex: 0 0 auto; }
}
@media (max-width: 360px) {
  .chart-rebase-toggle { font-size: 0.65rem; padding: 4px 5px; gap: 4px; }
  table.cw-table { font-size: 0.65rem; }
  table.cw-table th, table.cw-table td { padding: 3px 4px; }
  .cl-item { font-size: 0.65rem; gap: 3px; }
  .cdb-field input[type="date"] { font-size: 0.70rem; padding: 5px 4px; }
  .cdb-reset { padding: 6px 7px; font-size: 0.68rem; }
}

/* Auto-Tune controls (shared by every page that has an optimizer) */
.opt-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; margin-bottom: 6px; }
.opt-btn {
  flex: 1; background: rgba(0, 229, 255, 0.12); color: var(--cyan);
  border: 1px solid rgba(0, 229, 255, 0.45); border-radius: 7px;
  padding: 6px 10px; font-size: 0.76rem; font-weight: 700; cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease;
}
.opt-btn:hover { background: rgba(0, 229, 255, 0.22); border-color: var(--cyan); }
.opt-btn:disabled { opacity: 0.5; cursor: wait; }

/* Loading dots: blink in sequence */
.ld-dots i { font-style: normal; animation: ldBlink 1.2s infinite both; }
.ld-dots i:nth-child(2) { animation-delay: 0.2s; }
.ld-dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes ldBlink { 0%, 70%, 100% { opacity: 0.15; } 25% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .ld-dots i { animation: none; opacity: 1; } }
.trade-cap { font-size: 0.76rem; color: var(--muted); margin: 2px 0 10px; }

/* Segmented button rows (short dropdowns shown as buttons) */
.seg { display: flex; gap: 5px; }
.seg-btn { flex: 1 1 0; min-width: 0; height: 34px; padding: 0 6px; white-space: nowrap; background: var(--bg); border: 1px solid var(--border); color: var(--text); font-size: 0.78rem; border-radius: 6px; cursor: pointer; transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease; }
.seg-btn[hidden] { display: none; }
.seg-btn:hover { border-color: var(--cyan); color: var(--cyan); }
.seg-btn.active { background: rgba(0, 229, 255, 0.16); border-color: var(--cyan); color: var(--cyan); font-weight: 700; }

/* chip rows are self-explanatory: no grey captions */
.pick-label, .mobile-zoom-bar .zoom-label, .sd-modebar .lbl { display: none; }

/* Loading state: keep the chip rows out of the layout until the chart card is built, and show a spinner in it */
html:not(.chart-ready) #pickBars, html:not(.chart-ready) .sd-modebar, html:not(.chart-ready) .mobile-zoom-bar { display: none; }
#chart:empty { position: relative; }
#chart:empty::before { content: ""; position: absolute; left: 50%; top: 40%; width: 34px; height: 34px; margin: -17px 0 0 -17px; border: 3px solid rgba(0, 229, 255, 0.2); border-top-color: var(--cyan); border-radius: 50%; animation: chartspin 0.8s linear infinite; }
#chart:empty::after { content: "Calculating\2026"; position: absolute; left: 0; right: 0; top: calc(40% + 28px); text-align: center; color: var(--muted); font-size: 0.8rem; }
@keyframes chartspin { to { transform: rotate(360deg); } }

/* Setup box: the gray detail line folds into a "Details" toggle (shared/backtest.js foldSetupNotes) */
details.wb-more { margin-top: 8px; }
details.wb-more > summary { cursor: pointer; color: var(--muted); font-size: 0.76rem; width: max-content; user-select: none; }
details.wb-more > summary:hover { color: var(--cyan); }
details.wb-more > .wb-note { margin-top: 6px !important; }

/* Busy overlay on the chart card while a long calculation runs (add class "calculating" to <html>) */
html.calculating .card:has(> #chart) { position: relative; }
/* Spinner sits near the top of the card, not its middle: the card is ~900px tall, so its middle can fall below the screen */
html.calculating .card:has(> #chart)::before { content: "Calculating\2026"; position: absolute; inset: 0; z-index: 20; display: flex; align-items: flex-start; justify-content: center; padding-top: 236px; box-sizing: border-box; background: rgba(13, 17, 23, 0.74); color: var(--muted); font-size: 0.85rem; border-radius: inherit; }
html.calculating .card:has(> #chart)::after { content: ""; position: absolute; z-index: 21; left: 50%; top: 180px; width: 36px; height: 36px; margin: 0 0 0 -18px; border: 3px solid rgba(0, 229, 255, 0.2); border-top-color: var(--cyan); border-radius: 50%; animation: chartspin 0.8s linear infinite; }

/* One loading indicator at a time, and a neutral signal banner until the first chart is drawn */
html.calculating #chart:empty::before, html.calculating #chart:empty::after { display: none; }
html:not(.chart-ready) .signal-banner { background: var(--panel); border-color: var(--border); border-left-color: var(--border); }
html:not(.chart-ready) .signal-banner .holding { color: var(--muted); }

/* Boxes above the chart look "loading" too while a recalculation runs (same neutral look as the first load) */
html.calculating .signal-banner, html.calculating .winner-banner, html.calculating .ts-answer,
html:not(.chart-ready) .signal-banner { background: var(--panel); border-color: var(--border); border-left-color: var(--border); animation: calcpulse 1.1s ease-in-out infinite; }
html.calculating .signal-banner .holding, html.calculating .winner-banner .wb-ticker { color: var(--muted); }
@keyframes calcpulse { 50% { opacity: 0.55; } }

/* Reset-all icon in the top-right corner of the chart card */
.card.has-chart-reset { position: relative; }
.card.has-chart-reset > :first-child { margin-right: 42px; }
/* Only the first row sits beside the reset button; the rows below use the full width */
.card.has-chart-reset > #pickBars { margin-right: 0; }
.card.has-chart-reset > #pickBars > :first-child { margin-right: 42px; }
@media (max-width: 600px) { .chart-reset-all { top: 10px !important; right: 9px !important; } }
.chart-reset-all { position: absolute; top: 16px; right: 16px; width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; padding: 0; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--muted); cursor: pointer; z-index: 5; }
/* no hover / press colors; a click spins the arrow once instead */
.chart-reset-all, .chart-reset-all:hover, .chart-reset-all:active, .chart-reset-all:focus { color: var(--muted); border-color: var(--border); background: var(--bg); outline: none; -webkit-tap-highlight-color: transparent; }
.chart-reset-all:focus-visible { outline: 2px solid var(--border); outline-offset: 2px; }
.chart-reset-all svg { transform-origin: 50% 50%; }
.chart-reset-all svg.spin { animation: chartResetSpin 0.6s cubic-bezier(0.3, 0.7, 0.3, 1); }
/* TradingView chart link under the chart, with its affiliate disclosure */
.tv-link-row { display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 0 0 12px; text-align: center; }
.tv-link-row[hidden] { display: none; }
.tv-link-row.tv-over { position: absolute; left: 14px; right: 14px; margin: 0; }
.tv-link-row a { display: inline-block; color: var(--cyan); text-decoration: none; font-weight: 700; font-size: 0.95rem; padding: 9px 18px; border: 1px solid var(--cyan); border-radius: 999px; background: rgba(34, 211, 238, 0.08); transition: background .15s, transform .15s; }
.tv-link-row a:hover { background: rgba(34, 211, 238, 0.18); text-decoration: none; transform: translateY(-1px); }
.tv-link-row .tv-aff { color: var(--muted); font-size: 0.72rem; }
/* Per-section "Reset" at the right end of a sidebar section title (no hover/press colors, same as the chart icon) */
.section-title.has-section-reset { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.section-reset { display: inline-flex; align-items: center; gap: 4px; margin: -4px -6px -4px 0; padding: 4px 6px; min-height: 28px; border: 0; background: none; color: var(--muted); font: inherit; font-size: 0.78rem; font-weight: 500; cursor: pointer; border-radius: 6px; -webkit-tap-highlight-color: transparent; }
.section-reset:hover, .section-reset:active, .section-reset:focus { color: var(--muted); background: none; outline: none; }
.section-reset:focus-visible { outline: 2px solid var(--border); }
.section-reset svg { transform-origin: 50% 50%; }
.section-reset svg.spin { animation: chartResetSpin 0.6s cubic-bezier(0.3, 0.7, 0.3, 1); }
@media (prefers-reduced-motion: reduce) { .section-reset svg.spin { animation-duration: 0.01s; } }
@keyframes chartResetSpin { from { transform: rotate(0deg); } to { transform: rotate(-360deg); } }
@media (prefers-reduced-motion: reduce) { .chart-reset-all svg.spin { animation-duration: 0.01s; } }

/* One size for every chart selector button on every page: pair / goal / mode bars, NDX 3x / TQQQ switch,
   era presets, the two chart toggles and the date-bar reset. Same height everywhere (32px). */
.pick-row .preset-btn, .sd-modebar .preset-btn, .mobile-zoom-bar .preset-btn, .preset-row .preset-btn, #tsPeriod .preset-btn,
.chart-rebase-toggle, .cdb-reset { box-sizing: border-box; min-height: 32px; font-size: 0.82rem; font-weight: 700; line-height: 1.2; padding: 7px 13px; border-radius: 6px; }
.chart-rebase-toggle { display: inline-flex; align-items: center; }
@media (max-width: 600px) {
  .pick-row .preset-btn, .sd-modebar .preset-btn, .mobile-zoom-bar .preset-btn, .preset-row .preset-btn, #tsPeriod .preset-btn,
  .chart-rebase-toggle, .cdb-reset { font-size: 0.76rem; padding: 7px 10px; }
  .chart-rebase-toggle { padding: 7px 6px; }
}
@media (max-width: 360px) {
  .pick-row .preset-btn, .sd-modebar .preset-btn, .mobile-zoom-bar .preset-btn, .preset-row .preset-btn, #tsPeriod .preset-btn,
  .chart-rebase-toggle, .cdb-reset { font-size: 0.7rem; padding: 7px 7px; }
  .chart-rebase-toggle { padding: 7px 5px; }
}

/* Phones: keep the menu on one line, with Share Setup as an icon button in the top-right corner */
@media (max-width: 600px) {
  .nav-bar { flex-wrap: nowrap; }
  .nav-left { min-width: 0; }
  .nav-left .nav-all { display: none; }
  .share-btn { white-space: nowrap; flex-shrink: 0; }
}

/* Era buttons that only make sense on the 1985+ data (pages with an NDX 3x / TQQQ data switch) */
body[data-mode="real"] .era-syn { display: none; }

/* "How people trade this" T-bill note under the chart */
.tbill-note { margin-top: 18px; font-size: 0.9rem; color: var(--muted); }
.tbill-note summary { cursor: pointer; color: var(--cyan); font-weight: 600; }
.tbill-note p { margin: 8px 0; line-height: 1.5; }
.tbill-note ul { margin: 6px 0 6px 18px; padding: 0; line-height: 1.5; }
.tbill-note li { margin: 3px 0; }

/* "Invest at Zoomed Date" / "Show to Present Day": plain checkbox text, not buttons */
.chart-toggle-group .chart-rebase-toggle { background: none; border: none; color: var(--text); font-weight: 600; padding: 7px 10px 7px 2px; justify-content: flex-start; }
.chart-toggle-group .chart-rebase-toggle input { width: 16px; height: 16px; }
