:root {
  color-scheme: light;
  --ink: #0f172a;
  --muted: #475569;
  --line: #dbe3ef;
  --indigo: #4338ca;
  --surface: #fff;
  --page: #f1f5f9;
  font: 14px/1.45 system-ui, "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--page);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 16px; }
h2 { font-size: 22px; }
h3 { font-size: 15px; }
p { color: var(--muted); }
button, input, select, textarea { font: inherit; color: inherit; }
button, input, select, textarea {
  min-height: 34px; border: 1px solid #9daac0; border-radius: 8px; background: var(--surface);
}
button { padding: 5px 10px; font-weight: 650; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--indigo); background: #eef2ff; }
button:disabled { opacity: .54; cursor: default; }
input, select, textarea { min-width: 0; padding: 5px 8px; }
input[type="checkbox"] { min-height: 0; width: 17px; height: 17px; margin: 4px; accent-color: var(--indigo); }
textarea { resize: vertical; }
:focus-visible { outline: 3px solid #6366f1; outline-offset: 2px; }
.primary, .primary:hover:not(:disabled) { color: white; background: var(--indigo); border-color: var(--indigo); }
.primary:hover:not(:disabled) { background: #3730a3; }
.masthead {
  min-height: 64px; padding: 10px clamp(12px, 2vw, 28px); display: flex; gap: 12px;
  align-items: center; justify-content: space-between; flex-wrap: wrap; color: white; background: #0f172a;
}
.identity, .actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.identity { flex-wrap: nowrap; gap: 12px; }
.monogram {
  width: 36px; height: 36px; display: grid; place-items: center; border-radius: 11px;
  background: #5145df; font-size: 16px; font-weight: 850;
}
.brand-label, #user { font-size: 12px; color: #cbd5e1; }
.masthead button { color: white; border-color: #64748b; background: #1e293b; }
.masthead button:hover:not(:disabled) { color: var(--ink); }
.panel { border: 1px solid var(--line); background: var(--surface); border-radius: 15px; }
.login-view { margin: min(10vh, 90px) auto; width: min(420px, calc(100% - 32px)); }
.login-view form, dialog form { padding: 22px; display: grid; gap: 14px; }
label { display: grid; gap: 5px; font-weight: 650; }
.inline { display: flex; align-items: center; }
#message { padding: 10px 18px; color: #065f46; background: #ecfdf5; overflow-wrap: anywhere; }
#message.error, .dialog-error { color: #9f1239; background: #fff1f2; }
.dialog-error { padding: 8px; border-radius: 8px; }
#workspace { max-width: 1720px; margin: auto; padding: clamp(12px, 2vw, 26px); }
.workspace-heading, .panel-head, .batch {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap;
}
.workspace-heading p, .panel-head p { font-size: 12px; margin-top: 2px; }
#metrics {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin: 14px 0;
}
.metric { padding: 11px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.metric span { color: var(--muted); font-size: 12px; display: block; }
.metric strong { font-size: 22px; color: var(--indigo); font-variant-numeric: tabular-nums; }
.metric.warning strong { color: #92400e; }
.workbench { align-items: start; display: grid; grid-template-columns: 264px minmax(0, 1fr); gap: 14px; }
.navigation { padding: 12px; }
.navigation h3 { margin: 0 0 8px; }
.world { background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; margin: 7px 0; padding: 5px; }
.world:last-child { margin-bottom: 0; }
.scope, .island-scope {
  width: 100%; border: 1px solid transparent; text-align: left; background: transparent;
  display: flex; justify-content: space-between; align-items: center; gap: 6px; padding: 4px 6px;
}
.scope { font-size: 12px; }
.island-scope { font-size: 11px; font-weight: 600; min-height: 30px; }
button[aria-pressed="true"], button[aria-pressed="true"]:hover:not(:disabled) {
  background: var(--indigo); color: white;
}
.island { display: flex; align-items: center; gap: 4px; padding-left: 5px; }
.count { white-space: nowrap; font-variant-numeric: tabular-nums; }
.empty-island .count { color: #92400e; background: #fef3c7; border-radius: 5px; padding: 1px 4px; }
.switch {
  flex: 0 0 44px; width: 44px; min-height: 27px; padding: 2px 3px; border-radius: 20px;
  background: #fff; color: #475569; font-size: 11px;
}
.switch[aria-checked="true"] { background: #eef2ff; border-color: #6366f1; color: #3730a3; }
.card-panel { min-width: 0; }
.card-panel > .panel-head { padding: 12px 14px; justify-content: flex-start; }
.card-panel > .panel-head button { margin-left: auto; }
#filters, .batch { border: 0; margin: 0; padding: 8px 14px; border-top: 1px solid var(--line); }
#filters { display: flex; flex-wrap: wrap; gap: 8px; }
#search { flex: 1 1 210px; }
.batch { background: #f5f7ff; color: #3730a3; font-size: 12px; }
.table-scroll { overflow: auto; }
table { border-collapse: collapse; width: 100%; min-width: 760px; text-align: left; font-size: 12px; }
th, td { padding: 8px; border-top: 1px solid var(--line); vertical-align: middle; }
th { color: #34435b; background: #f8fafc; white-space: nowrap; }
th:first-child, td:first-child { padding-left: 12px; }
tr:hover td { background: #f8fafc; }
.card-title { min-width: 180px; }
.card-meta { display: block; color: #4338ca; margin-bottom: 2px; font: 11px ui-monospace, monospace; }
.tag { display: inline-block; border-radius: 7px; padding: 3px 6px; white-space: nowrap; background: #dcfce7; color: #166534; }
.tag.warn, select.warn { background: #fef3c7; color: #854d0e; }
.tag.fix { background: #ffe4e6; color: #9f1239; }
.note { min-width: 75px; max-width: 200px; overflow-wrap: anywhere; }
.empty { padding: 20px; }
dialog { width: min(470px, calc(100% - 24px)); max-height: 86vh; border: 1px solid var(--line); border-radius: 15px; color: var(--ink); padding: 0; }
dialog::backdrop { background: #0f172a99; }
dialog.wide { width: min(760px, calc(100% - 24px)); padding: 14px; }
dialog .actions { justify-content: flex-end; }
.positions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
#logs { padding-left: 28px; }
#logs li { margin: 6px 0; }
#logs button { width: 100%; text-align: left; }
#log-detail { white-space: pre-wrap; overflow-wrap: anywhere; background: #f1f5f9; padding: 10px; }
@media (max-width: 950px) {
  .workbench { grid-template-columns: 220px minmax(0, 1fr); }
}
@media (max-width: 690px) {
  #metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workbench { grid-template-columns: minmax(0, 1fr); }
  #tree { max-height: 230px; overflow: auto; }
  .workspace-heading { align-items: flex-start; }
  .batch .actions { flex: 1 0 100%; }
}
