:root {
  --bg: #0a0a0a;
  --panel: #141414;
  --panel-2: #1c1c1c;
  --border: #2a2a2a;
  --border-strong: #3a3a3a;
  --text: #f0f0f0;
  --dim: #8a8a8a;
  --accent: #ff7a3d;
  --ok: #4ade80;
  --err: #f87171;
  --warn: #fbbf24;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 15px;
  line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }
img { display: block; }

.topbar { display: flex; justify-content: space-between; align-items: center;
  padding: 14px 28px; border-bottom: 1px solid var(--border); background: #050505;
  position: sticky; top: 0; z-index: 50; }
.topbar .brand { font-weight: 700; font-size: 22px; letter-spacing: -0.03em; color: var(--text); }
.topbar nav a { margin-left: 16px; color: var(--dim); }
.topbar nav .user { margin-right: 12px; color: var(--dim); font-size: 13px; }

.content { padding: 28px; max-width: 1400px; margin: 0 auto; }
.footer { text-align: center; color: var(--dim); font-size: 12px; padding: 24px; }

.flashes { padding: 12px 28px; }
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 6px; }
.flash-error { background: #3a1414; color: #ffb4b4; }
.flash-success { background: #143a14; color: #b4ffb4; }

h1 { font-weight: 600; letter-spacing: -0.02em; margin: 0 0 18px; }
h2 { font-weight: 600; letter-spacing: -0.01em; margin: 0; font-size: 18px; }
h3 { font-weight: 600; letter-spacing: -0.005em; margin: 24px 0 12px; font-size: 15px; }
h4 { font-weight: 600; margin: 14px 0 6px; font-size: 13px; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--dim); }
.dim { color: var(--dim); font-weight: normal; font-size: 13px; }
.empty { color: var(--dim); padding: 30px 0; text-align: center; font-size: 14px; }

.breadcrumb { color: var(--dim); margin-bottom: 8px; font-size: 13px; }
.breadcrumb a { color: var(--dim); }
.breadcrumb a:hover { color: var(--text); }

/* ---- auth ---- */
.auth-card { max-width: 360px; margin: 60px auto; background: var(--panel);
  padding: 32px; border-radius: 10px; border: 1px solid var(--border); }
.auth-card h1 { margin-bottom: 24px; }
.form label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--dim); }
.form input { display: block; width: 100%; margin-top: 4px; padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 6px; }
.form input:focus { outline: none; border-color: var(--accent); }
.form button, .btn-primary, .btn-secondary { padding: 10px 18px; background: var(--accent); color: #000;
  border: none; border-radius: 6px; font-weight: 600; cursor: pointer; font-size: 14px;
  transition: filter .15s, transform .05s; }
.btn-secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border-strong); }
.form button:hover, .btn-primary:hover { filter: brightness(1.1); }
.btn-primary:active, .btn-secondary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.5; cursor: wait; }

/* ---- page header ---- */
.page-header { display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 18px; flex-wrap: wrap; gap: 12px; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { padding: 8px 12px; background: var(--panel); border: 1px solid var(--border);
  color: var(--text); border-radius: 6px; min-width: 220px; }

/* ---- project grid ---- */
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.project-card { background: var(--panel); padding: 20px; border-radius: 10px;
  border: 1px solid var(--border); color: var(--text); transition: border-color .15s, transform .05s; }
.project-card:hover { border-color: var(--accent); text-decoration: none; }
.project-card:active { transform: translateY(1px); }
.project-card h2 { margin: 0 0 12px; font-size: 18px; }
.stats { list-style: none; padding: 0; margin: 0; color: var(--dim); font-size: 13px; }
.stats li { display: inline-block; margin-right: 14px; }

/* ---- project section ---- */
.proj-section { margin: 28px 0; }
.proj-section-head { display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 12px; }

/* ---- thumbnail rows (horizontal scroll) ---- */
.thumb-row { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; }
.thumb-row::-webkit-scrollbar { height: 8px; }
.thumb-row::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

.thumb-small { flex-shrink: 0; cursor: zoom-in; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 6px; padding: 0; overflow: hidden;
  color: var(--text); text-align: left; transition: border-color .15s, transform .05s; }
.thumb-small:hover { border-color: var(--accent); }
.thumb-small:active { transform: translateY(1px); }
.thumb-small img { width: 100%; object-fit: cover; display: block; background: #000; }
.thumb-small span { display: block; font-size: 11px; color: var(--dim); margin: 4px 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.thumb-small-portrait { width: 110px; }
.thumb-small-portrait img { aspect-ratio: 4/5; }
.thumb-small-landscape { width: 200px; }
.thumb-small-landscape img { aspect-ratio: 16/9; }

.thumb-more { display: flex; align-items: center; justify-content: center; text-decoration: none; }
.thumb-small.thumb-more.thumb-small-portrait { min-height: 138px; }
.thumb-small.thumb-more.thumb-small-landscape { min-height: 112px; }
.more-inner { color: var(--dim); text-align: center; font-size: 18px; line-height: 1.2; }
.more-inner small { font-size: 11px; }

/* ---- gallery (full grid) ---- */
.thumb-grid { display: grid; gap: 14px; }
.thumb-grid-portrait { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.thumb-grid-landscape { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.thumb-card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  overflow: hidden; cursor: zoom-in; padding: 0; color: var(--text); text-align: left;
  transition: border-color .15s, transform .05s; width: 100%; }
.thumb-card:hover { border-color: var(--accent); }
.thumb-card:active { transform: translateY(1px); }
.thumb-card img { width: 100%; object-fit: cover; background: #000; }
.thumb-grid-portrait .thumb-card img { aspect-ratio: 4/5; }
.thumb-grid-landscape .thumb-card img { aspect-ratio: 16/9; }
.thumb-meta { padding: 8px 10px; }
.thumb-meta strong { display: block; font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- scene list ---- */
.scene-list { list-style: none; padding: 0; }
.scene-list li { background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
  margin-bottom: 6px; }
.scene-list a { display: flex; justify-content: space-between; padding: 12px 16px;
  color: var(--text); align-items: center; gap: 12px; }
.scene-list a:hover { text-decoration: none; background: var(--panel-2); border-color: var(--accent); }
.status { padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em; display: inline-block; }
.status-draft { background: #2a2a2a; color: #aaa; }
.status-generating { background: #3a3014; color: #fbbf24; }
.status-complete { background: #14391c; color: #4ade80; }
.status-failed { background: #3a1414; color: #f87171; }
.status-unknown { background: #2a2a2a; color: #777; }

/* ---- scene builder ---- */
.scene-builder { display: grid; grid-template-columns: 320px 1fr; gap: 20px; }
.library { background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 14px; max-height: calc(100vh - 120px); overflow-y: auto;
  position: sticky; top: 80px; }
.library-section { margin-bottom: 20px; }
.library-section h3 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--dim); }
.library-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.lib-thumb { background: var(--panel-2); border: 1px solid var(--border); border-radius: 4px;
  cursor: grab; padding: 4px; transition: border-color .15s; user-select: none; }
.lib-thumb:hover { border-color: var(--accent); }
.lib-thumb:active { cursor: grabbing; }
.lib-thumb img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 3px; }
.lib-thumb-landscape img { aspect-ratio: 16/9; }
.lib-thumb span { display: block; font-size: 10px; margin-top: 4px; color: var(--dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-thumb.dragging { opacity: 0.4; }

.builder-main { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.form-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.form-row label { display: block; font-size: 12px; color: var(--dim); }
.form-row .grow { flex: 1; min-width: 200px; }
.form-row input, .form-row select { display: block; margin-top: 4px; padding: 8px 10px;
  background: var(--panel); border: 1px solid var(--border); color: var(--text); border-radius: 6px;
  font-size: 14px; }
.form-row .grow input { width: 100%; }
.form-row input:focus, .form-row select:focus { outline: none; border-color: var(--accent); }

.media-pool { min-height: 100px; background: var(--panel); border: 2px dashed var(--border);
  border-radius: 8px; padding: 12px; display: flex; flex-wrap: wrap; gap: 8px;
  align-content: flex-start; align-items: flex-start; transition: border-color .15s, background .15s; }
.media-pool.drag-over { border-color: var(--accent); background: #1c1410; }
.media-pool:empty::before { content: attr(data-empty); color: var(--dim); margin: auto;
  font-size: 13px; padding: 20px; }
.pool-item { position: relative; width: 100px; }
.pool-item-landscape { width: 160px; }
.pool-item img { width: 100%; object-fit: cover; border-radius: 4px;
  border: 1px solid var(--border); cursor: zoom-in; aspect-ratio: 1; background: #000; }
.pool-item-landscape img { aspect-ratio: 16/9; }
.pool-item img:hover { border-color: var(--accent); }
.pool-item .remove { position: absolute; top: -6px; right: -6px; background: var(--err); color: #000;
  border: none; width: 22px; height: 22px; border-radius: 50%; cursor: pointer; font-weight: 700;
  font-size: 14px; line-height: 1; padding: 0; z-index: 2; }
.pool-item .label { display: block; font-size: 10px; color: var(--dim); margin-top: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.master-prompt, .training-prompts { width: 100%; background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 12px; font-family: inherit;
  font-size: 14px; resize: vertical; line-height: 1.5; }
.master-prompt { min-height: 240px; }
.master-prompt:focus, .training-prompts:focus { outline: none; border-color: var(--accent); }
.advanced summary { cursor: pointer; padding: 8px 0; color: var(--dim); font-size: 13px;
  user-select: none; }
.advanced summary:hover { color: var(--text); }

.action-row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 10px; flex-wrap: wrap; }
.status-area { padding: 12px; border-radius: 6px; font-size: 13px; min-height: 20px;
  background: transparent; }
.status-area.ok { background: #143a14; color: #b4ffb4; }
.status-area.err { background: #3a1414; color: #ffb4b4; }
.status-area.info { background: #14233a; color: #b4d4ff; }

.prompt-box { background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
  padding: 14px; white-space: pre-wrap; font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 12px; max-height: 500px; overflow-y: auto; line-height: 1.5; }

.segment-list { list-style: none; padding: 0; }
.segment-list li { background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
  padding: 12px; margin-bottom: 8px; }
.segment-list .error { color: var(--err); font-size: 12px; margin-top: 6px; }

/* ---- lightbox modal ---- */
.lightbox { position: fixed; inset: 0; z-index: 100; display: none; }
.lightbox[aria-hidden="false"] { display: block; }
.lightbox-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.85);
  backdrop-filter: blur(4px); cursor: pointer; }
.lightbox-panel { position: absolute; inset: 24px; max-width: 1400px; max-height: calc(100vh - 48px);
  margin: auto; background: var(--panel); border: 1px solid var(--border-strong); border-radius: 12px;
  overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,0.5); display: flex; flex-direction: column; }
.lightbox-close { position: absolute; top: 12px; right: 12px; background: rgba(0,0,0,0.6);
  color: #fff; border: none; width: 36px; height: 36px; border-radius: 50%; font-size: 22px;
  cursor: pointer; z-index: 10; line-height: 1; padding: 0; }
.lightbox-close:hover { background: var(--err); color: #000; }
.lightbox-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 0; height: 100%; overflow: hidden; }
.lightbox-image { background: #000; display: flex; align-items: center; justify-content: center;
  overflow: hidden; min-height: 0; }
.lightbox-image img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox-meta { padding: 24px; overflow-y: auto; border-left: 1px solid var(--border); }
.lightbox-meta h3 { margin: 0 0 6px; font-size: 18px; word-wrap: break-word; }
.lightbox-meta #lightbox-kind { text-transform: lowercase; font-size: 12px; letter-spacing: 0.1em; }
.lightbox-prompt-wrap { margin-top: 20px; }
.lightbox-prompt-wrap .prompt-box { max-height: 32vh; }

.lightbox-subhead { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; }
.version-badge { background: var(--panel-2); border: 1px solid var(--border); border-radius: 4px;
  padding: 2px 8px; font-size: 11px; color: var(--dim); }
.active-badge { background: var(--ok); color: #000; padding: 2px 8px; border-radius: 4px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }

/* Modify box */
.modify-box { background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 14px; margin-bottom: 12px; }
.modify-label { display: block; font-size: 13px; color: var(--text); margin-bottom: 6px; font-weight: 600; }
.modify-label .dim { display: block; font-weight: normal; font-size: 11px; margin-top: 2px; }
.modify-input { width: 100%; background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 10px; font-family: inherit; font-size: 13px; resize: vertical; }
.modify-input:focus { outline: none; border-color: var(--accent); }
.modify-actions { display: flex; gap: 10px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.modify-actions .btn-primary { padding: 8px 14px; font-size: 13px; }
.modify-status { font-size: 12px; color: var(--dim); flex: 1; min-width: 0; word-break: break-word; }
.modify-status.ok { color: var(--ok); }
.modify-status.err { color: var(--err); }
.modify-status.info { color: var(--warn); }

/* Version slideshow strip below the image */
.lightbox-image-pane { display: flex; flex-direction: column; min-height: 0;
  background: #000; }
.lightbox-image-pane .lightbox-image { flex: 1; min-height: 0; }
.lightbox-versions { display: flex; gap: 6px; padding: 8px; background: #050505;
  border-top: 1px solid var(--border); overflow-x: auto; flex-shrink: 0; max-height: 100px; }
.version-thumb { background: var(--panel-2); border: 2px solid var(--border); border-radius: 4px;
  cursor: pointer; padding: 0; flex-shrink: 0; transition: border-color .12s; overflow: hidden;
  width: 70px; }
.version-thumb img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.version-thumb .vlabel { display: block; font-size: 9px; color: var(--dim); padding: 2px 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.version-thumb:hover { border-color: var(--accent); }
.version-thumb.selected { border-color: var(--accent); }
.version-thumb.is-active .vlabel { color: var(--ok); font-weight: 600; }

/* Version action buttons */
.version-actions { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.version-actions button { font-size: 12px; padding: 7px 12px; }

/* Pool item version chip */
.pool-item .ver { position: absolute; top: 4px; left: 4px; background: rgba(0,0,0,0.7);
  color: var(--accent); font-size: 10px; font-weight: 600; padding: 2px 5px; border-radius: 3px;
  pointer-events: none; }

/* ---- responsive ---- */
@media (max-width: 900px) {
  .scene-builder { grid-template-columns: 1fr; }
  .library { position: static; max-height: 320px; }
  .lightbox-grid { grid-template-columns: 1fr; grid-template-rows: 50% 50%; }
  .lightbox-image img { max-height: 100%; }
  .lightbox-meta { border-left: none; border-top: 1px solid var(--border); }
  .lightbox-panel { inset: 8px; }
  .content { padding: 16px; }
  .topbar { padding: 12px 16px; }
}
