/* ============================================================
   ECHOES — Echodio Module Builder
   ============================================================ */

/* ---- Shell ---- */
.builder-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-base);
}

/* ---- Top bar ---- */
.builder-topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

.builder-topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.builder-utility-btn,
.builder-user-btn {
  position: relative;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}

.builder-user-btn {
  border-radius: 50%;
  padding: 2px;
}

.builder-utility-btn:hover,
.builder-user-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-light);
  background: var(--bg-card);
}

.builder-utility-btn svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.builder-module-title {
  flex: 1;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  outline: none;
  border-bottom: 1px solid transparent;
  padding: 2px 4px;
  border-radius: 4px;
  transition: border-color var(--transition), background var(--transition);
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.builder-module-title:focus {
  border-bottom-color: var(--accent-a);
  background: var(--bg-card);
  white-space: normal;
  overflow: visible;
}

/* ---- Body ---- */
.builder-body {
  display: grid;
  grid-template-columns: 240px 1fr 320px;
  flex: 1;
  overflow: hidden;
}

/* ---- Chapter list ---- */
.builder-chapters {
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.builder-panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#chunk-list-inner {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

.chunk-list-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  user-select: none;
  border: 1px solid transparent;
}

.chunk-list-item:hover { background: var(--bg-card); }

.chunk-list-item.selected {
  background: var(--bg-elevated);
  border-color: var(--accent-a);
}

.chunk-order {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  min-width: 18px;
  padding-top: 2px;
}

.chunk-list-info { flex: 1; min-width: 0; }

.chunk-list-title {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.chunk-list-meta { display: flex; gap: 4px; flex-wrap: wrap; }

.chunk-tag {
  font-size: 0.7rem;
  padding: 1px 5px;
  border-radius: var(--radius-full);
}

.chunk-tag.combat { background: rgba(244,63,94,0.15); color: var(--accent-danger); }
.chunk-tag.media { background: rgba(139,92,246,0.12); color: var(--accent-a-light); }

/* ---- Editor panel ---- */
.builder-editor {
  overflow-y: auto;
  padding: 32px 40px;
  background: var(--bg-base);
}

.builder-empty-editor {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: var(--text-muted);
}

.editor-inner { max-width: 780px; }

.editor-section-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.editor-hint {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-faint);
  font-size: 0.7rem;
}

.editor-title-input {
  width: 100%;
  background: none;
  border: none;
  border-bottom: 2px solid var(--border);
  border-radius: 0;
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 600;
  padding: 6px 0;
  outline: none;
  transition: border-color var(--transition);
}

.editor-title-input:focus { border-bottom-color: var(--accent-a); }

.editor-textarea {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.9rem;
  line-height: 1.75;
  padding: 14px 16px;
  resize: vertical;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.editor-textarea:focus {
  border-color: var(--accent-a);
  box-shadow: 0 0 0 3px rgba(139,92,246,0.1);
}

.editor-textarea-scene { min-height: 120px; }
.editor-textarea-dm {
  min-height: 160px;
  border-color: rgba(212,175,55,0.3);
  background: rgba(212,175,55,0.03);
}
.editor-textarea-dm:focus { border-color: var(--accent-gold); box-shadow: 0 0 0 3px rgba(212,175,55,0.1); }

.editor-input-sm {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.875rem;
  padding: 9px 12px;
  outline: none;
  transition: border-color var(--transition);
}
.editor-input-sm:focus { border-color: var(--accent-a); }

.editor-row {
  display: flex;
  align-items: flex-start;
  gap: 20px;
}

/* ---- Echodio panel ---- */
.builder-echodio {
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.echodio-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
}

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

.echodio-logo {
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent-a-light);
  letter-spacing: 0.05em;
  text-shadow: var(--glow-a);
}

.echodio-section {
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.echodio-section:last-child { border-bottom: none; }

.echodio-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-muted);
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.echodio-hint {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.68rem;
  color: var(--text-faint);
}

/* ---- Upload zone ---- */
.upload-zone {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px dashed var(--border-light);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.78rem;
  color: var(--text-muted);
  transition: all var(--transition);
  margin-top: 8px;
}

.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--accent-a);
  background: rgba(139,92,246,0.05);
  color: var(--accent-a-light);
}

.upload-zone:focus-visible {
  outline: 2px solid var(--accent-a);
  outline-offset: 2px;
}

.upload-zone-icon {
  font-size: 1.2rem;
  color: var(--accent-a);
  line-height: 1;
}

/* ---- Asset cards ---- */
.asset-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 8px;
  transition: border-color var(--transition);
}

.asset-card:hover { border-color: var(--border-light); }

.asset-thumb {
  height: 90px;
  background-size: cover;
  background-position: center;
  background-color: var(--bg-base);
}

.asset-audio-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
}

.asset-play-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-a);
  border: none;
  color: white;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
}

.asset-play-btn:hover { background: var(--accent-a-light); transform: scale(1.05); }

.asset-audio-info { flex: 1; min-width: 0; }
.asset-name { font-size: 0.78rem; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.asset-size { font-size: 0.68rem; color: var(--text-muted); }

.asset-video-preview { padding: 8px 8px 0; }

.asset-card-footer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: var(--bg-base);
  border-top: 1px solid var(--border);
}

.asset-label-input {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 1px solid transparent;
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-family: var(--font-body);
  outline: none;
  padding: 2px 0;
  min-width: 0;
  transition: border-color var(--transition);
}

.asset-label-input:focus { border-bottom-color: var(--accent-a); color: var(--text-primary); }

/* ---- Scene viewer (table view, player side) ---- */
.scene-viewer {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
  transition: all 0.4s ease;
}

.scene-viewer.hidden-viewer { display: none; }

.scene-viewer-image {
  width: 100%;
  max-height: 280px;
  object-fit: cover;
  display: block;
}

.scene-viewer-video {
  width: 100%;
  max-height: 320px;
  display: block;
  background: #000;
}

.scene-viewer-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px 20px;
  background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
}

.scene-viewer-label {
  font-family: var(--font-display);
  font-size: 0.85rem;
  color: rgba(255,255,255,0.9);
}

.scene-viewer-controls {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
}

.scene-ctrl-btn {
  background: rgba(0,0,0,0.5);
  border: none;
  color: white;
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 0.72rem;
  cursor: pointer;
  backdrop-filter: blur(4px);
  font-family: var(--font-body);
  transition: background var(--transition);
}

.scene-ctrl-btn:hover { background: rgba(0,0,0,0.75); }

/* ---- Echodio DM control panel (table right sidebar) ---- */
.echodio-dm-panel {
  background: var(--bg-card);
  border: 1px solid rgba(139,92,246,0.25);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.echodio-dm-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: rgba(139,92,246,0.08);
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent-a-light);
}

.echodio-dm-section { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.echodio-dm-section:last-child { border-bottom: none; }
.echodio-dm-section-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.echodio-asset-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.78rem;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-body);
  margin-bottom: 5px;
  text-align: left;
}

.echodio-asset-btn:hover {
  background: var(--bg-elevated);
  border-color: var(--accent-a);
  color: var(--accent-a-light);
}

.echodio-asset-btn.active {
  background: var(--accent-a-dim);
  border-color: var(--accent-a);
  color: var(--accent-a-light);
}

.echodio-sfx-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}

.sfx-btn {
  padding: 8px 6px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.72rem;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
  font-family: var(--font-body);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sfx-btn:hover { background: rgba(6,182,212,0.1); border-color: var(--accent-b); color: var(--accent-b-light); }
.sfx-btn:active { transform: scale(0.95); }

/* ---- Ambient indicator ---- */
.ambient-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: rgba(139,92,246,0.08);
  border: 1px solid rgba(139,92,246,0.2);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: var(--accent-a-light);
}

.ambient-bars {
  display: flex;
  gap: 2px;
  align-items: flex-end;
  height: 14px;
}

.ambient-bar {
  width: 3px;
  background: var(--accent-a);
  border-radius: 2px;
  animation: ambientBar 1.2s ease-in-out infinite;
}

.ambient-bar:nth-child(2) { animation-delay: 0.2s; }
.ambient-bar:nth-child(3) { animation-delay: 0.4s; }
.ambient-bar:nth-child(4) { animation-delay: 0.1s; }

@keyframes ambientBar {
  0%, 100% { height: 4px; }
  50% { height: 14px; }
}

/* ---- Scene items (within chapter editor) ---- */
.scene-item {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.scene-item:hover { border-color: var(--border-light); }

.scene-item.scene-dragging {
  opacity: 0.4;
  box-shadow: none;
}

.scene-item.scene-drag-over {
  border-color: var(--accent-a);
  box-shadow: 0 0 0 2px rgba(139,92,246,0.2);
}

.scene-item-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  cursor: default;
}

.scene-drag-handle {
  font-size: 1rem;
  color: var(--text-faint);
  cursor: grab;
  line-height: 1;
  padding: 2px 2px;
  border-radius: 3px;
  transition: color var(--transition);
  user-select: none;
  flex-shrink: 0;
}

.scene-drag-handle:hover { color: var(--text-muted); }
.scene-drag-handle:active { cursor: grabbing; }

.scene-order {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  min-width: 16px;
  flex-shrink: 0;
}

.scene-title-input {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 1px solid transparent;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 2px 0;
  outline: none;
  min-width: 0;
  transition: border-color var(--transition);
}

.scene-title-input:focus { border-bottom-color: var(--accent-a); }

.scene-path-badge {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--accent-a-light);
  flex-shrink: 0;
}

.scene-toggle-btn,
.scene-delete-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.8rem;
  padding: 3px 6px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  line-height: 1;
  transition: all var(--transition);
  flex-shrink: 0;
}

.scene-toggle-btn:hover { color: var(--text-primary); background: var(--bg-card); }
.scene-delete-btn:hover { color: var(--accent-danger); background: rgba(244,63,94,0.1); }

.scene-item-body {
  padding: 0 14px 14px;
  border-top: 1px solid var(--border);
}

.scenes-empty {
  color: var(--text-muted);
  font-size: 0.82rem;
  font-style: italic;
  padding: 12px 0;
  text-align: center;
}

/* ---- Rich text editor ---- */
.rte-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: border-color var(--transition);
}

.rte-wrap:focus-within { border-color: var(--accent-a); }

.rte-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px 8px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.rte-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.78rem;
  padding: 3px 7px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-body);
  line-height: 1.4;
}

.rte-btn:hover { background: var(--bg-card); color: var(--text-primary); }
.rte-btn.rte-clear:hover { color: var(--accent-danger); }

.rte-sep {
  width: 1px;
  height: 14px;
  background: var(--border);
  margin: 0 3px;
  flex-shrink: 0;
}

.rte-content {
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.875rem;
  line-height: 1.75;
  padding: 10px 14px;
  min-height: 90px;
  outline: none;
}

.rte-content[data-placeholder]:empty::before {
  content: attr(data-placeholder);
  color: var(--text-faint);
  pointer-events: none;
}

.rte-content h3 { font-size: 1rem; margin-bottom: 6px; }
.rte-content h4 { font-size: 0.9rem; margin-bottom: 4px; }
.rte-content blockquote {
  border-left: 3px solid var(--accent-a);
  padding-left: 10px;
  margin: 6px 0;
  color: var(--text-secondary);
  font-style: italic;
}
.rte-content ul, .rte-content ol { padding-left: 20px; }

/* ---- Responsive builder ---- */
@media (max-width: 1100px) {
  .builder-body { grid-template-columns: 200px 1fr; }
  .builder-echodio { display: none; }
}

@media (max-width: 768px) {
  .builder-body { grid-template-columns: 1fr; }
  .builder-chapters { display: none; }
}
