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

:root {
  --bg:         #1a1a1a;
  --sidebar-bg: #222222;
  --card-bg:    #2a2a2a;
  --border:     #383838;
  --accent:     #f5c518;   /* makeagif yellow/gold */
  --accent-dark:#d4a800;
  --text:       #e8e8e8;
  --text-muted: #888;
  --danger:     #e05555;
  --radius:     6px;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Header ── */
header {
  background: #111;
  border-bottom: 1px solid #333;
  flex-shrink: 0;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: .7rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.2rem;
}

.logo {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -.5px;
}

.tagline {
  font-size: .75rem;
  color: var(--text-muted);
}

.header-tabs {
  margin-left: auto;
  display: flex;
  gap: 0;
}

.tab {
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .05em;
  padding: .5rem 1rem;
  color: var(--text-muted);
  cursor: default;
  border-bottom: 2px solid transparent;
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── App layout ── */
#app-wrap {
  display: flex;
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 1.2rem 1rem;
  gap: 1.2rem;
  align-items: flex-start;
}

/* ── Sidebar ── */
#sidebar {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: .8rem;
}

.sidebar-url-form { display: none; }

.sidebar-section {
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.sidebar-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .55rem .8rem;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  width: 22px;
  height: 22px;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}

.icon-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }

/* Filters */
.filter-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: .6rem;
}

.filter-grid button {
  padding: .32rem .2rem;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .04em;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  transition: border-color .12s, color .12s, background .12s;
}

.filter-grid button:hover { border-color: var(--accent); color: var(--text); }
.filter-grid button.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(245,197,24,.08);
}

/* Toggles */
.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .55rem .8rem;
  font-size: .8rem;
  border-bottom: 1px solid var(--border);
  gap: .5rem;
}
.toggle-row:last-child { border-bottom: none; }

.toggle {
  position: relative;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }

.toggle-track {
  position: absolute;
  inset: 0;
  background: #444;
  border-radius: 20px;
  transition: background .2s;
  cursor: pointer;
}

.toggle-track::before {
  content: "";
  position: absolute;
  width: 14px; height: 14px;
  left: 3px; top: 3px;
  background: #888;
  border-radius: 50%;
  transition: transform .2s, background .2s;
}

.toggle input:checked + .toggle-track { background: rgba(245,197,24,.25); }
.toggle input:checked + .toggle-track::before {
  transform: translateX(16px);
  background: var(--accent);
}

/* Caption list */
#caption-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.caption-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .3rem;
  padding: .35rem .6rem;
  border-bottom: 1px solid var(--border);
}

.caption-item:last-child { border-bottom: none; }

.caption-item input[type=text] {
  flex: 1 1 100%;
  padding: .28rem .45rem;
  background: #333;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: .78rem;
  outline: none;
  min-width: 0;
}

.caption-item input[type=text]:focus { border-color: var(--accent); }

.caption-colours {
  display: flex;
  gap: 4px;
  flex: 1;
}

.caption-colour-swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #555;
  background: var(--swatch, #fff);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

.caption-colour-swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.caption-item .rm-btn {
  padding: .2rem .45rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: .8rem;
  cursor: pointer;
  transition: background .12s, color .12s;
  margin-left: auto;
}

.caption-item .rm-btn:hover { background: var(--danger); border-color: var(--danger); color: #fff; }

#add-caption-btn {
  width: 100%;
  padding: .45rem;
  background: transparent;
  color: var(--text-muted);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  border: none;
  border-top: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .3rem;
  transition: color .12s;
}

#add-caption-btn:hover { color: var(--accent); }

/* ── Main column ── */
#main-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: .9rem;
}

/* Desktop URL form */
.desktop-url-form {
  display: flex;
  gap: .5rem;
}

.desktop-url-form input[type=text] {
  flex: 1;
  padding: .6rem 1rem;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: .9rem;
  outline: none;
  transition: border-color .15s;
}

.desktop-url-form input[type=text]:focus { border-color: var(--accent); }
.desktop-url-form input[type=text]::placeholder { color: var(--text-muted); }

.desktop-url-form button {
  padding: .6rem 1.4rem;
  background: var(--accent);
  color: #111;
  border: none;
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
}

.desktop-url-form button:hover { background: var(--accent-dark); }
.desktop-url-form button:disabled { opacity: .5; cursor: not-allowed; }

/* Player section */
#player-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
}

#player-wrap {
  position: relative;
  width: 100%;
  max-width: 640px;
  aspect-ratio: 16/9;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}

#player-wrap iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

#filter-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#caption-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.caption-node {
  position: absolute;
  transform: translate(-50%, -50%);
  color: white;
  -webkit-text-stroke: 1.5px black;
  paint-order: stroke fill;
  text-shadow:
    2px 2px 0 #000,
    -2px -2px 0 #000,
    2px -2px 0 #000,
    -2px 2px 0 #000;
  white-space: pre-wrap;
  text-align: center;
  font-family: Anton, Impact, "Arial Black", sans-serif;
  font-weight: 400;
  letter-spacing: .02em;
  text-transform: uppercase;
  user-select: none;
  cursor: grab;
  pointer-events: auto;
  touch-action: none;
  max-width: 90%;
  line-height: 1.1;
}

.caption-node.dragging {
  cursor: grabbing;
  opacity: .92;
}

#no-embed-warning {
  display: none;
  color: var(--text-muted);
  font-size: .82rem;
  text-align: center;
  padding: .6rem;
}

#no-embed-warning.visible { display: block; }

/* Video info strip */
#video-info {
  display: none;
  align-items: center;
  gap: .6rem;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .55rem .8rem;
  font-size: .82rem;
}

#video-info.visible { display: flex; }

#video-thumb {
  width: 56px;
  height: 32px;
  object-fit: cover;
  border-radius: 3px;
  flex-shrink: 0;
}

#video-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

#video-duration {
  color: var(--text-muted);
  font-size: .75rem;
  flex-shrink: 0;
}

/* Error */
#error-wrap {
  display: none;
  background: #2c1010;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: .8rem 1rem;
  color: var(--danger);
  font-size: .85rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

#error-wrap.visible { display: block; }

/* ── Controls card ── */
#controls-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: .8rem;
}

.ctrl-row {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.ctrl-label {
  font-size: .8rem;
  color: var(--text-muted);
  width: 90px;
  flex-shrink: 0;
}

/* Quality tabs */
.quality-tabs {
  display: flex;
  gap: .6rem;
  align-items: center;
}

.quality-tabs button {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: .88rem;
  font-weight: 600;
  padding: .15rem .3rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color .12s, border-color .12s;
}

.quality-tabs button:hover:not(:disabled) { color: var(--text); }
.quality-tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.quality-tabs button:disabled { opacity: .3; cursor: not-allowed; }

/* Time stepper */
.time-stepper {
  display: flex;
  align-items: center;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-left: auto;
}

.step-btn {
  background: #333;
  border: none;
  color: var(--text);
  width: 30px;
  height: 30px;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s;
  flex-shrink: 0;
}

.step-btn:hover { background: #444; }

.time-display {
  font-family: "SF Mono", "Fira Code", "Courier New", monospace;
  font-size: .82rem;
  font-variant-numeric: tabular-nums;
  background: #1e1e1e;
  color: var(--text);
  padding: .2rem .5rem;
  min-width: 110px;
  text-align: center;
  cursor: text;
  outline: none;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  white-space: nowrap;
  user-select: all;
}

.time-display:focus {
  background: #2a2a2a;
  color: var(--accent);
}

/* Slider rows */
.slider-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: 0 0 .25rem;
}

.slider-cap {
  font-size: .68rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  width: 36px;
}

.slider-cap.right { text-align: right; }

.slider-row input[type=range] {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
  height: 4px;
}

/* Speed section */
.speed-track-wrap {
  display: flex;
  align-items: center;
  gap: .6rem;
}

.speed-icon { font-size: 1.1rem; flex-shrink: 0; }

.speed-track {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: .2rem;
}

.speed-track input[type=range] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.speed-ticks {
  display: flex;
  justify-content: space-between;
  padding: 0 2px;
}

.speed-ticks span {
  font-size: .65rem;
  color: var(--text-muted);
  text-align: center;
}

/* Progress */
#progress-wrap {
  display: none;
  flex-direction: column;
  gap: .5rem;
  padding: .8rem;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

#progress-wrap.visible { display: flex; }
#progress-label { font-size: .85rem; }

#progress-bar-outer {
  height: 6px;
  background: #333;
  border-radius: 3px;
  overflow: hidden;
}

#progress-bar-inner {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  width: 0%;
  transition: width .2s;
}

@keyframes indeterminate {
  0%   { left: -40%; width: 40%; }
  60%  { left: 100%; width: 40%; }
  100% { left: 100%; width: 0%; }
}

#progress-bar-outer.indeterminate #progress-bar-inner {
  position: relative;
  width: 40% !important;
  animation: indeterminate 1.4s ease infinite;
}

/* Result */
#result-wrap {
  display: none;
  flex-direction: column;
  gap: .6rem;
  align-items: center;
}

#result-wrap.visible { display: flex; }

#result-img {
  max-width: 100%;
  border-radius: 4px;
}

#download-btn { width: 100%; }

/* ── Action bar ── */
#action-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .8rem;
}

.back-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: .65rem 1.2rem;
  border-radius: var(--radius);
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .04em;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}

.back-btn:hover { border-color: var(--text-muted); color: var(--text); }

.render-btn {
  background: var(--accent);
  color: #111;
  border: none;
  padding: .7rem 2rem;
  border-radius: var(--radius);
  font-size: .88rem;
  font-weight: 800;
  letter-spacing: .05em;
  cursor: pointer;
  transition: background .15s;
}

.render-btn:hover:not(:disabled) { background: var(--accent-dark); }
.render-btn:disabled { opacity: .45; cursor: not-allowed; }

/* ── Footer ── */
footer {
  text-align: center;
  padding: .8rem;
  font-size: .72rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── Responsive ── */
@media (max-width: 700px) {
  #app-wrap { flex-direction: column; padding: .8rem; }
  #sidebar { width: 100%; }
  .sidebar-url-form { display: flex; gap: .4rem; }
  .sidebar-url-form input { flex: 1; padding: .5rem .8rem; background: var(--sidebar-bg); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: .9rem; outline: none; }
  .sidebar-url-form button { padding: .5rem 1rem; background: var(--accent); color: #111; border: none; border-radius: var(--radius); font-weight: 700; cursor: pointer; }
  .desktop-url-form { display: none; }
}
