:root {
  color-scheme: light;
  --bg: #f6f7f9; --panel: #ffffff; --panel-2: #f1f3f6; --line: #dde1e7; --line-strong: #b9c1cc;
  --text: #1c2128; --muted: #5d6673; --faint: #8a93a0;
  --harm-bg: #fdecec; --harm-line: #e8a3a3; --harm-text: #a3262d;
  --blocked-bg: #e6f1fb; --blocked-line: #85b7eb; --blocked-text: #0c4a85;
  --allowed-bg: #e8f5e6; --allowed-line: #93c98a; --allowed-text: #24611a;
  --error-bg: #fbf0dc; --error-line: #e0b664; --error-text: #7a4b05;
  --gone-bg: #ececec; --gone-text: #6c6c6c;
  --accent: #e8452c;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1216; --panel: #171b21; --panel-2: #1e242c; --line: #2b323c; --line-strong: #46505d;
    --text: #e8ecf1; --muted: #9aa4b1; --faint: #6f7a87;
    --harm-bg: #3a1618; --harm-line: #7a2c30; --harm-text: #ff9da1;
    --blocked-bg: #0f2740; --blocked-line: #2f6aa6; --blocked-text: #9ccbff;
    --allowed-bg: #15301a; --allowed-line: #2f6b37; --allowed-text: #8fdb97;
    --error-bg: #33260d; --error-line: #6d521c; --error-text: #ffcc6b;
    --gone-bg: #262a30; --gone-text: #8b939e;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1216; --panel: #171b21; --panel-2: #1e242c; --line: #2b323c; --line-strong: #46505d;
  --text: #e8ecf1; --muted: #9aa4b1; --faint: #6f7a87;
  --harm-bg: #3a1618; --harm-line: #7a2c30; --harm-text: #ff9da1;
  --blocked-bg: #0f2740; --blocked-line: #2f6aa6; --blocked-text: #9ccbff;
  --allowed-bg: #15301a; --allowed-line: #2f6b37; --allowed-text: #8fdb97;
  --error-bg: #33260d; --error-line: #6d521c; --error-text: #ffcc6b;
  --gone-bg: #262a30; --gone-text: #8b939e;
}

* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100dvh; display: flex; flex-direction: column;
  background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
}
h1, h2, h3 { font-weight: 600; margin: 0; }
.hidden { display: none !important; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--faint); }

button {
  font: inherit; font-size: 14px; color: var(--text); cursor: pointer;
  background: var(--panel); border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 7px 12px; display: inline-flex; align-items: center; gap: 6px;
}
button:hover { background: var(--panel-2); }
button.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
button.primary:hover { opacity: .9; }
button.ghost { background: transparent; }
button.icon { padding: 7px 9px; }
button.small { font-size: 13px; padding: 5px 10px; }
button:disabled { opacity: .55; cursor: progress; }

/* Top bar */
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.logo { font-size: 26px; color: var(--accent); }
.brand { display: flex; flex-direction: column; line-height: 1.2; }
.title { font-weight: 700; font-size: 17px; }
.sub { color: var(--muted); font-size: 13px; }
.spacer { flex: 1; }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); cursor: pointer; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.track { width: 36px; height: 20px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line-strong); position: relative; transition: background .15s; }
.track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--muted); transition: transform .15s; }
.toggle input:checked + .track { background: var(--blocked-bg); border-color: var(--blocked-line); }
.toggle input:checked + .track::after { transform: translateX(16px); background: var(--blocked-text); }
.toggle input:focus-visible + .track { outline: 2px solid var(--blocked-line); outline-offset: 2px; }

/* Layout */
.layout { flex: 1; display: grid; grid-template-columns: 250px minmax(0, 1fr); }
.tray { border-right: 1px solid var(--line); padding: 16px; background: var(--panel); }
.stage { padding: 24px 28px 32px; display: flex; flex-direction: column; gap: 24px; max-width: 1200px; }

/* Tray */
.group-label { font-size: 12px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: .04em; margin: 18px 0 8px; }
.group-label:first-child { margin-top: 0; }
.chip {
  width: 100%; justify-content: flex-start; text-align: left; margin-bottom: 6px;
  border-color: var(--line); background: var(--panel); padding: 9px 11px;
}
.chip i { font-size: 18px; color: var(--muted); }
.chip .chip-text { display: flex; flex-direction: column; line-height: 1.25; flex: 1; min-width: 0; }
.chip .chip-req { font-family: var(--mono); font-size: 11px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body:not(.technical) .chip .chip-req { display: none; }
.chip.active { border: 2px solid var(--blocked-line); background: var(--blocked-bg); padding: 8px 10px; }
.chip.active i, .chip.active .chip-label { color: var(--blocked-text); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

/* Intro */
.intro h1 { font-size: 26px; margin-bottom: 10px; }
.intro p { color: var(--muted); max-width: 720px; font-size: 16px; }
.intro-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; margin: 20px 0; }
.intro-card { display: flex; gap: 14px; padding: 16px; border-radius: 12px; border: 1px solid; }
.intro-card i { font-size: 28px; }
.intro-card div { display: flex; flex-direction: column; gap: 4px; }
.intro-card span { font-size: 14px; }
.intro-card.bad { background: var(--harm-bg); border-color: var(--harm-line); color: var(--harm-text); }
.intro-card.good { background: var(--blocked-bg); border-color: var(--blocked-line); color: var(--blocked-text); }
.hint { display: flex; align-items: center; gap: 6px; }

/* Scenario */
.scenario h2 { font-size: 24px; }
.request-line { margin: 4px 0 14px; font-family: var(--mono); font-size: 13px; color: var(--faint); }
body:not(.technical) .request-line { display: none; }
.rulebook { display: flex; gap: 10px; align-items: flex-start; background: var(--panel-2); border-radius: 10px; padding: 12px 14px; margin-bottom: 18px; font-size: 15px; }
.rulebook i { font-size: 20px; color: var(--muted); margin-top: 1px; }

.panes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.pane { background: var(--panel); border: 2px solid var(--line); border-radius: 14px; padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; transition: border-color .2s; }
.pane > header { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.pane-title { font-weight: 600; font-size: 16px; }
.host { font-family: var(--mono); font-size: 12px; color: var(--faint); }
.pane.harm { border-color: var(--harm-line); }
.pane.blocked { border-color: var(--blocked-line); }
.pane.allowed { border-color: var(--allowed-line); }
.pane.error, .pane.unreachable { border-color: var(--error-line); }

.banner { border-radius: 10px; padding: 11px 13px; display: flex; gap: 10px; align-items: flex-start; font-size: 15px; min-height: 48px; }
.banner i { font-size: 22px; flex: none; }
.banner b { display: block; }
.banner.harm { background: var(--harm-bg); color: var(--harm-text); }
.banner.blocked { background: var(--blocked-bg); color: var(--blocked-text); }
.banner.allowed { background: var(--allowed-bg); color: var(--allowed-text); }
.banner.error, .banner.unreachable { background: var(--error-bg); color: var(--error-text); }
.banner.pending { background: var(--panel-2); color: var(--muted); }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Mini shop */
.promo { border-radius: 8px; padding: 6px 10px; font-size: 13px; font-weight: 600; background: var(--harm-bg); color: var(--harm-text); border: 1px dashed var(--harm-line); display: flex; gap: 6px; align-items: center; }
.products { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.product { border: 1px solid var(--line); border-radius: 10px; padding: 8px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 1px; position: relative; }
.product i { font-size: 22px; color: var(--muted); }
.product .name { font-size: 13px; font-weight: 500; }
.product .price { font-size: 12px; color: var(--muted); }
.product .tag { position: absolute; top: 4px; right: 4px; font-size: 10px; font-weight: 700; border-radius: 4px; padding: 1px 5px; }
.product.changed { border-color: var(--harm-line); background: var(--harm-bg); }
.product.changed .price, .product.changed .tag { color: var(--harm-text); }
.product.changed .tag { background: var(--panel); }
.product.gone { border: 1px dashed var(--harm-line); background: var(--gone-bg); }
.product.gone i, .product.gone .name { color: var(--gone-text); }
.product.gone .price { color: var(--harm-text); font-weight: 600; }
.product.focus:not(.changed):not(.gone) { border-color: var(--line-strong); }
.orders { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.order { border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; }
.order.gone { text-decoration: line-through; color: var(--harm-text); border-color: var(--harm-line); background: var(--harm-bg); }
.order.new { color: var(--allowed-text); border-color: var(--allowed-line); background: var(--allowed-bg); }
.pane-foot { font-size: 12.5px; color: var(--faint); display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; }
.pane-foot .expect { color: var(--error-text); }

/* Technical details */
.details { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 10px; }
.details summary { cursor: pointer; display: flex; align-items: center; gap: 8px; color: var(--muted); list-style: none; }
.details summary::-webkit-details-marker { display: none; }
.details summary i { transition: transform .15s; }
.details[open] summary i { transform: rotate(90deg); }
.details summary .mono { margin-left: auto; }
.details-body { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-top: 12px; }
.details h3 { font-size: 13px; color: var(--muted); font-weight: 600; margin: 12px 0 6px; }
.details h3:first-child { margin-top: 0; }
.details pre { background: var(--panel-2); border-radius: 8px; padding: 10px 12px; margin: 0 0 8px; white-space: pre-wrap; word-break: break-word; max-height: 260px; overflow: auto; }
.ok { color: var(--allowed-text); }
.no { color: var(--harm-text); }

/* Scoreboard */
.scoreboard { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; }
.scoreboard > header { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.scoreboard > header i { font-size: 20px; color: var(--muted); }
.scoreboard h2 { font-size: 18px; }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 14px; }
.metric { background: var(--panel-2); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; }
.metric span { font-size: 13px; color: var(--muted); }
.metric b { font-size: 26px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; color: var(--faint); font-weight: 600; padding: 6px 4px; }
td { border-top: 1px solid var(--line); padding: 8px 4px; }
.pill { display: inline-block; border-radius: 6px; padding: 2px 9px; font-size: 13px; font-weight: 500; }
.pill.harm { background: var(--harm-bg); color: var(--harm-text); }
.pill.blocked { background: var(--blocked-bg); color: var(--blocked-text); }
.pill.allowed { background: var(--allowed-bg); color: var(--allowed-text); }
.pill.error, .pill.unreachable { background: var(--error-bg); color: var(--error-text); }
.pill.pending { background: var(--panel-2); color: var(--muted); }

/* Legend */
.legend { display: flex; gap: 18px; flex-wrap: wrap; padding: 10px 20px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); background: var(--panel); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 12px; height: 12px; border-radius: 3px; border: 1px solid; display: inline-block; }
.sw.harm { background: var(--harm-bg); border-color: var(--harm-line); }
.sw.blocked { background: var(--blocked-bg); border-color: var(--blocked-line); }
.sw.allowed { background: var(--allowed-bg); border-color: var(--allowed-line); }
.sw.error { background: var(--error-bg); border-color: var(--error-line); }

/* Narrow screens: tray becomes a horizontal strip, panes stack */
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .tray { border-right: 0; border-bottom: 1px solid var(--line); }
  .tray-group { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
  .chip { width: auto; flex: none; margin: 0; }
  .stage { padding: 18px 16px 28px; }
  .panes, .details-body { grid-template-columns: minmax(0, 1fr); }
  .topbar { padding: 10px 16px; }
}
