:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;  /* portfolio */
  --series-2: #eb6834;  /* buy & hold */
  --series-3: #1baf7a;  /* TSMOM */
  --series-4: #eda100;  /* Turtle */
  --series-5: #e87ba4;  /* EMA */
  --good: #0ca30c; --warning: #fab219; --critical: #d03b3b;
  --good-text: #006300; --bad-text: #b42828;
  --accent: #2a78d6;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface-1: #1a1a19; --text-primary: #f0efec; --text-secondary: #c3c2b7;
    --text-muted: #898781; --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500; --series-5: #d55181;
    --good-text: #3fbf5a; --bad-text: #ef7070; --accent: #3987e5;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface-1: #1a1a19; --text-primary: #f0efec; --text-secondary: #c3c2b7;
  --text-muted: #898781; --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500; --series-5: #d55181;
  --good-text: #3fbf5a; --bad-text: #ef7070; --accent: #3987e5;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--text-primary);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 10px; font-weight: 600; }
code { font-size: 12px; }
.sub { margin: 2px 0 0; color: var(--text-secondary); font-size: 13px; }
.muted { color: var(--text-muted); }
.err { color: var(--critical); font-size: 13px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--surface-1);
  position: sticky; top: 0; z-index: 5; }
.actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.price { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.price .muted { font-size: 13px; font-weight: 500; margin-left: 8px; }
.pill { font-size: 12px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border);
  color: var(--text-secondary); white-space: nowrap; }
.pill::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px;
  background: var(--text-muted); vertical-align: 0; }
.pill.live::before { background: var(--good); }
.pill.wait::before { background: var(--warning); }
.pill.down::before { background: var(--critical); }
button { font: inherit; border-radius: 8px; padding: 8px 14px; cursor: pointer; border: 1px solid var(--border);
  background: var(--surface-1); color: var(--text-primary); }
button.primary { background: var(--accent); color: #fff; border-color: transparent; font-weight: 600; }
button.primary:disabled { opacity: 0.6; cursor: progress; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 16px 20px 40px; }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px;
  margin-bottom: 16px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.section-title { font-size: 17px; margin: 22px 0 12px; }
.hint { font-size: 12px; color: var(--text-muted); margin: 6px 0 0; }
.empty { color: var(--text-secondary); }
.notice { background: var(--surface-1); border: 1px solid var(--border); border-left: 4px solid var(--warning);
  border-radius: 8px; padding: 8px 12px; margin-bottom: 14px; font-size: 13px; }
.chart { position: relative; height: 300px; }
.share { background: var(--surface-1); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: 8px; padding: 8px 12px; margin-bottom: 14px; font-size: 13px; color: var(--text-secondary); }
.share .row { margin-top: 6px; }
input[type=text] { flex: 1 1 220px; padding: 6px 8px; font: inherit; font-size: 12.5px; color: var(--text-primary);
  background: var(--page); border: 1px solid var(--border); border-radius: 6px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; margin-bottom: 16px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.tile .k { font-size: 12px; color: var(--text-secondary); }
.tile .v { font-size: 22px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .c { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.pos { color: var(--good-text); }
.neg { color: var(--bad-text); }

.sleeves { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.sleeve { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px;
  border-top: 4px solid var(--c, var(--axis)); }
.sleeve.off { opacity: 0.55; }
.sleeve h3 { margin: 0; font-size: 15px; display: flex; justify-content: space-between; align-items: baseline; }
.sleeve .side { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); }
.sleeve dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 10px 0 0; font-size: 13px; }
.sleeve dt { color: var(--text-secondary); }
.sleeve dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.levels { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; font-size: 13px; }
.levels h4 { margin: 0 0 4px; font-size: 13px; }
.levels p { margin: 2px 0; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.countdown { font-variant-numeric: tabular-nums; color: var(--text-secondary); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.dot.s3 { background: var(--series-3); } .dot.s4 { background: var(--series-4); } .dot.s5 { background: var(--series-5); }

.tablewrap { overflow-x: auto; margin-top: 4px; }
.tablewrap.scroll { max-height: 420px; overflow-y: auto; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; font-variant-numeric: tabular-nums; }
th, td { padding: 5px 8px; border-bottom: 1px solid var(--grid); text-align: right; white-space: nowrap; }
th:first-child, td:first-child, th:nth-child(2), td:nth-child(2), th:last-child, td:last-child { text-align: left; }
thead th { color: var(--text-secondary); font-weight: 600; position: sticky; top: 0; background: var(--surface-1); }

details summary { font-weight: 600; cursor: pointer; padding: 2px 0; }
form { margin-top: 8px; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin: 10px 0; }
legend { padding: 0 4px; font-weight: 600; font-size: 13px; }
label { display: block; font-size: 12.5px; color: var(--text-secondary); margin: 6px 0; }
label.check { display: flex; align-items: center; gap: 6px; color: var(--text-primary); }
input[type=number], input[type=password] { width: 100%; margin-top: 3px; padding: 6px 8px; font: inherit;
  font-size: 13px; color: var(--text-primary); background: var(--page); border: 1px solid var(--border); border-radius: 6px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.row input { flex: 1 1 220px; width: auto; margin: 0; }
.row3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 12px; align-items: end; }
.notes ul { margin: 0; padding-left: 18px; color: var(--text-secondary); }
.notes li { margin: 5px 0; }

@media (max-width: 760px) {
  .topbar { position: static; padding: 12px 16px; }
  .wrap { padding: 12px 16px 32px; }
  .sleeves, .levels, .row3 { grid-template-columns: 1fr; }
  .chart { height: 240px; }
  .price { font-size: 19px; }
}
