:root {
  --bg: #0f1012;
  --bg-card: #1a1c20;
  --bg-hover: #23262b;
  --fg: #e8e6e1;
  --muted: #7a7a78;
  --accent: #c9a85b;
  --border: #2a2c31;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
.mono { font-family: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, monospace; }
a { color: var(--fg); text-decoration: none; }
a:hover { color: var(--accent); }

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 2rem; border-bottom: 1px solid var(--border);
}
.brand-link { font-weight: 700; letter-spacing: 0.1em; }
nav a { margin-left: 1.5rem; color: var(--muted); }
nav a:hover { color: var(--fg); }

main { padding: 2rem; max-width: 1400px; margin: 0 auto; }
main:has(.asset-page) { max-width: none; padding: 1rem 1.25rem 2rem; }
h1 { margin: 0 0 1.5rem; font-weight: 600; }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 0.85rem; }

.crumbs { margin-bottom: 1rem; color: var(--muted); font-size: 0.9rem; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--fg); }

.grid { display: grid; gap: 1rem; }
.grid-brands { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.grid-assets { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }

.card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 6px;
  overflow: hidden; transition: background 0.15s, border-color 0.15s;
  display: flex; flex-direction: column;
}
.card:hover { background: var(--bg-hover); border-color: var(--accent); }
.thumb { aspect-ratio: 1 / 1; overflow: hidden; background: var(--bg); display: flex; align-items: center; justify-content: center; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-logo img { object-fit: contain; padding: 1.25rem; }
.thumb.empty { color: var(--muted); font-size: 2rem; }
.card-body { padding: 0.7rem 0.85rem; }
.card-body .name { font-weight: 500; margin-bottom: 0.2rem; word-break: break-word; }
.card-body .muted { font-size: 0.8rem; }

.quick-links { margin-top: 2.5rem; display: flex; gap: 0.75rem; }

.world-toolbar { margin: 0 0 1rem; display: flex; gap: 0.75rem; }
.world-stage {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  overflow: auto;
}
.world-stage img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}
.pill {
  display: inline-block; padding: 0.4rem 0.9rem; border: 1px solid var(--border);
  border-radius: 999px; color: var(--muted); font-size: 0.9rem;
}
.pill:hover { color: var(--fg); border-color: var(--accent); }
.pill.active { color: var(--fg); border-color: var(--accent); background: var(--bg-hover); }
.pill.disabled { opacity: 0.4; cursor: default; }

.gallery-filters { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0 0 1.25rem; }
.entity-grid { display: grid; gap: 1rem; }
.entity-card { padding: 0; }
.entity-card-summary {
  list-style: none; cursor: pointer; display: grid;
  grid-template-columns: 120px 1fr; gap: 1rem; align-items: center; padding: 0.85rem 1rem;
}
.entity-card-summary::-webkit-details-marker { display: none; }
.entity-primary-thumb { width: 120px; height: 120px; }
.entity-card[open] .entity-card-summary {
  grid-template-columns: 1fr;
}
.entity-card[open] .entity-primary-thumb {
  display: none;
}
.entity-variations {
  padding: 0 1rem 1rem;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.gallery-tile-card:hover .badge { border-color: var(--accent); color: var(--fg); }
.gallery-tile-card img,
.entity-primary-thumb img {
  cursor: zoom-in;
}
.tile-badges { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.35rem; }
.badge {
  display: inline-block; padding: 0.15rem 0.45rem; border: 1px solid var(--border);
  border-radius: 4px; font-size: 0.72rem; color: var(--muted);
}

.gallery-modal {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.gallery-modal[hidden] { display: none; }
.gallery-modal-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(0, 0, 0, 0.78);
  cursor: zoom-out;
}
.gallery-modal-frame {
  position: relative;
  z-index: 1;
  max-width: min(96vw, 1400px);
  max-height: 92vh;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  padding: 0.75rem;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
}
.gallery-modal-frame img {
  display: block;
  max-width: calc(96vw - 1.5rem);
  max-height: calc(92vh - 1.5rem);
  object-fit: contain;
}
.gallery-modal-close {
  position: absolute;
  top: -0.7rem;
  right: -0.7rem;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  font-size: 1.2rem;
}

.asset-view { display: grid; grid-template-columns: 1fr 320px; gap: 2rem; margin-top: 0.5rem; }
.asset-view .asset-image { background: var(--bg-card); border: 1px solid var(--border); border-radius: 6px; padding: 1rem; display: flex; align-items: center; justify-content: center; }
.asset-view .asset-image img { max-width: 100%; max-height: 80vh; object-fit: contain; }
.asset-meta h2 { margin-top: 0; }
.asset-meta dl { display: grid; grid-template-columns: max-content 1fr; gap: 0.3rem 1rem; margin: 1.5rem 0; }
.asset-meta dt { color: var(--muted); font-size: 0.85rem; }
.asset-meta dd { margin: 0; word-break: break-all; }
.nav-pair { display: flex; gap: 0.5rem; margin-top: 1rem; }
.nav-pair .pill { flex: 1; text-align: center; }

/* ── asset viewer (full-width stage + top toolbar) ── */
.asset-page .crumbs { margin-bottom: 0.75rem; }

.asset-toolbar {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.55rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.35rem;
  overflow: hidden;
}

.toolbar-group {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.3rem;
  min-width: 0;
}

.toolbar-meta { flex: 1 1 auto; overflow: hidden; }

.asset-title {
  font-weight: 600;
  font-size: 0.82rem;
  flex-shrink: 0;
}

.chip {
  display: inline-block;
  padding: 0.12rem 0.38rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.7rem;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.chip-path {
  flex: 0 1 auto;
  max-width: 9rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toolbar-zoom {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.25rem;
  background: var(--bg);
}

.btn-icon,
.btn-text {
  border: none;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  font: inherit;
  line-height: 1;
}

.btn-icon {
  width: 1.45rem;
  height: 1.45rem;
  border-radius: 999px;
  font-size: 1rem;
}

.btn-icon:hover,
.btn-text:hover { color: var(--accent); background: var(--bg-hover); }

.btn-text {
  padding: 0.18rem 0.38rem;
  border-radius: 999px;
  font-size: 0.68rem;
  color: var(--muted);
}

.zoom-label {
  min-width: 2.6rem;
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.toolbar-nav { flex: 0 0 auto; gap: 0.25rem; }
.toolbar-nav .pill {
  font-size: 0.72rem;
  padding: 0.22rem 0.55rem;
  max-width: 9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.asset-hint { margin: 0 0 0.4rem; font-size: 0.75rem; }

.asset-stage {
  position: relative;
  min-height: calc(100vh - 200px);
  background-color: #060608;
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.28) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.28) 1px, transparent 1px),
    linear-gradient(to right, rgba(255, 255, 255, 0.5) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.5) 1px, transparent 1px);
  background-size:
    var(--grid-step-screen, 10px) var(--grid-step-screen, 10px),
    var(--grid-step-screen, 10px) var(--grid-step-screen, 10px),
    var(--grid-major-screen, 100px) var(--grid-major-screen, 100px),
    var(--grid-major-screen, 100px) var(--grid-major-screen, 100px);
  background-position:
    var(--grid-offset-x, 0) var(--grid-offset-y, 0),
    var(--grid-offset-x, 0) var(--grid-offset-y, 0),
    var(--grid-offset-x, 0) var(--grid-offset-y, 0),
    var(--grid-offset-x, 0) var(--grid-offset-y, 0);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: default;
  user-select: none;
}

.cursor-readout {
  position: absolute;
  z-index: 20;
  pointer-events: none;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-size: 0.78rem;
  background: rgba(0, 0, 0, 0.82);
  border: 1px solid var(--accent);
  color: var(--accent);
  white-space: nowrap;
}

.chip-coords {
  color: var(--accent);
  border-color: rgba(201, 168, 91, 0.35);
  min-width: 4.5rem;
  text-align: center;
}

.toolbar-tools { flex: 0 0 auto; }

.btn-text.is-active {
  color: var(--accent);
  background: var(--bg-hover);
}

.asset-world {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
}

.asset-stage .asset-image {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 1;
  display: block;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 0;
  background: transparent;
}

.asset-stage .asset-image img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  object-fit: fill;
  border: 0;
  image-rendering: auto;
  background: transparent;
}

.image-grid {
  pointer-events: none;
  background-color: transparent;
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.28) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.28) 1px, transparent 1px),
    linear-gradient(to right, rgba(255, 255, 255, 0.5) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.5) 1px, transparent 1px);
  background-size:
    var(--grid-step, 10px) var(--grid-step, 10px),
    var(--grid-step, 10px) var(--grid-step, 10px),
    calc(var(--grid-step, 10px) * 10) calc(var(--grid-step, 10px) * 10),
    calc(var(--grid-step, 10px) * 10) calc(var(--grid-step, 10px) * 10);
  position: absolute;
  inset: 0;
  z-index: 2;
}

.measure-overlay {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  z-index: 4;
  pointer-events: none;
  overflow: visible;
}

.measure-line {
  position: absolute;
  height: 2px;
  transform-origin: 0 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.65);
}

.measure-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.75);
}

.measure-label {
  position: absolute;
  transform: translate(-50%, -50%);
  padding: 0.12rem 0.4rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  background: rgba(0, 0, 0, 0.82);
  border: 1px solid rgba(201, 168, 91, 0.45);
  white-space: nowrap;
}

@media (max-width: 800px) {
  .asset-view { grid-template-columns: 1fr; }
  .toolbar-nav { width: 100%; }
  .toolbar-nav .pill { flex: 1; text-align: center; }
}

.mutate-layout {
  display: grid;
  grid-template-columns: minmax(280px, 420px) 1fr;
  gap: 1.5rem;
  align-items: start;
}
.mutate-panel, .mutate-history {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.1rem;
}
.mutate-form label {
  display: block;
  margin: 0.75rem 0;
  font-size: 0.85rem;
  color: var(--muted);
}
.mutate-form select,
.mutate-form input,
.mutate-form textarea {
  width: 100%;
  margin-top: 0.35rem;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 6px;
  padding: 0.5rem 0.65rem;
  font: inherit;
}
.mutate-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 0.5rem; }
.mutate-preview img {
  width: 100%;
  max-height: 360px;
  object-fit: contain;
  background: #111;
  border-radius: 6px;
}
.mutate-status { margin-top: 0.75rem; font-size: 0.9rem; color: var(--accent); }
.mutate-status.error { color: #ff6b6b; }
.mutate-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 1rem;
}
.mutate-compare.hidden { display: none; }
.mutate-compare img {
  width: 100%;
  background: #111;
  border-radius: 4px;
}
.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
}
.history-card {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg);
}
.history-card.current { border-color: var(--accent); }
.history-card img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.history-card figcaption { padding: 0.45rem 0.55rem; font-size: 0.75rem; }

@media (max-width: 900px) {
  .mutate-layout { grid-template-columns: 1fr; }
  .mutate-compare { grid-template-columns: 1fr; }
}

.inline-form { display: inline; }

.engine-hp { margin: 0 0 1.25rem; }
.engine-hp label { display: block; margin-bottom: 0.35rem; font-size: 0.9rem; }
.hp-bar {
  height: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.hp-fill {
  height: 100%;
  background: linear-gradient(90deg, #8b4513, #c9a85b);
}

.engine-layout {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
}
.scrubber-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 1rem;
}
.object-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
}
.object-card h3 { margin: 0 0 0.5rem; font-size: 0.95rem; }
.scrubber-preview {
  width: 100%;
  max-height: 180px;
  object-fit: contain;
  background: var(--bg);
  border-radius: 4px;
  margin-bottom: 0.5rem;
}
.scrubber-text { min-height: 2.5rem; margin: 0.35rem 0 0; }
.event-feed { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.75rem; }
.event-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.65rem 0.85rem;
}
.event-card summary { cursor: pointer; font-weight: 500; }
.event-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin: 0.75rem 0; }
.event-col h4 { margin: 0 0 0.35rem; color: var(--accent); }
.event-lifecycle { margin: 0.5rem 0; padding: 0.4rem 0.6rem; background: var(--bg); border-radius: 4px; }
.trace-panel { margin-top: 0.5rem; padding: 0.5rem; background: var(--bg); border-radius: 4px; }
.trace-phase { margin: 0.35rem 0; }
.trace-json { font-size: 0.75rem; overflow: auto; max-height: 200px; white-space: pre-wrap; }
.trace-thumb { margin: 0.25rem 0.5rem 0.25rem 0; border-radius: 4px; vertical-align: top; }
.world-header-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.scenario-select { margin-left: 0.35rem; background: var(--bg-card); color: var(--fg); border: 1px solid var(--border); border-radius: 4px; padding: 0.25rem 0.5rem; }
.event-feed { max-height: 520px; overflow-y: auto; }
.engine-gallery { margin-top: 0.75rem; }

.engine-loadout { margin: 0 0 1rem; }
.loadout-toggles { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.45rem 0; }
.loadout-pill { cursor: pointer; border-color: var(--border); color: var(--muted); }
.loadout-pill.active {
  color: var(--fg);
  border-color: var(--accent);
  background: rgba(201, 168, 91, 0.12);
}
#loadout-summary { margin: 0.2rem 0 0; }

.engine-error {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid #8b3a3a;
  background: #2a1515;
  color: #f0a8a8;
  border-radius: 6px;
  font-size: 0.9rem;
}

.world-toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  z-index: 1200;
  max-width: min(92vw, 36rem);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.92rem;
  line-height: 1.35;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.world-toast--success {
  color: #d7f0d0;
  background: #1f3a24;
  border: 1px solid #3f7a4a;
}

.world-toast--warn {
  color: #f5e6b8;
  background: #3a3018;
  border: 1px solid #8a7330;
}

.world-toast--error {
  color: #f0a8a8;
  background: #2a1515;
  border: 1px solid #8b3a3a;
}

.world-toast--info {
  color: var(--fg);
  background: var(--bg-card);
  border: 1px solid var(--border);
}
.event-mutation { margin-top: 0.25rem; padding-left: 0.5rem; }
.scrubber-mutation { margin-top: 0.2rem; font-style: italic; }

.world-stage-alpha,
.scrubber-thumb,
.thumb-alpha {
  background-color: var(--bg-card);
  background-image:
    linear-gradient(45deg, var(--border) 25%, transparent 25%),
    linear-gradient(-45deg, var(--border) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--border) 75%),
    linear-gradient(-45deg, transparent 75%, var(--border) 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}
.scrubber-thumb {
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}
.scrubber-thumb .scrubber-preview { margin-bottom: 0; background: transparent; }

@media (max-width: 900px) {
  .engine-layout { grid-template-columns: 1fr; }
  .scrubber-grid { grid-template-columns: 1fr; }
}

.engine-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(8, 8, 10, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.engine-modal[hidden] { display: none; }
.engine-modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
.engine-modal-busy { text-align: center; }
.engine-modal-title { margin: 0 0 0.75rem; font-size: 1.1rem; font-weight: 600; }
.engine-modal-body { margin: 0 0 1rem; font-size: 0.92rem; line-height: 1.5; }
.engine-modal-body .done-events {
  margin: 0.5rem 0 0;
  padding-left: 1.1rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.engine-spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 0.75rem;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: engine-spin 0.8s linear infinite;
}
@keyframes engine-spin { to { transform: rotate(360deg); } }
#done-ok { margin-top: 0.25rem; }

.actor-pose-stage {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  min-height: 160px;
  position: relative;
}
.scrubber-face-inset {
  position: absolute;
  right: 4px;
  top: 4px;
  width: 56px;
  height: 56px;
  object-fit: cover;
  border: 1px solid var(--border, #444);
  border-radius: 4px;
  background: #111;
}
.actor-pose-img {
  transition: transform 0.25s ease;
  transform-origin: bottom center;
  margin-bottom: 0;
}
