:root {
  --ink: #e8eef7;
  --muted: #8fa3bd;
  --alive: #7ee081;
  --dead: #55627a;
  --unknown: #a8b4c7;
  --warning: #f3c87a;
  --panel: rgba(12, 17, 28, 0.86);
  --edge: rgba(255, 255, 255, 0.1);
  --font: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

/* Author `display` rules below would otherwise beat the UA `[hidden]` rule. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #05070d;
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

#scene { display: block; width: 100%; height: 100%; }

#scene-error {
  position: fixed;
  top: 88px;
  left: 50%;
  z-index: 12;
  width: min(560px, calc(100vw - 32px));
  margin: 0;
  padding: 10px 14px;
  transform: translateX(-50%);
  color: var(--warning);
  background: rgba(34, 27, 17, 0.92);
  border: 1px solid currentColor;
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
}

/* --- boot --- */
#boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: #05070d;
  z-index: 20;
  transition: opacity 0.6s ease;
}
#boot.gone { opacity: 0; pointer-events: none; }
.boot-inner { text-align: center; }
.boot-logo { font-size: 40px; color: var(--alive); animation: pulse 1.4s ease-in-out infinite; }
.boot-text { margin-top: 12px; color: var(--muted); font-size: 12px; letter-spacing: 0.18em; }
@keyframes pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }

/* --- hud --- */
#hud-top {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 18px 22px;
  pointer-events: none;
  z-index: 10;
}
#hud-top button, #hud-top a { pointer-events: auto; }

.brand-area { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { color: var(--alive); font-size: 18px; }
.brand-name { font-size: 12px; letter-spacing: 0.28em; }
.hud-nav { display: flex; flex-wrap: wrap; gap: 12px; }
.hud-nav a {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-decoration: none;
  border-bottom: 1px solid var(--edge);
}
.hud-nav a:hover { color: var(--alive); border-color: var(--alive); }

.hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 12px; }
.network-stats { display: flex; gap: 22px; }
.network-stats div { text-align: right; line-height: 1.05; }
.network-stats b { display: block; font-size: 22px; font-weight: 500; }
.network-stats span { color: var(--muted); font-size: 9px; letter-spacing: 0.14em; }
.network-stats .online b { color: var(--alive); }
.load-progress { color: var(--muted); font-size: 9px; letter-spacing: 0.08em; }
#world-warning {
  max-width: min(440px, calc(100vw - 44px));
  margin: -7px 0 0;
  padding: 7px 9px;
  color: var(--warning);
  background: rgba(34, 27, 17, 0.9);
  border-left: 2px solid currentColor;
  font-size: 10px;
  line-height: 1.45;
  text-align: right;
  pointer-events: auto;
}

#auth-bar { display: flex; align-items: center; gap: 10px; }
#auth-bar button {
  padding: 7px 13px;
  font-family: var(--font);
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--ink);
  background: rgba(12, 17, 28, 0.7);
  border: 1px solid var(--edge);
  cursor: pointer;
}
#auth-bar button:hover { border-color: var(--alive); color: var(--alive); }
#auth-error { font-size: 10px; color: #ff8f8f; max-width: 260px; text-align: right; }

#legend {
  position: fixed;
  left: 22px;
  bottom: 20px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.9;
  pointer-events: none;
  z-index: 10;
}
.dot { display: inline-block; width: 8px; height: 8px; margin-right: 8px; vertical-align: 1px; }
.dot.alive { background: var(--alive); box-shadow: 0 0 8px var(--alive); }
.dot.dead { background: var(--dead); }
.dot.unknown { background: transparent; border: 1px solid var(--unknown); }
.hint { margin-top: 10px; opacity: 0.55; }

#home-btn {
  position: fixed;
  right: 22px;
  bottom: 20px;
  z-index: 10;
  padding: 9px 15px;
  font-family: var(--font);
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--alive);
  background: rgba(12, 17, 28, 0.7);
  border: 1px solid var(--alive);
  cursor: pointer;
}
#home-btn:hover { background: rgba(126, 224, 129, 0.12); }

/* --- panel --- */
#panel {
  position: fixed;
  top: 0; right: 0;
  width: min(400px, 94vw);
  height: 100%;
  padding: 64px 26px 26px;
  background: var(--panel);
  backdrop-filter: blur(18px);
  border-left: 1px solid var(--edge);
  overflow-y: auto;
  z-index: 15;
  animation: slide 0.22s ease;
}
@keyframes slide { from { transform: translateX(24px); opacity: 0; } }

#panel-close {
  position: absolute;
  top: 16px; right: 18px;
  width: 30px; height: 30px;
  border: 1px solid var(--edge);
  background: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
}
#panel-close:hover { color: var(--ink); }

.badge {
  display: inline-block;
  padding: 3px 9px;
  font-size: 10px;
  letter-spacing: 0.16em;
  border: 1px solid currentColor;
  color: var(--dead);
}
.badge.online, .badge.alive { color: var(--alive); }
.badge.offline { color: var(--dead); }
.badge.unknown { color: var(--unknown); }

#panel h2 { margin: 14px 0 4px; font-size: 19px; font-weight: 500; line-height: 1.3; }
#panel h3 { margin: 0 0 12px; font-size: 12px; font-weight: 500; letter-spacing: 0.16em; color: var(--alive); }
.muted { color: var(--muted); font-size: 11px; }
#panel-desc { font-size: 12.5px; line-height: 1.7; color: #c3d0e2; }
.panel-warning {
  padding: 9px 11px;
  color: var(--warning);
  background: rgba(243, 200, 122, 0.08);
  border-left: 2px solid currentColor;
  font-size: 10.5px;
  line-height: 1.6;
}

#panel-facts { display: grid; grid-template-columns: auto 1fr; gap: 7px 16px; margin: 22px 0; font-size: 11.5px; }
#panel-facts dt { color: var(--muted); }
#panel-facts dd { margin: 0; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tags span { padding: 3px 8px; font-size: 10px; color: var(--muted); border: 1px solid var(--edge); }

.visit {
  display: block;
  margin-top: 24px;
  padding: 11px;
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--alive);
  border: 1px solid var(--alive);
  text-decoration: none;
}
.visit:hover { background: rgba(126, 224, 129, 0.1); }

.signin-hint { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--edge); line-height: 1.7; }

/* --- agent chat --- */
.agent-section {
  margin-top: 26px;
  padding-top: 22px;
  border-top: 1px solid var(--edge);
}
.agent-section label {
  display: block;
  margin: 14px 0 6px;
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--muted);
}
.agent-section textarea {
  width: 100%;
  padding: 10px;
  font-family: var(--font);
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--edge);
  resize: vertical;
}
.agent-section textarea:focus { outline: none; border-color: var(--alive); }
.agent-section input[type="file"] {
  width: 100%;
  padding: 9px;
  font-family: var(--font);
  font-size: 10.5px;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--edge);
}
.agent-section input[type="file"]:focus { outline: none; border-color: var(--alive); }
.agent-section button {
  width: 100%;
  margin-top: 12px;
  padding: 11px;
  font-family: var(--font);
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--alive);
  background: none;
  border: 1px solid var(--alive);
  cursor: pointer;
}
.agent-section button:hover:not(:disabled) { background: rgba(126, 224, 129, 0.12); }
.agent-section button:disabled { color: var(--muted); border-color: var(--edge); cursor: wait; }
.generated-agent-section { display: none !important; }
.interaction-loading {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 38px;
  color: var(--muted);
  font-size: 10.5px;
}
.voxel-loader { display: flex; gap: 3px; align-items: flex-end; height: 16px; }
.voxel-loader i {
  display: block;
  width: 6px;
  height: 6px;
  background: var(--alive);
  box-shadow: 0 0 8px rgba(126, 224, 129, 0.5);
  animation: voxel-load 0.9s ease-in-out infinite alternate;
}
.voxel-loader i:nth-child(2) { animation-delay: 0.16s; }
.voxel-loader i:nth-child(3) { animation-delay: 0.32s; }
@keyframes voxel-load { to { transform: translateY(-8px); opacity: 0.35; } }
.interaction-field { margin-top: 15px; }
.interaction-field label { margin-bottom: 4px; color: #c3d0e2; }
.interaction-field-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 9.5px;
}
.interaction-required { color: var(--warning); }
#interaction-summary { margin: 0 0 8px; line-height: 1.6; }
#interaction-progress { min-height: 17px; margin: 10px 0 0; line-height: 1.5; }
.interaction-output { margin-top: 10px; }
.interaction-output:empty { display: none; }
.interaction-output pre,
.interaction-output .artifact-download {
  display: block;
  margin: 8px 0 0;
  padding: 10px;
  color: #c3d0e2;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--edge);
  font: 11.5px/1.6 var(--font);
  white-space: pre-wrap;
  word-break: break-word;
}
.interaction-output img { display: block; max-width: 100%; margin-top: 8px; border: 1px solid var(--edge); }
.interaction-output .artifact-download { color: var(--alive); text-decoration: none; }

pre.output {
  margin: 0;
  min-height: 46px;
  padding: 10px;
  font-size: 11.5px;
  line-height: 1.6;
  color: #c3d0e2;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--edge);
  white-space: pre-wrap;
  word-break: break-word;
}
pre.output img.output { max-width: 100%; }

/* --- static extension guide --- */
html.docs-root {
  height: auto;
  min-height: 100%;
  overflow-y: auto;
}
body.docs-page {
  height: auto;
  min-height: 100vh;
  overflow: visible;
  background:
    radial-gradient(circle at 85% 0%, rgba(126, 224, 129, 0.08), transparent 32rem),
    #05070d;
}
.docs-shell { width: min(920px, calc(100% - 36px)); margin: 0 auto; padding: 28px 0 80px; }
.docs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--edge);
}
.docs-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 16px; }
.docs-actions a, .docs-back { color: var(--alive); font-size: 11px; text-decoration: none; }
.docs-actions a:hover, .docs-back:hover { text-decoration: underline; }
.docs-content { width: min(760px, 100%); padding-top: 42px; }
.docs-content h1 { margin: 0 0 12px; font-size: clamp(26px, 5vw, 44px); font-weight: 500; letter-spacing: -0.04em; }
.docs-content h2 { margin: 42px 0 14px; color: var(--alive); font-size: 16px; font-weight: 500; }
.docs-content h3 { margin: 26px 0 10px; font-size: 13px; font-weight: 500; }
.docs-content p, .docs-content li { color: #c3d0e2; font-size: 12.5px; line-height: 1.75; }
.docs-content .lede { color: var(--muted); font-size: 14px; }
.docs-content a { color: var(--alive); }
.docs-content code { color: #d8e9ff; font-family: var(--font); }
.docs-content pre {
  overflow-x: auto;
  padding: 18px;
  color: #d8e9ff;
  background: rgba(12, 17, 28, 0.92);
  border: 1px solid var(--edge);
  font-size: 11.5px;
  line-height: 1.6;
}
.docs-content table { width: 100%; border-collapse: collapse; font-size: 11.5px; line-height: 1.6; }
.docs-content th, .docs-content td { padding: 9px 10px; border: 1px solid var(--edge); text-align: left; vertical-align: top; }
.docs-content th { color: var(--alive); font-weight: 500; }
.docs-note { padding: 12px 14px; border-left: 2px solid var(--warning); background: rgba(243, 200, 122, 0.07); }

.world-hierarchy {
  display: grid;
  gap: 7px;
  margin: 18px 0 30px;
  counter-reset: hierarchy;
}
.world-hierarchy div {
  display: grid;
  grid-template-columns: 22px 170px 1fr;
  gap: 10px;
  align-items: baseline;
  padding: 10px 12px;
  margin-left: calc((var(--depth, 0)) * 18px);
  border-left: 1px solid var(--alive);
  counter-increment: hierarchy;
}
.world-hierarchy div::before { content: counter(hierarchy); color: var(--alive); font-size: 10px; }
.world-hierarchy div:nth-child(2) { margin-left: 18px; }
.world-hierarchy div:nth-child(3) { margin-left: 36px; }
.world-hierarchy div:nth-child(4) { margin-left: 54px; }
.world-hierarchy b { color: var(--ink); font-size: 11.5px; font-weight: 500; }
.world-hierarchy span { color: var(--muted); font-size: 11px; }

.map-legend-grid, .architecture-legend {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 16px 0 28px;
}
.map-legend-grid div, .architecture-legend div {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 9px;
  align-items: center;
  padding: 10px 11px;
  background: rgba(12, 17, 28, 0.55);
  border: 1px solid var(--edge);
}
.map-legend-grid b, .architecture-legend b { color: var(--ink); font-size: 11px; font-weight: 500; }
.map-legend-grid span, .architecture-legend span { color: var(--muted); font-size: 10.5px; }
.architecture-legend div { grid-template-columns: 24px 1fr auto; }
.architecture-legend i { color: var(--alive); font-size: 16px; font-style: normal; text-align: center; }
.architecture-legend span { text-align: right; }

.block-catalog {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.block-card {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 12px;
  min-width: 0;
  padding: 16px;
  background: rgba(12, 17, 28, 0.7);
  border: 1px solid var(--edge);
}
.block-card h3 { margin: 1px 0 6px; color: var(--ink); }
.block-card p { margin: 0 0 12px; }
.block-card pre { margin: 0; padding: 11px; font-size: 10.5px; }
.block-icon { color: var(--alive); font-size: 22px; line-height: 1; }

.material-catalog {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 18px 0;
}
.material-catalog div {
  display: grid;
  grid-template-columns: 14px 62px 1fr;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--edge);
}
.material-catalog i { width: 12px; height: 12px; background: var(--swatch); }
.material-catalog span { color: var(--muted); font-size: 10.5px; }

.compose-steps { padding: 0; list-style: none; counter-reset: compose; }
.compose-steps li {
  display: grid;
  grid-template-columns: 24px 160px 1fr;
  gap: 10px;
  align-items: baseline;
  margin: 8px 0;
  padding: 10px 12px;
  border-left: 1px solid var(--alive);
  counter-increment: compose;
}
.compose-steps li::before { content: counter(compose); color: var(--alive); }
.compose-steps b { color: var(--ink); font-weight: 500; }
.compose-steps span { color: var(--muted); }

.coordinate-guide { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.coordinate-guide span { padding: 8px 12px; color: var(--muted); border: 1px solid var(--edge); font-size: 11px; }
.coordinate-guide b { color: var(--alive); font-weight: 500; }
.rules-list { padding-left: 20px; }
.docs-footer { margin-top: 54px; padding-top: 20px; border-top: 1px solid var(--edge); }

/* --- JSON builder --- */
.builder-page { background: #05070d; }
.builder-shell { display: flex; flex-direction: column; width: 100%; height: 100%; }
.builder-header {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 66px;
  padding: 16px 20px;
  background: rgba(12, 17, 28, 0.94);
  border-bottom: 1px solid var(--edge);
}
.builder-nav { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 16px; }
.builder-nav a { color: var(--muted); font-size: 10px; letter-spacing: 0.1em; text-decoration: none; }
.builder-nav a:hover { color: var(--alive); }
.builder-main {
  display: grid;
  grid-template-columns: minmax(360px, 44%) minmax(0, 1fr);
  flex: 1 1 auto;
  min-height: 0;
}
.builder-editor {
  overflow-y: auto;
  padding: 26px 24px 40px;
  background: rgba(8, 12, 20, 0.98);
  border-right: 1px solid var(--edge);
}
.builder-editor h1 { margin: 0 0 8px; font-size: 22px; font-weight: 500; }
.builder-editor p { color: var(--muted); font-size: 11.5px; line-height: 1.65; }
.builder-editor code { color: #d8e9ff; font-family: var(--font); }
.builder-editor a { color: var(--alive); }
.builder-options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 22px 0 16px; }
.builder-options label, .builder-json-label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.08em;
}
.builder-options select {
  width: 100%;
  padding: 9px;
  color: var(--ink);
  background: #0b111c;
  border: 1px solid var(--edge);
  font: 11px var(--font);
}
#builder-json {
  display: block;
  width: 100%;
  min-height: 440px;
  margin-top: 6px;
  padding: 14px;
  resize: vertical;
  color: #d8e9ff;
  background: #070a10;
  border: 1px solid var(--edge);
  font: 11.5px/1.55 var(--font);
  tab-size: 2;
}
#builder-json:focus { outline: none; border-color: var(--alive); }
.builder-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.builder-actions button {
  padding: 9px 11px;
  color: var(--ink);
  background: rgba(12, 17, 28, 0.9);
  border: 1px solid var(--edge);
  cursor: pointer;
  font: 10.5px var(--font);
}
.builder-actions button:first-child { color: var(--alive); border-color: var(--alive); }
.builder-actions button:hover { color: var(--alive); border-color: var(--alive); }
.builder-status { min-height: 38px; margin: 12px 0 0; padding: 9px 11px; border-left: 2px solid var(--unknown); }
.builder-status.valid { color: var(--alive); border-color: var(--alive); background: rgba(126, 224, 129, 0.06); }
.builder-status.invalid { color: #ff9b9b; border-color: #ff9b9b; background: rgba(255, 100, 100, 0.06); }
.builder-help { margin-bottom: 0; }
.builder-preview { position: relative; min-width: 0; min-height: 0; background: #05070d; }
#builder-scene { display: block; width: 100%; height: 100%; }
.builder-preview-label {
  position: absolute;
  top: 18px;
  left: 18px;
  display: grid;
  gap: 4px;
  pointer-events: none;
}
.builder-preview-label b { color: var(--alive); font-size: 10px; letter-spacing: 0.16em; }
.builder-preview-label span { color: var(--muted); font-size: 10px; }
.builder-scene-error {
  position: absolute;
  right: 18px;
  bottom: 18px;
  left: 18px;
  margin: 0;
  padding: 10px 12px;
  color: var(--warning);
  background: rgba(34, 27, 17, 0.94);
  border: 1px solid currentColor;
  font-size: 11px;
  line-height: 1.5;
}

@media (max-width: 720px) {
  #hud-top { padding: 14px; }
  .brand-name { letter-spacing: 0.16em; }
  .hud-right { gap: 10px; }
  .network-stats { gap: 14px; }
  .network-stats b { font-size: 18px; }
  .load-progress { max-width: 180px; text-align: right; line-height: 1.4; }
  #world-warning { max-width: min(260px, calc(100vw - 28px)); }
  #auth-bar { flex-wrap: wrap; justify-content: flex-end; max-width: 180px; }
  #auth-error { max-width: 180px; }
  #legend { left: 14px; bottom: 66px; max-width: calc(100vw - 28px); line-height: 1.65; }
  #home-btn { right: 14px; bottom: 14px; }
  #panel { width: 100%; padding-top: 58px; }
  #scene-error { top: 112px; }
  .docs-shell { width: min(100% - 28px, 920px); padding-top: 18px; }
  .docs-header { align-items: flex-start; }
  .docs-content { padding-top: 30px; }
  .docs-table-wrap { overflow-x: auto; }
  .block-catalog, .material-catalog, .map-legend-grid, .architecture-legend { grid-template-columns: 1fr; }
  .world-hierarchy div,
  .world-hierarchy div:nth-child(2),
  .world-hierarchy div:nth-child(3),
  .world-hierarchy div:nth-child(4) { grid-template-columns: 20px 1fr; margin-left: 0; }
  .world-hierarchy span { grid-column: 2; }
  .compose-steps li { grid-template-columns: 20px 1fr; }
  .compose-steps span { grid-column: 2; }
  html.builder-root { height: auto; min-height: 100%; overflow-y: auto; }
  body.builder-page { height: auto; min-height: 100vh; overflow: visible; }
  .builder-shell { min-height: 100vh; height: auto; }
  .builder-header { align-items: flex-start; }
  .builder-main { display: block; }
  .builder-editor { overflow: visible; padding: 22px 14px 32px; border-right: 0; border-bottom: 1px solid var(--edge); }
  .builder-options { grid-template-columns: 1fr; }
  #builder-json { min-height: 390px; }
  .builder-preview { height: 62vh; min-height: 420px; }
}

@media (prefers-reduced-motion: reduce) {
  #boot, #panel { transition: none; animation: none; }
  .boot-logo, .voxel-loader i { animation: none; opacity: 1; }
}
