:root {
  --bg: #0e1116;
  --bg-elev: #161b22;
  --bg-soft: #1c2330;
  --line: #2a3344;
  --text: #e8eef7;
  --muted: #8b97ab;
  --accent: #5b9dff;
  --accent-2: #7ee0b0;
  --warn: #f0b429;
  --danger: #ff6b7a;
  --staging: #f0b429;
  --prod: #7ee0b0;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(1200px 600px at 10% -10%, #1a2740 0%, transparent 55%),
              radial-gradient(900px 500px at 90% 0%, #15231f 0%, transparent 50%),
              var(--bg);
  color: var(--text);
  font-family: var(--font);
}

button, select, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(14, 17, 22, 0.88);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #2a3a55, #1a2436);
  border: 1px solid var(--line);
  font-size: 1.1rem;
}
.brand strong { display: block; letter-spacing: 0.01em; }
.muted { color: var(--muted); font-size: 0.82rem; }

.banner {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  font-size: 0.9rem;
}
.banner.staging { border-color: color-mix(in srgb, var(--staging) 55%, var(--line)); }
.banner.prod { border-color: color-mix(in srgb, var(--prod) 45%, var(--line)); }
.banner.staging #banner-label { color: var(--staging); font-weight: 700; }
.banner.prod #banner-label { color: var(--prod); font-weight: 700; }
.banner-actions { display: flex; gap: 8px; }

.btn {
  border: 1px solid var(--line);
  background: var(--bg-soft);
  border-radius: 10px;
  padding: 8px 12px;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.btn:hover { border-color: #3d4b63; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn.primary {
  background: linear-gradient(180deg, #4f8fff, #3a74db);
  border-color: #6aa4ff;
  color: #fff;
  font-weight: 600;
}
.btn.ghost { background: transparent; }
.btn.quiet { opacity: 0.72; font-size: 0.9em; }

.lot { padding: 36px 28px 64px; max-width: 960px; margin: 0 auto; }
.lot h1 { margin: 0 0 8px; font-size: 1.85rem; letter-spacing: -0.02em; }
.lede { color: var(--muted); margin: 0 0 24px; }
.lot-grid { display: grid; gap: 16px; }
.lot-card {
  display: grid; grid-template-columns: 140px 1fr; gap: 18px;
  text-align: left; width: 100%;
  padding: 0; overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-elev);
  box-shadow: var(--shadow);
}
.lot-card:hover { border-color: #4a5d7c; }
.lot-thumb {
  min-height: 120px;
  background:
    linear-gradient(160deg, rgba(91,157,255,0.25), transparent 55%),
    linear-gradient(20deg, #1d3a2e, #24324a 60%, #3a2a1d);
}
.lot-meta { padding: 18px 18px 18px 0; }
.lot-meta h2 { margin: 0 0 6px; font-size: 1.2rem; }
.lot-meta p { margin: 0; color: var(--muted); font-size: 0.92rem; }

.project { min-height: calc(100vh - 72px); }
.project-nav {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px;
  padding: 12px 20px; border-bottom: 1px solid var(--line);
  background: rgba(22, 27, 34, 0.7);
}
.project-nav h1 { margin: 0; font-size: 1.15rem; flex: 1; min-width: 160px; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 999px;
}
.tab:hover { color: var(--text); background: var(--bg-soft); }
.tab.active {
  color: var(--text);
  background: var(--bg-soft);
  border-color: var(--line);
}

.workspace { padding: 16px 20px 40px; }
.panel { animation: fade 0.18s ease; }
@keyframes fade { from { opacity: 0.4; } to { opacity: 1; } }

.board-toolbar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
  margin-bottom: 12px; color: var(--muted); font-size: 0.88rem;
}
.board-toolbar label { display: flex; align-items: center; gap: 6px; }
.board-toolbar select {
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px;
}

.tool-group {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-elev);
}
.tool-btn {
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  padding: 8px 14px;
  font-size: 0.86rem;
  font-weight: 600;
}
.tool-btn:last-child { border-right: 0; }
.tool-btn:hover { color: var(--text); background: var(--bg-soft); }
.tool-btn.active {
  color: #fff;
  background: linear-gradient(180deg, #3f6fbf, #2f5699);
}

.place-kind-wrap.is-disabled { opacity: 0.45; }

.viewport-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.toggle-btn {
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--muted);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 0.86rem;
  font-weight: 600;
}
.toggle-btn:hover { color: var(--text); background: var(--bg-soft); }
.toggle-btn.active {
  color: #0e1116;
  background: linear-gradient(180deg, #7ee0b0, #4fb888);
  border-color: #7ee0b0;
}
.device-wrap select { max-width: min(280px, 42vw); }

.history-btns { display: flex; gap: 6px; }
.hint { margin-left: auto; font-size: 0.8rem; opacity: 0.85; max-width: 420px; text-align: right; }

.board-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 14px;
  min-height: 540px;
}
@media (max-width: 980px) {
  .board-row { grid-template-columns: 1fr; }
}

.board-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.board-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, #152033 0%, #101821 55%, #0c1410 100%);
  overflow: hidden;
  box-shadow: var(--shadow);
  position: relative;
  touch-action: none;
}
#board { display: block; width: 100%; height: 520px; cursor: grab; }
#board.tool-pan { cursor: grab; }
#board.tool-pan.dragging,
#board.panning { cursor: grabbing; }
#board.tool-select { cursor: default; }
#board.tool-select.dragging { cursor: move; }
#board.tool-annotate { cursor: crosshair; }

.props-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}
.props-panel h3 {
  margin: 0 0 10px;
  font-size: 0.85rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.props-body { display: grid; gap: 10px; }
.props-empty { margin: 0; color: var(--muted); font-size: 0.9rem; }
.props-row {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}
.props-row label {
  color: var(--muted);
  font-size: 0.82rem;
  padding-top: 8px;
}
.props-row input,
.props-row select,
.props-row textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}
.props-row textarea { min-height: 72px; resize: vertical; }
.props-id {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--accent-2);
}
.props-kind {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 999px;
  background: #1c2a3d;
  color: var(--accent);
  margin-bottom: 4px;
}

.json-side {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
  padding: 12px;
  display: flex; flex-direction: column; min-height: 0;
}
.json-side h3 { margin: 0 0 8px; font-size: 0.85rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
#level-json {
  margin: 0; flex: 1; overflow: auto;
  font-family: var(--mono); font-size: 0.72rem; line-height: 1.45;
  color: #c9d6ea; white-space: pre-wrap; word-break: break-word;
}

.shelf { display: grid; gap: 10px; }
.shelf-row {
  display: grid;
  grid-template-columns: 120px 1fr 140px;
  gap: 12px; align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elev);
}
.shelf-row img {
  width: 120px; height: 72px; object-fit: cover;
  border-radius: 8px; background: #0a0d12; border: 1px solid var(--line);
}
.shelf-meta strong { display: block; margin-bottom: 4px; }
.shelf-meta .path { color: var(--muted); font-family: var(--mono); font-size: 0.78rem; word-break: break-all; }
.shelf-row input[type="text"] {
  width: 100%; background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; margin-top: 6px;
}
.preview-stub {
  height: 72px; border-radius: 8px; border: 1px dashed var(--line);
  display: grid; place-items: center; color: var(--muted); font-size: 0.8rem;
  background: #0a0d12;
}

.dialog-list, .scrum-col { display: grid; gap: 10px; }
.line-card, .note-card {
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg-elev); padding: 12px 14px;
}
.line-card .speaker { color: var(--accent); font-weight: 700; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
.line-card textarea {
  width: 100%; margin-top: 8px; min-height: 64px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px;
}
.scrum-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px;
}
@media (max-width: 900px) { .scrum-grid { grid-template-columns: 1fr; } }
.scrum-col h3 {
  margin: 0 0 10px; font-size: 0.95rem;
  padding-bottom: 8px; border-bottom: 1px solid var(--line);
}
.note-card .sev {
  display: inline-block; font-size: 0.72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em;
  padding: 2px 8px; border-radius: 999px; margin-bottom: 6px;
}
.sev.nice { background: #1c3a2c; color: var(--accent-2); }
.sev.issue { background: #3a3218; color: var(--warn); }
.sev.blocker { background: #3a1c22; color: var(--danger); }

.stub-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.stub-card {
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg-elev); padding: 16px;
}
.stub-card h3 { margin: 0 0 6px; }
.stub-card p { margin: 0; color: var(--muted); font-size: 0.9rem; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1f2a3c; border: 1px solid #3d5275; color: var(--text);
  padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow);
  z-index: 50; max-width: min(520px, 92vw); text-align: center;
}

#annot-dialog {
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--bg-elev); color: var(--text);
  padding: 18px; width: min(420px, 92vw);
}
#annot-dialog::backdrop { background: rgba(0,0,0,0.55); }
#annot-dialog h3 { margin: 0 0 10px; }
#annot-dialog textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px; resize: vertical;
}
.annot-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}
.annot-fields label {
  display: grid;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--muted);
}
.annot-fields select {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
}
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }

.props-snap, .scrum-snap {
  display: block;
  max-width: 100%;
  max-height: 140px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #0a0d12;
  object-fit: contain;
}
.scrum-snap { margin: 6px 0 8px; max-height: 96px; }

/* Cast shelf — characters / weapons / collectibles */
.cast-layout {
  display: grid;
  grid-template-columns: minmax(220px, 280px) 1fr;
  gap: 16px;
  min-height: 480px;
}
@media (max-width: 900px) {
  .cast-layout { grid-template-columns: 1fr; }
}
.cast-nav {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elev);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.cast-nav-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.cast-shelf-btn {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 6px;
  font-size: 0.82rem;
  cursor: pointer;
}
.cast-shelf-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: #152033;
}
.cast-hint {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
}
.cast-types {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  display: grid;
  gap: 6px;
}
.cast-types-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.85rem;
}
.cast-type-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 6px;
}
.cast-type-row input,
.cast-fields input,
.cast-fields select,
.cast-detail textarea,
.cast-detail input[type="text"],
.cast-detail input[type="number"],
.cast-skill-card input,
.cast-skill-card textarea,
.cast-skill-card select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  color: var(--text);
}
.cast-list {
  display: grid;
  gap: 6px;
  max-height: 320px;
  overflow: auto;
}
.cast-list-item {
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  cursor: pointer;
  display: grid;
  gap: 2px;
}
.cast-list-item.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.cast-list-item .muted { font-size: 0.75rem; color: var(--muted); }
.cast-add-item { width: 100%; margin-top: 4px; }
.btn.tiny {
  padding: 4px 8px;
  font-size: 0.75rem;
  line-height: 1.2;
}
.cast-detail {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elev);
  padding: 16px;
}
.cast-detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.cast-detail-head h2 { margin: 0; font-size: 1.15rem; }
.cast-detail h3 {
  margin: 16px 0 8px;
  font-size: 0.9rem;
}
.cast-detail h3 .muted { font-weight: 400; font-size: 0.78rem; }
.cast-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}
.cast-armor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 10px;
}
.cast-armor-cell {
  display: grid;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--muted);
}
.cast-sprites, .cast-skills { display: grid; gap: 10px; }
.cast-sprite-row {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 10px;
  align-items: center;
}
.cast-thumb {
  width: 72px;
  height: 72px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #0a0d12;
}
.cast-sprite-fields { display: grid; gap: 6px; }
.cast-skill-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: var(--bg);
  display: grid;
  gap: 8px;
}
.cast-skill-top {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: center;
}
.cast-when-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}
.cast-when-label { display: grid; gap: 4px; font-size: 0.82rem; color: var(--muted); }
.cast-skill-card > label { display: grid; gap: 4px; font-size: 0.82rem; color: var(--muted); }

/* Libraries shelf — studio-wide kits */
.libraries-panel { display: grid; gap: 18px; max-width: 960px; }
.lib-header h2 { margin: 0 0 4px; }
.lede-inline { margin: 0; color: var(--muted); font-size: 0.92rem; max-width: 52rem; }
.lib-section h3 { margin: 0 0 10px; font-size: 1rem; }
.lib-list { display: grid; gap: 10px; }
.lib-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elev);
  padding: 12px 14px;
}
.lib-row-title { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 6px; }
.lib-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #0a0d12;
  color: var(--muted);
  text-transform: lowercase;
}
.lib-badge.cat { color: #9ecbff; border-color: #2a4a6a; }
.lib-badge.status-in-use { color: #8dffb0; border-color: #2a6a44; }
.lib-badge.status-own { color: #ffd58d; border-color: #6a522a; }
.lib-badge.status-candidate { color: #c9b0ff; border-color: #4a3a6a; }
.lib-usedby { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.lib-chip {
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: 6px;
  background: #121820;
  border: 1px solid var(--line);
  color: #c7d0dc;
}
.lib-notes { margin: 0 0 6px; color: var(--muted); font-size: 0.88rem; }
.lib-links { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 0.78rem; }
.lib-path { font-family: var(--mono); color: var(--muted); word-break: break-all; }
.lib-url { color: #9ecbff; word-break: break-all; }
.lib-row-actions { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.lib-watch { margin: 0; padding-left: 1.2rem; color: var(--muted); font-size: 0.9rem; }
.lib-watch li { margin-bottom: 6px; }
.lib-add-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  align-items: end;
}
.lib-add-form label {
  display: grid;
  gap: 4px;
  font-size: 0.82rem;
  color: var(--muted);
}
.lib-add-form input,
.lib-add-form select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: inherit;
  font: inherit;
}
.lib-add-notes { grid-column: 1 / -1; }
@media (max-width: 640px) {
  .lib-row { grid-template-columns: 1fr; }
  .lib-row-actions { flex-direction: row; }
}


.scrum-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  margin-bottom: 14px;
}
.scrum-toolbar select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  color: inherit; padding: 4px 8px; margin-left: 6px;
}
.scrum-filter-hint { font-size: 0.82rem; }
.scope-chip {
  display: inline-block; font-size: 0.72rem; font-weight: 600;
  letter-spacing: 0.02em; padding: 2px 8px; border-radius: 999px;
  margin: 0 0 6px 6px; vertical-align: middle;
  background: #1a2433; color: #9ec3ff; border: 1px solid #2a3a52;
}
.props-scope-chip { margin: 4px 0 10px; font-size: 0.8rem; }
