    :root {
      color-scheme: dark;
      --bg: #050608;
      --panel: #0c0f14;
      --panel-2: #11151c;
      --line: #232a34;
      --text: #d6dde6;
      --muted: #7d8794;
      --accent: #ff9e16;
      --accent-soft: #2a2008;
      --warn: #ffb020;
      --danger: #ff5247;
      --ok: #2fd07a;
      --grid: #1a1f27;
      --shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
      --radius: 2px;
      --mono: "Cascadia Mono", Consolas, "SF Mono", Menlo, Monaco, "Roboto Mono", "Courier New", monospace;
    }

    @keyframes loading-bar-slide {
      0% { transform: translateX(-100%); }
      100% { transform: translateX(250%); }
    }

    @keyframes loading-spinner-rotate {
      to { transform: rotate(360deg); }
    }

    * { box-sizing: border-box; }
    body {
      margin: 0;
      font-family: var(--mono);
      font-size: 13px;
      letter-spacing: 0.01em;
      background: var(--bg);
      color: var(--text);
    }

    header {
      background: #07090c;
      border-bottom: 2px solid var(--accent);
    }

    .wrap {
      max-width: 1600px;
      margin: 0 auto;
      padding: 16px;
    }

    .loading-bar {
      position: relative;
      height: 3px;
      margin-top: 12px;
      overflow: hidden;
      border-radius: 0;
      background: rgba(255, 158, 22, 0.1);
      opacity: 0;
      transition: opacity 0.16s ease;
    }

    .loading-bar::before {
      content: '';
      position: absolute;
      inset: 0;
      width: 40%;
      background: linear-gradient(90deg, transparent 0%, var(--accent) 50%, transparent 100%);
      transform: translateX(-100%);
    }

    .loading-bar.is-active {
      opacity: 1;
    }

    .loading-bar.is-active::before {
      animation: loading-bar-slide 1.05s linear infinite;
    }

    .topbar {
      display: grid;
      grid-template-columns: 1.3fr 1fr;
      gap: 12px;
      align-items: start;
    }

    h1 {
      margin: 0 0 6px 0;
      font-size: 16px;
      line-height: 1.2;
      color: var(--accent);
      text-transform: uppercase;
      letter-spacing: 0.14em;
      font-weight: 700;
    }

    .subtle {
      color: var(--muted);
      font-size: 13px;
      line-height: 1.4;
    }

    .controls {
      display: grid;
      grid-template-columns: 1fr auto auto auto;
      gap: 8px;
      align-items: center;
    }

    input, button, select {
      font: inherit;
      border: 1px solid var(--line);
      border-radius: var(--radius);
      background: var(--panel-2);
      color: var(--text);
      padding: 8px 10px;
    }

    input:focus, select:focus {
      outline: none;
      border-color: var(--accent);
    }

    input {
      width: 100%;
    }

    button {
      cursor: pointer;
      background: var(--panel-2);
      text-transform: uppercase;
      letter-spacing: 0.06em;
      font-size: 12px;
    }

    button:hover {
      border-color: var(--accent);
      color: var(--accent);
    }

    button.primary {
      background: var(--accent);
      color: #050608;
      border-color: var(--accent);
      font-weight: 700;
    }

    button.primary:hover {
      background: #ffb648;
      color: #050608;
    }

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

    .metric {
      background: var(--panel);
      border: 1px solid var(--line);
      border-radius: var(--radius);
      box-shadow: var(--shadow);
      padding: 10px 12px;
    }

    .metric .label {
      display: block;
      color: var(--muted);
      font-size: 12px;
      margin-bottom: 6px;
    }

    .metric .value {
      font-size: 16px;
      font-weight: 700;
      color: var(--accent);
    }

    .metric .label {
      text-transform: uppercase;
      letter-spacing: 0.06em;
    }

    main {
      padding: 14px 16px 28px;
      max-width: 1680px;
      margin: 0 auto;
    }

    /* Markets view: list pane (left) + detail pane (right). */
    #view-markets {
      display: grid;
      grid-template-columns: 360px minmax(0, 1fr);
      gap: 12px;
      align-items: start;
    }

    #view-markets[hidden],
    #view-arbitrage[hidden] {
      display: none;
    }

    /* Left list pane sticks and scrolls on its own so the detail pane can be read
       without scrolling the whole page back and forth. */
    .markets-col {
      position: sticky;
      top: 12px;
      align-self: start;
      max-height: calc(100vh - 24px);
      overflow: auto;
      padding-right: 2px;
    }

    .markets-col::-webkit-scrollbar,
    .arb-chart::-webkit-scrollbar { height: 8px; width: 8px; }
    .markets-col::-webkit-scrollbar-thumb,
    .arb-chart::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

    section {
      background: var(--panel);
      border: 1px solid var(--line);
      border-radius: var(--radius);
      box-shadow: var(--shadow);
      padding: 12px;
      min-width: 0;
    }

    section + section {
      margin-top: 12px;
    }

    section.tabs-section {
      padding-bottom: 14px;
    }

    .detail-header-block {
      margin-bottom: 14px;
    }

    #detailSection {
      position: relative;
      order: -1; /* selected market shows at the top of the right column, not the bottom */
      margin-top: 0;
    }

    .detail-body {
      display: grid;
      gap: 12px;
      transition: opacity 0.16s ease;
    }

    #detailSection.is-loading .detail-body {
      opacity: 0.72;
    }

    .detail-loading {
      position: absolute;
      top: 12px;
      right: 12px;
      z-index: 1;
      display: inline-flex;
      align-items: center;
      gap: 8px;
      padding: 7px 10px;
      border: 1px solid rgba(255, 158, 22, 0.4);
      border-radius: 2px;
      background: rgba(12, 15, 20, 0.96);
      color: var(--accent);
      font-size: 12px;
      line-height: 1;
      box-shadow: var(--shadow);
      pointer-events: none;
    }

    .detail-loading[hidden] {
      display: none;
    }

    .detail-loading::before {
      content: '';
      width: 12px;
      height: 12px;
      border: 2px solid rgba(255, 158, 22, 0.25);
      border-top-color: var(--accent);
      border-radius: 50%;
      animation: loading-spinner-rotate 0.8s linear infinite;
      flex: 0 0 auto;
    }

    h2 {
      margin: 0 0 10px 0;
      font-size: 15px;
    }

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

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

    th {
      color: var(--muted);
      font-weight: 600;
      white-space: nowrap;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      font-size: 11px;
    }

    th .help-mark {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 14px;
      height: 14px;
      margin-left: 4px;
      border: 1px solid var(--line);
      border-radius: 50%;
      color: var(--muted);
      font-size: 10px;
      line-height: 1;
      vertical-align: middle;
    }

    tr:hover td {
      background: #14181f;
    }

    .clickable {
      cursor: pointer;
    }

    .active-row td {
      background: var(--accent-soft);
    }

    .pill {
      display: inline-block;
      padding: 2px 8px;
      border-radius: 2px;
      background: var(--panel-2);
      border: 1px solid var(--line);
      color: var(--muted);
      font-size: 11px;
      text-transform: uppercase;
      letter-spacing: 0.04em;
    }

    .pill.warn { background: rgba(255, 176, 32, 0.12); color: var(--warn); border-color: rgba(255, 176, 32, 0.4); }
    .pill.danger { background: rgba(255, 82, 71, 0.12); color: var(--danger); border-color: rgba(255, 82, 71, 0.4); }
    .pill.ok { background: rgba(47, 208, 122, 0.12); color: var(--ok); border-color: rgba(47, 208, 122, 0.4); }

    .layout-two {
      display: grid;
      grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
      gap: 12px;
    }

    .layout-three {
      display: grid;
      grid-template-columns: repeat(3, minmax(0, 1fr));
      gap: 12px;
    }

    .stack {
      display: grid;
      gap: 12px;
    }

    .muted {
      color: var(--muted);
    }

    .tab-note {
      margin-bottom: 12px;
    }

    /* Dense pair/signal tables can be wider than the right column; let them
       scroll horizontally INSIDE the panel instead of pushing the page wider. */
    #globalDivergenceView,
    #divergenceView,
    #signalsView,
    #relatedView {
      overflow-x: auto;
    }

    .pair-market-link {
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      width: 100%;
      min-width: 120px;
      padding: 0;
      border: 0;
      background: transparent;
      color: var(--accent);
      text-align: left;
      font-weight: 600;
      line-height: 1.3;
      cursor: pointer;
      overflow: hidden;
      overflow-wrap: anywhere;
    }

    .pair-market-link:hover {
      text-decoration: underline;
    }

    .pair-market-meta {
      margin-top: 3px;
      color: var(--muted);
      font-size: 11px;
      line-height: 1.3;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .num {
      font-variant-numeric: tabular-nums;
      white-space: nowrap;
    }

    .num-positive {
      color: var(--ok);
    }

    .num-negative {
      color: var(--danger);
    }

    .num-zero,
    .num-muted {
      color: var(--muted);
    }

    .title-row {
      display: flex;
      justify-content: space-between;
      gap: 8px;
      align-items: start;
    }

    .section-note {
      margin: 4px 0 10px 0;
    }

    .detail-title {
      margin: 0;
      font-size: 18px;
      line-height: 1.25;
      overflow-wrap: anywhere;
    }

    .detail-header {
      display: grid;
      gap: 8px;
    }

    .detail-selected-title {
      margin-top: 2px;
      font-size: 15px;
      line-height: 1.35;
      font-weight: 600;
      overflow-wrap: anywhere;
    }

    .detail-label {
      display: grid;
      gap: 2px;
    }

    .detail-market-id {
      color: var(--muted);
      font-size: 12px;
      line-height: 1.35;
    }

    .detail-meta {
      margin-top: 6px;
      color: var(--muted);
      font-size: 13px;
      line-height: 1.4;
    }

    .sparkline {
      width: 100%;
      height: 120px;
      display: block;
      margin-top: 12px;
      border: 1px solid var(--line);
      border-radius: var(--radius);
      background: var(--panel-2);
    }

    /* --- Selected-market detail components --- */
    .stat-grid {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(108px, 1fr));
      gap: 1px;
      background: var(--line);
      border: 1px solid var(--line);
      border-radius: var(--radius);
      margin: 12px 0;
    }
    .stat-cell {
      display: flex;
      flex-direction: column;
      gap: 3px;
      padding: 7px 9px;
      background: var(--panel-2);
    }
    .stat-k {
      font-size: 10px;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      color: var(--muted);
    }
    .stat-v {
      font-size: 14px;
      font-weight: 600;
      color: var(--text);
    }

    .block-label {
      font-size: 11px;
      text-transform: uppercase;
      letter-spacing: 0.06em;
      color: var(--accent);
    }
    .block-label-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      margin-bottom: 6px;
    }

    .detail-block { margin-bottom: 14px; }

    .outcome-row {
      display: grid;
      grid-template-columns: 64px 1fr 56px;
      align-items: center;
      gap: 8px;
      padding: 4px 0;
    }
    .outcome-name { font-size: 12px; color: var(--text); }
    .outcome-pct { font-size: 13px; font-weight: 600; text-align: right; color: var(--text); }

    .pbar {
      position: relative;
      display: block;
      height: 8px;
      background: var(--panel);
      border: 1px solid var(--line);
      border-radius: 2px;
      overflow: hidden;
    }
    .pbar-fill {
      position: absolute;
      left: 0; top: 0; bottom: 0;
      background: var(--accent);
    }

    .event-block {
      border: 1px solid var(--line);
      border-radius: var(--radius);
      padding: 10px;
      background: var(--panel-2);
    }
    .event-title-sub {
      font-size: 12px;
      color: var(--muted);
      margin-bottom: 8px;
      overflow-wrap: anywhere;
    }
    .members { display: grid; gap: 2px; }
    .member-row {
      display: grid;
      grid-template-columns: 22px minmax(0, 1fr) 84px 50px 116px 52px;
      align-items: center;
      gap: 8px;
      width: 100%;
      text-align: left;
      background: var(--panel);
      border: 1px solid transparent;
      border-radius: 2px;
      padding: 5px 7px;
      color: var(--text);
      font-family: var(--mono);
      font-size: 12px;
      cursor: pointer;
    }
    .member-row:hover { border-color: var(--accent); }
    .member-row.is-selected {
      border-color: var(--accent);
      background: var(--accent-soft);
    }
    .member-rank { color: var(--muted); font-size: 11px; }
    .member-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .member-pct { text-align: right; font-weight: 600; }
    .member-liq { text-align: right; color: var(--muted); font-size: 11px; }
    .mini-spark { width: 116px; height: 26px; display: block; }
    .mini-empty { color: var(--muted); font-size: 11px; text-align: center; }

    .sum-badge {
      font-size: 11px;
      padding: 2px 7px;
      border: 1px solid var(--line);
      border-radius: 2px;
      color: var(--muted);
      white-space: nowrap;
    }
    .sum-badge.sum-ok { color: var(--ok); border-color: var(--ok); }
    .sum-badge.sum-bad { color: var(--danger); border-color: var(--danger); }

    @media (max-width: 1100px) {
      .member-row {
        grid-template-columns: 20px minmax(0, 1fr) 64px 46px;
      }
      .member-row .mini-spark { display: none; }
      .member-liq { display: none; }
    }

    pre {
      margin: 0;
      padding: 10px;
      max-height: 280px;
      overflow: auto;
      background: #0b1020;
      color: #c9d4ff;
      border-radius: var(--radius);
      font-size: 12px;
      line-height: 1.45;
    }

    .nowrap {
      white-space: nowrap;
    }

    .right {
      text-align: right;
    }

    .note {
      padding: 10px 12px;
      border: 1px dashed var(--line);
      border-radius: var(--radius);
      background: var(--panel-2);
      color: var(--muted);
      font-size: 12px;
    }

    .tabs {
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
      padding-bottom: 10px;
      margin-bottom: 12px;
      border-bottom: 1px solid var(--line);
    }

    .tab-button {
      border: 1px solid var(--line);
      background: var(--panel-2);
      color: var(--muted);
      padding: 7px 12px;
      border-radius: 2px;
      font-size: 12px;
      line-height: 1;
      text-transform: uppercase;
      letter-spacing: 0.05em;
    }

    .tab-button:hover {
      border-color: var(--accent);
      color: var(--accent);
    }

    .tab-button[aria-selected="true"] {
      background: var(--accent);
      color: #050608;
      border-color: var(--accent);
      font-weight: 700;
    }

    .tab-panel[hidden] {
      display: none;
    }

    .view-nav {
      display: inline-flex;
      margin: 0 0 14px;
      border: 1px solid var(--line);
      border-radius: 2px;
      overflow: hidden;
    }

    .view-nav .tab-button {
      border: 0;
      border-right: 1px solid var(--line);
      border-radius: 0;
      padding: 7px 18px;
    }

    .view-nav .tab-button:last-child {
      border-right: 0;
    }

    .arb-controls {
      display: flex;
      flex-wrap: wrap;
      gap: 12px;
      align-items: flex-end;
      margin: 12px 0 14px;
    }

    .arb-controls label {
      display: flex;
      flex-direction: column;
      gap: 4px;
      font-size: 12px;
      color: var(--muted);
    }

    .arb-controls input,
    .arb-controls select {
      padding: 6px 8px;
      border: 1px solid var(--line);
      border-radius: 8px;
      font-size: 13px;
    }

    .arb-chart {
      overflow-x: auto;
    }

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

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

    .arb-legend i {
      width: 14px;
      height: 3px;
      display: inline-block;
      border-radius: 2px;
    }

    .arb-table {
      width: 100%;
      border-collapse: collapse;
      font-size: 13px;
    }

    .arb-table th,
    .arb-table td {
      text-align: left;
      padding: 6px 8px;
      border-bottom: 1px solid var(--line);
      white-space: nowrap;
    }

    .arb-table th {
      color: var(--muted);
      font-weight: 600;
    }

    .arb-table td.num {
      text-align: right;
      font-variant-numeric: tabular-nums;
    }

    .arb-link {
      color: var(--accent);
      cursor: pointer;
      text-decoration: underline;
    }

    .arb-pos { color: var(--ok); }
    .arb-neg { color: var(--danger); }
    .arb-warn { color: var(--danger); font-weight: 600; }
    .arb-soon { color: var(--accent); }

    .arb-caption {
      font-size: 11px;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      color: var(--muted);
      margin-bottom: 6px;
    }

    /* color key linking a charted line to its table row */
    .arb-key {
      display: inline-block;
      width: 16px;
      height: 16px;
      line-height: 16px;
      text-align: center;
      border-radius: 2px;
      color: #fff;
      font-size: 10px;
      font-weight: 700;
      font-variant-numeric: tabular-nums;
    }

    .arb-legend b { color: var(--text); margin-right: 2px; }

    /* --- Interactive chart shell (zoom + hover info) shared by the detail
       sparkline and the arbitrage chart --- */
    .chart-wrap { position: relative; }
    .chart-wrap svg {
      display: block;
      width: 100%;
      height: auto;
      border: 1px solid var(--line);
      border-radius: var(--radius);
      background: var(--panel-2);
      cursor: crosshair;
      touch-action: none;
    }
    .chart-wrap.panning svg { cursor: grabbing; }
    .chart-info {
      position: absolute;
      top: 6px;
      right: 6px;
      min-width: 116px;
      max-width: 72%;
      background: rgba(7, 9, 12, 0.93);
      border: 1px solid var(--line);
      border-radius: var(--radius);
      padding: 6px 8px;
      font-family: var(--mono);
      font-size: 11px;
      line-height: 1.45;
      color: var(--text);
      pointer-events: none;
      opacity: 0;
      transition: opacity 0.08s ease;
      z-index: 3;
    }
    .chart-info.show { opacity: 1; }
    .chart-info .ci-time { color: var(--muted); margin-bottom: 3px; letter-spacing: 0.03em; }
    .chart-info .ci-row { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
    .chart-info .ci-row i { width: 8px; height: 8px; border-radius: 2px; flex: 0 0 auto; }
    .chart-info .ci-val { font-weight: 700; margin-left: auto; font-variant-numeric: tabular-nums; }
    .chart-hint {
      position: absolute;
      left: 6px;
      bottom: 6px;
      font-size: 10px;
      color: var(--muted);
      letter-spacing: 0.04em;
      background: rgba(7, 9, 12, 0.66);
      padding: 2px 6px;
      border-radius: var(--radius);
      pointer-events: none;
      opacity: 0.7;
    }
    .chart-reset {
      position: absolute;
      top: 6px;
      left: 6px;
      font-family: var(--mono);
      font-size: 10px;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      background: var(--panel-2);
      color: var(--muted);
      border: 1px solid var(--line);
      border-radius: var(--radius);
      padding: 2px 7px;
      cursor: pointer;
      z-index: 3;
      opacity: 0;
      transition: opacity 0.1s ease;
    }
    .chart-reset.show { opacity: 1; }
    .chart-reset:hover { color: var(--accent); border-color: var(--accent); }

    /* --- Relationship graph pan/zoom + node info --- */
    .graph-frame { position: relative; }
    .graph-svg { cursor: grab; }
    .graph-frame.panning .graph-svg { cursor: grabbing; }
    .graph-info {
      position: absolute;
      top: 8px;
      right: 8px;
      max-width: 62%;
      background: rgba(7, 9, 12, 0.93);
      border: 1px solid var(--line);
      border-radius: var(--radius);
      padding: 7px 9px;
      font-size: 11px;
      color: var(--text);
      pointer-events: none;
      opacity: 0;
      transition: opacity 0.08s ease;
      z-index: 3;
    }
    .graph-info.show { opacity: 1; }
    .graph-info .gi-title { font-weight: 700; margin-bottom: 3px; line-height: 1.3; }
    .graph-info .gi-meta { color: var(--muted); font-family: var(--mono); }
    .graph-zoom-hint {
      position: absolute;
      left: 8px;
      bottom: 8px;
      font-size: 10px;
      color: var(--muted);
      letter-spacing: 0.04em;
      background: rgba(7, 9, 12, 0.66);
      padding: 2px 6px;
      border-radius: var(--radius);
      pointer-events: none;
      opacity: 0.7;
    }
    .graph-zoom-reset {
      position: absolute;
      top: 8px;
      left: 8px;
      font-family: var(--mono);
      font-size: 10px;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      background: var(--panel-2);
      color: var(--muted);
      border: 1px solid var(--line);
      border-radius: var(--radius);
      padding: 2px 7px;
      cursor: pointer;
      z-index: 3;
    }
    .graph-zoom-reset:hover { color: var(--accent); border-color: var(--accent); }

    /* --- Data freshness bar --- */
    .freshness {
      display: flex;
      align-items: center;
      gap: 8px;
      margin: 8px 0 4px;
      padding: 5px 10px;
      border: 1px solid var(--line);
      border-radius: var(--radius);
      background: var(--panel-2);
      font-size: 12px;
      color: var(--muted);
      font-family: var(--mono);
    }
    .freshness .fresh-dot {
      width: 8px;
      height: 8px;
      border-radius: 50%;
      flex: 0 0 auto;
      background: var(--muted);
    }
    .freshness .fresh-label { color: var(--text); }
    .freshness .fresh-label strong { font-weight: 700; }
    .freshness .fresh-state { color: var(--muted); }
    .freshness #refreshView {
      margin-left: auto;
      font-family: var(--mono);
      font-size: 11px;
      text-transform: uppercase;
      letter-spacing: 0.04em;
      background: transparent;
      color: var(--muted);
      border: 1px solid var(--line);
      border-radius: var(--radius);
      padding: 3px 9px;
      cursor: pointer;
    }
    .freshness #refreshView:hover { color: var(--accent); border-color: var(--accent); }
    .freshness #refreshView:disabled { opacity: 0.5; cursor: default; }
    .freshness.fresh-ok .fresh-dot { background: var(--ok); }
    .freshness.fresh-soon .fresh-dot { background: var(--accent); }
    .freshness.fresh-stale { border-color: var(--danger); }
    .freshness.fresh-stale .fresh-dot { background: var(--danger); }
    .freshness.fresh-stale .fresh-state { color: var(--danger); }
    .freshness.is-busy .fresh-dot {
      background: var(--accent);
      animation: freshPulse 0.9s ease-in-out infinite;
    }
    @keyframes freshPulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }
    .fresh-mini { color: var(--muted); font-weight: 400; }

    .panel-grid {
      display: grid;
      gap: 12px;
    }

    .panel-grid.two {
      grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
    }

    .panel-grid.graph {
      grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.95fr);
      align-items: start;
    }

    .graph-shell {
      display: grid;
      gap: 10px;
    }

    .graph-selection {
      display: flex;
      justify-content: space-between;
      gap: 12px;
      align-items: center;
      padding: 10px 12px;
      border: 1px solid var(--line);
      border-radius: var(--radius);
      background: var(--panel-2);
    }

    .graph-frame {
      border: 1px solid var(--line);
      border-radius: var(--radius);
      background: #07090c;
      overflow: hidden;
      min-height: 420px;
    }

    .graph-svg {
      display: block;
      width: 100%;
      height: auto;
      min-height: 420px;
    }

    .graph-legend {
      display: flex;
      flex-wrap: wrap;
      gap: 8px 12px;
      align-items: center;
      color: var(--muted);
      font-size: 12px;
    }

    .legend-item {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      white-space: nowrap;
    }

    .swatch {
      width: 10px;
      height: 10px;
      border-radius: 3px;
      border: 1px solid rgba(0, 0, 0, 0.08);
      display: inline-block;
      flex: 0 0 auto;
    }

    .edge-list {
      display: grid;
      gap: 10px;
      align-content: start;
    }

    .edge-list table {
      font-size: 12px;
    }

    .edge-list th,
    .edge-list td {
      padding: 7px 5px;
    }

    .json-pre {
      max-height: 640px;
      min-height: 420px;
    }

    .chip-row {
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
    }

    .chip {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      padding: 3px 8px;
      border-radius: 2px;
      border: 1px solid var(--line);
      background: var(--panel-2);
      color: var(--text);
      font-size: 12px;
      white-space: nowrap;
    }

    .market-list {
      display: grid;
      gap: 4px;
    }

    .market-list-help {
      color: var(--muted);
      font-size: 12px;
      line-height: 1.45;
      margin-bottom: 8px;
    }

    /* The card is the wrap; the Paper button is pinned into its top-right corner
       (can't nest a <button> inside the .market-row <button>). The row reserves a
       right gutter so its content never slides under the Paper button. */
    .market-row-wrap {
      position: relative;
    }

    .market-row-wrap .market-row {
      width: 100%;
      min-width: 0;
    }

    .mkt-spark {
      display: inline-flex;
      align-items: center;
      padding: 0;
    }

    .paper-btn {
      position: absolute;
      top: 6px;
      right: 6px;
      z-index: 1;
      background: var(--panel);
      border: 1px solid var(--line);
      color: var(--muted);
      font: 600 10px var(--mono);
      text-transform: uppercase;
      letter-spacing: .5px;
      padding: 2px 6px;
      border-radius: var(--radius);
      line-height: 1.3;
      cursor: pointer;
    }

    .paper-btn:hover {
      border-color: var(--accent);
      color: var(--accent);
      background: var(--accent-soft);
    }

    .market-row {
      width: 100%;
      display: grid;
      gap: 4px;
      padding: 6px 44px 6px 8px;
      border: 1px solid var(--line);
      border-radius: var(--radius);
      background: var(--panel-2);
      cursor: pointer;
      text-align: left;
    }

    .market-row.active-row {
      border-left: 2px solid var(--accent);
      padding-left: 7px;
    }

    .market-row:hover {
      background: #161b22;
      border-color: #34404e;
    }

    .market-row.active-row {
      background: var(--accent-soft);
      border-color: var(--accent);
    }

    .market-row-main {
      min-width: 0;
      display: grid;
      gap: 4px;
    }

    .market-row-title {
      font-weight: 600;
      font-size: 12px;
      line-height: 1.25;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }

    .market-row-slug {
      display: none;
    }

    .market-row-stats {
      display: flex;
      flex-wrap: wrap;
      gap: 4px;
      align-items: center;
    }

    .stat-chip {
      display: inline-flex;
      align-items: center;
      gap: 3px;
      padding: 1px 5px;
      border-radius: 2px;
      border: 1px solid var(--line);
      background: var(--panel);
      font-size: 10px;
      line-height: 1.2;
      white-space: nowrap;
    }

    .stat-chip strong {
      font-weight: 600;
      color: var(--muted);
      text-transform: uppercase;
      font-size: 9px;
      letter-spacing: 0.04em;
    }

    @media (max-width: 1100px) {
      .topbar, .layout-two, .layout-three,
      #view-markets {
        grid-template-columns: 1fr;
      }

      .markets-col {
        position: static;
        max-height: none;
        overflow: visible;
      }

      .metrics {
        grid-template-columns: repeat(2, minmax(0, 1fr));
      }

      .controls {
        grid-template-columns: 1fr 1fr;
      }

      .panel-grid.two,
      .panel-grid.graph {
        grid-template-columns: 1fr;
      }
    }

    /* ── Portfolio (paper trading) ── */
    .pf-stats {
      display: flex;
      flex-wrap: wrap;
      gap: 18px;
      padding: 12px 16px;
      border: 1px solid var(--line);
      border-radius: var(--radius);
      margin-bottom: 14px;
    }
    .pf-stat { display: flex; flex-direction: column; gap: 2px; }
    .pf-stat-val { font: 600 17px var(--mono); }
    .pf-stat-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
    .pnl-pos { color: var(--ok); }
    .pnl-neg { color: var(--danger); }
    .pnl-neu { color: var(--muted); }

    .trade-modal-backdrop {
      position: fixed;
      inset: 0;
      background: rgba(0, 0, 0, .6);
      display: flex;
      align-items: center;
      justify-content: center;
      z-index: 100;
    }
    .trade-modal-backdrop[hidden] { display: none; }
    .trade-modal {
      background: var(--panel-2);
      border: 1px solid var(--line);
      border-radius: var(--radius);
      padding: 20px;
      width: 460px;
      max-width: 95vw;
    }
    .trade-modal-title { font: 600 13px var(--mono); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 12px; }
    .trade-modal-q { font-size: 12px; color: var(--muted); margin-bottom: 14px; }
    .trade-modal-row { display: flex; gap: 12px; }
    .trade-modal-row label,
    .trade-modal-note {
      display: flex;
      flex-direction: column;
      gap: 4px;
      font-size: 10px;
      color: var(--muted);
      text-transform: uppercase;
      letter-spacing: 1px;
      flex: 1;
    }
    .trade-modal-note { margin-top: 12px; }
    .trade-modal-actions { display: flex; gap: 10px; margin-top: 18px; }
    .trade-modal-actions button { flex: 1; }
