:root {
  --bg: #0E1014;
  --panel: #161920;
  --panel-2: #1D212A;
  --line: #2A2F3A;
  --text: #E8EAEE;
  --muted: #8F96A3;
  --amber: #F2A93B;
  --amber-ink: #1A1306;
  --blue: #6FA8FF;
  --green: #5BC48A;
  --red: #FF6B6B;
  --radius: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel-2); border-radius: 8px; padding: 7px 14px; }
button:hover { border-color: #3A4150; }
a.button { display: inline-block; border: 1px solid var(--line); background: var(--panel-2); border-radius: 8px; padding: 7px 14px; color: var(--text); text-decoration: none; }
a.button:hover { border-color: #3A4150; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--amber); color: var(--amber-ink); border-color: var(--amber); font-weight: 600; }
button.primary:hover { filter: brightness(1.06); }
button.ghost { background: transparent; }
button.small { padding: 3px 10px; font-size: 13px; }
button.danger { color: var(--red); border-color: #5a2a2a; background: transparent; }
input, select { background: #0F1217; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
label.check { flex-direction: row; align-items: center; color: var(--text); }
label.check input { width: auto; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; align-items: flex-end; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; }
.hint { color: var(--muted); font-size: 12px; margin: 0; }
.error { color: var(--red); min-height: 1.2em; margin: 0; font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.chip { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.chip.amber { color: var(--amber); border-color: #5c4318; }
.chip.blue { color: var(--blue); border-color: #23395c; }
.chip.green { color: var(--green); border-color: #1f4a33; }
.chip.red { color: var(--red); border-color: #5a2a2a; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 30px; height: 30px; }
.brand div { display: flex; flex-direction: column; line-height: 1.2; }
.brand span { color: var(--muted); font-size: 12px; }

/* Sign-in */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(ellipse at 30% 0%, #2a2214 0%, transparent 55%), radial-gradient(ellipse at 90% 100%, #132034 0%, transparent 50%), var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; display: flex; flex-direction: column; gap: 20px; }
.tabs { display: flex; background: #0F1217; border-radius: 9px; padding: 3px; }
.tabs button { flex: 1; border: 0; background: transparent; color: var(--muted); }
.tabs button.on { background: var(--panel-2); color: var(--text); }

/* Workbench */
.app { display: flex; flex-direction: column; height: 100%; }
.top { display: flex; align-items: center; gap: 24px; padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav button { border: 0; background: transparent; color: var(--muted); white-space: nowrap; }
.nav button.on { color: var(--text); background: var(--panel-2); }
.who { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.main { flex: 1; display: flex; min-height: 0; }
.list { flex: 1; overflow-y: auto; padding: 18px 20px 40px; min-width: 0; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input[type=search] { width: 200px; }
.spacer { flex: 1; }
.seg { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 3px; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 5px 12px; }
.seg button.on { background: var(--panel-2); color: var(--text); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; display: flex; flex-direction: column; text-align: left; padding: 0; }
.card:hover { border-color: #444b5a; }
.card.sel { border-color: var(--amber); }
.thumb { aspect-ratio: 4 / 3; background: #0B0D11 center / cover no-repeat; position: relative; display: grid; place-items: center; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .glyph { font-size: 34px; color: #3a4150; }
.thumb .badge { position: absolute; left: 8px; top: 8px; }
.thumb .vis { position: absolute; right: 8px; top: 8px; }
.card .meta { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; }
.card .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .sub { color: var(--muted); font-size: 12px; display: flex; gap: 6px; align-items: center; white-space: nowrap; overflow: hidden; }
.empty { color: var(--muted); text-align: center; padding: 60px 0; }
.more { text-align: center; margin-top: 18px; }

.jobs { display: flex; flex-direction: column; gap: 8px; }
.job { display: grid; grid-template-columns: 64px 1fr auto; gap: 14px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
.job .thumb { aspect-ratio: 1; border-radius: 8px; }
.job .title { font-weight: 600; }
.job .sub { color: var(--muted); font-size: 12px; }

/* Detail */
.detail { width: 440px; border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; position: relative; min-height: 0; }
.close { position: absolute; right: 10px; top: 10px; z-index: 2; width: 32px; height: 32px; padding: 0; border-radius: 50%; background: rgba(14,16,20,.7); font-size: 20px; line-height: 1; }
.stage { height: 340px; background: radial-gradient(ellipse at 50% 30%, #252a35 0%, #0B0D11 75%); position: relative; flex-shrink: 0; }
.stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.stage img { width: 100%; height: 100%; object-fit: contain; }
.stage .overlay { position: absolute; left: 12px; bottom: 10px; display: flex; gap: 6px; }
.stage .overlay button { background: rgba(14,16,20,.75); }
.stage .loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.detail-body { padding: 18px 20px 28px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.detail-body h2 { margin: 0; font-size: 18px; }
.kv { display: grid; grid-template-columns: 76px 1fr; gap: 6px 10px; font-size: 13px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.section-title { font-size: 12px; color: var(--muted); margin: 0 0 8px; }
.mini-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mini-grid .card .meta { padding: 6px 8px; }
.mini-grid .card .title { font-size: 12px; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 24px; width: min(460px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(5,6,8,.7); }
dialog h2 { margin: 0; font-size: 18px; }
.drop { border: 1.5px dashed var(--line); border-radius: 10px; min-height: 150px; display: grid; place-items: center; text-align: center; cursor: pointer; position: relative; overflow: hidden; padding: 0; }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop img { max-height: 200px; max-width: 100%; }
.drop.over { border-color: var(--amber); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #252a35; border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.4); z-index: 10; max-width: calc(100vw - 32px); }

@media (max-width: 860px) {
  .top { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  .nav { order: 3; flex-basis: 100%; }
  .brand span { display: none; }
  .list { padding: 14px 16px 32px; }
  .toolbar input[type=search] { width: 100%; order: 5; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .detail { position: fixed; inset: 0; width: auto; z-index: 5; border: 0; }
  .stage { height: 46vh; }
}

/* Scene editor */
body.editing { overflow: hidden; }
.editor { position: fixed; inset: 0; z-index: 8; background: var(--bg); display: flex; flex-direction: column; }
.ed-top { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
.ed-title { width: 260px; font-weight: 600; }
.ed-status { white-space: nowrap; }
.ed-body { flex: 1; display: flex; min-height: 0; }
.ed-left, .ed-right { width: 260px; background: var(--panel); padding: 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; flex-shrink: 0; }
.ed-left { border-right: 1px solid var(--line); }
.ed-right { border-left: 1px solid var(--line); }
.ed-left h3, .ed-right h3 { margin: 4px 0 0; font-size: 13px; color: var(--muted); font-weight: 600; }
.ed-view { flex: 1; position: relative; min-width: 0; }
.ed-view canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.ed-modes { position: absolute; left: 12px; top: 12px; display: flex; gap: 6px; }
.ed-modes button { background: rgba(22,25,32,.85); }
.ed-modes button.on, .ed-modes button.on:hover { border-color: var(--amber); color: var(--amber); }
.ed-lib { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ed-item { display: flex; flex-direction: column; gap: 4px; }
.ed-add { padding: 0; overflow: hidden; display: flex; flex-direction: column; text-align: left; }
.ed-add .thumb { aspect-ratio: 1; width: 100%; }
.ed-add span { font-size: 12px; padding: 4px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ed-outline { display: flex; flex-direction: column; gap: 2px; }
.ed-row { text-align: left; border: 0; background: transparent; padding: 5px 8px; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ed-trial { margin-top: 12px; border-top: 1px solid var(--line, #2f3542); padding-top: 8px; }
.rng-patrol { color: #4fd18b; } .rng-chase { color: #f2a93b; } .rng-attack { color: #ff5c5c; }
.ed-row.on { background: var(--panel-2); color: var(--amber); }
.ed-name { margin: 0; font-weight: 600; }
.ed-grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.ed-grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.ed-grid3 input, .ed-grid2 input { padding: 6px 8px; }
@media (max-width: 860px) {
  .ed-left { display: none; }
  .ed-right { position: absolute; right: 0; bottom: 0; left: 0; width: auto; max-height: 40vh; border-left: 0; border-top: 1px solid var(--line); }
  .ed-body { position: relative; }
  .ed-title { width: 140px; }
}

/* official content */
.official { flex: 1; overflow-y: auto; padding: 18px 20px 40px; min-width: 0; }
.official h2 { margin: 4px 0 4px; font-size: 18px; }
.official h3 { margin: 0; font-size: 15px; flex: 1; }
.official-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; margin-top: 14px; align-items: start; }
.official-list, .official-detail { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.official-stage { height: 300px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.official .table { width: 100%; border-collapse: collapse; font-size: 13px; }
.official .table th, .official .table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.official .table th { color: var(--muted); font-weight: 500; }
.official .table tr.sel td { background: var(--panel-2); }
.official fieldset { border: 0; padding: 0; margin: 0; }
.official fieldset[disabled] { opacity: .85; }
.official label { display: flex; flex-direction: column; gap: 4px; flex: 1; font-size: 13px; }
.official .card-form { max-width: 420px; margin-top: 20px; }
@media (max-width: 900px) { .official-split { grid-template-columns: 1fr; } }

/* assembled 3D views (homes, official scenes, terrains) */
.homes { display: flex; flex-direction: column; }
.hv-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.hv-head h2 { margin: 0; font-size: 18px; }
.hv-tools { align-items: center; }
.hv-body { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; flex: 1; min-height: 520px; }
.hv-stage { position: relative; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; min-height: 520px; }
.hv-stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.hv-stage .loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.hv-side { display: flex; flex-direction: column; gap: 14px; overflow-y: auto; max-height: calc(100vh - 160px); }
.hv-list { display: flex; flex-direction: column; gap: 4px; max-height: 260px; overflow-y: auto; }
.hv-item { text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 13px; }
button.hv-item:hover { border-color: #444b5a; }
.note-line { margin: 0; font-size: 12px; color: var(--muted); border-left: 2px solid var(--amber); padding-left: 8px; }
.hv-dialog { width: min(720px, 94vw); background: var(--bg, #0e1014); color: inherit; border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.hv-dialog::backdrop { background: rgba(0,0,0,.6); }
.hv-dialog .stage { margin: 10px 0; }
.stage .overlay { flex-wrap: wrap; right: 12px; }
@media (max-width: 900px) { .hv-body { grid-template-columns: 1fr; } .hv-stage { min-height: 360px; } .hv-side { max-height: none; } }
.hv-tools { flex-wrap: wrap; justify-content: flex-end; }
.hv-tools .seg button { white-space: nowrap; }
.hv-search { width: 340px; max-width: 100%; }
.hv-tools select { width: auto; }
.problems { margin: 8px 0; padding-left: 20px; color: var(--red); font-size: 13px; display: flex; flex-direction: column; gap: 4px; }

/* moderation centre */
textarea { font: inherit; color: inherit; background: #0F1217; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; resize: vertical; }
textarea:focus { outline: 2px solid var(--blue); outline-offset: 1px; }
.moderation .mod-reason { max-width: 280px; overflow-wrap: anywhere; }
.moderation .mod-quote { margin: 0; padding: 10px 12px; border-left: 3px solid var(--amber); background: var(--panel); border-radius: 0 8px 8px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.moderation .kv dd { overflow-wrap: anywhere; }
.mod-dialog { width: min(520px, calc(100vw - 32px)); }
.mod-dialog .hint { font-size: 13px; line-height: 1.6; }
.moderation .kv { grid-template-columns: 96px 1fr; }
.moderation .table th { white-space: nowrap; }

/* players */
.pl-list { display: flex; flex-direction: column; gap: 8px; }
.pl-row { display: grid; grid-template-columns: 96px minmax(0, 1fr) auto; gap: 14px; align-items: center; text-align: left; padding: 8px; border-radius: 12px; }
.pl-row .thumb.small { aspect-ratio: 4 / 3; border-radius: 8px; }
.pl-row .title { font-weight: 700; }
.pl-row .sub { color: #8a909c; font-size: 13px; margin-top: 2px; }
.pl-counts { display: flex; gap: 12px; color: #a9aeb8; font-size: 13px; flex-wrap: wrap; justify-content: flex-end; }
.pl-section { margin-top: 22px; }
.pl-section h3 { margin: 0 0 10px; }
.pl-home { display: grid; grid-template-columns: minmax(0, 260px) minmax(0, 1fr); gap: 16px; align-items: start; }
.pl-home .thumb { border-radius: 12px; }
.pl-home .row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.thumb img.rendered { object-fit: contain; background: radial-gradient(circle at 50% 40%, #1d222b, #0b0d11); }
@media (max-width: 720px) { .pl-row { grid-template-columns: 72px minmax(0, 1fr); } .pl-counts { grid-column: 1 / -1; justify-content: flex-start; } .pl-home { grid-template-columns: 1fr; } }
