:root {
  --bg-color: #09090b; /* Zinc 950 */
  --card-bg: rgba(255, 255, 255, 0.03);
  --card-border: rgba(255, 255, 255, 0.08);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  
  --primary: #8b5cf6;
  --primary-hover: #7c3aed;
  --primary-glow: rgba(139, 92, 246, 0.4);
  
  --accent: #06b6d4;
  --accent-glow: rgba(6, 182, 212, 0.4);
  
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-glow: rgba(239, 68, 68, 0.4);
  
  --surface: #18181b;
  --input-bg: rgba(0, 0, 0, 0.2);
  --input-border: rgba(255, 255, 255, 0.12);
  --input-focus: #8b5cf6;
}

body {
  font-family: 'Outfit', system-ui, -apple-system, sans-serif;
  margin: 0;
  background: var(--bg-color);
  color: var(--text-main);
  background-image: 
    radial-gradient(circle at 15% 50%, rgba(139, 92, 246, 0.08), transparent 25%),
    radial-gradient(circle at 85% 30%, rgba(6, 182, 212, 0.08), transparent 25%);
  background-attachment: fixed;
}

.wrap {
  max-width: 1200px; /* Wider for 2 column */
  margin: 0 auto;
  padding: 24px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  align-items: start;
}

.col-left, .col-right {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

@media (min-width: 900px) {
  .grid {
    grid-template-columns: 1.2fr 1fr;
  }
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 20px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  transition: border-color 0.3s ease;
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.15);
}

.card h2 {
  margin: 0 0 12px 0;
  font-size: 18px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
}

.card h2 .ico {
  color: var(--primary);
  filter: drop-shadow(0 0 4px var(--primary-glow));
}

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 8px;
}

input[type="text"], input[type="password"], input[type="number"], select {
  width: 100%;
  box-sizing: border-box;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text-main);
  font-family: inherit;
  font-size: 14px;
  transition: all 0.2s ease;
}

input[type="text"]:focus, input[type="password"]:focus, input[type="number"]:focus, select:focus {
  outline: none;
  border-color: var(--input-focus);
  box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.15);
  background: rgba(0, 0, 0, 0.4);
}

input.timeInvalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 4px var(--danger-glow);
}

.row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.row > * {
  flex: 1 1 200px;
  min-width: 0;
}

.btn {
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.05);
  color: var(--text-main);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(4px);
}

.btn:hover {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.2);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn.primary {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border: none;
  color: white;
  box-shadow: 0 4px 14px var(--primary-glow);
  font-weight: 600;
}

.btn.primary:hover {
  box-shadow: 0 6px 20px var(--primary-glow);
  filter: brightness(1.1);
}

.btn.danger {
  background: linear-gradient(135deg, #f43f5e, #e11d48);
  border: none;
  box-shadow: 0 4px 14px var(--danger-glow);
}

.btn.danger:hover {
  box-shadow: 0 6px 20px var(--danger-glow);
  filter: brightness(1.1);
}

.muted {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.4;
}

.btnLabel {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.spinner {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  animation: spin 0.8s linear infinite;
  display: none;
  flex: 0 0 auto;
}

.ico {
  width: 18px;
  height: 18px;
  display: inline-block;
  flex: 0 0 auto;
}

.divider {
  height: 1px;
  background: var(--card-border);
  margin: 20px 0;
}

.sectionTitle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #fff;
  font-weight: 600;
  margin: 0 0 10px 0;
}

.sectionTitle .ico {
  color: var(--accent);
}

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

input[type="range"] {
  width: 100%;
  margin: 0;
  -webkit-appearance: none;
  appearance: none;
  height: 8px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]:focus { outline: none; }
input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary) 0%, var(--primary) var(--pct, 0%), rgba(255,255,255,0.1) var(--pct, 0%), rgba(255,255,255,0.1) 100%);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -4px;
  border-radius: 999px;
  background: #fff;
  border: 2px solid var(--primary);
  box-shadow: 0 0 10px var(--primary-glow);
  transition: transform 0.1s ease;
}
input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}
input[type="range"]::-moz-range-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(255,255,255,0.1);
}
input[type="range"]::-moz-range-progress {
  height: 8px;
  border-radius: 999px;
  background: var(--primary);
}
input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: #fff;
  border: 2px solid var(--primary);
  box-shadow: 0 0 10px var(--primary-glow);
}

.player {
  width: 100%;
  aspect-ratio: 16/9;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--card-border);
  background: #000;
  position: relative;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.player iframe { width: 100%; height: 100%; border: 0; }
.cropOverlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 150ms ease;
}
.cropOverlay.on { opacity: 1; }

.seglist { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 10px; }
.seglist th, .seglist td { padding: 10px 8px; border-bottom: 1px solid var(--card-border); }
.seglist th { text-align: left; color: var(--text-muted); font-weight: 500; text-transform: uppercase; font-size: 11px; letter-spacing: 0.5px; }
.seglist tr { transition: background 0.2s ease; }
.seglist tr:hover { background: rgba(255,255,255,0.02); }
.seglist tr.activeSeg { background: rgba(139, 92, 246, 0.1); }

.progress {
  height: 12px;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}
.bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  background-size: 200% 100%;
  transition: width 300ms ease;
  position: relative;
}
.bar.active {
  animation: wave 2s linear infinite;
}
@keyframes wave {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}
.bar::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.3) 50%, transparent 100%);
  background-size: 50% 100%;
  animation: shimmer 1.5s infinite;
}
@keyframes shimmer {
  0% { background-position: -100% 0; }
  100% { background-position: 200% 0; }
}
.bar:not(.active)::after { animation: none; opacity: 0; }

#log { margin-top: 12px; }
#log:empty { display: none; }
pre {
  white-space: pre-wrap;
  word-wrap: break-word;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 14px;
  height: 200px;
  overflow: auto;
  font-size: 12px;
  color: #a1a1aa;
}

.summary {
  background: rgba(0,0,0,0.2);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 16px;
  max-height: 400px;
  overflow: auto;
}
.summaryTop { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.summaryKv {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 12px;
  min-width: 0;
}
.summaryK { color: var(--text-muted); font-size: 12px; margin: 0 0 4px 0; font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }
.summaryV { font-family: 'Outfit', sans-serif; font-size: 14px; font-weight: 500; word-break: break-word; color: #fff; }
.summaryH { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 16px 0 10px 0; }
.summaryH .t { font-size: 14px; color: #fff; font-weight: 600; }
.summaryH .s { color: var(--text-muted); font-size: 12px; }
.summaryTable { width: 100%; border-collapse: collapse; font-size: 13px; border: 1px solid var(--card-border); border-radius: 12px; overflow: hidden; background: rgba(0,0,0,0.1); }
.summaryTable th, .summaryTable td { padding: 10px; border-bottom: 1px solid var(--card-border); }
.summaryTable th { text-align: left; color: var(--text-muted); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; background: rgba(255,255,255,0.02); }
.summaryTable tr:last-child td { border-bottom: 0; }
.summaryFoot { margin-top: 12px; display: flex; gap: 10px; justify-content: space-between; flex-wrap: wrap; color: var(--text-muted); font-size: 13px; }

.modal, .busy {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1000;
}
.modal.on, .busy.on { display: flex; animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal .box {
  width: min(900px, 100%);
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 24px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  overflow-x: hidden;
  box-sizing: border-box;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.7);
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal .box h3 { margin: 0 0 16px 0; font-size: 20px; color: #fff; font-weight: 600; }

.busy { z-index: 9999; }
.busy .box {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 20px;
  box-sizing: border-box;
  text-align: center;
}
.busyTop { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.busyTitle { font-size: 16px; font-weight: 600; color: #fff; }
.busyMsg { margin-top: 4px; font-size: 13px; color: var(--text-muted); }
.spinner.big { width: 40px; height: 40px; border-width: 3px; border-top-color: var(--primary); }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }

.durMeter {
  --pct: 0%;
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--card-border);
  background: linear-gradient(90deg, rgba(139, 92, 246, 0.2) 0%, rgba(139, 92, 246, 0.2) var(--pct), rgba(0,0,0,0.2) var(--pct), rgba(0,0,0,0.2) 100%);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  transition: all 0.3s ease;
}
.durMeter.near { border-color: rgba(234, 179, 8, 0.5); color: #facc15; background-image: linear-gradient(90deg, rgba(234, 179, 8, 0.2) 0%, rgba(234, 179, 8, 0.2) var(--pct), rgba(0,0,0,0.2) var(--pct), rgba(0,0,0,0.2) 100%); }
.durMeter.warn { border-color: rgba(249, 115, 22, 0.6); color: #fb923c; background-image: linear-gradient(90deg, rgba(249, 115, 22, 0.2) 0%, rgba(249, 115, 22, 0.2) var(--pct), rgba(0,0,0,0.2) var(--pct), rgba(0,0,0,0.2) 100%); }
.durMeter.max { border-color: rgba(239, 68, 68, 0.8); color: #f87171; background-image: linear-gradient(90deg, rgba(239, 68, 68, 0.2) 0%, rgba(239, 68, 68, 0.2) var(--pct), rgba(0,0,0,0.2) var(--pct), rgba(0,0,0,0.2) 100%); animation: durPulse 1.5s ease-in-out infinite; }
@keyframes durPulse { 0% { box-shadow: 0 0 0 0 transparent; } 50% { box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.2); } 100% { box-shadow: 0 0 0 0 transparent; } }

/* Custom Checkbox */
input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--text-muted);
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  display: inline-block;
  position: relative;
  transition: all 0.2s ease;
}
input[type="checkbox"]:checked {
  background: var(--primary);
  border-color: var(--primary);
}
input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 1px;
  width: 4px;
  height: 10px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.toastWrap { position: fixed; top: 20px; right: 20px; display: flex; flex-direction: column; gap: 12px; z-index: 10000; pointer-events: none; }
.toast {
  position: relative;
  width: min(380px, calc(100vw - 40px));
  background: rgba(24, 24, 27, 0.95);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  backdrop-filter: blur(12px);
  pointer-events: auto;
  opacity: 0;
  transform: translateX(20px);
  animation: toastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.toast::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  border-radius: 12px 0 0 12px;
  background: var(--toast-accent, var(--primary));
}
.toast.info { --toast-accent: #3b82f6; }
.toast.success { --toast-accent: #10b981; }
.toast.warn { --toast-accent: #f59e0b; }
.toast.error { --toast-accent: #ef4444; }
.toast.out { animation: toastOut 0.3s ease forwards; }

.toastHead { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.toastTitle { font-weight: 600; font-size: 14px; color: #fff; margin: 0; }
.toastMsg { margin-top: 6px; font-size: 13px; color: var(--text-muted); white-space: pre-wrap; word-break: break-word; }
.toastClose {
  width: 28px; height: 28px; border-radius: 8px; border: none;
  background: rgba(255,255,255,0.05); color: var(--text-muted); cursor: pointer; transition: all 0.2s ease; display: flex; align-items: center; justify-content: center;
}
.toastClose:hover { background: rgba(255,255,255,0.1); color: #fff; }

@keyframes toastIn { to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(20px); } }

.modal.sys { z-index: 10001; }
.sysTop { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 12px; }
.sysIcon {
  width: 44px; height: 44px; border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.05); flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center;
}
.sysIcon.info { background: rgba(59, 130, 246, 0.1); border-color: rgba(59, 130, 246, 0.3); color: #60a5fa; }
.sysIcon.success { background: rgba(16, 185, 129, 0.1); border-color: rgba(16, 185, 129, 0.3); color: #34d399; }
.sysIcon.warn { background: rgba(245, 158, 11, 0.1); border-color: rgba(245, 158, 11, 0.3); color: #fbbf24; }
.sysIcon.error { background: rgba(239, 68, 68, 0.1); border-color: rgba(239, 68, 68, 0.3); color: #f87171; }
.sysTitle { margin: 0; font-size: 16px; font-weight: 600; color: #fff; }
.sysMsg { margin-top: 6px; font-size: 13px; color: var(--text-muted); white-space: pre-wrap; word-break: break-word; }

/* Custom Scrollbar for a polished look */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-color); }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }

@media (max-width: 900px) {
  .wrap { max-width: 100%; padding: 16px; }
}

/* Shorts Simulator Modal */
.shorts-container {
  width: min(100vw - 32px, 36vh);
  aspect-ratio: 9/16;
  margin: 0 auto;
  background: #000;
  border-radius: 24px;
  overflow: hidden;
  position: relative;
  box-shadow: 0 0 0 10px #1a1a1b, 0 0 30px rgba(0,0,0,0.8);
}
.shorts-crop-box {
  position: absolute;
  overflow: hidden;
}
.shorts-iframe {
  position: absolute;
  pointer-events: none; /* Disable interaction to prevent double audio issues */
  border: none;
}
/* Default Mode */
.shorts-box-default { width: 100%; height: 100%; top: 0; left: 0; }
.shorts-if-default { width: 316.05%; height: 100%; left: 50%; top: 0; transform: translateX(-50%); }
/* Fit Mode */
.shorts-box-fit { width: 100%; height: 100%; top: 0; left: 0; background: #000; }
.shorts-if-fit { width: 100%; height: 31.64%; left: 0; top: 50%; transform: translateY(-50%); }
/* Split Mode - Top */
.shorts-box-top { width: 100%; height: 75%; top: 0; left: 0; }
.shorts-if-top { width: 316.05%; height: 133.33%; left: 50%; top: 0; transform: translateX(-50%); }
/* Split Mode - Bottom */
.shorts-box-bottom { width: 100%; height: 25%; bottom: 0; left: 0; }
.shorts-if-bottom-left { width: 316.05%; height: 400%; left: 0; top: -300%; }
.shorts-if-bottom-right { width: 316.05%; height: 400%; right: 0; top: -300%; }

/* Result Modal Grid */
.result-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 20px;
}

.result-item {
  width: 220px;
  flex: 0 0 auto;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.result-item video {
  width: 100%;
  aspect-ratio: 9/16;
  object-fit: cover;
  background: #000;
}

.result-item .result-actions {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.result-item-title {
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  word-break: break-all;
  color: var(--text-main);
  margin-bottom: 4px;
}
