:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #fcfcfb;
  --fg: #0b0b0b;
  --fg2: #52514e;
  --muted: #74736e;
  --line: #e2e1dc;
  --grid: #ecebe7;
  --accent: #2a78d6;
  --s-actual: #8a8984;
  --s-promo: #eb6834;
  --s-base: #2a78d6;
  --s-cur: #eb6834;
  --s-a: #1baf7a;
  --s-b: #4a3aa7;
  --s-c: #e87ba4;
  --s-stock: #52514e;
  --good: #0a7d3b;
  --bad: #c03a2b;
  --hilite: #eef4fc;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --fg: #ffffff;
    --fg2: #c3c2b7;
    --muted: #9a998f;
    --line: #2e2e2b;
    --grid: #262624;
    --accent: #3987e5;
    --s-actual: #7d7c76;
    --s-promo: #d95926;
    --s-base: #3987e5;
    --s-cur: #d95926;
    --s-a: #199e70;
    --s-b: #9085e9;
    --s-c: #d55181;
    --s-stock: #c3c2b7;
    --good: #4cc27c;
    --bad: #ef7a6c;
    --hilite: #1d2a3a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --fg: #ffffff; --fg2: #c3c2b7; --muted: #9a998f; --line: #2e2e2b; --grid: #262624;
  --accent: #3987e5; --s-actual: #7d7c76; --s-promo: #d95926; --s-base: #3987e5; --s-cur: #d95926; --s-a: #199e70;
  --s-b: #9085e9; --s-c: #d55181; --s-stock: #c3c2b7; --good: #4cc27c; --bad: #ef7a6c; --hilite: #1d2a3a;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.center { text-align: center; padding: 4rem 1rem; }
[hidden] { display: none !important; }

header.top {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
h1 { font-size: 1.15rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.02rem; margin: 0 0 8px; }
h3 { font-size: 0.9rem; margin: 0 0 6px; }
.top-right { display: flex; align-items: center; gap: 10px; }
.pill { font-size: 12px; padding: 3px 9px; border: 1px solid var(--line); border-radius: 999px; color: var(--fg2); background: var(--bg); }

button {
  font: inherit; font-size: 13px; padding: 6px 12px; border: 1px solid var(--accent); border-radius: 6px;
  background: var(--accent); color: #fff; cursor: pointer;
}
button.secondary { background: transparent; color: var(--accent); }
button.ghost { background: transparent; border-color: var(--line); color: var(--fg2); }
button:hover { opacity: 0.88; }
button.small { padding: 3px 8px; font-size: 12px; }

#app { display: grid; grid-template-columns: 330px minmax(0, 1fr); min-height: calc(100vh - 52px); }
#picker {
  border-right: 1px solid var(--line); background: var(--surface); padding: 12px;
  position: sticky; top: 52px; height: calc(100vh - 52px); display: flex; flex-direction: column; gap: 8px;
}
#search { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); font: inherit; }
.picker-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
select, input[type=number] { font: inherit; padding: 4px 6px; border: 1px solid var(--line); border-radius: 5px; background: var(--bg); color: var(--fg); }
#style-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
#style-list li { padding: 8px 8px; border-bottom: 1px solid var(--line); cursor: pointer; border-radius: 4px; }
#style-list li:hover { background: var(--bg); }
#style-list li.sel { background: var(--hilite); }
.li-top { display: flex; justify-content: space-between; gap: 6px; }
.li-name { font-weight: 600; font-size: 13px; }
.li-liab { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 13px; white-space: nowrap; }
.li-meta, .li-stat { font-size: 12px; color: var(--muted); }
.li-stat { color: var(--fg2); }

#main { padding: 16px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; min-width: 0; }
#style-head h2 { font-size: 1.2rem; margin-bottom: 2px; }
#style-head .outlook { margin: 6px 0 0; color: var(--fg2); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.tag { font-size: 12px; padding: 1px 8px; border-radius: 4px; background: var(--bg); border: 1px solid var(--line); color: var(--fg2); }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(135px, 1fr)); gap: 8px; margin: 6px 0 12px; }
.kpi { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--bg); }
.kpi .k { font-size: 11.5px; color: var(--muted); }
.kpi .v { font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 11.5px; color: var(--fg2); }

figure { margin: 6px 0 10px; }
figcaption { font-size: 12.5px; font-weight: 600; color: var(--fg2); }
.chart { position: relative; width: 100%; }
.h160 { height: 160px; } .h180 { height: 180px; } .h220 { height: 220px; } .h280 { height: 290px; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--fg2); margin: 3px 0 4px; }
.legend i { display: inline-block; width: 14px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.legend i.line { height: 3px; vertical-align: 2px; }
.legend i.dash { height: 0; border-top: 2px dashed; background: none !important; vertical-align: 3px; }
.legend i.band { opacity: 0.25; }

.playground { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 16px; margin-top: 4px; }
.controls { display: flex; flex-direction: column; gap: 12px; }
.ctl-group { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--bg); display: flex; flex-direction: column; gap: 8px; }
.ctl-group label { display: flex; flex-direction: column; gap: 2px; font-size: 12.5px; color: var(--fg2); }
.ctl-group label.switch { flex-direction: row; align-items: center; gap: 8px; font-weight: 600; color: var(--fg); }
.ctl-group .val { font-weight: 600; color: var(--fg); font-variant-numeric: tabular-nums; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.charts { min-width: 0; }
.disabled { opacity: 0.45; pointer-events: none; }

.table-wrap { overflow-x: auto; margin-top: 8px; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; font-size: 13px; }
th, td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { font-size: 12px; color: var(--fg2); vertical-align: bottom; white-space: normal; min-width: 130px; }
thead th .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; }
thead th .sub { font-weight: 400; color: var(--muted); display: block; font-size: 11.5px; }
tr.total td { font-weight: 700; }
td.delta-good { color: var(--good); } td.delta-bad { color: var(--bad); }
th button.small { margin-top: 3px; }

#why ul { margin: 4px 0 8px; padding-left: 20px; }
#why li { margin: 3px 0; }
#why .factor-table td, #why .factor-table th { text-align: left; white-space: normal; }
#why .factor-table td:nth-child(2) { white-space: nowrap; }
#why .bar { display: inline-block; height: 8px; border-radius: 2px; vertical-align: middle; }

dialog#explained { width: min(860px, 94vw); max-height: 88vh; border: 1px solid var(--line); border-radius: 10px; padding: 0; background: var(--surface); color: var(--fg); }
dialog::backdrop { background: rgba(0,0,0,0.35); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); }
.md { padding: 6px 20px 20px; line-height: 1.6; }
.md table { width: auto; margin: 8px 0; } .md th, .md td { text-align: left; white-space: normal; }
.md pre { overflow-x: auto; background: var(--bg); padding: 10px; border-radius: 6px; }
.md code { font-size: 12.5px; }

#gate { max-width: 420px; margin: 4rem auto; text-align: center; }

@media (max-width: 1100px) {
  .playground { grid-template-columns: minmax(0, 1fr); }
  .controls { display: grid; grid-template-columns: 1fr 1fr; }
}
@media (max-width: 900px) {
  #app { grid-template-columns: minmax(0, 1fr); }
  #picker { position: static; height: auto; max-height: 330px; border-right: none; border-bottom: 1px solid var(--line); }
  #main { padding: 12px 16px; }
}
@media (max-width: 620px) {
  .controls { grid-template-columns: 1fr; }
  .brand span { display: none; }
}

.li-flag { display: inline-block; font-size: 11.5px; font-weight: 600; color: var(--bad); border: 1px solid var(--bad); border-radius: 4px; padding: 0 6px; margin: 2px 0; }
p.flag { margin: 8px 0 0; padding: 8px 10px; border: 1px solid var(--bad); border-radius: 6px; color: var(--bad); font-weight: 600; }
.ctl-group label.small-switch { font-weight: 400; font-size: 12.5px; color: var(--fg2); }
.md svg { max-width: 100%; height: auto; }
.md table { display: block; overflow-x: auto; }
dialog#explained { overflow-x: hidden; }
