/* ═══════════════════════════════════════════════════════════════════════════
   M4BConvert — Converter App Shell
   Token system shared with index.css. Dense, product-focused (shadcn
   "Mira" direction): neutral charcoal surfaces, hairline borders, a single
   restrained accent reserved for focus rings and selection — no gradients,
   no glow, no emoji.
   ═══════════════════════════════════════════════════════════════════════════ */

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

/* ── Tokens ── */
:root {
  --bg-base:     #0a0a0b;
  --bg-app:      #0a0a0b;
  --bg-panel:    #131316;
  --bg-raised:   #1c1c1f;
  --bg-input:    #0e0e10;
  --bg-hover:    rgba(255,255,255,0.04);

  --border:       #27272a;
  --border-soft:  #1e1e21;
  --border-strong:#3f3f46;
  --border-focus: #6366f1;

  --text:         #fafafa;
  --text-muted:   #a1a1aa;
  --text-dim:     #52525b;

  --primary:        #f4f4f5;
  --primary-hover:  #e4e4e7;
  --primary-ink:    #18181b;

  --accent:       #818cf8;
  --accent-ring:  rgba(99,102,241,0.35);
  --accent-light: #a5b4fc;

  --success:   #34d399;
  --success-bg:rgba(52,211,153,0.10);
  --warn:      #fbbf24;
  --warn-bg:   rgba(251,191,36,0.10);
  --danger:    #f87171;
  --danger-bg: rgba(248,113,113,0.10);

  --radius:    7px;
  --radius-lg: 10px;

  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'Fira Code', monospace;
}

/* ── Base ── */
body {
  font-family: var(--font-sans);
  background: var(--bg-app);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ── Utilities ── */
.hidden          { display: none !important; }
.text-accent     { color: var(--text-muted); }
.text-muted      { color: var(--text-muted); }
.text-xs         { font-size: 0.72rem; }
.font-mono       { font-family: var(--font-mono); }
.uppercase       { text-transform: uppercase; letter-spacing: 0.06em; }
.icon            { display: block; flex-shrink: 0; }
.btn-icon        { display: inline-flex; align-items: center; gap: 0.45rem; }

/* ── App Bar ── */
.app-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 52px;
  background: rgba(10,10,11,0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
}

/* Logo = back link: clicking it returns to index.html */
.app-bar-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  padding: 0.25rem 0;
  transition: opacity 0.15s;
}
.app-bar-logo:hover { opacity: 0.8; }
.app-bar-logo .text-accent { color: var(--text-muted); font-weight: 500; }

/* The small arrow that sits to the left of the logo mark */
.app-bar-back-icon {
  display: flex;
  align-items: center;
  color: var(--text-dim);
  margin-right: -0.1rem;
  transition: color 0.15s;
}
.app-bar-logo:hover .app-bar-back-icon { color: var(--text-muted); }

.logo-mark { color: var(--text); flex-shrink: 0; }
.logo-mark rect { fill: currentColor; }

.header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ── Header hamburger menu (same pattern as index.html) ── */
.menu-wrap { position: relative; }
.menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.menu-btn:hover { color: var(--text); border-color: var(--border-strong); background: var(--bg-hover); }

.menu-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 220px;
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 32px -8px rgba(0,0,0,0.55);
  padding: 0.4rem;
  z-index: 30;
}
.menu-category {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  padding: 0.5rem 0.6rem;
}
.menu-item {
  display: block;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  transition: background 0.15s;
}
.menu-item:hover { background: var(--bg-hover); }
/* Highlight the current page in the menu */
.menu-item.active { color: var(--primary); background: var(--primary-dim, rgba(99,102,241,0.1)); }

/* ── Hero converter selector ── */
.hero-section {
  text-align: center;
  padding: 1.75rem 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.hero-title {
  font-size: clamp(1.3rem, 2.6vw, 1.7rem);
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.hero-select-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.hero-select-wrapper::after {
  content: '';
  position: absolute;
  right: 0.85rem;
  top: 50%;
  width: 14px;
  height: 14px;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--text-muted);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
}
.hero-select {
  font-size: 1.05rem;
  font-weight: 600;
  font-family: var(--font-mono);
  letter-spacing: 0.01em;
  color: var(--text);
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 0.5rem 2.25rem 0.5rem 1.1rem;
  cursor: pointer;
  appearance: none;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.hero-select:hover { border-color: var(--text-dim); background: var(--bg-raised); }
.hero-select:focus-visible { border-color: var(--accent); }

/* Status badges */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.74rem;
  font-weight: 500;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  white-space: nowrap;
  border: 1px solid var(--border);
}
.badge-green { background: var(--success-bg); color: var(--success); border-color: rgba(52,211,153,0.25); }
.badge-amber { background: var(--warn-bg); color: var(--warn); border-color: rgba(251,191,36,0.25); }
.badge-dim   { background: transparent; color: var(--text-dim); }

/* ── Table loading state ──
   Shown briefly while a file is being scanned for chapters, or while a
   large batch of files is being added to the merge list — distinct from
   the log/progress bar, which only appears once real conversion starts. */
.table-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  padding: 2.75rem 1rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.spinner-ring {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

.btn-outline {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  border: 1px solid var(--border);
  background: transparent;
  padding: 0.35rem 0.8rem;
  border-radius: var(--radius);
  text-decoration: none;
  transition: color 0.15s, border-color 0.15s;
}
.btn-outline:hover { color: var(--text); border-color: var(--border-strong); }

/* ── Workspace grid ── */
.workspace {
  display: grid;
  grid-template-columns: 300px 1fr 280px;
  gap: 1rem;
  padding: 1rem 1.25rem;
  flex: 1;
  min-height: 0;
}

/* ── Panel base ── */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Left Panel ── */
.left-panel {
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.panel-section {
  padding: 1rem;
  border-bottom: 1px solid var(--border-soft);
}
.panel-section:last-child { border-bottom: none; }

.panel-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 0.65rem;
}

/* Drop zone */
.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 1.4rem 1rem;
  text-align: center;
  cursor: pointer;
  background: var(--bg-input);
  transition: border-color 0.15s, background 0.15s;
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--accent);
  border-style: solid;
  background: var(--bg-raised);
}
.drop-zone-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
}
#drop-zone-loaded.drop-zone-state {
  flex-direction: row;
  align-items: center;
  gap: 0.6rem;
  text-align: left;
}
.drop-zone .detected-icon { color: var(--success); display: flex; flex-shrink: 0; }
.drop-zone .detected-name {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.drop-zone .change-file-btn {
  font-size: 0.72rem;
  color: var(--text-muted);
  border: 1px solid var(--border);
  background: none;
  padding: 0.25rem 0.55rem;
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  font-family: var(--font-sans);
  transition: color 0.15s, border-color 0.15s;
}
.drop-zone .change-file-btn:hover { color: var(--text); border-color: var(--border-strong); }
.drop-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  margin-bottom: 0.6rem;
  border-radius: 999px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.drop-text     { font-size: 0.85rem; color: var(--text); line-height: 1.4; }
.drop-subtext  { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.2rem; }

/* Mode cards */
.mode-cards { display: flex; flex-direction: column; gap: 0.4rem; }
.mode-card input { position: absolute; opacity: 0; pointer-events: none; }
.mode-card { position: relative; display: block; }
.mode-card-inner {
  border: 1px solid var(--border);
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  background: var(--bg-input);
}
.mode-card input:checked + .mode-card-inner {
  border-color: var(--text-muted);
  background: var(--bg-raised);
}
.mode-card input:focus-visible + .mode-card-inner {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.mode-name { display: block; font-size: 0.82rem; font-weight: 600; color: var(--text); }
.mode-desc { display: block; font-size: 0.7rem; color: var(--text-muted); margin-top: 0.15rem; }

/* Inputs */
.input-field {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.6rem 0.75rem;
  font-size: 0.83rem;
  font-family: var(--font-sans);
  transition: border-color 0.15s;
  appearance: none;
}
.input-field:focus { outline: none; border-color: var(--border-focus); }
select.input-field {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  background-size: 13px;
  padding-right: 2rem;
}

/* ── Engine Mode Section (Low-RAM · Normal · Turbo) ── */
.mode-section { background: var(--bg-raised); }

/* Each toggle row (Low-RAM row / Turbo row) */
.mode-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.1rem 0;
}

.mode-label-row { display: flex; align-items: center; gap: 0.4rem; }
.mode-subtext   { font-size: 0.7rem; color: var(--text-muted); margin-top: 0.15rem; }

/* Thin rule between the two toggles */
.mode-divider {
  height: 1px;
  background: var(--border);
  margin: 0.55rem 0;
  opacity: 0.5;
}

/* Thread-state row — replaces the old header badge */
.mode-thread-row {
  display: flex;
  align-items: center;
  margin-bottom: 0.65rem;
}

.thread-status {
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: transparent;
}

.thread-status.thread-ok {
  color: var(--success);
  background: var(--success-bg);
  border-color: rgba(52,211,153,0.25);
}

.thread-status.thread-warn {
  color: var(--warn);
  background: var(--warn-bg);
  border-color: rgba(251,191,36,0.25);
}

/* Auto-route status pill — appears after a file is dropped */
.auto-route-status {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.6rem;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 0.72rem;
  line-height: 1.45;
}
.auto-route-status .icon { flex-shrink: 0; }
.auto-route-ok   { background: var(--bg-input); color: var(--text-muted); }
.auto-route-ok   .icon { color: var(--success); }
.auto-route-warn { background: var(--warn-bg); border-color: rgba(251,191,36,0.35); color: #fcd34d; }
.auto-route-warn .icon { color: var(--warn); }

/* Amber variant of the toggle for Low-RAM */
.toggle-switch-amber input:checked ~ .toggle-track {
  background: var(--warn);
  border-color: var(--warn);
}
.toggle-switch-amber input:checked ~ .toggle-track .toggle-thumb {
  background: var(--bg-panel);
}

/* Speed Mode (kept for .speed-section fallback compatibility) */
.speed-section { background: var(--bg-raised); }

.speed-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}
.speed-label-row { display: flex; align-items: center; gap: 0.4rem; }
.speed-subtext { font-size: 0.7rem; color: var(--text-muted); margin-top: 0.15rem; }

/* Toggle switch */
.toggle-switch { position: relative; display: inline-block; flex-shrink: 0; }
.toggle-switch input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track {
  display: block;
  width: 36px;
  height: 21px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  position: relative;
}
.toggle-thumb {
  position: absolute;
  top: 1px;
  left: 1px;
  width: 17px;
  height: 17px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}
.toggle-switch input:checked ~ .toggle-track { background: var(--primary); border-color: var(--primary); }
.toggle-switch input:checked ~ .toggle-track .toggle-thumb { transform: translateX(15px); background: var(--primary-ink); }
.toggle-switch input:focus-visible ~ .toggle-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Concurrency slider */
.slider-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}
.slider-label  { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; }
.slider-value  { font-family: var(--font-mono); font-size: 0.75rem; color: var(--text); white-space: nowrap; font-weight: 500; min-width: 60px; text-align: right; }
.slider {
  -webkit-appearance: none;
  flex: 1;
  height: 3px;
  border-radius: 2px;
  background: var(--border-strong);
  outline: none;
  cursor: pointer;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--bg-panel);
  box-shadow: 0 0 0 1px var(--border-strong);
}
.slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--bg-panel);
  box-shadow: 0 0 0 1px var(--border-strong);
}

.cpu-hint { font-size: 0.68rem; color: var(--text-dim); margin-bottom: 0.6rem; }

/* RAM warning — restructured with a dedicated stat row */
.ram-warning {
  border-radius: var(--radius);
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.7rem;
  border: 1px solid var(--border);
  background: var(--bg-input);
}
.ram-stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.35rem;
}
.ram-stat-label { font-size: 0.7rem; color: var(--text-muted); }
.ram-stat-value { font-family: var(--font-mono); font-size: 0.78rem; font-weight: 600; color: var(--text); }
.ram-msg-row { display: flex; align-items: flex-start; gap: 0.45rem; }
.ram-msg-row .icon { margin-top: 0.05rem; }
.ram-msg { font-size: 0.72rem; line-height: 1.5; }
.ram-ok    .ram-msg-row .icon { color: var(--success); }
.ram-ok    .ram-msg { color: var(--text-muted); }
.ram-tight { border-color: rgba(251,191,36,0.3); background: var(--warn-bg); }
.ram-tight .ram-msg-row .icon { color: var(--warn); }
.ram-tight .ram-msg { color: #fcd34d; }

/* Buttons */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.7rem;
  background: var(--primary);
  color: var(--primary-ink);
  border: none;
  border-radius: var(--radius);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-sans);
  letter-spacing: 0.01em;
  transition: background 0.15s, opacity 0.15s;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-primary:disabled { background: var(--bg-raised); color: var(--text-dim); cursor: not-allowed; }

.btn-success {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.65rem;
  background: transparent;
  color: var(--success);
  border: 1px solid rgba(52,211,153,0.3);
  border-radius: var(--radius);
  font-size: 0.83rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: background 0.15s;
}
.btn-success:hover:not(:disabled) { background: var(--success-bg); }
.btn-success:disabled { opacity: 0.5; cursor: default; }
.btn-success .icon.spin { animation: spin 0.85s linear infinite; }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0.3rem 0.7rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-sans);
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.btn-ghost:hover { color: var(--text); border-color: var(--border-strong); background: var(--bg-hover); }

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Center Panel ── */
.center-panel { overflow: hidden; }

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

.table-wrapper {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.studio-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
}
.studio-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-raised);
  color: var(--text-dim);
  font-size: 0.66rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.55rem 0.65rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.studio-table td {
  padding: 0.2rem 0.3rem;
  border-bottom: 1px solid var(--border-soft);
}
.studio-table tr:last-child td { border-bottom: none; }
.studio-table tr:hover td { background: var(--bg-hover); }

/* Darker adjustable inputs */
.studio-table input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid transparent;
  color: var(--text);
  padding: 0.4rem 0.5rem;
  font-size: 0.82rem;
  font-family: var(--font-mono);
  border-radius: 5px;
  transition: border-color 0.12s, background 0.12s;
}
.studio-table input:hover  { border-color: var(--border); }
.studio-table input:focus  { outline: none; border-color: var(--border-focus); background: var(--bg-raised); }
.studio-table .ch-title-input { font-family: var(--font-sans); }

.btn-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0.3rem;
  border-radius: 5px;
  transition: color 0.15s, background 0.15s;
}
.btn-remove:hover { color: var(--danger); background: var(--danger-bg); }

/* ── Drag-to-reorder (merge file list) ── */
.drag-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: grab;
  padding: 0.3rem;
  border-radius: 5px;
  touch-action: none; /* let pointermove drive reordering instead of page scroll */
  transition: color 0.15s, background 0.15s;
}
.drag-handle:hover  { color: var(--text); background: var(--bg-hover); }
.drag-handle:active { cursor: grabbing; }

.order-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.4rem;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--text-dim);
}

.studio-table tr[data-idx] td { transition: background 0.1s; }
.studio-table tr.drag-source { opacity: 0.35; }
.studio-table tr.drag-over-top    { box-shadow: inset 0 2px 0 0 var(--accent); }
.studio-table tr.drag-over-bottom { box-shadow: inset 0 -2px 0 0 var(--accent); }

body.dragging-row { cursor: grabbing; user-select: none; -webkit-user-select: none; }
body.dragging-row .studio-table tr:not(.drag-source) { transition: box-shadow 0.08s; }

.drag-ghost {
  position: fixed;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.65rem;
  background: var(--bg-raised);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: 0 10px 28px -10px rgba(0,0,0,0.55);
  font-size: 0.85rem;
  color: var(--text);
  pointer-events: none;
  opacity: 0.96;
}
.drag-ghost-icon { display: flex; color: var(--text-dim); flex-shrink: 0; }
.drag-ghost-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  padding: 3rem 1rem !important;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.83rem;
  border-bottom: none !important;
  line-height: 1.6;
}

/* ── Right Panel ── */
.right-panel {
  display: flex;
  flex-direction: column;
  padding: 1rem;
  gap: 0.75rem;
  overflow: hidden;
}

.log-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.log-panel-header .panel-label { margin-bottom: 0; }
.btn-clear-log {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.68rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.btn-clear-log:hover { color: var(--text-muted); background: var(--bg-hover); }

.progress-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}
.progress-bar-bg {
  flex: 1;
  height: 5px;
  background: var(--bg-raised);
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.25s ease;
}
.progress-pct {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  min-width: 32px;
  text-align: right;
}
.progress-status-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.progress-status {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* VU meter — small live-bar indicator shown only while a worker is active.
   Stands in for the old shimmer animation, but ties directly to the
   product's subject matter instead of a generic loading effect. */
.vu-meter {
  display: none;
  align-items: flex-end;
  gap: 2px;
  height: 12px;
  flex-shrink: 0;
}
.vu-meter.active { display: flex; }
.vu-meter span {
  display: block;
  width: 2.5px;
  height: 40%;
  background: var(--accent-light);
  border-radius: 1px;
  animation: vu-bounce 0.9s ease-in-out infinite;
}
.vu-meter span:nth-child(1) { animation-delay: 0s; }
.vu-meter span:nth-child(2) { animation-delay: 0.15s; }
.vu-meter span:nth-child(3) { animation-delay: 0.3s; }
.vu-meter span:nth-child(4) { animation-delay: 0.45s; }
@keyframes vu-bounce {
  0%, 100% { height: 25%; }
  50%      { height: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .vu-meter span { animation: none; height: 60%; }
  .spinner-ring { animation-duration: 1.4s; }
}

/* Terminal — structured rows: timestamp + level tag + message,
   closer to a real dev console than a flat scrolling text block. */
.terminal {
  flex: 1 1 0;
  height: 0;
  overflow-y: auto;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem 0;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  line-height: 1.6;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.log-line {
  display: grid;
  grid-template-columns: 62px 42px 1fr;
  gap: 0.5rem;
  padding: 0.15rem 0.8rem;
  word-break: break-word;
  border-left: 2px solid transparent;
}
.log-line:hover { background: var(--bg-hover); }
.log-time  { color: var(--text-dim); }
.log-tag   { font-weight: 600; letter-spacing: 0.03em; }
.log-msg   { color: var(--text-muted); }

.log-info    .log-tag { color: var(--text-dim); }
.log-progress{ border-left-color: rgba(52,211,153,0.4); }
.log-progress .log-tag { color: var(--success); }
/* Raw ffmpeg progress ticks (time=/size=/bitrate=) — mid-encode chatter,
   not a completion. Kept visually muted/quiet so it reads as "still
   running" rather than "something finished," which is what the old shared
   'progress' level wrongly implied for these lines. */
.log-stat    .log-tag { color: var(--text-dim); }
.log-stat    .log-msg { color: var(--text-dim); }
.log-warn    { border-left-color: rgba(251,191,36,0.4); }
.log-warn .log-tag, .log-warn .log-msg { color: var(--warn); }
.log-error   { border-left-color: rgba(248,113,113,0.4); }
.log-error .log-tag, .log-error .log-msg { color: var(--danger); }

/* Last line always highlighted */
.log-line:last-child .log-msg { color: var(--text); }

/* ── Responsive ── */
@media (max-width: 1100px) {
  body { height: auto; min-height: 100vh; overflow: visible; }
  .workspace { grid-template-columns: 280px 1fr; height: auto; }
  .right-panel { grid-column: 1 / -1; height: 360px; }
}
@media (max-width: 720px) {
  .workspace { grid-template-columns: 1fr; height: auto; }
  .right-panel, .center-panel { min-height: 300px; }
  .log-line { grid-template-columns: 58px 38px 1fr; gap: 0.4rem; padding: 0.15rem 0.6rem; }
}



/* ── Locked hero select (non-changeable format side) ── */
.hero-select.locked {
  background: transparent;
  border-color: var(--border);
  color: var(--text-dim);
  cursor: default;
}
.hero-select.locked:hover { background: transparent; border-color: var(--border); }
.hero-select-wrapper.locked::after { display: none; }

/* ── Toast notifications ── */
.toast-root {
  position: fixed;
  top: 4.5rem;        /* clears the sticky app-bar */
  right: 1.25rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: min(360px, calc(100vw - 2.5rem));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 0.85rem 0.9rem;
  box-shadow: 0 8px 24px -8px rgba(0,0,0,0.5);
  opacity: 0;
  transform: translateY(-8px) scale(0.98);
  transition: opacity 0.18s ease, transform 0.18s ease;
  overflow: hidden;
}
.toast.toast-in  { opacity: 1; transform: translateY(0) scale(1); }
.toast.toast-out { opacity: 0; transform: translateY(-4px) scale(0.98); }

.toast-icon { flex-shrink: 0; margin-top: 0.1rem; color: var(--text-muted); }
.toast-warning  .toast-icon,
.toast-error    .toast-icon { color: var(--warn); }
.toast-success  .toast-icon { color: var(--success); }
.toast-info     .toast-icon { color: var(--primary); }
.toast-transfer .toast-icon { color: var(--primary); }

.toast-body { flex: 1; min-width: 0; }
.toast-title { font-size: 0.85rem; font-weight: 600; color: var(--text); }
.toast-desc  { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.2rem; line-height: 1.45; }

.toast-action-row { margin-top: 0.55rem; }
.toast-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--primary);
  background: transparent;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.toast-action-btn:hover { background: var(--primary); color: var(--primary-ink, #fff); }

.toast-close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0.15rem;
  border-radius: 4px;
  display: flex;
  transition: color 0.15s, background 0.15s;
}
.toast-close:hover { color: var(--text); background: var(--bg-hover); }

.toast-timer {
  position: absolute;
  left: 0; bottom: 0;
  height: 2px;
  width: 100%;
  background: var(--border-strong);
  transform-origin: left;
  animation: toast-shrink linear forwards;
}
@keyframes toast-shrink {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}

@media (max-width: 600px) {
  .toast-root { left: 1rem; right: 1rem; width: auto; top: 4.25rem; }

  /* On mobile the header is tight — hide the engine-mode badge entirely.
     Wake-lock badge and notification button are already removed from the DOM.
     Nothing is lost: the mode is visible via the panel toggles below the fold. */
  #engine-mode-badge { display: none !important; }
}

/* ── Site footer ───────────────────────────────────────────────────────── */
.site-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  text-align: center;
  padding: 1.75rem 1.5rem;
  font-size: 0.78rem;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.footer-links {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  justify-content: center;
}
.footer-links a {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-decoration: none;
}
.footer-links a:hover { color: var(--text); }
