/* ── File browser modal ───────────────────────────────────────── */
#fb-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
#fb-panel {
  background: #1e1e1e;
  border: 1px solid #3a3a3a;
  border-radius: 8px;
  width: 500px;
  max-width: 92vw;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
}
#fb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #2a2a2a;
}
#fb-title  { font-size: 13px; color: #ddd; }
#fb-close  {
  background: none; border: none; color: #666;
  font-size: 16px; cursor: pointer; padding: 0 4px; line-height: 1;
}
#fb-close:hover { color: #ccc; }
#fb-path {
  padding: 6px 16px;
  font-family: monospace;
  font-size: 10px;
  color: #666;
  border-bottom: 1px solid #222;
  word-break: break-all;
}
#fb-list {
  overflow-y: auto;
  flex: 1;
  padding: 6px 0;
}
.fb-item {
  padding: 6px 16px;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fb-item:hover  { background: #2a2a2a; }
.fb-dir         { color: #7ac; }
.fb-dir::before { content: "📁  "; }
.fb-file        { color: #aed; }
.fb-file::before{ content: "{ }  "; font-family: monospace; font-size: 10px; }
.fb-error       { padding: 16px; color: #f87; font-size: 12px; }

/* ── Setup overlay ────────────────────────────────────────────── */
#setup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
#setup-panel {
  background: #1e1e1e;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 32px;
  width: 420px;
  max-width: 90vw;
}
#setup-panel h2 { font-size: 17px; color: #eee; margin-bottom: 6px; }
.setup-hint     { color: #666; font-size: 11px; margin-bottom: 22px; }
.setup-field    { margin-bottom: 16px; }
.setup-field label {
  display: block;
  color: #999;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.choose-row   { display: flex; align-items: center; gap: 10px; }
.choose-btn   {
  flex-shrink: 0;
  padding: 6px 14px;
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 4px;
  color: #ccc;
  font-size: 12px;
  cursor: pointer;
}
.choose-btn:hover  { background: #333; border-color: #666; }
.chosen-name  { color: #888; font-size: 11px; font-family: monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#setup-error  { color: #f87; font-size: 11px; margin-bottom: 12px; line-height: 1.4; }
#setup-btn {
  width: 100%;
  padding: 9px;
  background: #2a5f9e;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  margin-top: 8px;
}
#setup-btn:hover    { background: #3a7fbe; }
#setup-btn:disabled { background: #2a2a2a; color: #555; cursor: default; }
#btn-change-load {
  margin-left: 8px;
  font-size: 11px;
  padding: 2px 8px;
  background: transparent;
  border: 1px solid #444;
  border-radius: 3px;
  color: #888;
  cursor: pointer;
}
#btn-change-load:hover { border-color: #888; color: #ccc; }

/* ── Reset / base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 13px;
  background: #1a1a1a;
  color: #ddd;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Header ───────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  background: #111;
  border-bottom: 1px solid #333;
  flex-shrink: 0;
}

header h1 {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
}

.status-loading { color: #aaa; }
.status-ready   { color: #6f6; }
.status-working { color: #fa0; }
.status-error   { color: #f66; }

/* ── Toolbar ──────────────────────────────────────────────────── */
#toolbar {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  background: #222;
  border-bottom: 1px solid #333;
  flex-shrink: 0;
  box-sizing: border-box;
}

.toolbar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 5px 12px;
  min-height: 38px;
  flex-wrap: nowrap;
}

.toolbar-row + .toolbar-row {
  border-top: 1px solid #2a2a2a;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Toolbar settings dropdowns ──────────────────────────────── */
.toolbar-advanced {
  position: relative;
}
.toolbar-advanced summary {
  font-size: 11px;
  color: #888;
  cursor: pointer;
  user-select: none;
  list-style: none;
  padding: 3px 8px;
  border: 1px solid #444;
  border-radius: 3px;
  white-space: nowrap;
}
.toolbar-advanced summary::-webkit-details-marker { display: none; }
.toolbar-advanced summary::after { content: " ▾"; font-size: 9px; }
.toolbar-advanced[open] > summary { color: #ccc; border-color: #666; }
.toolbar-advanced[open] > summary::after { content: " ▴"; font-size: 9px; }

.toolbar-advanced-panel {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 200;
  background: #2a2a2a;
  border: 1px solid #555;
  border-radius: 5px;
  padding: 10px 12px;
  min-width: 200px;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
}
.toolbar-advanced[open] .toolbar-advanced-panel { display: flex; }

.toolbar-advanced-sep {
  height: 1px;
  background: #3a3a3a;
  margin: 2px 0;
}

.toolbar-spacer { flex: 1; min-width: 0; }

/* ── Speed slider ─────────────────────────────────────────────── */
.speed-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: #999;
  cursor: default;
  white-space: nowrap;
}
.speed-row {
  display: flex;
  align-items: center;
  gap: 4px;
}
.speed-hint-text {
  font-size: 9px;
  color: #666;
}
.speed-label input[type="range"] {
  width: 80px;
  accent-color: #2a5f9e;
  cursor: pointer;
  margin: 0;
}

/* ── Toolbar vertical divider ─────────────────────────────────── */
.toolbar-vdiv {
  width: 1px;
  height: 20px;
  background: #3a3a3a;
  margin: 0 2px;
  flex-shrink: 0;
}

.btn-history {
  padding: 5px 10px;
  font-size: 14px;
  line-height: 1;
}

button {
  padding: 5px 12px;
  background: #333;
  color: #ddd;
  border: 1px solid #555;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.15s;
}
button:hover:not(:disabled) { background: #444; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

button#btn-generate  { background: #1e4d1e; border-color: #3a7a3a; opacity: 0.8; }
button#btn-generate:hover:not(:disabled)  { background: #285a28; opacity: 1; }

button#btn-add-keypoint.active {
  background: #1a3a5c;
  border-color: #4a8aba;
  color: #7abfff;
}
button#btn-add-keypoint.active:hover:not(:disabled) { background: #204a75; }

.recommend-label {
  font-size: 11px;
  color: #666;
  gap: 5px;
}

button#btn-optimize  { background: #1a3a5c; border-color: #2a5f9e; }
button#btn-optimize:hover:not(:disabled)  { background: #204a75; }

button#btn-save      { background: #4a2a00; border-color: #8a5000; }
button#btn-save:hover:not(:disabled)      { background: #5a3400; }

button#btn-composite { background: #3a1a5c; border-color: #6a2a9e; }
button#btn-composite:hover:not(:disabled) { background: #4a2275; }

label {
  display: flex;
  align-items: center;
  gap: 4px;
  color: #aaa;
  white-space: nowrap;
}

label select, label input[type="number"] {
  background: #2a2a2a;
  color: #ddd;
  border: 1px solid #555;
  border-radius: 3px;
  padding: 3px 6px;
  font-size: 12px;
  width: 90px;
}
label select { width: 100px; }

.checkbox-label { cursor: pointer; gap: 6px; }
.checkbox-label input { cursor: pointer; }

/* ── View tabs ────────────────────────────────────────────────── */
#view-tabs {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  padding: 4px 12px 0;
  background: #1a1a1a;
  border-bottom: 1px solid #444;
  flex-shrink: 0;
  height: 36px;
}

.tab {
  padding: 5px 18px 6px;
  background: #252525;
  color: #666;
  border: 1px solid #3a3a3a;
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.12s, color 0.12s;
  margin-bottom: -1px;
  line-height: 1;
}
.tab:hover:not(:disabled) { background: #2e2e2e; color: #bbb; }
.tab.active {
  background: #2a2a2a;
  color: #fff;
  border-color: #555;
  border-bottom-color: #2a2a2a;
}
.tab:disabled { opacity: 0.35; cursor: not-allowed; }

.tab-spacer { flex: 1; }
#view-tabs button:not(.tab) { margin-bottom: 4px; align-self: center; }

/* ── Main area ────────────────────────────────────────────────── */
#main-area {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#center {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  background: #111;
}

/* ── Canvas view (depth / trajectory / preview) ─────────────── */
#canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
}

#editor-canvas {
  display: block;
  cursor: default;
}

.preview-sprite-img {
  position: absolute;
  left: -9999px;
  pointer-events: none;
}

/* ── Sidebar ──────────────────────────────────────────────────── */
#sidebar {
  width: 300px;
  flex-shrink: 0;
  background: #1e1e1e;
  border-left: 1px solid #333;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-section {
  padding: 10px 12px;
  border-bottom: 1px solid #2a2a2a;
}

.sidebar-section h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #888;
  margin-bottom: 8px;
}

.hint { color: #666; font-size: 11px; line-height: 1.5; }

/* ── Hint feature list ────────────────────────────────────────── */
.hint-feature-list {
  list-style: none;
  padding: 0;
  margin: 6px 0 8px;
}
.hint-feature {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-size: 11px;
  line-height: 1.4;
  margin-bottom: 5px;
  color: #555;
}
.hint-icon {
  flex-shrink: 0;
  width: 14px;
  text-align: center;
  font-size: 11px;
  margin-top: 1px;
}
/* ready: green checkmark, muted text */
.hint-feature[data-status="ready"] .hint-icon  { color: #5a8a5a; }
.hint-feature[data-status="ready"] .hint-icon::before { content: "✓"; }
.hint-feature[data-status="ready"]             { color: #777; }
/* loading: spinner, normal text */
.hint-feature[data-status="loading"] .hint-icon::before { content: ""; }
.hint-feature[data-status="loading"] .hint-icon {
  display: inline-block;
  width: 10px; height: 10px;
  border: 1.5px solid #444;
  border-top-color: #bbb;
  border-radius: 50%;
  animation: hint-spin 0.75s linear infinite;
  margin-top: 2px;
}
@keyframes hint-spin {
  to { transform: rotate(360deg); }
}
#hint-tip { margin-top: 6px; }

/* ── Animation preview (sidebar) ─────────────────────────────── */
.anim-preview-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}
#anim-preview-canvas {
  width: 80px;
  height: 80px;
  background: #111;
  border-radius: 5px;
  border: 1px solid #333;
  flex-shrink: 0;
  image-rendering: pixelated;
}
.anim-preview-label {
  font-size: 12px;
  color: #bbb;
  font-style: italic;
}

#keypoint-list { display: flex; flex-direction: column; gap: 2px; }

.kp-row {
  display: grid;
  grid-template-columns: 18px 1fr 58px 1fr 14px;
  align-items: center;
  gap: 4px;
  padding: 3px 4px;
  border-radius: 3px;
  font-size: 11px;
  cursor: pointer;
  border: 1px solid transparent;
}
.kp-row:hover    { background: #2a2a2a; }
.kp-row.selected { background: #1a2a3a; border-color: #2a5f9e; }

.kp-idx   { color: #888; text-align: right; }
.kp-pos   { color: #ccc; font-family: monospace; font-size: 10px; }
.kp-depth-wrap { display: flex; align-items: center; gap: 1px; }
.kp-depth-input {
  width: 36px;
  background: transparent;
  border: 1px solid #444;
  border-radius: 2px;
  color: #fa8;
  font-family: monospace;
  font-size: 10px;
  text-align: right;
  padding: 1px 2px;
  -moz-appearance: textfield;
}
.kp-depth-input::-webkit-inner-spin-button,
.kp-depth-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.kp-depth-input:focus { outline: none; border-color: #fa8; background: #1e1e1e; }
.kp-depth-unit { color: #fa8; font-family: monospace; font-size: 10px; }
.kp-anim-select {
  width: 100%;
  background: transparent;
  border: 1px solid #444;
  border-radius: 2px;
  color: #6af;
  font-family: monospace;
  font-size: 10px;
  padding: 1px 2px;
  cursor: pointer;
}
.kp-anim-select:focus { outline: none; border-color: #6af; }
.kp-ontop-badge {
  font-size: 11px;
  color: #fc6;
  text-align: center;
}
#kp-count { color: #666; font-weight: normal; font-size: 11px; }

/* ── Occlusion panel ──────────────────────────────────────────── */
.occlusion-row {
  padding: 6px 0;
  border-bottom: 1px solid #252525;
}
.occlusion-row:last-child { border-bottom: none; }

.occlusion-obj-label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}
.occlusion-obj-id    { font-family: monospace; font-size: 10px; color: #aaa; }
.occlusion-obj-depth { font-family: monospace; font-size: 10px; color: #fa8; }

.occlusion-btns { display: flex; gap: 4px; }

.btn-occlude {
  flex: 1;
  padding: 3px 0;
  font-size: 10px;
  background: #262626;
  border: 1px solid #3a3a3a;
  border-radius: 3px;
  color: #666;
  cursor: pointer;
}
.btn-occlude:hover:not(.active-front):not(.active-behind):not(.active-ontop) {
  background: #2e2e2e;
  color: #aaa;
}
.btn-occlude.active-front  { background: #1a3a1a; border-color: #3a7a3a; color: #6f6; }
.btn-occlude.active-behind { background: #1a1a3a; border-color: #3a3a8a; color: #88f; }
.btn-occlude.active-ontop  { background: #3a2a0a; border-color: #8a6a2a; color: #fc6; }

/* ── Quality check panel ──────────────────────────────────────── */
.quality-ok   { color: #4c4; }
.quality-hint { color: #666; font-style: italic; }
.quality-issue {
  font-size: 11px;
  line-height: 1.5;
  padding: 3px 0;
  border-bottom: 1px solid #2a2a2a;
}
.quality-issue:last-child { border-bottom: none; }
.quality-issue-depth { color: #fa0; }
.quality-issue-flip  { color: #f66; }

/* ── Comparison panel ─────────────────────────────────────────── */
#comparison {
  flex: 1;
  display: flex;
  gap: 0;
  background: #111;
  overflow-y: auto;
}

.compare-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #333;
  overflow: hidden;
}
.compare-panel:last-child { border-right: none; }

.compare-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 10px;
  background: #1a1a1a;
  border-bottom: 1px solid #333;
  flex-shrink: 0;
}
.compare-header h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #888;
}
.btn-save-panel { font-size: 10px; padding: 2px 8px; }
.compare-panel canvas { display: block; width: 100%; height: auto; }

/* ── Composite panel ──────────────────────────────────────────── */
#composite-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0;
  background: #111;
  overflow-y: auto;
}

#composite-cfg {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 28px 32px;
  border-bottom: 1px solid #2a2a2a;
  max-width: 440px;
}

#composite-cfg h2 {
  font-size: 13px;
  font-weight: 600;
  color: #ccc;
  margin-bottom: 4px;
}

#composite-cfg label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #aaa;
}

#composite-cfg select,
#composite-cfg input[type="number"] {
  background: #2a2a2a;
  color: #ddd;
  border: 1px solid #555;
  border-radius: 3px;
  padding: 4px 8px;
  font-size: 12px;
  width: 150px;
}

#composite-cfg select { width: 170px; }

#btn-composite {
  align-self: flex-start;
  margin-top: 8px;
  padding: 7px 20px;
  font-size: 13px;
}

#composite-result {
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#composite-msg {
  color: #666;
  font-size: 12px;
}

#composite-download {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}

.download-links {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.download-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  background: #1e4d1e;
  color: #6f6;
  border: 1px solid #3a7a3a;
  border-radius: 4px;
  text-decoration: none;
  font-size: 13px;
  transition: background 0.15s;
}
.download-btn:hover { background: #285a28; }

.download-btn-raw {
  background: #2a2a1a;
  color: #cc9;
  border-color: #6a6a3a;
}
.download-btn-raw:hover { background: #38381f; }

#composite-elapsed {
  color: #666;
  font-size: 11px;
}

/* ── Video overlay (replaces Video tab) ──────────────────────── */
#video-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: #0a0a0a;
  flex-direction: column;
}

#video-overlay-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: #111;
  border-bottom: 1px solid #333;
  flex-shrink: 0;
}

#btn-video-close {
  flex-shrink: 0;
  background: #2a2a2a;
  border-color: #555;
  color: #bbb;
  font-size: 12px;
  padding: 4px 10px;
}
#btn-video-close:hover:not(:disabled) { background: #3a3a3a; color: #fff; }

#video-overlay-status {
  flex: 1;
  font-size: 12px;
  color: #888;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#video-overlay-topbar .overlay-download-btn {
  flex-shrink: 0;
  padding: 5px 14px;
  font-size: 12px;
}

#video-overlay-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 16px;
}

#video-overlay-msg {
  color: #888;
  font-size: 13px;
}

#video-overlay-body video {
  max-width: 100%;
  max-height: 100%;
  border-radius: 4px;
  background: #000;
}

/* ── Floating corner overlay buttons (Make Video) ─────────────── */
.canvas-overlay-corner {
  position: absolute;
  bottom: 16px;
  right: 16px;
  z-index: 10;
}
#btn-make-video {
  font-size: 13px;
  font-weight: 600;
  padding: 9px 20px;
  background: #2a5f9e;
  border: none;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
#btn-make-video:hover:not(:disabled) { background: #3a70b0; }
#btn-make-video:disabled { background: #333; color: #666; cursor: default; box-shadow: none; }
.overlay-download-btn {
  display: inline-block;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 20px;
  background: #2a7a4f;
  border-radius: 6px;
  color: #fff;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.overlay-download-btn:hover { background: #3a8a5f; }

#composite-video {
  max-width: 100%;
  max-height: 100%;
  border-radius: 4px;
  background: #000;
}

/* ── Library tab ──────────────────────────────────────── */
#library-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #111;
  overflow-y: auto;
}

#library-cfg {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 28px 32px;
}

#library-cfg h2 {
  font-size: 13px;
  font-weight: 600;
  color: #ccc;
  margin-bottom: 4px;
}

#library-cfg label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #aaa;
}

#library-cfg select {
  background: #2a2a2a;
  color: #ddd;
  border: 1px solid #555;
  border-radius: 3px;
  padding: 4px 8px;
  font-size: 12px;
  width: 230px;
}

.library-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.library-msg {
  font-size: 12px;
  color: #888;
  min-height: 16px;
}

.library-msg.library-error { color: #e57373; }

#library-local-link { color: #6ab7ff; text-decoration: none; }
#library-local-link:hover { text-decoration: underline; }

.library-sep { border: 0; border-top: 1px solid #2a2a2a; margin: 10px 0; }
#btn-library-save { align-self: flex-start; }

.library-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid #2a2a2a;
}
.library-footer .library-msg { margin: 0; }
button#btn-library-load { background: #1a3a5c; border-color: #2a5f9e; flex-shrink: 0; }
button#btn-library-load:hover:not(:disabled) { background: #204a75; }

#library-cfg input[type="text"] {
  background: #2a2a2a;
  color: #ddd;
  border: 1px solid #555;
  border-radius: 3px;
  padding: 4px 8px;
  font-size: 12px;
}
#library-cfg input[type="file"] { color: #aaa; font-size: 12px; max-width: 220px; }
.library-actions { flex-wrap: wrap; align-items: center; }

/* ── Generate a creature (user's own Gemini key) ───────────────── */
.creature-gen {
  border: 1px solid #2a2a2a;
  border-radius: 6px;
  padding: 8px 12px;
  margin: 10px 0;
  background: #1e1e1e;
}
.cg-summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: #cbe6cb;
  user-select: none;
}
.cg-form { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; max-width: 360px; }
.cg-field { display: flex; flex-direction: column; gap: 3px; }
.cg-field label { font-size: 11px; color: #aaa; }
.cg-inline-hint { color: #666; font-weight: normal; }
.creature-gen input[type="text"],
.creature-gen input[type="password"] {
  background: #2a2a2a;
  color: #ddd;
  border: 1px solid #555;
  border-radius: 3px;
  padding: 5px 8px;
  font-size: 12px;
  width: 100%;
  box-sizing: border-box;
}
.creature-gen input:focus { outline: none; border-color: #3a7a3a; }
.cg-actions { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
button#cg-submit { background: #1e4d1e; border-color: #3a7a3a; }
button#cg-submit:hover:not(:disabled) { background: #285a28; }
.cg-status { font-size: 12px; color: #888; min-height: 16px; }
.cg-status.cg-error { color: #e57373; }
.cg-status.cg-done  { color: #6abf69; }
.cg-status.cg-warn  { color: #e5b567; }  /* "unusable" — terminal but not an error */

.cg-result { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.cg-result h4 { margin: 0; font-size: 13px; color: #ddd; }
.cg-result .cg-meta { font-size: 11px; color: #999; line-height: 1.5; }
.cg-appearance {
  max-width: 220px;
  border-radius: 6px;
  border: 1px solid #333;
  image-rendering: pixelated;
  background: #111;
}
.cg-anim-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.cg-anim-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px;
  background: #222;
  border: 1px solid #333;
  border-radius: 6px;
}
.cg-anim-card img {
  width: 96px;
  height: 96px;
  object-fit: contain;
  image-rendering: pixelated;
  background: #111;
  border-radius: 4px;
}
.cg-anim-card .cg-anim-name { font-size: 11px; color: #bbb; }

#save-render-msg { font-size: 12px; margin-left: 8px; align-self: center; }
#save-render-msg.save-render-ok  { color: #6abf69; }
#save-render-msg.save-render-err { color: #e57373; }

/* ── Library gallery (card grids) ──────────────────────────────── */
.lib-subtabs {
  display: flex;
  gap: 6px;
  margin: 4px 0 2px;
}
.lib-subtab {
  padding: 5px 16px;
  background: #262626;
  border: 1px solid #3a3a3a;
  border-radius: 4px;
  color: #888;
  font-size: 12px;
  cursor: pointer;
}
.lib-subtab:hover:not(.active) { background: #2e2e2e; color: #bbb; }
.lib-subtab.active {
  background: #2a2a2a;
  color: #fff;
  border-color: #2a5f9e;
}

.lib-gallery-section { display: none; }
.lib-gallery-section.active {
  display: block;
  max-height: 55vh;
  overflow-y: auto;
}

.lib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 8px;
  max-width: 1100px;
}

.lib-card {
  display: flex;
  flex-direction: column;
  background: #1e1e1e;
  border: 1px solid #333;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.lib-card:hover    { border-color: #555; background: #222; }
.lib-card.selected { border-color: #2a5f9e; background: #1a2a3a; }

.lib-card-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background-color: #262626;
  background-image:
    linear-gradient(45deg, #333 25%, transparent 25%, transparent 75%, #333 75%, #333),
    linear-gradient(45deg, #333 25%, transparent 25%, transparent 75%, #333 75%, #333);
  background-size: 16px 16px;
  background-position: 0 0, 8px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.lib-card-thumb img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.lib-thumb-placeholder {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #333;
  color: #888;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
}

.lib-card-body { padding: 8px 10px; }
.lib-card-name {
  font-size: 12px;
  font-weight: 600;
  color: #ddd;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lib-card-meta {
  font-size: 10px;
  color: #888;
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.lib-card-actions {
  display: flex;
  gap: 6px;
  padding: 0 10px 10px;
  margin-top: auto;
}
.lib-card-btn {
  flex: 1;
  padding: 4px 0;
  font-size: 11px;
  background: #262626;
  border: 1px solid #3a3a3a;
  border-radius: 3px;
  color: #aaa;
  cursor: pointer;
}
.lib-card-btn:hover:not(:disabled) { background: #2e2e2e; color: #ddd; }
.lib-card-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.lib-card-btn-primary { border-color: #2a5f9e; color: #6ab7ff; }
.lib-card-btn-primary:hover:not(:disabled) { background: #1a2a3a; }

/* ── Classic picker (kept for comparison/debugging) ────────────── */
.scene-upload-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0 10px;
  flex-wrap: wrap;
}
.scene-upload-btn {
  padding: 5px 14px;
  background: #1e2e1e;
  border: 1px solid #3a6a3a;
  border-radius: 4px;
  color: #7abf7a;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.scene-upload-btn:hover:not(:disabled) { background: #243824; }
.scene-upload-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── State viewer (per-creature animation preview) ─────────────── */
.state-viewer {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 28px 32px;
  overflow-y: auto;
}

.sv-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}
.sv-eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #888;
}
.sv-header h3 { font-size: 18px; color: #fff; margin-top: 2px; }

.sv-close { background: #262626; border-color: #3a3a3a; color: #aaa; }
.sv-close:hover:not(:disabled) { background: #2e2e2e; color: #ddd; }

.sv-body {
  display: flex;
  gap: 24px;
  flex: 1;
  min-height: 0;
}

.sv-preview-pane {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.sv-preview-box {
  width: 320px;
  height: 320px;
  background-color: #262626;
  background-image:
    linear-gradient(45deg, #333 25%, transparent 25%, transparent 75%, #333 75%, #333),
    linear-gradient(45deg, #333 25%, transparent 25%, transparent 75%, #333 75%, #333);
  background-size: 20px 20px;
  background-position: 0 0, 10px 10px;
  border: 1px solid #333;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#sv-canvas { max-width: 100%; max-height: 100%; image-rendering: pixelated; }

.sv-meta { color: #888; font-size: 12px; text-align: center; }

.sv-select-btn { background: #1a3a5c; border-color: #2a5f9e; color: #6ab7ff; }
.sv-select-btn:hover:not(:disabled) { background: #204a75; }

.sv-anim-grid {
  flex: 1;
  align-content: flex-start;
  overflow-y: auto;
  margin-bottom: 0;
}

.sv-anim-card.active { border-color: #3a7fbe; background: #1a2a3a; }
