/* Tokens first, then layout. Dark is the default; light follows the system. */
:root {
  color-scheme: dark light;

  --bg: #0e1013;
  --bg-panel: #171a1f;
  --bg-sunken: #0a0c0f;
  --line: #262b33;
  --line-soft: #1f242b;
  --text: #e8ebf0;
  --text-dim: #9aa3b0;
  --text-faint: #6b7480;
  --accent: #5b9dff;
  --accent-ink: #06121f;
  --accent-soft: #1b2b45;
  --good: #49c98a;
  --warn: #e0a33a;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .28);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f6f9;
    --bg-panel: #ffffff;
    --bg-sunken: #eceff4;
    --line: #dde2ea;
    --line-soft: #e8ecf2;
    --text: #151a21;
    --text-dim: #5b6674;
    --text-faint: #8a939f;
    --accent: #1f6feb;
    --accent-ink: #ffffff;
    --accent-soft: #e4edfd;
    --good: #1a7f4b;
    --warn: #96650c;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .07);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: 0 16px 64px;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
  cursor: default;
}

/* Header */
.top {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 0 18px;
}
.top h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -.01em;
}
.sub {
  margin: 4px 0 0;
  color: var(--text-dim);
  font-size: 14px;
}

main { max-width: 1180px; margin: 0 auto; }

.usage {
  margin: 10px 0 0;
  color: var(--text-dim);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow);
}

/* Drop zone */
.drop {
  border: 2px dashed var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-panel);
  padding: 44px 20px;
  text-align: center;
  transition: border-color .15s, background .15s;
}
.drop.over {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.drop-inner { display: grid; gap: 10px; justify-items: center; }
.drop-big { margin: 0; font-size: 19px; font-weight: 600; }
.drop-small { margin: 0; color: var(--text-dim); font-size: 14px; }
.drop-url { display: flex; gap: 8px; margin-top: 8px; width: min(440px, 100%); }
.drop-url input { flex: 1; }
.drop-note { margin: 6px 0 0; min-height: 1.2em; color: var(--warn); font-size: 13px; }

/* Workspace */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.result { grid-column: 1 / -1; }

@media (max-width: 960px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
}

/* Preview stage */
.stage-frame {
  background: var(--bg-sunken);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 8px;
  display: grid;
  place-items: center;
  min-height: 180px;
}
#preview {
  display: block;
  max-width: 100%;
  max-height: 52vh;
  height: auto;
  border-radius: 6px;
  background: #000;
}

.scrub-row { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.scrub-row input[type="range"] { flex: 1; }
.clock {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
}

.trim {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
}
.trim-field { display: flex; align-items: center; gap: 6px; }
.trim-field label { font-size: 13px; color: var(--text-dim); cursor: default; }
.trim-field input { width: 84px; }

.source {
  margin: 12px 0 0;
  font-size: 12.5px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

/* Options */
.presets {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line-soft);
}
.presets-label { font-size: 13px; color: var(--text-dim); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
}
.field { display: grid; gap: 5px; align-content: start; }
.field > label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: default;
}
.hint {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-faint);
}

.switches {
  display: grid;
  gap: 8px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
}
.switch {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  cursor: pointer;
}
.switch input { cursor: pointer; }
.switch.off { color: var(--text-faint); cursor: not-allowed; }
.switch.off input { cursor: not-allowed; }

/* Plan readout */
.plan {
  margin-top: 16px;
  padding: 11px 12px;
  background: var(--bg-sunken);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.plan b { color: var(--text); font-weight: 600; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

/* Progress */
.progress { margin-top: 14px; }
.bar {
  height: 7px;
  background: var(--bg-sunken);
  border: 1px solid var(--line-soft);
  border-radius: 99px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 99px;
  transition: width .12s linear;
}
.phase {
  margin: 7px 0 0;
  font-size: 13px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* Result */
.result-head {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}
.result-head h2 { margin: 0; font-size: 17px; font-weight: 650; }
.meta {
  margin: 8px 0 12px;
  font-size: 13px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.meta b { color: var(--text); font-weight: 600; }
.result-frame {
  background: var(--bg-sunken);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 8px;
  display: grid;
  place-items: center;
}
#gifOut {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}

/* Controls. Every clickable thing names its own cursor: a control left on
   `auto` renders an I-beam over its text, which reads as "select me". */
button, .btn, select, input[type="range"], input[type="checkbox"], summary {
  cursor: pointer;
}
input[type="text"], input[type="number"], input[type="url"] {
  cursor: text;
}

.btn {
  appearance: none;
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  color: var(--text);
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  transition: border-color .12s, background .12s, color .12s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover:not(:disabled) {
  filter: brightness(1.08);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.btn-big { padding: 10px 20px; font-size: 15px; }
.btn-tiny { padding: 5px 9px; font-size: 12.5px; }
.btn-chip { padding: 6px 12px; font-size: 13px; border-radius: 99px; }
.btn-chip[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

select, input[type="text"], input[type="number"], input[type="url"] {
  appearance: none;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
  min-width: 0;
}
select {
  padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
select:focus-visible, input:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

input[type="range"] {
  appearance: none;
  height: 22px;
  background: transparent;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 5px;
  background: var(--line);
  border-radius: 99px;
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 15px;
  height: 15px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-panel);
  cursor: pointer;
}
input[type="range"]::-moz-range-track {
  height: 5px;
  background: var(--line);
  border-radius: 99px;
}
input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-panel);
  cursor: pointer;
}

/* Footer */
.foot {
  max-width: 1180px;
  margin: 26px auto 0;
  font-size: 12.5px;
  color: var(--text-faint);
}
.foot a { color: var(--text-dim); }
.foot a:hover { color: var(--accent); }
