:root {
  color-scheme: dark;
  --bg: #11130f;
  --panel: #1b1e18;
  --panel-2: #24281f;
  --ink: #f3f0e7;
  --muted: #b6baab;
  --line: #3b4034;
  --accent: #e6bf5c;
  --accent-2: #73c7a6;
  --danger: #d97f67;
  --shadow: 0 18px 46px rgba(0, 0, 0, .32);
  font-family: "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button,
select,
input {
  border: 1px solid var(--line);
  background: #151811;
  color: var(--ink);
}

button {
  min-height: 38px;
  padding: 0 14px;
  cursor: pointer;
}

button:hover,
button:focus-visible,
select:focus-visible,
input:focus-visible {
  border-color: var(--accent);
  outline: 2px solid rgba(230, 191, 92, .24);
  outline-offset: 2px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 28px 16px;
  border-bottom: 1px solid var(--line);
  background: #151811;
  position: sticky;
  top: 0;
  z-index: 5;
}

.eyebrow,
.label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: 11px;
  margin: 0 0 4px;
}

h1,
h2 {
  margin: 0;
  line-height: 1.1;
}

h1 {
  font-size: 30px;
  font-weight: 700;
}

h2 {
  font-size: 17px;
}

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tab {
  border-radius: 0;
}

.tab.is-active {
  background: var(--accent);
  color: #19160d;
  border-color: var(--accent);
}

main {
  padding: 20px 28px 28px;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  margin-bottom: 20px;
}

.status-strip > div {
  min-width: 0;
  padding: 14px;
  background: var(--panel);
}

.status-strip strong {
  display: block;
  overflow-wrap: anywhere;
}

.view {
  display: none;
}

.view.is-visible {
  display: block;
}

.play-layout,
.asset-layout,
.boot-layout {
  display: grid;
  gap: 18px;
}

.play-layout {
  grid-template-columns: minmax(0, 1fr) 320px;
}

.stage-wrap,
.side-panel,
.asset-preview,
.system-card,
.boot-layout > div {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.stage-wrap {
  min-width: 0;
}

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #0a0c08;
}

.stage-toolbar,
.asset-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}

.stage-toolbar label,
.asset-tools label,
.field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.stage-toolbar input {
  width: 160px;
}

.side-panel {
  padding: 16px;
  display: grid;
  align-content: start;
  gap: 14px;
}

.field input,
.field select,
.asset-tools input,
.asset-tools select {
  min-height: 38px;
  padding: 0 10px;
}

.check-row {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
}

.muted {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.asset-summary,
.asset-tools {
  background: var(--panel);
  border: 1px solid var(--line);
}

.asset-summary {
  margin-bottom: 10px;
  padding: 12px;
  color: var(--muted);
  line-height: 1.45;
}

.asset-tools {
  margin-bottom: 18px;
}

.asset-count {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
  align-self: end;
  padding: 0 0 9px;
}

.asset-layout {
  grid-template-columns: 420px minmax(0, 1fr);
}

.asset-list-wrap {
  min-width: 0;
}

.asset-list {
  height: min(72vh, 740px);
  overflow: auto;
  border: 1px solid var(--line);
  background: var(--panel);
}

.asset-row {
  width: 100%;
  min-height: 52px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  padding: 8px 10px;
}

.asset-row.is-selected {
  background: var(--panel-2);
}

.load-more {
  width: 100%;
  border-top: 0;
}

.load-more[disabled] {
  cursor: default;
  opacity: .55;
}

.asset-path {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.asset-meta {
  color: var(--muted);
  font-size: 12px;
}

.asset-preview {
  min-height: 520px;
  padding: 16px;
}

.preview-body {
  margin-top: 14px;
}

.preview-body img,
.preview-body video {
  max-width: 100%;
  max-height: 62vh;
  object-fit: contain;
  background: #0b0d09;
  border: 1px solid var(--line);
}

.preview-body pre,
.boot-layout pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 68vh;
  overflow: auto;
  color: #d9dccf;
  background: #0f120c;
  border: 1px solid var(--line);
  padding: 12px;
}

.system-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.system-card {
  padding: 16px;
  min-height: 150px;
}

.system-card .status {
  display: inline-block;
  color: #13160f;
  background: var(--accent-2);
  padding: 3px 7px;
  margin: 10px 0;
  font-size: 12px;
  text-transform: uppercase;
}

.system-card.disabled .status {
  background: var(--danger);
}

.boot-layout {
  grid-template-columns: minmax(0, 1fr) minmax(320px, .7fr);
}

.boot-layout > div {
  padding: 16px;
}

.boot-layout h2 {
  margin-bottom: 12px;
}

@media (max-width: 940px) {
  .topbar {
    display: block;
  }

  .tabs {
    margin-top: 14px;
  }

  .status-strip,
  .play-layout,
  .asset-layout,
  .boot-layout,
  .char-layout,
  .system-grid {
    grid-template-columns: 1fr;
  }

  main {
    padding: 14px;
  }

  .asset-list {
    height: 340px;
  }

  .char-list {
    max-height: 340px;
  }
}

/* ---- Characters view ---- */
.char-summary {
  margin-bottom: 14px;
  color: var(--muted);
}
.char-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 16px;
  align-items: start;
}
.char-list-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
}
.char-list-wrap input {
  width: 100%;
  margin-bottom: 8px;
  padding: 7px 9px;
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.char-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  max-height: 560px;
  overflow-y: auto;
}
.char-row {
  min-width: 0;
  padding: 8px 9px;
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  text-align: left;
}
.char-row:hover { border-color: var(--accent); }
.char-row.is-selected {
  background: var(--accent);
  color: #1b1d16;
  font-weight: 700;
}
.char-stage {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}
.spine-host {
  width: 100%;
  height: 560px;
  background: var(--panel-2);
  border-radius: 10px;
  overflow: hidden;
}
.combined-spine-host {
  position: relative;
  width: 100%;
  height: 560px;
  background: var(--panel-2);
  border-radius: 10px;
  overflow: hidden;
}
.combined-spine-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.combined-character-layer {
  z-index: 1;
}
.combined-effect-layer {
  z-index: 2;
  pointer-events: none;
}
.combined-effect-layer canvas {
  background: transparent;
}
.preview-spine {
  height: 460px;
}
.spine-error {
  padding: 20px;
  color: var(--danger);
}
.char-meta { margin-top: 12px; }
.char-meta h2 { margin: 0 0 6px; }
.char-anims {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
  word-break: break-word;
}
.hero-blurb {
  margin: 0 0 5px;
  color: var(--ink);
  line-height: 1.4;
}
.hero-traits {
  margin-bottom: 5px;
  color: var(--accent-2);
  font-weight: 700;
}
.hero-skin {
  margin-bottom: 5px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}
.hero-source {
  overflow-wrap: anywhere;
}

/* ---- UI map layout preview ---- */
.map-stage {
  position: relative;
  margin-top: 10px;
  background:
    repeating-conic-gradient(#23271e 0% 25%, #1b1e18 0% 50%) 50% / 24px 24px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.map-node {
  position: absolute;
  object-fit: fill;
}
.map-node-missing {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--danger);
  border: 1px dashed var(--danger);
  text-align: center;
  overflow: hidden;
}

/* ---- Lua info card ---- */
.lua-info { line-height: 1.5; }
.lua-info code {
  background: var(--panel-2);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 12px;
  word-break: break-all;
}
.lua-info table.kv { border-collapse: collapse; margin: 8px 0; }
.lua-info table.kv td {
  border: 1px solid var(--line);
  padding: 5px 10px;
  vertical-align: top;
}
.lua-info table.kv td:first-child { color: var(--muted); white-space: nowrap; }

/* ---- Spine category selector ---- */
.char-cat-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}
.char-cat-label select {
  width: 100%;
  margin-top: 4px;
  padding: 7px 9px;
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
}

/* ---- Hero variant switcher + badges ---- */
.char-variants {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.skin-switcher {
  flex: 1 0 100%;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding-bottom: 8px;
  margin-bottom: 2px;
  border-bottom: 1px solid var(--line);
}
.skin-btn {
  min-height: 32px;
  padding: 5px 10px;
  background: #151811;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
}
.skin-btn:hover { border-color: var(--accent); }
.skin-btn.is-active {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #10140f;
  font-weight: 700;
}
.variant-btn {
  padding: 7px 12px;
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
.variant-btn:hover { border-color: var(--accent); }
.variant-btn.is-active {
  background: var(--accent);
  color: #1b1d16;
  font-weight: 700;
}
.char-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.char-label {
  min-width: 0;
  display: grid;
  gap: 2px;
}
.char-id,
.char-row-meta {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.char-row-meta {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}
.char-badge {
  flex: 0 0 auto;
  font-size: 9px;
  letter-spacing: 1px;
  opacity: 0.6;
  font-weight: 700;
}
.char-row.is-selected .char-badge { opacity: 0.85; }
.char-row.is-selected .char-row-meta {
  color: rgba(27, 29, 22, .72);
}

/* ---- Spritesheet gallery ---- */
.spritesheet-gallery {
  width: 100%;
  max-height: 600px;
  overflow-y: auto;
  background: var(--panel-2);
  border-radius: 10px;
  padding: 14px;
  display: grid;
  gap: 16px;
}
.sheet-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.sheet-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.sheet-label {
  font-weight: 700;
  font-size: 14px;
  color: var(--accent);
}
.sheet-path {
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sheet-img {
  display: block;
  width: 100%;
  max-height: 400px;
  object-fit: contain;
  background:
    repeating-conic-gradient(#23271e 0% 25%, #1b1e18 0% 50%) 50% / 16px 16px;
  padding: 8px;
}
.sheet-img-error {
  padding: 24px;
  text-align: center;
  color: var(--danger);
}
.sheet-actions {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}
.sheet-download {
  display: inline-block;
  padding: 6px 14px;
  background: var(--accent);
  color: #19160d;
  font-weight: 700;
  font-size: 13px;
  border-radius: 6px;
  text-decoration: none;
}
.sheet-download:hover {
  filter: brightness(1.1);
}
