:root {
  --bg: #fafafb;
  --surface: #ffffff;
  --surface-2: #f5f5f7;
  --border: #ececef;
  --border-strong: #d2d2d7;
  --text: #1d1d1f;
  --muted: #86868b;
  /* myClip brand navy. Hover swatch is slightly lighter (one Lab step) so
     the button still reads as "pressed → released" without losing contrast
     against the white surface. */
  --accent: #1e3a5f;
  --accent-hover: #2a4d7a;
  --accent-soft: rgba(30, 58, 95, 0.08);
  --favorite: #ffd60a;
  --danger: #ff3b30;
  --success: #34c759;
  --scene-color: #4f9eea;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.brand {
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}

.brand-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.content-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  /* Right padding reserves space for the fixed-positioned #user-widget
     (email + usage badge + logout pill) at top: 12px, right: 16px. Without
     this, "+ 새 프로젝트" and the project selector would slide under the
     widget on wide screens. */
  padding: 14px 360px 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

/* On narrow screens the widget shrinks (see media query below) so the
   reserved padding can shrink too. */
@media (max-width: 720px) {
  .content-toolbar { padding: 14px 170px 14px 16px; }
}

.toolbar-spacer { flex: 1; }

#project-select {
  min-width: 200px;
  padding: 7px 10px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: white;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px 10px;
}

.sidebar-header h2 {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.scene-list {
  padding: 0 12px 16px;
}

.scene-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.scene-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.12s, border-color 0.12s;
}

.scene-item:hover { background: var(--bg); }
.scene-item.active {
  background: var(--accent-soft);
  border-color: rgba(0, 113, 227, 0.3);
}

.scene-item-arrows {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.scene-item-arrows button {
  padding: 1px 4px;
  font-size: 9px;
  line-height: 1;
  border: 1px solid var(--border);
  background: transparent;
}

.scene-item-main {
  flex: 1;
  min-width: 0;
}

.scene-item-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scene-item-meta {
  font-size: 11px;
  color: var(--muted);
  display: flex;
  gap: 6px;
  margin-top: 2px;
}

.scene-item-meta .unmapped { color: var(--danger); }

.pause-tag {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 5px;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  background: var(--surface-2);
  color: var(--muted);
  border-radius: 3px;
}

.scene-item.active .pause-tag { background: rgba(255, 255, 255, 0.7); }

.scene-item-count {
  font-size: 10px;
  color: var(--muted);
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 8px;
}

.scene-item.active .scene-item-count { background: var(--surface); }

.empty-state {
  padding: 50px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.content {
  padding: 20px 24px;
  overflow-y: auto;
}

.scene-detail { max-width: 920px; }

/* ===== Video panel & Timeline ===== */

.video-panel {
  background: var(--surface);
  padding: 16px 20px;
  border-radius: 12px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}

.video-upload-zone {
  border: 2px dashed var(--border-strong);
  border-radius: 10px;
  padding: 28px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}

.video-upload-zone:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.video-upload-zone p {
  font-size: 13px;
  color: var(--muted);
  margin-top: 6px;
}

.video-upload-zone .icon {
  font-size: 28px;
}

#video-file-input { display: none; }

.video-stage {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.video-stage video {
  width: 360px;
  max-width: 100%;
  border-radius: 8px;
  background: #000;
  display: block;
}

.video-meta {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.video-meta strong { color: var(--text); }

.video-meta-actions {
  margin-top: 6px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.timeline-wrap {
  margin-top: 12px;
}

.tl-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--muted);
  margin-bottom: 4px;
  font-variant-numeric: tabular-nums;
}

.tl-track {
  position: relative;
  height: 56px;
  background: linear-gradient(to bottom, #f0f0f3, #e8e8ed);
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  overflow: hidden;
  user-select: none;
  touch-action: none;
}

.tl-playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--danger);
  pointer-events: none;
  z-index: 4;
}

.tl-playhead::before {
  content: "";
  position: absolute;
  top: -4px;
  left: -5px;
  width: 12px;
  height: 8px;
  background: var(--danger);
  border-radius: 2px;
}

.tl-block {
  position: absolute;
  top: 4px;
  bottom: 4px;
  background: var(--scene-color);
  border-radius: 5px;
  display: flex;
  color: white;
  font-size: 11px;
  cursor: grab;
  min-width: 18px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.tl-block.selected {
  background: var(--accent);
  z-index: 3;
  outline: 2px solid #fff;
  outline-offset: -2px;
}

.tl-block.dragging { cursor: grabbing; opacity: 0.85; }

.tl-handle {
  width: 8px;
  flex-shrink: 0;
  background: rgba(0, 0, 0, 0.15);
  cursor: ew-resize;
}

.tl-handle:hover { background: rgba(0, 0, 0, 0.3); }
.tl-handle.left { border-radius: 5px 0 0 5px; }
.tl-handle.right { border-radius: 0 5px 5px 0; }

.tl-block-body {
  flex: 1;
  padding: 4px 6px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  cursor: grab;
}

.tl-block-body.empty-block { cursor: default; }

.tl-block-label {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.tl-block-time {
  font-size: 9px;
  opacity: 0.85;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
}

.tl-hint {
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
  text-align: center;
}

/* ===== Scene detail ===== */

.scene-header {
  background: var(--surface);
  padding: 18px 22px;
  border-radius: 12px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.scene-header-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.scene-header-row input.scene-name {
  flex: 1;
  font-size: 18px;
  font-weight: 600;
  border: none;
  background: transparent;
  padding: 4px 0;
  min-width: 0;
}

.scene-header-row input.scene-name:focus {
  outline: none;
  border-bottom: 2px solid var(--accent);
}

.segment-panel {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 13px;
}

.segment-panel .seg-field {
  display: flex;
  align-items: center;
  gap: 6px;
}

.segment-panel .seg-field input {
  width: 90px;
  padding: 5px 8px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.segment-panel .seg-label {
  font-size: 11px;
  color: var(--muted);
}

.scene-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.scene-toolbar .gap-control {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.scene-toolbar .gap-control input {
  width: 70px;
  padding: 5px 8px;
  font-size: 12px;
  text-align: center;
}

.card {
  background: var(--surface);
  padding: 18px 22px;
  border-radius: 12px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

.card h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
}

textarea, input[type="text"], input[type="number"], select {
  font-family: inherit;
  font-size: 13px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  padding: 8px 11px;
  background: white;
  width: 100%;
}

textarea { resize: vertical; min-height: 80px; }

textarea:focus, input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
}

.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 8px 0;
}

label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: var(--muted);
  flex: 1;
  min-width: 140px;
}

label.full {
  display: block;
  margin-bottom: 10px;
}

label.full span {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 3px;
}

button {
  border: 1px solid var(--border);
  background: white;
  color: var(--text);
  padding: 7px 12px;
  border-radius: 7px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 450;
  transition: background 0.12s, border-color 0.12s, transform 0.05s;
}

button:hover { background: var(--surface-2); border-color: var(--border-strong); }
button:active { transform: scale(0.98); }

button.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  font-weight: 500;
}

button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

button.ghost:hover { background: var(--surface-2); color: var(--text); border-color: transparent; }

button.danger {
  border-color: var(--border);
}

button.danger:hover {
  background: #fff0f0;
  border-color: var(--danger);
  color: var(--danger);
}

button.ghost.danger { color: var(--muted); }
button.ghost.danger:hover { background: #fff0f0; color: var(--danger); }

button.primary.small, button.small { padding: 6px 11px; font-size: 12px; }

button:disabled { opacity: 0.5; cursor: not-allowed; }

.step-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px 8px 8px;
  font-size: 13px;
  font-weight: 500;
}

.dub-lang {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 7px;
  padding: 4px 8px 4px 10px;
  min-width: auto;
  flex: none;
}

.dub-lang-label {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}

.dub-lang select {
  border: none;
  background: transparent;
  padding: 4px 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  width: auto;
}

.dub-lang select:focus { box-shadow: none; }

.step-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  flex: none;
}

.step-text { line-height: 1; }

.action-divider {
  width: 1px;
  align-self: stretch;
  background: rgba(0, 0, 0, 0.08);
  margin: 2px 4px;
}

.actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.status { font-size: 12px; color: var(--muted); }
.status.error { color: var(--danger); }
.status.success { color: var(--success); }

/* Narration cards */

.narration {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
  margin-bottom: 10px;
}

.narration.favorite {
  border-color: var(--favorite);
  background: #fffdf2;
}

.narration-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  gap: 10px;
  flex-wrap: wrap;
}

.narration-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 500;
  font-size: 13px;
}

.order-badge {
  background: var(--bg);
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 8px;
}

.fav-mark { color: var(--favorite); font-size: 13px; }

.narration-tags { font-size: 11px; color: var(--muted); }

.narration-tags .tag {
  display: inline-block;
  padding: 2px 6px;
  background: var(--bg);
  border-radius: 4px;
  margin-right: 3px;
}

.narration-text {
  font-size: 13px;
  margin-bottom: 6px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.narration-instructions {
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
  margin-bottom: 6px;
}

.narration audio {
  width: 100%;
  height: 34px;
  margin-bottom: 8px;
}

.narration-actions {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.icon-btn { padding: 4px 9px; font-size: 11px; }

.icon-btn.fav-on {
  background: var(--favorite);
  border-color: var(--favorite);
  color: #5c4a00;
}

.icon-btn.danger:hover {
  background: #fff0f0;
  border-color: var(--danger);
  color: var(--danger);
}

.narration-edit { padding: 10px 0 4px; }

.edit-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 6px;
}

.bar-sep {
  width: 1px;
  height: 22px;
  background: var(--border);
  margin: 0 4px;
}

/* ===== Modal ===== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.modal-backdrop.open {
  display: flex;
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--surface);
  border-radius: 14px;
  max-width: 720px;
  width: 100%;
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

.modal-header {
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 { font-size: 16px; font-weight: 600; }

.modal-tabs {
  display: flex;
  gap: 2px;
  padding: 0 22px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.modal-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 10px 16px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  margin-bottom: -1px;
}

.modal-tab:hover { background: var(--bg); color: var(--text); }

.modal-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 500;
  background: transparent;
}

.tab-pane { display: block; }
.tab-pane[hidden] { display: none; }

.field-row {
  display: flex;
  gap: 12px;
  margin: 10px 0;
  flex-wrap: wrap;
}

.field {
  flex: 1;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field > label {
  display: block;
  font-size: 12px;
  color: var(--text);
  font-weight: 500;
  flex: none;
  min-width: auto;
}

.field > select {
  width: 100%;
  color: var(--text);
  background: white;
  cursor: pointer;
}

.field > select:hover { border-color: var(--accent); }


.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0 6px;
}

.modal-close:hover { color: var(--text); background: transparent; }

.modal-body {
  padding: 16px 22px;
  overflow-y: auto;
  flex: 1;
}

.modal-intro {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 14px;
  line-height: 1.6;
}

.modal-intro code {
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11px;
}

.modal-body textarea { min-height: 200px; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  flex-direction: row;
  min-width: auto;
  margin-top: 4px;
}

.checkbox-row input { cursor: pointer; }

.modal-info { margin-top: 8px; font-size: 12px; color: var(--muted); min-height: 18px; }

/* Concat (영상 합치기) modal — ordered list with reorder + remove buttons */
.concat-list {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  max-height: 280px;
  overflow-y: auto;
}
.concat-list .concat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.concat-list .concat-row:last-child { border-bottom: none; }
.concat-list .concat-row .ord {
  min-width: 22px;
  text-align: center;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.concat-list .concat-row .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.concat-list .concat-row .size {
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.concat-list .concat-row .icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
}
.concat-list .concat-row .icon-btn:hover { background: var(--border); }
.concat-list .concat-row .icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.concat-list .concat-row .icon-btn.danger { color: #c33; }
.concat-list #concat-empty-hint { padding: 14px; margin: 0; text-align: center; }

/* Per-clip duration controls inside each row */
.concat-list .concat-row .dur-orig {
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  min-width: 58px;
  text-align: right;
}
.concat-list .concat-row .dur-arrow {
  color: var(--muted);
  font-size: 11px;
}
.concat-list .concat-row .dur-input {
  width: 64px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  background: var(--card-bg, white);
  color: inherit;
}
.concat-list .concat-row .dur-input:focus {
  outline: none;
  border-color: var(--accent, #4a7);
}
.concat-list .concat-row .dur-input.changed {
  background: #fffbe6;
  border-color: #d4a017;
}
.concat-list .concat-row .dur-unit {
  color: var(--muted);
  font-size: 11px;
  margin-right: 2px;
}
.concat-list .concat-row .mode-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  cursor: pointer;
  font-size: 11px;
  line-height: 1.4;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  min-width: 56px;
  text-align: center;
}
.concat-list .concat-row .mode-btn:hover { background: var(--border); }
.concat-list .concat-row .mode-btn.stretch {
  background: #e6f4ea;
  border-color: #4a7;
  color: #1a6;
  font-weight: 600;
}
.concat-list .concat-row .mode-btn.stretch:hover { background: #d4ecd9; }

#concat-total {
  margin-left: 12px;
  font-weight: 600;
  color: var(--accent, #4a7);
  font-variant-numeric: tabular-nums;
}

.modal-footer {
  padding: 12px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: center;
}

.modal-footer .status { margin-left: auto; }

/* ===== Ken Burns slideshow panel (independent full-screen menu) ===== */

.kb-panel {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.kb-panel[hidden] { display: none; }

.kb-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.kb-title { font-size: 15px; font-weight: 700; letter-spacing: -0.02em; }

.kb-header-spacer { flex: 1; }

#kb-show-select {
  min-width: 200px;
  padding: 7px 10px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: white;
}

.kb-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.kb-slide-list {
  max-width: 920px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.kb-slide {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  padding: 14px 16px;
}

.kb-slide-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.kb-slide-num {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 9px;
  border-radius: 6px;
}

.kb-slide-arrows { display: flex; gap: 2px; }
.kb-slide-spacer { flex: 1; }

.kb-narr-status { font-size: 11px; color: var(--muted); }
.kb-narr-status.ready { color: var(--success); }

.kb-slide-body { display: flex; gap: 14px; }

.kb-img-zone {
  flex: none;
  width: 220px;
  height: 124px;
  border: 2px dashed var(--border-strong);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  background: var(--surface-2);
  position: relative;
}

.kb-img-zone:hover { border-color: var(--accent); }

.kb-img-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.kb-img-placeholder {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  line-height: 1.6;
}

.kb-slide-fields {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.kb-script {
  width: 100%;
  resize: vertical;
  min-height: 60px;
}

.kb-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.kb-controls label {
  flex: 1;
  min-width: 110px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: var(--muted);
}

.kb-add-row {
  max-width: 920px;
  margin: 14px auto 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.kb-hint { font-size: 12px; color: var(--muted); }

.kb-empty {
  max-width: 920px;
  margin: 40px auto;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 200px;
  }
  .video-stage { flex-direction: column; }
  .video-stage video { width: 100%; }
}

/* ===== Auth gate ===== */
/* Full-viewport overlay shown until JWT is established. The body gets
   ``.auth-gating`` to hide the main layout while this is up — avoids a
   flash of the app behind the form. */
body.auth-gating .layout { display: none; }

.auth-gate {
  position: fixed;
  inset: 0;
  background: linear-gradient(180deg, #f5f5f7 0%, #e8e8ec 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 999;
}

/* Restore the browser's default ``[hidden] { display: none }`` semantics —
   the ``.auth-gate { display: flex }`` rule above wins by specificity over
   ``[hidden]`` alone, so without this the gate stays visible even after we
   set ``el.hidden = true``. This was the silent-login bug: login succeeded
   but the form never went away. */
.auth-gate[hidden] { display: none; }

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 28px 22px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.08);
}

.auth-brand {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-align: center;
  margin-bottom: 18px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 20px;
}

.auth-tab {
  background: transparent;
  border: none;
  padding: 8px 12px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.auth-card[data-mode="login"] .auth-tab[data-tab="login"],
.auth-card[data-mode="signup"] .auth-tab[data-tab="signup"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* Mode-conditional fields/text */
.auth-card[data-mode="login"] [data-only-on="signup"],
.auth-card[data-mode="signup"] [data-only-on="login"] {
  display: none;
}

.auth-field {
  display: block;
  margin-bottom: 12px;
}

.auth-field > span {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

.auth-field input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
}

.auth-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.auth-hint {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

.auth-error {
  background: rgba(255, 59, 48, 0.08);
  border: 1px solid rgba(255, 59, 48, 0.2);
  color: var(--danger);
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
  white-space: pre-wrap;
}

.auth-submit {
  width: 100%;
  padding: 11px;
  font-size: 14px;
  font-weight: 600;
  margin-top: 4px;
}

.auth-foot {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin-top: 14px;
}

.auth-foot a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.auth-foot a:hover { text-decoration: underline; }

/* ===== User widget (top-right, fixed) ===== */
/* Floats above .layout in the top-right corner. Same z-index region as
   modals so it stays visible during navigation, but lower than the auth
   gate (which is z:999) so it's covered while logged out. */

.user-widget {
  position: fixed;
  top: 12px;
  right: 16px;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
}

/* Same trick as .auth-gate: explicit display rule wins over [hidden] by
   specificity, so re-assert display:none when hidden is set. Without this,
   the widget would briefly flash before JS hides it on logged-out load. */
.user-widget[hidden] { display: none; }

.user-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.2;
}

.user-email {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-usage {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.user-usage.warn { color: #ff9500; }
.user-usage.over { color: var(--danger); font-weight: 600; }

#logout-btn {
  /* Round logout to match the pill-shaped widget. */
  border-radius: 999px;
  padding: 4px 10px;
}

/* Narrow screens: shrink so it doesn't crowd the top toolbar buttons. */
@media (max-width: 720px) {
  .user-widget {
    top: 8px;
    right: 8px;
    padding: 4px 8px 4px 10px;
    gap: 6px;
  }
  .user-email { max-width: 120px; font-size: 11px; }
  .user-usage { font-size: 10px; }
}

