:root {
  --bg: #14161c;
  --panel: #1d2029;
  --panel2: #262a36;
  --border: #363c4d;
  --text: #d8dce8;
  --muted: #8b93a7;
  --accent: #d4a24a;
  --accent2: #7aa2f7;
  --danger: #e06c75;
  --ok: #98c379;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
header {
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; flex-wrap: wrap; align-items: center; gap: 16px;
  background: var(--panel);
  position: sticky; top: 0; z-index: 20;
}
h1 { font-size: 18px; margin: 0; color: var(--accent); white-space: nowrap; }
h2 { font-size: 15px; margin: 0 0 10px; color: var(--accent2); }
h3 { font-size: 13px; margin: 16px 0 6px; color: var(--muted); font-weight: 600; }

.server-row { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 320px; }
.server-row label { color: var(--muted); }
#serverUrl { flex: 0 1 320px; }
.status { color: var(--muted); font-variant-numeric: tabular-nums; }
.status.running { color: var(--accent); }
.status.ok { color: var(--ok); }
.status.err { color: var(--danger); }

main {
  display: grid;
  grid-template-columns: minmax(430px, 1fr) minmax(430px, 1.1fr);
  gap: 14px; padding: 14px; align-items: start;
}
@media (max-width: 980px) { main { grid-template-columns: 1fr; } }
.col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
}
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.section-head h2 { margin: 0; }

input, select, textarea, button {
  font: inherit; color: var(--text);
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 5px 8px;
}
input:focus, select:focus, textarea:focus { outline: 1px solid var(--accent2); }
input[type="checkbox"] { accent-color: var(--accent); }
input[type="number"] { width: 90px; }
code { color: var(--accent); background: var(--panel2); padding: 0 4px; border-radius: 3px; }

button { cursor: pointer; }
button:hover { border-color: var(--accent2); }
button.primary { background: var(--accent); color: #1a1405; font-weight: 600; border-color: var(--accent); }
button.danger { color: var(--danger); }
button.small { padding: 3px 8px; font-size: 12.5px; }
button:disabled { opacity: .5; cursor: wait; }

.grid-fields { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-bottom: 8px; }
.grid-fields label { display: flex; flex-direction: column; gap: 3px; color: var(--muted); font-size: 12.5px; }
.grid-fields label.wide { flex: 1 1 100%; }
.check-row { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--muted); }
.check-row label { display: flex; align-items: center; gap: 6px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 4px 0 8px; }

.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; }
.tab {
  background: transparent; border: 1px solid var(--border);
  border-radius: 5px 5px 0 0; padding: 4px 12px; color: var(--muted);
}
.tab.active { background: var(--panel2); color: var(--text); border-bottom-color: var(--accent); }
.zone-tabs { margin-top: 8px; }
.tab .count { color: var(--accent); margin-left: 5px; font-size: 11.5px; }

.search-row { display: flex; align-items: center; gap: 10px; }
#cardSearch { flex: 1; }
.search-results {
  border: 1px solid var(--border); border-radius: 5px; margin-top: 4px;
  max-height: 220px; overflow-y: auto; background: var(--panel2);
}
.search-results div { padding: 5px 10px; cursor: pointer; }
.search-results div:hover, .search-results div.sel { background: var(--border); }

.card-list, .cast-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.card-list li, .cast-list li {
  display: flex; align-items: center; gap: 6px;
  background: var(--panel2); border: 1px solid var(--border);
  border-radius: 5px; padding: 4px 8px;
}
.card-list .cname { flex: 1; cursor: pointer; }
.card-list .cname:hover { color: var(--accent2); }
.badges { display: flex; gap: 4px; }
.badge {
  font-size: 11px; padding: 0 6px; border-radius: 8px;
  background: var(--border); color: var(--text); white-space: nowrap;
}
.badge.tapped { background: #5a4a1e; }
.badge.cmd { background: #4a3a5e; }
.icon-btn { background: none; border: none; padding: 2px 4px; color: var(--muted); }
.icon-btn:hover { color: var(--text); }
.empty { color: var(--muted); font-style: italic; padding: 6px 2px; }

.cast-list select, .cast-list input { background: var(--panel); }
.cast-list .cast-card { flex: 2; min-width: 100px; }
.cast-list .cast-target { flex: 1.4; min-width: 80px; }
.cast-list .stack-pos { color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.cast-list .act-index { width: 62px; }
.cast-list .act-color { width: 80px; }
.kind-chip {
  font-size: 11px; padding: 1px 8px; border-radius: 8px;
  color: var(--text); white-space: nowrap;
}
.chip-cast { background: #4a3a5e; }
.chip-act { background: #1e4a5a; }

.json-details summary {
  cursor: pointer; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
}
.json-details summary h2 { display: inline; margin: 0; }
.json-details summary .hint { margin: 0; }
.json-details summary:hover h2 { color: var(--accent); }
.json-toolbar { display: flex; gap: 8px; margin: 12px 0 8px; }

#jsonArea {
  width: 100%; min-height: 260px; resize: vertical;
  font: 12.5px/1.4 ui-monospace, "Cascadia Code", Menlo, monospace;
  white-space: pre; tab-size: 2;
}
.error {
  color: var(--danger); background: #3a2027; border: 1px solid var(--danger);
  border-radius: 5px; padding: 8px 10px; margin-top: 8px;
  white-space: pre-wrap; word-break: break-word;
}

.results .tabs { margin-bottom: 0; }
.result-pane { width: 100%; min-height: 480px; margin-top: 10px; }
#reportFrame { border: 1px solid var(--border); border-radius: 5px; background: #fff; height: 70vh; }
#rawPre {
  overflow: auto; max-height: 70vh; background: var(--panel2);
  border: 1px solid var(--border); border-radius: 5px; padding: 10px;
  font: 12px/1.4 ui-monospace, Menlo, monospace;
}
#summaryDiv { overflow: auto; max-height: 70vh; }
#summaryDiv .outcome { font-size: 16px; color: var(--accent); margin: 8px 0; }
#summaryDiv table { border-collapse: collapse; width: 100%; margin: 8px 0 16px; }
#summaryDiv th, #summaryDiv td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; }
#summaryDiv th { background: var(--panel2); color: var(--muted); }
#summaryDiv td.kind { color: var(--accent2); white-space: nowrap; }
#summaryDiv td.mana { white-space: nowrap; }
.pip {
  display: inline-block; width: 17px; height: 17px; line-height: 17px;
  border-radius: 50%; text-align: center;
  font-size: 11px; font-weight: 700; margin-right: 2px;
}
.pip-W { background: #f9f7e0; color: #3a3320; }
.pip-U { background: #3a6ea5; color: #fff; }
.pip-B { background: #2b2b2b; color: #e8e8e8; border: 1px solid #555; }
.pip-R { background: #b5482e; color: #fff; }
.pip-G { background: #2e7d4f; color: #fff; }
.pip-C { background: #9aa0a6; color: #14161c; }
.pip-X { background: var(--border); color: var(--text); border-radius: 5px; width: auto; padding: 0 5px; }
#summaryDiv pre {
  background: var(--panel2); border: 1px solid var(--border); border-radius: 5px;
  padding: 8px; overflow: auto; font-size: 12px;
}

dialog {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  max-width: 540px; width: 92%;
}
dialog::backdrop { background: rgba(0,0,0,.6); }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

#cardPreview {
  position: fixed; z-index: 50; pointer-events: none;
}
#cardPreview img { width: 244px; border-radius: 12px; box-shadow: 0 4px 24px rgba(0,0,0,.7); display: block; }
