/* ============================================================
   Epic Studio — theme tokens
   ============================================================ */
:root {
  color-scheme: light;
  --bg:            #f6f7f9;
  --bg-elev:       #ffffff;
  --bg-sunken:     #eceef2;
  --sidebar:       #ffffff;
  --line:          #e2e5ea;
  --line-soft:     #edeff3;
  --text:          #12151b;
  --text-dim:      #5c6472;
  --text-faint:    #8b93a1;
  /* Accent kept under ~80% saturation — a fully saturated red reads cheap. */
  --accent:        #db4348;
  --accent-hi:     #e76a72;
  --accent-soft:   rgba(219, 67, 72, .10);
  --ok:            #17936a;
  --ok-soft:       rgba(23, 147, 106, .12);
  --warn:          #b7791f;
  --err:           #d1373c;
  --err-soft:      rgba(209, 55, 60, .10);
  /* Shadows carry the surface hue rather than flat black. */
  --shadow:        0 1px 2px rgba(24,30,45,.06), 0 8px 24px -12px rgba(24,30,45,.20);
  --shadow-lg:     0 2px 4px rgba(24,30,45,.07), 0 24px 48px -20px rgba(24,30,45,.30);
  --r:             14px;
  --r-sm:          10px;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg:            #0d0f14;
  --bg-elev:       #161922;
  --bg-sunken:     #0a0c10;
  --sidebar:       #11141b;
  --line:          #252a35;
  --line-soft:     #1d212a;
  --text:          #eef1f6;
  --text-dim:      #9aa3b2;
  --text-faint:    #6a7383;
  --accent:        #eb5e63;
  --accent-hi:     #f17e86;
  --accent-soft:   rgba(235, 94, 99, .14);
  --ok:            #35d39a;
  --ok-soft:       rgba(53, 211, 154, .14);
  --warn:          #e2b23c;
  --err:           #ff6166;
  --err-soft:      rgba(255, 97, 102, .13);
  --shadow:        0 1px 2px rgba(4,6,12,.55), 0 12px 28px -14px rgba(4,6,12,.75);
  --shadow-lg:     0 2px 6px rgba(4,6,12,.6), 0 32px 60px -24px rgba(4,6,12,.85);
}

* { box-sizing: border-box; }

/* Class-level `display` rules outrank the UA's [hidden] sheet — restore it. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

html { scroll-behavior: smooth; }

/* Keyboard users need a visible focus ring; mouse users shouldn't see one.
   :focus-visible gives both. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
.btn:focus-visible, .btn-icon:focus-visible, .nav-item:focus-visible,
.seg:focus-visible, .chips-select button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
/* Inputs already signal focus with their own ring. */
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; }

/* Stop headings breaking with a single orphaned word on the last line. */
h1, h2, h3 { text-wrap: balance; }
p, li { text-wrap: pretty; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background .25s ease, color .25s ease;
}

svg { width: 1em; height: 1em; stroke-linecap: round; stroke-linejoin: round; }

button, input, select, textarea { font: inherit; color: inherit; }

::selection { background: var(--accent-soft); }

/* scrollbars */
*::-webkit-scrollbar { width: 11px; height: 11px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 99px;
  border: 3px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--text-faint); background-clip: content-box; }

/* ============================================================
   Shell
   ============================================================ */
.shell {
  display: grid;
  grid-template-columns: 244px 1fr;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 20px 14px 14px;
  gap: 26px;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 0 6px; }

.brand-mark {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 11px;
  background: linear-gradient(145deg, var(--accent-hi), var(--accent));
  color: #fff;
  font-size: 19px;
  box-shadow: 0 6px 16px -6px var(--accent);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 14.5px; letter-spacing: -.01em; }
.brand-text span { font-size: 11.5px; color: var(--text-faint); }

.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }

.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px;
  border: 0; border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-dim);
  font-size: 14px; font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background .15s, color .15s;
}
.nav-item svg { font-size: 17px; opacity: .85; }
.nav-item:hover { background: var(--bg-sunken); color: var(--text); }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent); }
.nav-item.is-active svg { opacity: 1; }

.badge {
  margin-left: auto;
  font-style: normal; font-size: 11px; font-weight: 700;
  min-width: 20px; padding: 1px 6px;
  border-radius: 99px;
  background: var(--accent); color: #fff;
  text-align: center;
}

.sidebar-foot { display: flex; flex-direction: column; gap: 10px; }

.theme-toggle {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 11px;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: transparent; color: var(--text-dim);
  font-size: 13px; cursor: pointer;
  transition: background .15s, color .15s;
}
.theme-toggle:hover { background: var(--bg-sunken); color: var(--text); }
.theme-toggle svg { font-size: 16px; }
[data-theme="dark"] .i-sun { display: none; }
[data-theme="light"] .i-moon, :root:not([data-theme="dark"]) .i-moon { display: none; }

.status {
  display: flex; align-items: center; gap: 8px;
  padding: 0 6px;
  font-size: 11.5px; color: var(--text-faint);
}
.status .dot {
  width: 7px; height: 7px; border-radius: 99px;
  background: var(--text-faint);
  flex: none;
}
.status.is-ok .dot { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.status.is-bad .dot { background: var(--err); box-shadow: 0 0 0 3px var(--err-soft); }

/* ============================================================
   Main / views
   ============================================================ */
.main { overflow-y: auto; scroll-behavior: smooth; }

.view {
  display: none;
  max-width: 940px;
  margin: 0 auto;
  padding: 40px 40px 80px;
  animation: rise .28s cubic-bezier(.2,.7,.3,1);
}
.view.is-active { display: block; }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.view-head { margin-bottom: 26px; }
.view-head.row { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.view-head h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: -.025em; font-weight: 650; }
.view-head p { margin: 0; color: var(--text-dim); font-size: 14px; max-width: 62ch; }

/* ============================================================
   Cards & fields
   ============================================================ */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
}

.opt-card { padding: 18px 20px 20px; }

.card-title {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .09em;
  color: var(--text-faint);
  margin-bottom: 14px;
}

.field { margin-bottom: 15px; }
.field:last-child { margin-bottom: 0; }
.field > label {
  display: block;
  font-size: 12.5px; font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.field small { display: block; margin-top: 6px; font-size: 12px; color: var(--text-faint); }
.field small code { font-family: var(--mono); font-size: 11.5px; background: var(--bg-sunken); padding: 1px 5px; border-radius: 5px; }

.field.inline { display: flex; align-items: center; gap: 12px; }
.field.inline > label { margin: 0; flex: none; min-width: 78px; }
.field.inline input { flex: 1; }

/* Match every text-entry input by exclusion — listing types individually meant
   email/password fields silently fell back to the browser's white default. */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="submit"]),
select, textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-sunken);
  color: var(--text);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  outline: none;
  transition: border-color .15s, background-color .15s, box-shadow .15s;
}

input:not([type="checkbox"]):not([type="radio"]):hover, select:hover, textarea:hover {
  border-color: var(--line);
}
input:not([type="checkbox"]):not([type="radio"]):focus, select:focus, textarea:focus {
  background: var(--bg-elev);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }

/* Autofill paints its own opaque background; the inset shadow is the only way
   to override it, and the long transition stops it flashing back on blur. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 100px var(--bg-sunken) inset;
  caret-color: var(--text);
  transition: background-color 100000s ease-in-out 0s;
}
input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 100px var(--bg-elev) inset, 0 0 0 3px var(--accent-soft);
}

select {
  appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b93a1' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  background-size: 15px;
  cursor: pointer;
}

.row-input { display: flex; gap: 8px; }
.row-input input { flex: 1; }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: var(--bg-sunken);
  font-size: 13.5px; font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: transform .12s, background .15s, border-color .15s, opacity .15s, box-shadow .15s;
}
.btn:active { transform: scale(.975); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn svg { font-size: 16px; }

.btn-ghost { background: transparent; border-color: var(--line); color: var(--text-dim); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-sunken); color: var(--text); }

.btn-primary {
  background: linear-gradient(160deg, var(--accent-hi), var(--accent));
  color: #fff;
  box-shadow: 0 4px 14px -6px var(--accent);
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 6px 20px -6px var(--accent); filter: brightness(1.06); }

.btn-lg { padding: 12px 26px; font-size: 15px; border-radius: 12px; }

.btn-icon {
  width: 32px; height: 32px; padding: 0;
  border-radius: 9px;
  background: transparent; border: 1px solid var(--line);
  color: var(--text-dim);
  display: grid; place-items: center;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.btn-icon:hover { background: var(--bg-sunken); color: var(--text); }
.btn-icon.danger:hover { color: var(--err); border-color: var(--err); background: var(--err-soft); }

.link-btn {
  background: none; border: 0; padding: 0;
  color: var(--accent); font-size: 12.5px; font-weight: 600;
  cursor: pointer; text-decoration: none;
}
.link-btn:hover { text-decoration: underline; }

.spinner {
  width: 15px; height: 15px;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 99px;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   URL bar
   ============================================================ */
.url-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 8px 8px 16px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  transition: border-color .18s, box-shadow .18s;
}
.url-bar:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow);
}
.url-icon { font-size: 18px; color: var(--text-faint); flex: none; }

#urlInput {
  flex: 1;
  padding: 8px 0;
  background: none; border: 0;
  resize: none;
  max-height: 168px;
  font-size: 14.5px;
  font-family: var(--mono);
  font-size: 13.5px;
}
#urlInput:hover, #urlInput:focus { background: none; border: 0; box-shadow: none; }

.hint-row {
  display: flex; align-items: center; gap: 10px;
  min-height: 22px;
  padding: 6px 4px 0;
  font-size: 12px; color: var(--text-faint);
}

/* ============================================================
   Alerts / preview
   ============================================================ */
.alert {
  margin-top: 14px;
  padding: 11px 15px;
  border-radius: var(--r-sm);
  font-size: 13.5px;
  border: 1px solid transparent;
}
.alert-error { background: var(--err-soft); border-color: var(--err); color: var(--err); }

.preview {
  display: flex; gap: 18px;
  margin-top: 18px;
  padding: 16px;
  animation: rise .3s cubic-bezier(.2,.7,.3,1);
}

.preview-thumb {
  position: relative;
  flex: none;
  width: 208px; height: 117px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-sunken);
}
.preview-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pill {
  position: absolute; right: 7px; bottom: 7px;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(0,0,0,.78);
  color: #fff;
  font-size: 11.5px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.preview-body { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.preview-kind {
  font-size: 10.5px; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--accent);
}
.preview-body h2 {
  margin: 0;
  font-size: 17px; font-weight: 620; letter-spacing: -.015em;
  line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.preview-meta { font-size: 13px; color: var(--text-dim); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }
.chips span {
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--bg-sunken);
  font-size: 11.5px; font-weight: 600;
  color: var(--text-dim);
}

.chips-select { margin-top: 0; }
.chips-select button {
  padding: 6px 13px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: transparent;
  color: var(--text-dim);
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.chips-select button:hover { border-color: var(--text-faint); color: var(--text); }
.chips-select button.is-active {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: 0 3px 10px -4px var(--accent);
}
.chips-select button.is-unavailable { opacity: .35; }

/* playlist */
.playlist-box { margin-top: 14px; padding: 16px 18px; }
.pl-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.pl-head strong { font-size: 14px; }
.pl-list {
  list-style: none; margin: 12px 0 0; padding: 0;
  max-height: 190px; overflow-y: auto;
  border-top: 1px solid var(--line-soft);
}
.pl-list li {
  display: flex; gap: 10px; align-items: baseline;
  padding: 7px 2px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13px;
}
.pl-list li:last-child { border-bottom: 0; }
.pl-list .idx { color: var(--text-faint); font-variant-numeric: tabular-nums; min-width: 26px; font-size: 12px; }
.pl-list .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-list .d { color: var(--text-faint); font-size: 12px; font-variant-numeric: tabular-nums; }

/* ============================================================
   Options grid, switches
   ============================================================ */
.options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 18px;
}
@media (max-width: 860px) { .options { grid-template-columns: 1fr; } }

.segmented {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--bg-sunken);
  border-radius: 12px;
  margin-bottom: 18px;
}
.seg {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px;
  border: 0; border-radius: 9px;
  background: transparent;
  color: var(--text-dim);
  font-size: 13.5px; font-weight: 600;
  cursor: pointer;
  transition: background .18s, color .18s, box-shadow .18s;
}
.seg svg { font-size: 16px; }
.seg.is-active {
  background: var(--bg-elev);
  color: var(--text);
  box-shadow: var(--shadow);
}

.switch {
  display: flex; align-items: center; gap: 11px;
  padding: 7px 0;
  cursor: pointer;
  font-size: 13.5px;
}
.switch input { display: none; }
.switch i {
  flex: none;
  width: 34px; height: 20px;
  border-radius: 99px;
  background: var(--line);
  position: relative;
  transition: background .2s;
}
.switch i::after {
  content: "";
  position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 99px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
  transition: transform .2s cubic-bezier(.3,1.4,.5,1);
}
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(14px); }
.switch span { color: var(--text-dim); }
.switch input:checked ~ span { color: var(--text); }

.check {
  display: flex; align-items: center; gap: 9px;
  font-size: 13px; color: var(--text-dim);
  cursor: pointer;
  padding: 4px 0;
}
.check input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; flex: none; }

.sub-opts {
  margin: 8px 0 0 45px;
  padding: 12px 14px;
  border-left: 2px solid var(--line);
  background: var(--bg-sunken);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
}

/* advanced */
.advanced { margin-top: 16px; padding: 0; overflow: hidden; }
.advanced summary {
  display: flex; align-items: center; gap: 9px;
  padding: 15px 20px;
  cursor: pointer;
  font-size: 13px; font-weight: 650;
  color: var(--text-dim);
  list-style: none;
  user-select: none;
}
.advanced summary::-webkit-details-marker { display: none; }
.advanced summary svg { font-size: 15px; transition: transform .2s; }
.advanced[open] summary { color: var(--text); border-bottom: 1px solid var(--line-soft); }
.advanced[open] summary svg { transform: rotate(90deg); }
.adv-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 16px 20px;
  padding: 18px 20px 20px;
}
@media (max-width: 860px) { .adv-grid { grid-template-columns: 1fr; } }
.field-checks { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px 24px; }

/* action bar */
.action-bar {
  position: sticky; bottom: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  margin-top: 22px;
  padding: 14px 18px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(12px);
}
.out-line {
  display: flex; align-items: center; gap: 8px;
  min-width: 0;
  font-size: 12.5px; color: var(--text-dim);
}
.out-line svg { font-size: 16px; color: var(--text-faint); flex: none; }
.out-line span {
  font-family: var(--mono); font-size: 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ============================================================
   Job cards
   ============================================================ */
.job-list { display: flex; flex-direction: column; gap: 12px; }

.job {
  display: grid;
  grid-template-columns: 112px 1fr auto;
  gap: 16px;
  padding: 14px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  animation: rise .25s cubic-bezier(.2,.7,.3,1);
  transition: border-color .2s;
}
.job.is-running { border-color: var(--accent); }
.job.is-error { border-color: var(--err); }

.job-thumb {
  position: relative;
  width: 112px; height: 63px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-sunken);
  display: grid; place-items: center;
  color: var(--text-faint);
}
.job-thumb img { width: 100%; height: 100%; object-fit: cover; }

.job-body { min-width: 0; display: flex; flex-direction: column; gap: 7px; }
.job-title {
  font-size: 14px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.job-sub {
  font-size: 12px; color: var(--text-faint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.bar {
  height: 6px;
  border-radius: 99px;
  background: var(--bg-sunken);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent-hi), var(--accent));
  transition: width .3s cubic-bezier(.3,.8,.4,1);
}
.job.is-done .bar-fill { background: var(--ok); }
.job.is-error .bar-fill { background: var(--err); }
.job.is-canceled .bar-fill { background: var(--text-faint); }

.bar.indeterminate .bar-fill {
  width: 35% !important;
  animation: slide 1.3s ease-in-out infinite;
}
@keyframes slide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(300%); }
}

.job-stats {
  display: flex; align-items: center; gap: 14px;
  font-size: 12px; color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  flex-wrap: wrap;
}
.job-stats .state { font-weight: 650; }
.job.is-done .state { color: var(--ok); }
.job.is-error .state { color: var(--err); }
.job.is-running .state { color: var(--accent); }

.job-err {
  font-size: 12px; color: var(--err);
  background: var(--err-soft);
  padding: 7px 10px; border-radius: 8px;
  word-break: break-word;
}

.job-actions { display: flex; align-items: flex-start; gap: 6px; }

/* history */
.history-list { display: flex; flex-direction: column; gap: 8px; }
.hist {
  display: flex; align-items: center; gap: 14px;
  padding: 11px 14px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}
.hist-thumb {
  width: 68px; height: 39px; flex: none;
  border-radius: 6px; overflow: hidden;
  background: var(--bg-sunken);
}
.hist-thumb img { width: 100%; height: 100%; object-fit: cover; }
.hist-body { flex: 1; min-width: 0; }
.hist-title { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-sub { font-size: 12px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* empty state */
.empty { text-align: center; padding: 64px 20px; color: var(--text-faint); }
.empty-art {
  width: 66px; height: 66px;
  margin: 0 auto 18px;
  display: grid; place-items: center;
  border-radius: 20px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  font-size: 30px;
  color: var(--text-faint);
}
.empty h3 { margin: 0 0 5px; font-size: 16px; color: var(--text); font-weight: 600; }
.empty p { margin: 0; font-size: 13.5px; }

/* settings */
.kv { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 9px 22px; font-size: 13.5px; }
.kv dt { color: var(--text-dim); }
.kv dd { margin: 0; font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--text-dim); font-size: 13.5px; margin: 0 0 12px; }
.code {
  margin: 0;
  padding: 11px 14px;
  background: var(--bg-sunken);
  border-radius: var(--r-sm);
  font-family: var(--mono); font-size: 12.5px;
  overflow-x: auto;
}
.ok-text { color: var(--ok); }
.bad-text { color: var(--err); }

/* ============================================================
   Toasts
   ============================================================ */
.toasts {
  position: fixed; right: 22px; bottom: 22px;
  display: flex; flex-direction: column; gap: 9px;
  z-index: 100;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 16px;
  min-width: 230px; max-width: 380px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  animation: toast-in .3s cubic-bezier(.2,.9,.3,1);
  pointer-events: auto;
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--err); }
.toast.leaving { animation: toast-out .25s ease forwards; }
@keyframes toast-in  { from { opacity: 0; transform: translateX(30px); } }
@keyframes toast-out { to   { opacity: 0; transform: translateX(30px); } }

/* ============================================================
   Auth page
   ============================================================ */
.auth-body { display: grid; place-items: center; min-height: 100dvh; padding: 24px; }

.auth-wrap {
  display: grid;
  /* The left column flexes so the two panels always fill the card exactly. */
  grid-template-columns: minmax(0, 1fr) minmax(0, 320px);
  gap: 0;
  width: 100%; max-width: 760px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.auth-panel { padding: 34px 34px 28px; }
.auth-brand { margin-bottom: 26px; padding: 0; text-decoration: none; color: inherit; width: fit-content; }
.auth-brand:hover .brand-text strong { color: var(--accent); }
.brand-text strong { transition: color .15s; }
.auth-tabs { margin-bottom: 22px; }
.auth-form .field { margin-bottom: 16px; }
.auth-submit { width: 100%; margin-top: 6px; }
.auth-foot { margin: 18px 0 0; text-align: center; font-size: 13px; color: var(--text-faint); }

.auth-side {
  padding: 34px 30px;
  background: linear-gradient(165deg, var(--accent-soft), transparent 65%), var(--bg-sunken);
  border-left: 1px solid var(--line);
}
.auth-side h2 { margin: 0 0 8px; font-size: 17px; letter-spacing: -.02em; }
.auth-side > p { margin: 0 0 20px; font-size: 13px; color: var(--text-dim); }

.auth-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.auth-list li {
  display: grid; grid-template-columns: 1fr auto;
  gap: 2px 10px;
  padding-bottom: 11px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13px;
}
.auth-list li:last-child { border-bottom: 0; }
.auth-list strong { font-size: 13.5px; }
.auth-list span { font-weight: 700; color: var(--accent); font-size: 13px; }
.auth-list em { grid-column: 1 / -1; font-style: normal; font-size: 12px; color: var(--text-faint); }

@media (max-width: 700px) {
  .auth-wrap { grid-template-columns: 1fr; max-width: 420px; }
  .auth-side { display: none; }
}

@media (max-width: 480px) {
  .auth-body { padding: 16px; align-items: start; padding-top: max(24px, env(safe-area-inset-top)); }
  .auth-wrap { border-radius: 14px; }
  .auth-panel { padding: 24px 20px 20px; }
  .auth-brand { margin-bottom: 20px; }
}

/* ============================================================
   Usage meter
   ============================================================ */
.meter {
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--bg-sunken);
}
.meter-top {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  font-size: 12px; font-weight: 600;
  margin-bottom: 7px;
}
.meter-bar { height: 5px; border-radius: 99px; background: var(--line); overflow: hidden; }
.meter-fill {
  height: 100%; border-radius: 99px;
  background: var(--accent);
  transition: width .35s ease;
}
.meter-fill.is-warn { background: var(--warn); }
.meter-fill.is-full { background: var(--err); }
.meter-fill.is-unlimited { background: linear-gradient(90deg, var(--accent-hi), var(--ok)); }
.meter small { display: block; margin-top: 6px; font-size: 11px; color: var(--text-faint); }

.alert-warn { background: rgba(226,178,60,.12); border-color: var(--warn); color: var(--warn); }
.warn-text { color: var(--warn); font-weight: 600; }
.is-over { color: var(--err) !important; }

/* ============================================================
   Plan locks & cards
   ============================================================ */
.lock-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 7px;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase;
  vertical-align: middle;
}
.is-locked { opacity: .58; }
.is-locked, .is-locked * { cursor: not-allowed; }
.chips-select button.is-locked { opacity: .3; text-decoration: line-through; }

.section-title { margin: 30px 0 12px; }

.plan-now { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 12px; }
.plan-now strong { font-size: 18px; letter-spacing: -.02em; }
.plan-now .plan-price { margin-left: 8px; color: var(--text-dim); font-size: 14px; }
.plan-usage { font-size: 12.5px; color: var(--text-dim); text-align: right; }
.plan-actions { margin-top: 16px; }

.pill-status {
  margin-left: 8px; padding: 2px 8px;
  border-radius: 99px; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em;
}
.pill-status.is-bad { background: var(--err-soft); color: var(--err); }
.pill-status.is-warn { background: rgba(226,178,60,.14); color: var(--warn); }

.plan-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 880px) { .plan-grid { grid-template-columns: 1fr; } }

.plan-card {
  display: flex; flex-direction: column;
  padding: 20px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
}
.plan-card.is-current { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow); }
.plan-head strong { font-size: 15px; }
.plan-head .plan-price { font-size: 27px; font-weight: 650; letter-spacing: -.03em; margin: 6px 0 2px; }
.plan-head .plan-price em { font-style: normal; font-size: 13px; font-weight: 500; color: var(--text-faint); }
/* Reserved height so every card's feature list starts on the same baseline —
   otherwise a longer blurb pushes one column out of alignment. */
.plan-head p { margin: 0 0 14px; font-size: 12.5px; color: var(--text-dim); min-height: 3.1em; }

.plan-feats { list-style: none; margin: 0 0 18px; padding: 0; flex: 1; display: flex; flex-direction: column; gap: 7px; }
.plan-feats li { position: relative; padding-left: 20px; font-size: 13px; color: var(--text-dim); }
.plan-feats li::before {
  content: ""; position: absolute; left: 3px; top: 7px;
  width: 5px; height: 9px;
  border: solid var(--ok); border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.plan-card .btn { width: 100%; }
.billing-note { margin-top: 14px; font-size: 12.5px; }

.hist.is-gone { opacity: .5; }

/* ============================================================
   Presets
   ============================================================ */
.preset-bar {
  display: flex; align-items: center; gap: 9px;
  margin-top: 18px;
  padding: 9px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow);
}
.preset-bar > svg { font-size: 16px; color: var(--text-faint); flex: none; }
.preset-bar select { width: auto; min-width: 190px; flex: none; padding: 7px 32px 7px 11px; }
.preset-bar .btn { padding: 7px 13px; }
.preset-count { margin-left: auto; font-size: 11.5px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.preset-count.is-over { color: var(--warn); cursor: help; }

/* ============================================================
   Clip range
   ============================================================ */
.clip-field .opt-hint {
  margin-left: 6px; font-weight: 500;
  font-size: 11px; color: var(--text-faint);
  text-transform: uppercase; letter-spacing: .06em;
}
.clip-row { display: flex; align-items: center; gap: 8px; }
.clip-row input { flex: 1; font-family: var(--mono); font-size: 13px; }
.clip-arrow { color: var(--text-faint); flex: none; }
.clip-field.is-set input { border-color: var(--accent); }

/* ============================================================
   Exact format table
   ============================================================ */
.fmt-wrap { padding: 16px 20px 20px; }
.fmt-note { margin: 0 0 12px; font-size: 12.5px; }
.fmt-chosen {
  margin-left: auto;
  padding: 2px 9px;
  border-radius: 99px;
  background: var(--bg-sunken);
  font-family: var(--mono); font-size: 11.5px; font-weight: 600;
  color: var(--text-faint);
}
.fmt-chosen.is-set { background: var(--accent-soft); color: var(--accent); }
.fmt-chosen.is-bad { background: var(--err-soft); color: var(--err); }

.fmt-scroll, .table-scroll { max-height: 340px; overflow: auto; border-radius: var(--r-sm); }
.table-scroll { max-height: none; }

.fmt-table, .admin-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.fmt-table th, .admin-table th {
  position: sticky; top: 0; z-index: 1;
  padding: 8px 10px;
  background: var(--bg-sunken);
  text-align: left;
  font-size: 10.5px; font-weight: 700;
  letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-faint);
  white-space: nowrap;
}
.fmt-table td, .admin-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
.fmt-table tr:last-child td, .admin-table tr:last-child td { border-bottom: 0; }
.fmt-table tbody tr:hover { background: var(--bg-sunken); }
.fmt-table tr.is-picked { background: var(--accent-soft); }
.fmt-table code { font-family: var(--mono); font-size: 12px; }
.fmt-ext { color: var(--text-faint); font-size: 11px; text-transform: uppercase; }
.fmt-note { color: var(--text-faint); }
.fmt-wrap .btn { margin-top: 14px; }

/* ============================================================
   Admin
   ============================================================ */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat {
  display: flex; flex-direction: column; gap: 3px;
  padding: 15px 17px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow);
}
.stat-v { font-size: 21px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-k { font-size: 11.5px; color: var(--text-faint); }

.admin-table select { width: auto; min-width: 104px; padding: 5px 28px 5px 9px; font-size: 12.5px; }
.admin-table .num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.au-email { display: flex; align-items: center; gap: 7px; font-weight: 600; font-size: 13px; }
.au-sub { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }
.au-actions { display: flex; gap: 5px; justify-content: flex-end; }
.au-actions .btn-icon { width: 28px; height: 28px; }

.event-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1px; }
.event-list li {
  display: grid;
  grid-template-columns: minmax(120px, auto) minmax(0, 1fr) minmax(0, 1.2fr) auto;
  gap: 14px; align-items: baseline;
  padding: 8px 2px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 12.5px;
}
.event-list li:last-child { border-bottom: 0; }
.ev-kind { font-family: var(--mono); font-size: 11.5px; color: var(--accent); }
.ev-who { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-detail { color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-when { color: var(--text-faint); font-size: 11.5px; white-space: nowrap; }

@media (max-width: 780px) {
  .event-list li { grid-template-columns: 1fr; gap: 2px; }
}

/* ============================================================
   Media preview modal
   ============================================================ */
.modal { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 24px; }
.modal-back {
  position: absolute; inset: 0;
  background: rgba(3, 5, 9, .72);
  backdrop-filter: blur(4px);
  animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0; } }

.modal-card {
  position: relative;
  width: min(920px, 100%);
  max-height: calc(100dvh - 48px);
  display: flex; flex-direction: column;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: rise .24s cubic-bezier(.2,.7,.3,1);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
}
.modal-head strong {
  font-size: 14px; font-weight: 620;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.modal-body { background: #000; min-height: 0; }
.modal-body video { display: block; width: 100%; max-height: min(62vh, 520px); background: #000; }
.audio-wrap {
  display: grid; place-items: center;
  padding: 40px 24px;
  background: var(--bg-sunken);
}
.audio-wrap audio { width: 100%; max-width: 520px; }
.audio-wrap p { margin: 0; }
.modal-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 13px 16px;
  border-top: 1px solid var(--line);
}
.modal-foot .btn { text-decoration: none; }

.hist-actions { display: flex; gap: 5px; }



/* Inline preset naming (replaces window.prompt) */
.preset-name { display: flex; align-items: center; gap: 8px; flex: 1; }
.preset-name input { flex: 1; min-width: 0; padding: 7px 11px; }
.preset-name .btn { padding: 7px 13px; }

/* Cookie jar upload */
.cookie-box {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 12px;
  background: var(--bg-sunken);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
}
.cookie-state { font-size: 12.5px; color: var(--text-faint); min-width: 0; }
.cookie-state.is-set { color: var(--text-dim); }
.cookie-state strong { color: var(--ok); }
.cookie-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.cookie-actions .btn { padding: 6px 12px; cursor: pointer; }
.field-cookies small strong { color: var(--warn); }

/* ============================================================
   Mobile — the sidebar becomes a top bar plus bottom tab bar.
   `display: contents` lets the sidebar's children be positioned
   independently without duplicating any markup.
   ============================================================ */
@media (max-width: 760px) {
  .shell {
    display: block;
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .sidebar { display: contents; }

  /* top bar */
  .brand {
    position: fixed; inset: 0 0 auto 0;
    z-index: 40;
    height: calc(54px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 16px 0;
    gap: 10px;
    background: color-mix(in srgb, var(--sidebar) 92%, transparent);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
  }
  .brand-mark { width: 30px; height: 30px; border-radius: 9px; font-size: 16px; }
  .brand-text strong { font-size: 14px; }
  .brand-text span { font-size: 11px; }

  /* theme toggle sits in the top bar; the meter and status move to Settings */
  .sidebar-foot {
    position: fixed;
    top: env(safe-area-inset-top); right: 10px;
    z-index: 41;
    height: 54px;
    flex-direction: row; align-items: center; gap: 8px;
  }
  .sidebar-foot .meter, .sidebar-foot .status { display: none; }
  .theme-toggle { padding: 8px; border-radius: 9px; }
  .theme-toggle span { display: none; }

  /* bottom tab bar */
  .nav {
    position: fixed; inset: auto 0 0 0;
    z-index: 40;
    flex-direction: row;
    gap: 0;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--sidebar) 94%, transparent);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
  }
  .nav-item {
    flex: 1 1 0;
    min-width: 0;
    flex-direction: column;
    gap: 3px;
    padding: 7px 2px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    text-align: center;
    position: relative;
  }
  .nav-item svg { font-size: 20px; }
  .nav-item span {
    display: block;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    max-width: 100%;
  }
  .nav-item.is-active { background: transparent; }
  .nav-item.is-active::before {
    content: ""; position: absolute; top: 0; left: 50%;
    width: 22px; height: 2px; margin-left: -11px;
    border-radius: 0 0 3px 3px;
    background: var(--accent);
  }
  .badge {
    position: absolute; top: 3px; right: 50%;
    margin-right: -20px;
    font-size: 9px; min-width: 15px; padding: 0 4px;
  }

  /* content clears both bars */
  .main {
    overflow: visible;
    padding-top: calc(54px + env(safe-area-inset-top));
    padding-bottom: calc(66px + env(safe-area-inset-bottom));
  }
  .view { padding: 22px 16px 28px; }
  .view-head h1 { font-size: 22px; }
  .view-head.row { flex-direction: column; gap: 12px; }
  .view-head.row .btn { align-self: flex-start; }

  /* URL bar stacks so the field gets full width */
  .url-bar { flex-wrap: wrap; padding: 12px; gap: 8px; }
  .url-icon { display: none; }
  #urlInput { flex: 1 1 100%; font-size: 16px; }   /* 16px stops iOS zooming on focus */
  .url-bar .btn { flex: 1; }

  /* forms: 16px avoids the iOS focus zoom */
  input:not([type="checkbox"]):not([type="radio"]), select, textarea { font-size: 16px; }

  .preview { flex-direction: column; padding: 12px; }
  .preview-thumb { width: 100%; height: auto; aspect-ratio: 16 / 9; }
  .preview-body h2 { font-size: 16px; }

  .opt-card { padding: 16px; }
  .adv-grid { padding: 16px; }
  .segmented { grid-template-columns: 1fr 1fr; }
  .chips-select button { padding: 8px 14px; }      /* larger touch targets */

  .preset-bar { flex-wrap: wrap; gap: 8px; }
  .preset-bar select { flex: 1 1 100%; min-width: 0; }
  .preset-bar .btn { flex: 1; }
  .preset-name { flex: 1 1 100%; flex-wrap: wrap; }
  .preset-name input { flex: 1 1 100%; }

  /* The tab bar is fixed over the viewport, so the sticky action bar has to be
     lifted clear of it or the Download button sits underneath and can't be tapped. */
  .action-bar {
    position: sticky;
    bottom: calc(72px + env(safe-area-inset-bottom));
    flex-direction: column; align-items: stretch; gap: 12px;
    padding: 14px;
  }
  .action-bar .btn-lg { width: 100%; justify-content: center; }
  .out-line { justify-content: center; }

  /* queue cards keep the thumbnail, just smaller */
  .job { grid-template-columns: 76px 1fr; gap: 12px; padding: 12px; }
  .job-thumb { display: grid; width: 76px; height: 44px; }
  .job-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .job-stats { font-size: 11.5px; gap: 10px; }

  .hist { padding: 10px; gap: 10px; }
  .hist-thumb { width: 56px; height: 32px; }

  /* admin */
  .stat-row { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 12px 14px; }
  .stat-v { font-size: 18px; }
  .table-scroll, .fmt-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .admin-table, .fmt-table { min-width: 620px; }

  /* player fills the screen */
  .modal { padding: 0; }
  .modal-card {
    width: 100%; height: 100dvh; max-height: none;
    border-radius: 0; border: 0;
  }
  .modal-head { padding: calc(12px + env(safe-area-inset-top)) 14px 12px; }
  .modal-body { flex: 1; display: grid; place-items: center; }
  .modal-body video { max-height: 100%; }
  .modal-foot {
    flex-direction: column; align-items: stretch; gap: 10px;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  }
  .modal-foot .btn { width: 100%; justify-content: center; }

  .cookie-box { flex-direction: column; align-items: stretch; gap: 10px; }
  .cookie-actions .btn { width: 100%; justify-content: center; }

  .toasts { right: 12px; left: 12px; bottom: calc(74px + env(safe-area-inset-bottom)); }
  .toast { max-width: none; }

  .plan-now { flex-direction: column; }
  .plan-usage { text-align: left; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { margin-top: 8px; }
}

/* Very narrow phones */
@media (max-width: 380px) {
  .nav-item { font-size: 9px; }
  .nav-item svg { font-size: 18px; }
  .view { padding: 18px 12px 24px; }
}
