:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #eef0ea;
  --border: #dcdfd6;
  --text: #1d2119;
  --muted: #646b5c;
  --accent: #4f7f2a;
  --accent-ink: #ffffff;
  --accent-soft: #e3eed8;
  --danger: #b3261e;
  --danger-soft: #f9e1df;
  --warn: #9a6400;
  --warn-soft: #fbefd6;
  --ok: #2e7d32;
  --console-bg: #15181a;
  --console-text: #d6dbd2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 1px 1px rgba(0, 0, 0, .04);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121411;
    --surface: #1a1d18;
    --surface-2: #22261f;
    --border: #2f342b;
    --text: #e6e9e2;
    --muted: #9aa190;
    --accent: #7cb342;
    --accent-ink: #0f1a06;
    --accent-soft: #263420;
    --danger: #ef6b5f;
    --danger-soft: #3a1f1c;
    --warn: #e0a83a;
    --warn-soft: #3a2f17;
    --ok: #81c784;
    --console-bg: #0c0e0c;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 15px; margin: 0 0 12px; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 4px 8px 16px; }
.brand img { width: 26px; height: 26px; image-rendering: pixelated; border-radius: 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px;
  color: var(--text); text-decoration: none;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav svg { width: 18px; height: 18px; flex: none; }
.sidebar .spacer { flex: 1; }
.sidebar .who { color: var(--muted); font-size: 12px; padding: 0 10px 8px; }
main { padding: 24px 28px 48px; min-width: 0; max-width: 1200px; }
.topbar { display: none; }

@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 30% 0 0; z-index: 20; transform: translateX(-100%); transition: transform .2s; height: 100%; }
  .shell.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .topbar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 10; }
  main { padding: 16px; }
}

/* ---------- components ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--muted); font-size: 12px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 12px; border-radius: 8px; font: inherit; cursor: pointer; text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 4px 8px; font-size: 12px; }
.btn svg { width: 16px; height: 16px; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
input[type=range] { padding: 0; accent-color: var(--accent); }
textarea { font-family: var(--mono); font-size: 12.5px; min-height: 360px; resize: vertical; tab-size: 2; }
label.field { display: flex; flex-direction: column; gap: 4px; }
label.field > span { font-size: 12px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 16px; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: var(--accent-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; white-space: nowrap; }
.table-wrap { overflow-x: auto; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { background: none; border: 0; padding: 8px 12px; font: inherit; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-radius: var(--radius); background: var(--warn-soft); color: var(--warn); margin-bottom: 16px; flex-wrap: wrap; }

.console {
  background: var(--console-bg); color: var(--console-text);
  border-radius: var(--radius); padding: 12px; height: calc(100vh - 230px); min-height: 300px;
  overflow-y: auto; font-family: var(--mono); font-size: 12.5px; line-height: 1.45;
  white-space: pre-wrap; word-break: break-word;
}
.console .warn { color: #e6c06a; }
.console .error { color: #ff8a80; }
.console .cmd { color: #9ccc65; }
.console .resp { color: #90caf9; }
.console-input { display: flex; gap: 8px; margin-top: 10px; }
.console-input input { font-family: var(--mono); }

.player { display: flex; align-items: center; gap: 10px; }
.player img { width: 24px; height: 24px; border-radius: 4px; image-rendering: pixelated; background: var(--surface-2); }

.plugin-card { display: flex; gap: 12px; align-items: flex-start; }
.plugin-card img { width: 40px; height: 40px; border-radius: 8px; background: var(--surface-2); flex: none; object-fit: cover; }
.plugin-card .body { flex: 1; min-width: 0; }
.plugin-card .desc { color: var(--muted); font-size: 13px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.crumbs { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.crumbs button { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 2px 4px; }
.file-name { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.file-name svg { width: 16px; height: 16px; color: var(--muted); flex: none; }

.map-frame { width: 100%; height: calc(100vh - 160px); min-height: 400px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; }
.login .brand { justify-content: center; font-size: 18px; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 8px; padding: 10px 14px; box-shadow: 0 6px 24px rgba(0,0,0,.15); white-space: pre-wrap; }
.toast.error { border-left-color: var(--danger); }

.meter { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.meter > div { height: 100%; background: var(--accent); }
.empty { color: var(--muted); padding: 24px; text-align: center; }
pre.preview { background: var(--surface-2); padding: 12px; border-radius: 8px; overflow-x: auto; margin: 0; }
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 20px; max-width: 440px; width: calc(100% - 32px); }
dialog::backdrop { background: rgba(0,0,0,.4); }
