@font-face {
  font-family: "LatoCredit";
  src: url("/static/fonts/Lato-Semibold.ttf") format("truetype");
  font-weight: 600;
}

:root {
  --bg: #0b0d10;
  --surface: #14171c;
  --surface-2: #1b1f26;
  --line: #262c35;
  --text: #eef1f4;
  --muted: #8a94a0;
  --accent: #c8ff2e;
  --accent-ink: #0b0d10;
  --danger: #ff5a5f;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, "Segoe UI", system-ui, sans-serif;
  min-height: 100dvh;
}
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 16px 16px calc(110px + var(--safe-b)); }

/* ---------- header */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 4px 0 16px;
}
.brand {
  font-weight: 900; font-style: italic; letter-spacing: -0.02em; font-size: 22px;
  text-decoration: none; text-transform: uppercase; line-height: 1;
}
.brand b { color: var(--accent); font-weight: 900; }
.top nav { display: flex; gap: 8px; }

/* ---------- buttons */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface-2);
  border-radius: 999px; padding: 10px 16px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  text-decoration: none; white-space: nowrap; min-height: 42px;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 6px 12px; min-height: 34px; font-size: 13px; }
.btn.icon { width: 42px; padding: 0; }
.btn.sm.icon { width: 34px; }

/* ---------- forms */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
input[type=text], input[type=url], input[type=password], input[type=search] {
  width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 14px; outline: none; min-height: 44px; font-size: 16px; /* 16px: no iOS zoom */
}
input:focus { border-color: var(--accent); }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap-ok { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg button {
  appearance: none; border: 0; background: transparent; padding: 7px 14px; border-radius: 999px;
  font-weight: 600; font-size: 13px; color: var(--muted); cursor: pointer;
}
.seg button.on { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }

.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch i {
  position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: background .15s;
}
.switch i::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; transition: transform .15s;
}
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(20px); background: var(--accent-ink); }

input[type=range] { width: 100%; accent-color: var(--accent); }

/* ---------- sections */
h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
  margin: 28px 0 12px; display: flex; align-items: center; gap: 10px;
}
h2 .count { background: var(--surface-2); color: var(--text); border-radius: 999px; padding: 1px 8px; font-size: 12px; }
h2 .spacer { flex: 1; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.empty { color: var(--muted); padding: 18px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.err { color: var(--danger); font-size: 13px; word-break: break-word; }

/* ---------- add bar */
.addbar { display: flex; gap: 8px; padding: 8px; }
.addbar input { border: 0; background: transparent; }

/* ---------- inbox strip */
.strip { display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 4px; }
.strip::-webkit-scrollbar { display: none; }
.icard {
  flex: none; width: 116px; scroll-snap-align: start; text-decoration: none; position: relative;
}
.thumb {
  position: relative; aspect-ratio: 9/16; border-radius: 12px; overflow: hidden;
  background: var(--surface-2) center/cover no-repeat; border: 1px solid var(--line);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .state {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  font-size: 12px; color: var(--muted); padding: 8px; background: rgba(11,13,16,.55);
}
.icard .meta { font-size: 12px; margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill {
  position: absolute; left: 6px; bottom: 6px; background: rgba(0,0,0,.6); backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px); border-radius: 999px; padding: 2px 7px; font-size: 11px; font-weight: 600;
}
.pill.r { left: auto; right: 6px; }
.pill.top { bottom: auto; top: 6px; }
.badge-new { background: var(--accent); color: var(--accent-ink); }

.bar { height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; width: 70%; margin: 6px auto 0; }
.bar > i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .4s; }

/* ---------- clip grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); } }
.ccard { position: relative; cursor: pointer; user-select: none; -webkit-user-select: none; }
.ccard .thumb { transition: box-shadow .12s, transform .12s; }
.ccard.sel .thumb { box-shadow: 0 0 0 3px var(--accent); transform: scale(.97); }
.ccard .order {
  position: absolute; top: 6px; left: 6px; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 800; font-size: 13px;
  background: rgba(0,0,0,.45); border: 2px solid rgba(255,255,255,.75); z-index: 2;
}
.ccard.sel .order { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.ccard .acts { position: absolute; top: 6px; right: 6px; display: flex; flex-direction: column; gap: 6px; z-index: 2; }
.ccard .acts button, .ccard .acts a {
  width: 30px; height: 30px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: rgba(0,0,0,.55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  cursor: pointer; text-decoration: none; font-size: 13px;
}
.ccard .cap { font-size: 12px; margin-top: 6px; display: flex; justify-content: space-between; gap: 6px; }
.ccard .cap span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- compilations */
.vlist { display: flex; flex-direction: column; gap: 10px; }
.vitem { display: flex; gap: 12px; padding: 10px; align-items: center; }
.vitem .thumb { width: 64px; flex: none; border-radius: 10px; }
.vitem .info { flex: 1; min-width: 0; }
.vitem .title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vitem .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- selection bar */
.selbar {
  position: fixed; left: 12px; right: 12px; bottom: calc(12px + var(--safe-b)); z-index: 20;
  max-width: 640px; margin: 0 auto; display: flex; align-items: center; gap: 10px;
  background: rgba(27,31,38,.92); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: 999px; padding: 8px 8px 8px 18px;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
  transform: translateY(160%); transition: transform .22s cubic-bezier(.2,.8,.2,1);
}
.selbar.show { transform: none; }
.selbar .txt { flex: 1; font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- sheet / modal */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.65); z-index: 40; display: none;
  align-items: flex-end; justify-content: center;
}
.overlay.show { display: flex; }
.sheet {
  background: var(--surface); border: 1px solid var(--line); border-bottom: 0;
  width: 100%; max-width: 560px; max-height: 88dvh; overflow: auto;
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + var(--safe-b));
  display: flex; flex-direction: column; gap: 14px;
}
@media (min-width: 700px) { .overlay { align-items: center; } .sheet { border-radius: 20px; border-bottom: 1px solid var(--line); } }
.sheet h3 { margin: 0; font-size: 18px; }
.olist { display: flex; flex-direction: column; gap: 6px; }
.oitem { display: flex; align-items: center; gap: 10px; background: var(--surface-2); border-radius: 12px; padding: 6px; }
.oitem img { width: 34px; aspect-ratio: 9/16; object-fit: cover; border-radius: 6px; }
.oitem .n { width: 22px; text-align: center; font-weight: 800; color: var(--accent); }
.oitem .t { flex: 1; min-width: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.player { background: #000; display: flex; align-items: center; justify-content: center; }
.player video { max-width: 100vw; max-height: 86dvh; }
.player .close { position: absolute; top: calc(12px + env(safe-area-inset-top, 0px)); right: 12px; }

/* ---------- toast */
.toast {
  position: fixed; left: 50%; top: calc(14px + env(safe-area-inset-top, 0px)); z-index: 60;
  transform: translate(-50%, -150%); transition: transform .25s;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px;
  padding: 10px 18px; font-weight: 600; font-size: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.5);
  max-width: calc(100vw - 28px);
}
.toast.show { transform: translate(-50%, 0); }
.toast.bad { border-color: var(--danger); color: var(--danger); }

/* ---------- editor */
.editor { display: grid; gap: 18px; }
@media (min-width: 900px) { .editor { grid-template-columns: auto 1fr; align-items: start; } }

.stage {
  position: relative; aspect-ratio: 9/16; height: min(58dvh, calc((100vw - 32px) * 16 / 9));
  margin: 0 auto; border-radius: 16px; overflow: hidden; background: #000;
  container-type: size; border: 1px solid var(--line);
}
@media (min-width: 900px) { .stage { height: min(80dvh, 760px); } }
.stage .bgblur {
  position: absolute; inset: -8%; width: 116%; height: 116%; object-fit: cover;
  filter: blur(18px) brightness(.85); display: none;
}
.stage.fit-blur .bgblur { display: block; }
.stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.stage.fit-crop video { object-fit: cover; }
.stage .credit {
  position: absolute; left: 5.5%; top: 14%; z-index: 3;
  font-family: "LatoCredit", sans-serif; font-weight: 600; font-size: 2.4cqh; line-height: 1.2;
  color: rgba(255,255,255,.82); text-shadow: .1cqh .1cqh 0 rgba(0,0,0,.45);
  white-space: pre; cursor: ns-resize; touch-action: none; user-select: none; -webkit-user-select: none;
  outline: 1px dashed transparent; outline-offset: 4px; border-radius: 2px;
}
.stage .credit.dragging { outline-color: rgba(200,255,46,.7); }
.stage .credit.right { left: auto; right: 5.5%; }
.stage .credit.off { display: none; }
.stage .tap { position: absolute; inset: 0; z-index: 2; }
.stage .bigplay {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); z-index: 2;
  width: 64px; height: 64px; border-radius: 50%; background: rgba(0,0,0,.45); display: grid; place-items: center;
  pointer-events: none; transition: opacity .15s; font-size: 22px;
}
.stage.playing .bigplay { opacity: 0; }

.timeline { position: relative; height: 56px; margin: 6px 14px 0; touch-action: none; cursor: pointer; }
.timeline .track { position: absolute; left: 0; right: 0; top: 20px; height: 16px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); }
.timeline .range { position: absolute; top: 20px; height: 16px; background: rgba(200,255,46,.22); border-top: 2px solid var(--accent); border-bottom: 2px solid var(--accent); }
.timeline .handle {
  position: absolute; top: 10px; width: 28px; height: 36px; margin-left: -14px; z-index: 3;
  display: grid; place-items: center; touch-action: none;
}
.timeline .handle::before { content: ""; width: 12px; height: 36px; background: var(--accent); border-radius: 4px; box-shadow: 0 2px 8px rgba(0,0,0,.5); }
.timeline .head { position: absolute; top: 4px; width: 2px; height: 48px; background: #fff; margin-left: -1px; z-index: 2; pointer-events: none; border-radius: 2px; }
.times { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); margin: 2px 2px 0; }
.times b { color: var(--text); }

.controls { display: flex; gap: 8px; justify-content: center; }
.controls .btn.icon { width: 52px; }
.panel { padding: 14px; display: flex; flex-direction: column; gap: 14px; }
.panel .lbl { font-weight: 600; }

.sclips { display: flex; flex-direction: column; gap: 8px; }
.sclip { display: flex; align-items: center; gap: 10px; padding: 8px; }
.sclip img, .sclip .ph { width: 40px; aspect-ratio: 9/16; object-fit: cover; border-radius: 6px; background: var(--surface-2); }
.sclip.editing { border-color: var(--accent); }

.loading { padding: 40px 16px; text-align: center; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite; margin: 0 auto 14px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- setup / login */
.narrow { max-width: 560px; margin: 0 auto; }
.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.steps li { counter-increment: s; position: relative; padding: 12px 14px 12px 48px; }
.steps li::before {
  content: counter(s); position: absolute; left: 12px; top: 12px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 13px; display: grid; place-items: center;
}
code, .mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; }
.copybox { display: flex; gap: 8px; align-items: center; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 6px 6px 6px 12px; margin-top: 8px; }
.copybox code { flex: 1; overflow-x: auto; white-space: nowrap; }
