:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --bg-2: #101720;
  --panel: rgba(21, 29, 38, 0.94);
  --panel-2: rgba(28, 39, 50, 0.86);
  --line: rgba(177, 202, 216, 0.16);
  --text: #edf4f8;
  --muted: #9fb0bb;
  --dim: #738391;
  --cyan: #2ee8d6;
  --amber: #f3b34c;
  --green: #7ce38b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 0;
  min-height: 100dvh;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(135deg, rgba(46, 232, 214, 0.05), transparent 28%),
    linear-gradient(180deg, #0b0f14 0%, #101720 58%, #0b0f14 100%);
  color: var(--text);
  letter-spacing: 0;
}

html,
body {
  overflow-x: hidden;
}

button {
  border: 1px solid rgba(46, 232, 214, 0.28);
  border-radius: 8px;
  background: rgba(46, 232, 214, 0.12);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  padding: 10px 14px;
}

[hidden] {
  display: none !important;
}

body.modal-open {
  overflow: hidden;
}

.app-shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 100dvh;
}

.rail {
  position: sticky;
  top: 0;
  height: 100dvh;
  max-width: 100vw;
  padding: 22px 18px;
  border-right: 1px solid var(--line);
  background: rgba(9, 13, 18, 0.88);
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--cyan), var(--amber));
  box-shadow: 0 0 28px rgba(46, 232, 214, 0.22);
}

.brand strong, .brand small { display: block; }
.brand small, .rail-foot span { color: var(--dim); font-size: 12px; }

nav { display: grid; gap: 8px; }
nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 11px 12px;
  border-radius: 8px;
}
nav a.active, nav a:hover {
  color: var(--text);
  background: rgba(237, 244, 248, 0.08);
}

.sponsor-button {
  width: 100%;
  text-align: left;
  border-color: rgba(243, 179, 76, 0.34);
  background:
    linear-gradient(135deg, rgba(243, 179, 76, 0.18), rgba(46, 232, 214, 0.1));
  color: var(--text);
  font-weight: 800;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.sponsor-button:hover {
  border-color: rgba(243, 179, 76, 0.56);
  background:
    linear-gradient(135deg, rgba(243, 179, 76, 0.26), rgba(46, 232, 214, 0.14));
}

.rail-foot {
  margin-top: auto;
  border-top: 1px solid var(--line);
  padding-top: 16px;
  display: grid;
  gap: 6px;
}

main {
  padding: 22px;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 18px;
}

h1, h2, p { margin: 0; }
h1 { font-size: clamp(28px, 4vw, 54px); line-height: 1; max-width: 780px; }
h2 { font-size: 18px; }
p { color: var(--muted); line-height: 1.55; margin-top: 8px; }

.status-stack {
  display: grid;
  gap: 8px;
  justify-items: end;
  color: var(--dim);
  font-size: 13px;
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(46, 232, 214, 0.25);
  background: rgba(46, 232, 214, 0.08);
  border-radius: 999px;
  padding: 9px 12px;
}

.live-pill i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 18px var(--cyan);
  animation: pulse 1.6s ease-in-out infinite;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.kpi-grid article, .panel {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.24);
}

.kpi-grid article {
  padding: 16px;
}

.kpi-grid span {
  color: var(--dim);
  font-size: 12px;
}

.kpi-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.scan-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(21, 29, 38, 0.62);
  padding: 12px;
  margin-bottom: 12px;
}

.scan-strip div {
  min-width: 0;
}

.scan-strip span {
  display: block;
  color: var(--dim);
  font-size: 12px;
}

.scan-strip strong {
  display: block;
  margin-top: 6px;
  color: var(--text);
  font-size: 15px;
  overflow-wrap: anywhere;
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) minmax(320px, 0.8fr);
  gap: 12px;
}

.main-grid > * {
  min-width: 0;
}

.panel {
  padding: 16px;
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.panel-head.compact {
  align-items: center;
}

.table-wrap {
  overflow-x: auto;
  max-width: 100%;
  width: 100%;
  -webkit-overflow-scrolling: touch;
}

table {
  border-collapse: collapse;
  min-width: 920px;
  width: 100%;
  font-size: 13px;
}

th, td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--dim);
  font-weight: 600;
  background: rgba(255,255,255,0.03);
}

td { color: var(--muted); }
td strong, .symbol { color: var(--text); }

.candidate-row {
  outline: none;
}

.candidate-row:hover,
.candidate-row:focus-visible {
  background: rgba(46, 232, 214, 0.045);
}

.candidate-row:hover .symbol,
.candidate-row:focus-visible .symbol {
  color: var(--cyan);
}

td:nth-child(7),
td:nth-child(10) {
  line-height: 1.35;
  overflow-wrap: anywhere;
  white-space: normal;
}

.tag {
  display: inline-flex;
  border-radius: 999px;
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 700;
}

.BUY_SETUP { color: #062017; background: var(--green); }
.BUY_SETUP_PAUSED { color: #1f1700; background: #f6d66c; }
.LIMIT_UP_QUEUE_ONLY { color: #2b1a00; background: var(--amber); }
.WATCH, .WATCH_CLOSED, .WATCH_AUCTION { color: var(--cyan); background: rgba(46, 232, 214, 0.1); }

.thinking {
  max-height: 650px;
  overflow: auto;
}

#thinking-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 10px;
}

#thinking-list li {
  border-left: 2px solid rgba(46, 232, 214, 0.48);
  background: rgba(255,255,255,0.04);
  border-radius: 0 8px 8px 0;
  padding: 12px;
  color: var(--muted);
  line-height: 1.5;
}

#thinking-list li strong,
#thinking-list li span {
  display: block;
}

#thinking-list li strong {
  color: var(--text);
  margin-bottom: 8px;
}

#thinking-list li span + span {
  margin-top: 4px;
}

.signal-history {
  border-top: 1px solid var(--line);
  margin-top: 14px;
  padding-top: 14px;
}

.signal-history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.signal-history-head h3 {
  margin: 0;
  font-size: 14px;
}

.signal-history-head button {
  padding: 6px 9px;
  font-size: 12px;
}

#signal-history-list {
  list-style: none;
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
}

#signal-history-list li {
  border-left: 2px solid rgba(243, 179, 76, 0.58);
  background: rgba(255, 255, 255, 0.035);
  border-radius: 0 8px 8px 0;
  padding: 10px;
  color: var(--muted);
  line-height: 1.45;
}

#signal-history-list li strong,
#signal-history-list li span {
  display: block;
}

#signal-history-list li strong {
  color: var(--text);
  margin-bottom: 6px;
}

#signal-history-list li span + span {
  margin-top: 4px;
}

#signal-history-list .tag {
  display: inline-flex;
  margin: 0 3px;
  padding: 3px 7px;
}

.method-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.learning-panel {
  margin-top: 12px;
}

.learning-status {
  border: 1px solid rgba(243, 179, 76, 0.35);
  border-radius: 999px;
  color: var(--amber);
  background: rgba(243, 179, 76, 0.08);
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 700;
}

.learning-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.learning-grid div,
.weights-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.025);
}

.learning-grid span,
.weights-grid span {
  color: var(--dim);
  display: block;
  font-size: 12px;
}

.learning-grid strong,
.weights-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 22px;
}

.weights-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.weights-grid strong {
  color: var(--cyan);
  font-size: 18px;
}

.learning-feed {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  margin-top: 16px;
}

.learning-feed h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.learning-feed ol {
  list-style: none;
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
}

.learning-feed li {
  border-left: 2px solid rgba(243, 179, 76, 0.5);
  padding: 8px 10px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.025);
  border-radius: 0 8px 8px 0;
  line-height: 1.45;
}

.method-card {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 8px;
  padding: 15px;
  min-height: 190px;
}

.method-card span {
  color: var(--amber);
  font-size: 12px;
  font-weight: 700;
}

.method-card h3 {
  margin: 10px 0 8px;
  font-size: 16px;
}

.method-card p {
  font-size: 13px;
}

.risk {
  margin-top: 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 520px);
  gap: 18px;
  align-items: center;
}

.risk-contract {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.risk-contract span, .risk-contract strong {
  border: 1px solid var(--line);
  padding: 10px;
  border-radius: 8px;
}

.risk-contract span { color: var(--dim); }

.kline-popover {
  position: fixed;
  z-index: 70;
  width: min(460px, calc(100vw - 24px));
  border: 1px solid rgba(177, 202, 216, 0.24);
  border-radius: 8px;
  background: rgba(12, 18, 25, 0.98);
  box-shadow: 0 24px 82px rgba(0, 0, 0, 0.52);
  padding: 12px;
  pointer-events: none;
}

.kline-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 8px;
}

.kline-head strong,
.kline-head span {
  display: block;
}

.kline-head strong {
  font-size: 15px;
}

.kline-head span {
  color: var(--dim);
  font-size: 12px;
}

#kline-status {
  border: 1px solid rgba(46, 232, 214, 0.22);
  border-radius: 999px;
  color: var(--cyan);
  background: rgba(46, 232, 214, 0.08);
  padding: 5px 8px;
  white-space: nowrap;
}

#kline-canvas {
  display: block;
  width: 100%;
  height: 260px;
  border: 1px solid rgba(177, 202, 216, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.025);
}

.kline-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 9px;
  color: var(--muted);
  font-size: 12px;
}

.kline-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.kline-legend i {
  width: 16px;
  height: 2px;
  border-radius: 999px;
  background: var(--muted);
}

.kline-legend .ma5 { background: #f3b34c; }
.kline-legend .ma10 { background: #2ee8d6; }
.kline-legend .ma20 { background: #8fb2ff; }
.kline-legend .ma60 { background: #edf4f8; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(3, 7, 11, 0.74);
  backdrop-filter: blur(12px);
}

.sponsor-modal {
  position: relative;
  width: min(94vw, 520px);
  max-height: min(94dvh, 860px);
  overflow: auto;
  border: 1px solid rgba(177, 202, 216, 0.22);
  border-radius: 8px;
  background: rgba(15, 22, 30, 0.98);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.54);
  padding: 18px;
}

.sponsor-modal > span {
  display: inline-flex;
  border: 1px solid rgba(46, 232, 214, 0.26);
  border-radius: 999px;
  color: var(--cyan);
  background: rgba(46, 232, 214, 0.08);
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
}

.sponsor-modal h2 {
  margin-top: 12px;
  font-size: 24px;
}

.sponsor-modal p {
  margin-bottom: 14px;
}

.sponsor-modal img {
  display: block;
  width: min(100%, 420px);
  height: auto;
  margin: 0 auto;
  border: 1px solid rgba(177, 202, 216, 0.14);
  border-radius: 8px;
  background: #fff;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  padding: 7px 10px;
  border-color: rgba(177, 202, 216, 0.2);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 12px;
}

.modal-close:hover {
  color: var(--text);
  border-color: rgba(237, 244, 248, 0.34);
}

@keyframes pulse {
  50% { transform: scale(1.4); opacity: 0.45; }
}

@media (prefers-reduced-motion: reduce) {
  .live-pill i { animation: none; }
}

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; }
  .rail {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    width: 100%;
  }
  .rail nav { grid-auto-flow: column; grid-auto-columns: max-content; }
  .sponsor-button { width: auto; white-space: nowrap; }
  .rail-foot { margin-left: auto; margin-top: 0; border-top: 0; padding-top: 0; }
  .main-grid, .risk { grid-template-columns: 1fr; }
  .learning-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .scan-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .weights-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .learning-feed { grid-template-columns: 1fr; }
  .method-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  table { min-width: 920px; }
}

@media (min-width: 1101px) {
  table {
    min-width: 100%;
    table-layout: fixed;
  }

  th, td { padding: 10px 8px; }
  th:nth-child(1), td:nth-child(1) { width: 9%; }
  th:nth-child(2), td:nth-child(2) { width: 15%; }
  th:nth-child(3), td:nth-child(3) { width: 7%; }
  th:nth-child(4), td:nth-child(4) { width: 7%; }
  th:nth-child(5), td:nth-child(5) { width: 7%; }
  th:nth-child(6), td:nth-child(6) { width: 8%; }
  th:nth-child(7), td:nth-child(7) { width: 16%; }
  th:nth-child(8), td:nth-child(8) { width: 6%; }
  th:nth-child(9), td:nth-child(9) { width: 6%; }
  th:nth-child(10), td:nth-child(10) { width: 19%; }
}

@media (max-width: 720px) {
  main { padding: 14px; }
  .topbar { display: grid; }
  .status-stack { justify-items: start; }
  .learning-panel .panel-head.compact {
    display: grid;
    align-items: start;
  }
  .learning-status {
    justify-self: start;
  }
  .kpi-grid, .scan-strip, .learning-grid, .weights-grid, .method-grid, .risk-contract { grid-template-columns: 1fr; }
  .rail {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    padding: 12px;
    overflow: hidden;
  }
  .app-shell,
  main,
  .topbar,
  .topbar > div {
    min-width: 0;
    max-width: 100vw;
  }
  .rail nav {
    min-width: 0;
    overflow-x: auto;
  }
  .sponsor-button {
    grid-column: 1 / -1;
    width: 100%;
  }
  .rail-foot {
    display: none;
  }
  .kline-popover {
    display: none;
  }
  .sponsor-modal {
    width: min(96vw, 440px);
    padding: 14px;
  }
}
