:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1c1f24;
  --muted: #5b6370;
  --line: #d9dce1;
  --accent: #2357c5;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --ok: #1d7a3a;
  --warn: #9a6200;
  --focus: #ff9e1b;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171b;
    --panel: #1e2127;
    --text: #e7e9ec;
    --muted: #a3aab5;
    --line: #343943;
    --accent: #7aa2ff;
    --accent-text: #0d1220;
    --danger: #ff8a80;
    --ok: #6fd08c;
    --warn: #f3c25b;
  }
}

* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, sans-serif; background: var(--bg); color: var(--text); }
h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .5rem; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; background: var(--panel); padding: .5rem; z-index: 10; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 1.25rem; }
.login .card { width: min(360px, 100%); display: grid; gap: .75rem; }

label { display: grid; gap: .25rem; color: var(--muted); font-size: .9rem; }
input, select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: .4rem .55rem; }

.btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 6px; padding: .35rem .8rem; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.small { padding: .15rem .5rem; font-size: .85rem; }
.link { font: inherit; background: none; border: 0; color: var(--accent); cursor: pointer; text-decoration: underline; padding: 0; }

.app { display: grid; grid-template-columns: 200px 1fr; min-height: 100vh; }
.nav { background: var(--panel); border-right: 1px solid var(--line); padding: 1rem; display: flex; flex-direction: column; gap: 1rem; }
.nav ul { list-style: none; margin: 0; padding: 0; display: grid; gap: .25rem; }
.nav a { display: block; padding: .4rem .6rem; border-radius: 6px; text-decoration: none; color: var(--text); }
.nav a[aria-current="page"] { background: var(--accent); color: var(--accent-text); }
.brand { font-weight: 700; margin: 0; }
.who { margin-top: auto; color: var(--muted); font-size: .9rem; }
main { padding: 1.5rem; min-width: 0; }

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .nav { border-right: 0; border-bottom: 1px solid var(--line); }
  .nav ul { grid-auto-flow: column; overflow-x: auto; }
  main { padding: 1rem 16px; }
}

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .75rem; }
.stat .k { color: var(--muted); font-size: .85rem; }
.stat .v { font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; }

.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: .75rem; margin-top: .75rem; }
.chart svg { width: 100%; height: 60px; display: block; }
.chart polyline { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }

.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .85rem; }
tr:last-child td { border-bottom: 0; }
td.data { font-family: ui-monospace, monospace; font-size: .8rem; max-width: 40ch; overflow-wrap: anywhere; }

.filters { display: flex; flex-wrap: wrap; gap: .75rem; align-items: end; margin-bottom: .75rem; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.pager { margin-top: .75rem; }

.badge { display: inline-block; padding: 0 .45rem; border-radius: 999px; font-size: .8rem; border: 1px solid currentColor; }
.badge.ok { color: var(--ok); }
.badge.bad { color: var(--danger); }
.badge.warn { color: var(--warn); }
.badge.muted { color: var(--muted); }

meter { width: 120px; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 0; }

.detail { margin-top: 1rem; }
.detail pre { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: .75rem; overflow: auto; max-height: 50vh; font-size: .8rem; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

.toast { position: fixed; right: 16px; bottom: 16px; margin: 0; max-width: calc(100% - 32px); }
.toast:not(:empty) { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .6rem .9rem; box-shadow: 0 4px 16px #0003; }
.toast.err { color: var(--danger); }

dialog { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); max-width: min(420px, calc(100% - 32px)); }
dialog::backdrop { background: #0007; }

/* Editor */
.tabs { display: flex; gap: .25rem; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 1rem; }
.tabs a { padding: .4rem .8rem; text-decoration: none; color: var(--text); border-radius: 6px 6px 0 0; }
.tabs a[aria-current="page"] { background: var(--panel); border: 1px solid var(--line); border-bottom-color: var(--panel); margin-bottom: -1px; font-weight: 600; }
.tabs.sub { border: 0; }
.tabs.sub a { border-radius: 999px; border: 1px solid var(--line); }
.tabs.sub a[aria-current="page"] { background: var(--accent); color: var(--accent-text); margin: 0; }
.banner { background: var(--panel); border: 1px solid var(--warn); color: var(--text); border-radius: 8px; padding: .5rem .75rem; margin-bottom: .75rem; display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.ed-error { color: var(--danger); white-space: pre-wrap; margin: 0 0 .75rem; font-size: .85rem; }
.ed-error:empty { display: none; }
.num { width: 6.5em; }
textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: .4rem .55rem; width: 100%; }
label.check { display: flex; gap: .4rem; align-items: center; }
.ed-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .75rem; align-content: start; }
.ed-fields .wide { grid-column: 1 / -1; }
#edItem { max-width: min(560px, calc(100% - 32px)); width: 100%; }
#edItem form { display: grid; gap: .75rem; }
#edItem h2 { margin: 0; }

.ed-graph { width: 100%; height: auto; display: block; margin-bottom: 1rem; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.ed-graph rect.zone { fill: var(--bg); stroke: var(--muted); stroke-width: 1.5; }
.ed-graph a:hover rect.zone, .ed-graph a:focus rect.zone { stroke: var(--accent); stroke-width: 3; }
.ed-graph a:focus { outline: none; }
.ed-graph .portal { fill: var(--accent); }
.ed-graph .edges line { stroke: var(--accent); stroke-width: 1.5; opacity: .7; }
.ed-graph marker path { fill: var(--accent); }
.ed-graph text { fill: var(--text); font-size: 13px; }
.ed-graph text.name { font-weight: 600; }
.ed-graph text.sub { fill: var(--muted); font-size: 11px; }

.zone-layout { display: grid; grid-template-columns: minmax(0, 560px) minmax(260px, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 900px) { .zone-layout { grid-template-columns: 1fr; } }
.zone-map { width: 100%; height: auto; display: block; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.zone-map.placing { cursor: crosshair; outline: 3px solid var(--focus); }
.zone-map .bounds { fill: var(--bg); stroke: var(--muted); stroke-width: 2; vector-effect: non-scaling-stroke; }
.zone-map .area { fill: var(--warn); fill-opacity: .12; stroke: var(--warn); stroke-dasharray: 6 4; vector-effect: non-scaling-stroke; }
.zone-map text { fill: var(--text); }
.zone-map .portal circle { fill: var(--accent); fill-opacity: .3; stroke: var(--accent); vector-effect: non-scaling-stroke; }
.zone-map .spawn circle { fill: var(--ok); }
.zone-map .lore circle { fill: var(--text); }
.zone-map .lore .range { fill: var(--ok); fill-opacity: .08; stroke: var(--ok); stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; }
.zone-map .lore.auto .range { fill-opacity: .2; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
input.mod { width: 7em; padding: .2rem .4rem; font-variant-numeric: tabular-nums; }
input[aria-invalid="true"] { border-color: var(--danger); outline: 2px solid var(--danger); }
th .badge { font-weight: 400; margin-top: .15rem; }

/* -- Skin editor ------------------------------------------------------------- */
.sk-bar { margin-bottom: .75rem; }
.sk-play { margin-left: auto; display: flex; gap: .4rem; align-items: center; }
.sk-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 1rem; align-items: start; }
#skFrame { width: 100%; height: calc(100vh - 170px); min-height: 480px; border: 1px solid var(--line); border-radius: 8px; background: #000; }
.sk-side { display: grid; gap: .75rem; max-height: calc(100vh - 170px); overflow-y: auto; }
.sk-side h2 { margin-top: 0; }
.sk-side .ed-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.sk-side > * { min-width: 0; }
.sk-side :is(input:not([type=checkbox]):not([type=file]), select) { width: 100%; min-width: 0; }
.sk-side input[type=search] { width: 100%; margin-bottom: .5rem; }
.sk-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.sk-list button { width: 100%; text-align: left; font: inherit; color: var(--text); background: none; border: 0; border-radius: 6px; padding: .25rem .5rem; cursor: pointer; }
.sk-list button:hover { background: var(--bg); }
.sk-list button[aria-current=true] { background: var(--accent); color: var(--accent-text); }
.sk-list button[aria-current=true] .muted { color: inherit; }
.sk-img { display: grid; place-items: center; min-height: 64px; margin: .5rem 0; border-radius: 6px;
  background: repeating-conic-gradient(#8884 0 25%, transparent 0 50%) 0 0 / 16px 16px; }
.sk-img img { max-width: 100%; max-height: 160px; }
.sk-drop { display: block; border: 2px dashed var(--line); border-radius: 8px; padding: .75rem; margin-bottom: .75rem; cursor: pointer; }
.sk-drop.over { border-color: var(--accent); }
.sk-drop input { display: block; margin-top: .5rem; max-width: 100%; }
.sk-check { display: flex; gap: .4rem; align-items: center; }
[aria-pressed=true].btn { border-color: var(--accent); font-weight: 600; }
@media (max-width: 1000px) { .sk-layout { grid-template-columns: 1fr; } .sk-side { max-height: none; } }