/* gifsmith --------------------------------------------------------------- */

:root {
  color-scheme: light dark;

  --bg:        #f6f7f9;
  --surface:   #ffffff;
  --surface-2: #eef0f4;
  --line:      #d8dce4;
  --text:      #1b1f27;
  --muted:     #656d7e;
  --accent:    #4f46e5;
  --accent-in: #ffffff;
  --danger:    #c02b3f;
  --ok:        #12855f;
  --shadow:    0 1px 2px rgb(16 20 30 / .06), 0 8px 24px rgb(16 20 30 / .06);
  --radius:    10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #14161c;
    --surface:   #1c1f27;
    --surface-2: #252932;
    --line:      #333846;
    --text:      #e7e9ee;
    --muted:     #9aa3b5;
    --accent:    #7c74f5;
    --accent-in: #14161c;
    --danger:    #ef6b7c;
    --ok:        #3ecf9a;
    --shadow:    0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .28);
  }
}

* { box-sizing: border-box; }

/* Several components below set an explicit `display`, which would otherwise win
   against the user-agent rule for [hidden] and leave hidden elements visible. */
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: 0 0 4rem;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* --- header -------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: baseline;
  gap: .9rem;
  flex-wrap: wrap;
  padding: 1.5rem clamp(1rem, 4vw, 2.5rem) 1.1rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.topbar h1 { margin: 0; font-size: 1.35rem; letter-spacing: -.02em; }
.mark { color: var(--accent); }
.tagline { margin: 0; color: var(--muted); font-size: .9rem; flex: 1 1 18rem; }

.pill {
  font-size: .75rem;
  padding: .25rem .6rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  white-space: nowrap;
}
.pill-wait { color: var(--muted); }
.pill-ok   { color: var(--ok);     border-color: color-mix(in srgb, var(--ok) 40%, var(--line)); }
.pill-bad  { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }

/* --- layout -------------------------------------------------------------- */

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 21rem;
  gap: 1.25rem;
  align-items: start;
  max-width: 78rem;
  margin: 1.5rem auto 0;
  padding: 0 clamp(1rem, 4vw, 2.5rem);
}
.col-main, .col-side { display: grid; gap: 1.25rem; min-width: 0; }

@media (max-width: 62rem) {
  main { grid-template-columns: minmax(0, 1fr); }
  .col-side { order: -1; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem;
}
.panel h2 { margin: 0; font-size: 1rem; letter-spacing: -.01em; }
.panel-head {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
  margin-bottom: .5rem;
}
.count {
  font-size: .8rem;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 999px;
  padding: .1rem .5rem;
}
.toolbar { margin-left: auto; display: flex; gap: .4rem; flex-wrap: wrap; }
.hint { margin: 0 0 .9rem; color: var(--muted); font-size: .8rem; }
.note { display: block; margin: .3rem 0 0; color: var(--muted); font-size: .78rem; font-weight: 400; }
kbd {
  font: inherit; font-size: .75em;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 .3em;
}

/* --- dropzone ------------------------------------------------------------ */

.dropzone {
  display: grid;
  justify-items: center;
  gap: .2rem;
  padding: 2rem 1rem;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); outline: none; }
.dropzone.over {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}
.dz-icon { width: 2.4rem; height: 2.4rem; color: var(--accent); }
.dz-title { margin: .4rem 0 0; font-weight: 600; }
.dz-sub { margin: 0; color: var(--muted); font-size: .78rem; }
.linkish {
  background: none; border: none; padding: 0;
  color: var(--accent); font: inherit; font-weight: 600;
  text-decoration: underline; cursor: pointer;
}

/* --- timeline ------------------------------------------------------------ */

.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr));
  gap: .7rem;
}
.frame {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  overflow: hidden;
  cursor: grab;
  transition: box-shadow .12s, border-color .12s, opacity .12s;
}
.frame:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.frame.selected { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent); }
.frame.dragging { opacity: .35; cursor: grabbing; }
.frame.drop-before { box-shadow: -3px 0 0 var(--accent); }
.frame.drop-after  { box-shadow:  3px 0 0 var(--accent); }

.frame .thumb {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  background:
    repeating-conic-gradient(var(--surface) 0 25%, var(--surface-2) 0 50%) 0 0 / 14px 14px;
}
.frame .idx {
  position: absolute; top: .3rem; left: .3rem;
  font-size: .68rem; font-variant-numeric: tabular-nums;
  background: rgb(0 0 0 / .62); color: #fff;
  border-radius: 4px; padding: .05rem .35rem;
}
.frame .kill {
  position: absolute; top: .25rem; right: .25rem;
  width: 1.3rem; height: 1.3rem; line-height: 1;
  border: none; border-radius: 4px;
  background: rgb(0 0 0 / .62); color: #fff;
  cursor: pointer; font-size: .85rem;
  opacity: 0; transition: opacity .12s;
}
.frame:hover .kill, .frame:focus-within .kill { opacity: 1; }
.frame .meta {
  display: flex; align-items: center; gap: .3rem;
  padding: .3rem .4rem;
  font-size: .7rem; color: var(--muted);
}
.frame .name {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.frame .delay {
  width: 3.6rem; flex: none;
  font: inherit; font-size: .7rem;
  padding: .1rem .2rem;
  text-align: right;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
}
.frame .delay.custom { border-color: var(--accent); color: var(--text); }

/* --- video card ---------------------------------------------------------- */

.video-card { display: grid; gap: .8rem; }
.video-card .vhead { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.video-card .vname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.video-card video {
  width: 100%; max-height: 13rem;
  background: #000; border-radius: 8px;
}
.video-card .grid3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(6.5rem, 1fr));
  gap: .6rem;
}
.badge {
  font-size: .68rem; padding: .1rem .45rem; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}

/* --- form controls ------------------------------------------------------- */

fieldset { border: none; margin: 0 0 1.1rem; padding: 0; }
fieldset:last-of-type { margin-bottom: .6rem; }
legend {
  padding: 0 0 .5rem;
  font-size: .72rem; font-weight: 700;
  letter-spacing: .07em; text-transform: uppercase;
  color: var(--muted);
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.field {
  display: grid; gap: .25rem;
  margin-bottom: .6rem;
  font-size: .78rem; font-weight: 600; color: var(--muted);
}
.field output { float: right; font-weight: 400; font-variant-numeric: tabular-nums; }

input[type=number], input[type=text], select {
  width: 100%;
  padding: .4rem .5rem;
  font: inherit; font-size: .85rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
}
input[type=color] { width: 100%; height: 2.05rem; padding: 2px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
input[type=range] { width: 100%; accent-color: var(--accent); margin: .1rem 0; }

.check {
  display: flex; align-items: flex-start; gap: .45rem;
  margin-bottom: .55rem;
  font-size: .82rem; color: var(--text);
  cursor: pointer;
}
.check input { accent-color: var(--accent); margin-top: .18rem; flex: none; }

button, .button {
  font: inherit; font-size: .82rem; font-weight: 600;
  padding: .42rem .7rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
  text-decoration: none;
  transition: filter .12s;
}
button:hover:not(:disabled), .button:hover { filter: brightness(1.06); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.wide { width: 100%; margin-bottom: .6rem; }
button.primary, .primary.button {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-in);
}
button.danger { color: var(--danger); }
button.ghost { background: transparent; }

.actions { display: flex; gap: .5rem; }
.actions .primary { flex: 1; padding: .55rem; }

/* --- progress + result --------------------------------------------------- */

.progress {
  position: relative;
  margin-top: .7rem;
  height: 1.4rem;
  border-radius: 7px;
  background: var(--surface-2);
  overflow: hidden;
}
.progress-bar {
  height: 100%; width: 0;
  background: var(--accent);
  transition: width .12s linear;
}
.progress-text {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: .72rem; font-weight: 600;
  mix-blend-mode: difference; color: #fff;
}

.result { display: grid; gap: .8rem; }
.result img {
  width: 100%;
  border-radius: 8px;
  background:
    repeating-conic-gradient(var(--surface-2) 0 25%, var(--surface) 0 50%) 0 0 / 16px 16px;
}
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin: 0; }
.stats div { display: grid; gap: .1rem; }
.stats dt { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.stats dd { margin: 0; font-size: .9rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.result .button { text-align: center; padding: .55rem; }

/* --- toasts -------------------------------------------------------------- */

.toasts {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 50;
  display: grid; gap: .5rem;
  max-width: min(26rem, calc(100vw - 2rem));
}
.toast {
  padding: .6rem .8rem;
  font-size: .82rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  animation: rise .18s ease-out;
}
.toast.bad  { border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.toast.good { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.toast b { display: block; margin-bottom: .1rem; }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
