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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f0f4f8;
  color: #24292f;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 2rem;
}

.container { max-width: 780px; width: 100%; }

/* --- App Header --- */
.app-header {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  margin-bottom: 1.75rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid #008cc8;
}

.app-logo {
  height: 38px;
  width: auto;
}

h1 {
  font-size: 1.2rem;
  font-weight: 700;
  color: #008cc8;
}

/* --- Fields --- */
label {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
  color: #57606a;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.field { margin-bottom: 1.1rem; }

input[type="file"] {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px dashed #b0b7c0;
  border-radius: 6px;
  background: #ffffff;
  color: #24292f;
  cursor: pointer;
  font-size: 0.85rem;
}

input[type="file"]::file-selector-button {
  background: #f0f4f8;
  color: #24292f;
  border: 1px solid #d0d7de;
  border-radius: 4px;
  padding: 0.3rem 0.7rem;
  margin-right: 0.7rem;
  cursor: pointer;
  font-size: 0.82rem;
}

select {
  width: 100%;
  padding: 0.45rem 0.65rem;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  background: #ffffff;
  color: #24292f;
  font-size: 0.88rem;
}

select:focus { outline: none; border-color: #008cc8; box-shadow: 0 0 0 3px rgba(0,140,200,0.12); }

textarea {
  width: 100%;
  min-height: 240px;
  padding: 0.75rem;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  background: #ffffff;
  color: #24292f;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.83rem;
  resize: vertical;
  tab-size: 2;
}

textarea:focus, input[type="file"]:focus { outline: none; border-color: #008cc8; }

input[type="number"] {
  padding: 0.45rem 0.55rem;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  background: #ffffff;
  color: #24292f;
  font-size: 0.88rem;
  width: 100%;
}

input[type="number"]:focus { outline: none; border-color: #008cc8; box-shadow: 0 0 0 3px rgba(0,140,200,0.12); }

/* --- Checkbox --- */
.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  color: #57606a;
  margin-top: 0.5rem;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] { margin: 0; cursor: pointer; }
.checkbox-label input[type="checkbox"]:disabled { cursor: not-allowed; }

/* --- Tabs --- */
.tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1.1rem;
  border-bottom: 1px solid #d0d7de;
}

.tab {
  background: none;
  border: none;
  color: #57606a;
  padding: 0.55rem 1.15rem;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s;
}

.tab:hover { color: #24292f; }
.tab.active { color: #008cc8; border-bottom-color: #008cc8; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* --- Settings Grid --- */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem 1.4rem;
}

/* --- Range Sliders --- */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 5px;
  border-radius: 3px;
  background: #d0d7de;
  outline: none;
  margin-top: 0.3rem;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #008cc8;
  cursor: pointer;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 1px #008cc8;
}

.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  color: #8c959f;
  margin-top: 0.2rem;
}

.slider-value {
  float: right;
  text-transform: none;
  font-weight: 400;
  color: #008cc8;
}

/* --- Timeline --- */
.timeline-help {
  font-size: 0.76rem;
  color: #8c959f;
  margin-bottom: 0.45rem;
}

#timeline-container {
  background: #ffffff;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  padding: 0.7rem;
  user-select: none;
}

#timeline-container.disabled {
  opacity: 0.4;
  pointer-events: none;
}

#timeline-track {
  position: relative;
  height: 44px;
  background: #f0f4f8;
  border-radius: 4px;
  cursor: crosshair;
  overflow: hidden;
}

.timeline-segment {
  position: absolute;
  top: 0;
  height: 100%;
  background: rgba(0, 140, 200, 0.18);
  border-left: 2px solid #008cc8;
  border-right: 2px solid #008cc8;
  cursor: pointer;
  transition: background 0.15s;
}

.timeline-segment:hover {
  background: rgba(0, 140, 200, 0.28);
}

/* Resize handles on segment edges */
.handle-left,
.handle-right {
  position: absolute;
  top: 0;
  width: 10px;
  height: 100%;
  cursor: ew-resize;
  z-index: 2;
}

.handle-left  { left: 0; }
.handle-right { right: 0; }

.handle-left:hover,
.handle-right:hover { background: rgba(0, 140, 200, 0.35); }

.timeline-segment-label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.68rem;
  color: #24292f;
  white-space: nowrap;
  pointer-events: none;
}

.timeline-drag-preview {
  position: absolute;
  top: 0;
  height: 100%;
  background: rgba(0, 140, 200, 0.1);
  border-left: 1px dashed #008cc8;
  border-right: 1px dashed #008cc8;
  pointer-events: none;
}

#timeline-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: #8c959f;
  margin-top: 0.3rem;
}

#segment-list {
  margin-top: 0.45rem;
}

.segment-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.1rem;
  background: #e6f4fb;
  border: 1px solid #b0d9ed;
  border-radius: 4px;
  padding: 0.15rem 0.45rem;
  font-size: 0.76rem;
  color: #005f8a;
  margin: 0.2rem 0.25rem 0.2rem 0;
}

.segment-chip-sep {
  margin: 0 0.25rem;
  color: #7ab8d4;
}

.segment-chip .segment-input {
  width: 4.5rem;
  padding: 0.1rem 0.25rem;
  border: 1px solid #b0d9ed;
  border-radius: 3px;
  background: #f0f8ff;
  color: #005f8a;
  font-size: 0.76rem;
  text-align: center;
}

.segment-chip .remove {
  color: #cf222e;
  margin-left: 0.35rem;
  cursor: pointer;
  font-weight: bold;
}

/* --- Toast notification --- */
#toast {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background: rgba(207, 34, 46, 0.12);
  color: #cf222e;
  padding: 0.65rem 1.2rem;
  font-size: 0.84rem;
  font-weight: 600;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translateY(100%);
  transition: opacity 0.3s, transform 0.3s;
  z-index: 1000;
}

#toast.visible {
  opacity: 1;
  transform: translateY(0);
}

/* --- Buttons --- */
button#submit {
  background: #008cc8;
  color: #fff;
  border: none;
  padding: 0.65rem 1.6rem;
  border-radius: 6px;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 0.5rem;
  transition: background 0.15s;
}

button#submit:hover { background: #006fa3; }
button#submit:disabled { opacity: 0.5; cursor: not-allowed; }

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 0.5rem;
  vertical-align: middle;
}

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

/* --- Result --- */
#result {
  margin-top: 1.4rem;
  padding: 0.9rem 1rem;
  border-radius: 6px;
  font-size: 0.88rem;
}

#result.success {
  background: #dafbe1;
  border: 1px solid #56d364;
  color: #1a7f37;
}

#result.error {
  background: #ffebe9;
  border: 1px solid #ff8182;
  color: #cf222e;
}

.download-btn {
  display: inline-block;
  margin-top: 0.65rem;
  background: #008cc8;
  color: #fff;
  padding: 0.5rem 1.3rem;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.88rem;
  transition: background 0.15s;
}

.download-btn:hover { background: #006fa3; }

/* --- Helpers --- */
.optional-tag {
  text-transform: none;
  font-weight: 400;
  color: #8c959f;
  font-size: 0.78rem;
}

.field-help {
  font-size: 0.75rem;
  color: #8c959f;
  margin-top: 0.3rem;
}

/* --- Collapsible sections (Audio / Intro / Outro) --- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: 0.45rem 0.7rem;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  background: #f6f8fa;
  transition: background 0.12s, border-color 0.12s;
  user-select: none;
}

.section-header:hover { background: #e6f4fb; border-color: #008cc8; }

.section-header.open {
  border-radius: 6px 6px 0 0;
  border-color: #008cc8;
  background: #e6f4fb;
}

.section-header label {
  margin: 0;
  text-transform: uppercase;
  font-size: 0.78rem;
  font-weight: 700;
  color: #24292f;
  cursor: pointer;
  letter-spacing: 0.05em;
}

.section-chevron {
  font-size: 0.8rem;
  color: #008cc8;
  transition: transform 0.2s;
  display: inline-block;
}

.section-header.open .section-chevron { transform: rotate(90deg); }

.section-body {
  border: 1px solid #008cc8;
  border-top: none;
  border-radius: 0 0 6px 6px;
  padding: 0.65rem 0.75rem;
  background: #ffffff;
}

/* --- Compact row (source toggle + controls inline) --- */
.compact-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.compact-row .source-toggle { flex-shrink: 0; }
.compact-row .source-panel { flex: 1; min-width: 0; }
.compact-row .source-panel select,
.compact-row .source-panel input[type="file"] { margin: 0; }

/* --- Inline control row for intro/outro --- */
.video-controls-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.vc-video { flex: 2; min-width: 130px; }
.vc-transition { flex: 1; min-width: 110px; }
.vc-duration { width: 70px; flex-shrink: 0; }
.vc-file { flex: 3; min-width: 160px; }

/* --- Intro title / subtitle side-by-side row --- */
.intro-title-row {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.6rem;
  align-items: flex-end;
}

.intro-title-field {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.intro-title-field label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #57606a;
  margin-bottom: 0;
}

.intro-title-field input[type="text"] {
  width: 100%;
  box-sizing: border-box;
}

/* --- Source toggle (Library / Upload) --- */
.source-toggle {
  display: flex;
  gap: 0;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  overflow: hidden;
  width: fit-content;
}

.source-btn {
  background: #f6f8fa;
  border: none;
  color: #57606a;
  padding: 0.3rem 0.85rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.source-btn:not(:last-child) { border-right: 1px solid #d0d7de; }
.source-btn:hover { background: #e6f4fb; color: #008cc8; }
.source-btn.active { background: #008cc8; color: #ffffff; }

/* --- Overlays --- */
.overlay-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.overlay-row {
  background: #f6f8fa;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  padding: 0.55rem 0.7rem;
}

.overlay-row-fields {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.overlay-field {
  display: flex;
  flex-direction: column;
  min-width: 78px;
}

.overlay-field-text {
  flex: 1;
  min-width: 170px;
}

.overlay-field label {
  font-size: 0.68rem;
  margin-bottom: 0.2rem;
  text-transform: none;
  font-weight: 600;
  letter-spacing: 0;
  color: #57606a;
}

.overlay-field input[type="text"],
.overlay-field input[type="number"] {
  padding: 0.38rem 0.5rem;
  border: 1px solid #d0d7de;
  border-radius: 4px;
  background: #ffffff;
  color: #24292f;
  font-size: 0.84rem;
  width: 100%;
}

.overlay-field input:focus {
  outline: none;
  border-color: #008cc8;
}

.overlay-field select {
  padding: 0.38rem 0.5rem;
  font-size: 0.82rem;
}

.ov-remove {
  background: none;
  border: none;
  color: #cf222e;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0 0.25rem;
  line-height: 1;
  align-self: flex-end;
  margin-bottom: 0.1rem;
}

.ov-remove:hover { color: #a40e26; }

.btn-secondary {
  background: #f6f8fa;
  color: #24292f;
  border: 1px solid #d0d7de;
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.btn-secondary:hover { background: #e6f4fb; border-color: #008cc8; color: #008cc8; }

/* --- JSON validation errors --- */
#json-errors {
  margin-top: 0.45rem;
  padding: 0.5rem 0.7rem;
  background: #ffebe9;
  border: 1px solid #ff8182;
  border-radius: 6px;
  font-size: 0.8rem;
  color: #cf222e;
}

.json-error-item {
  padding: 0.15rem 0;
}

.json-error-item strong {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.78rem;
}

textarea.has-error {
  border-color: #ff8182;
  box-shadow: 0 0 0 3px rgba(207, 34, 46, 0.1);
}
