/* ---------- Theme tokens ---------- */
:root,
:root[data-theme="light"] {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #f5f5f7;
  --seg-on: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --faint: #86868b;
  --line: rgba(0, 0, 0, 0.08);
  --line-strong: #d2d2d7;
  --primary: #1d1d1f;
  --primary-hover: #000000;
  --on-primary: #ffffff;
  --accent: #834aff;
  --accent-fill: #834aff;
  --accent-soft: rgba(131, 74, 255, 0.08);
  --field-bg: #ffffff;
  --field-border: #d2d2d7;
  --field-hover: #b0b0b8;
  --field-focus: #1d1d1f;
  --ok: #1a7f37;
  --warn: #a15c00;
  --bad: #d70015;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  --ring: 0 0 0 3px rgba(131, 74, 255, 0.22);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131517;
    --surface: #16181b;
    --surface-2: #1c1e21;
    --seg-on: rgba(255, 255, 255, 0.12);
    --text: #ffffff;
    --muted: #a1a1a6;
    --faint: #737475;
    --line: rgba(255, 255, 255, 0.1);
    --line-strong: rgba(255, 255, 255, 0.2);
    --primary: #ffffff;
    --primary-hover: rgba(255, 255, 255, 0.9);
    --on-primary: #000000;
    --accent: #3d8af7;
    --accent-fill: linear-gradient(100deg, #5ef0ff, #3d8af7);
    --accent-soft: rgba(61, 138, 247, 0.12);
    --field-bg: transparent;
    --field-border: rgba(255, 255, 255, 0.1);
    --field-hover: rgba(255, 255, 255, 0.2);
    --field-focus: rgba(255, 255, 255, 0.4);
    --ok: #4cc27f;
    --warn: #e0a640;
    --bad: #ff6b6b;
    --shadow: none;
    --ring: 0 0 0 3px rgba(61, 170, 247, 0.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"],
.auth {
  --bg: #131517;
  --surface: #16181b;
  --surface-2: #1c1e21;
  --seg-on: rgba(255, 255, 255, 0.12);
  --text: #ffffff;
  --muted: #a1a1a6;
  --faint: #737475;
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.2);
  --primary: #ffffff;
  --primary-hover: rgba(255, 255, 255, 0.9);
  --on-primary: #000000;
  --accent: #3d8af7;
  --accent-fill: linear-gradient(100deg, #5ef0ff, #3d8af7);
  --accent-soft: rgba(61, 138, 247, 0.12);
  --field-bg: transparent;
  --field-border: rgba(255, 255, 255, 0.1);
  --field-hover: rgba(255, 255, 255, 0.2);
  --field-focus: rgba(255, 255, 255, 0.4);
  --ok: #4cc27f;
  --warn: #e0a640;
  --bad: #ff6b6b;
  --shadow: none;
  --ring: 0 0 0 3px rgba(61, 170, 247, 0.35);
  color-scheme: dark;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
body:has(#login:not([hidden])) { background: #131517; }
[hidden] { display: none !important; }
h2 { font-size: 17px; font-weight: 600; margin: 0; letter-spacing: -0.02em; }
a { color: var(--text); font-weight: 500; text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--text); }
.muted { color: var(--muted); font-size: 13px; font-weight: 400; }
.error { color: var(--bad); margin: 0; font-size: 13px; }
.error:empty { display: none; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
::selection { background: var(--primary); color: var(--on-primary); }
.wordmark { display: block; height: 24px; width: auto; color: var(--text); }

/* ---------- Sign-in (always dark) ---------- */
.auth { min-height: 100dvh; display: flex; flex-direction: column; background: var(--bg); color: var(--text); }
.auth-head { height: 59px; display: flex; align-items: center; padding: 0 32px; }
.auth-head .wordmark { height: 28px; }
.auth-main { flex: 1; display: flex; flex-direction: column; justify-content: center; width: 100%; max-width: 383px; margin: 0 auto; padding: 16px 24px 48px; }
.auth-title { margin: 0; text-align: center; font-size: 46px; line-height: 1.02; font-weight: 700; letter-spacing: -0.045em; }
.auth-form { margin-top: 28px; display: grid; gap: 14px; }
.auth .field-label { font-size: 12px; line-height: 18px; font-weight: 400; color: var(--faint); }
.auth .input { height: 52px; font-size: 14px; }
.auth .input::placeholder { color: #828282; }
.auth .btn-primary { height: 40px; margin-top: 4px; font-size: 14px; }
.auth .btn-primary.is-empty { background: #292b2c; color: var(--faint); }

/* ---------- App layout ---------- */
.top {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  max-width: 900px; margin: 0 auto; padding: 16px 16px 12px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-sep { width: 1px; height: 22px; background: var(--line-strong); }
.account { display: flex; align-items: center; gap: 10px; min-width: 0; }
.account img { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line); }
.account div { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.account strong { font-size: 14px; font-weight: 600; }
.who { display: flex; align-items: center; gap: 8px; }
main { max-width: 900px; margin: 0 auto; padding: 0 16px 48px; display: grid; gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 22px;
  box-shadow: var(--shadow); display: grid; gap: 16px; min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.stack { display: grid; gap: 16px; }
.group { display: grid; gap: 8px; }
.inline-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.list { display: grid; gap: 10px; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; border: 1px solid transparent; border-radius: 10px; padding: 0 16px;
  font: inherit; font-size: 14px; font-weight: 600; line-height: 20px; cursor: pointer; user-select: none; white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.btn:focus-visible, .icon-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--line); }
.btn-secondary:hover:not(:disabled) { border-color: var(--line-strong); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--surface-2); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn-xs { height: 26px; padding: 0 9px; font-size: 12px; font-weight: 500; border-radius: 7px; }
.btn-block { width: 100%; }
.icon-btn {
  appearance: none; display: inline-grid; place-items: center; width: 34px; height: 34px; padding: 0;
  border: 1px solid var(--line); border-radius: 10px; background: transparent; color: var(--text); cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}
.icon-btn:hover { border-color: var(--line-strong); background: var(--surface-2); }
.icon-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .icon-moon { fill: currentColor; stroke: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon,
:root[data-theme="light"] .theme-toggle .icon-sun { display: none; }

/* ---------- Fields ---------- */
.field { display: grid; gap: 6px; }
.field-label { font-weight: 500; font-size: 13px; color: var(--text); }
.field-label .muted { margin-left: 4px; font-size: 12px; }
.input {
  appearance: none; width: 100%; height: 44px; padding: 0 14px; font: inherit; font-size: 14px; color: var(--text);
  background: var(--field-bg); border: 1px solid var(--field-border); border-radius: 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input::placeholder { color: var(--faint); }
.input:hover { border-color: var(--field-hover); }
.input:focus { outline: none; border-color: var(--field-focus); }
.input:disabled { opacity: 0.55; }
textarea.input { height: auto; padding: 12px 14px; resize: vertical; min-height: 104px; line-height: 1.5; }
.input-auto { width: auto; }
.counter { justify-self: end; font-size: 12px; }

/* ---------- Segmented controls and tabs ---------- */
.seg {
  display: inline-flex; gap: 2px; padding: 3px; border-radius: 12px; background: var(--surface-2);
  border: 1px solid var(--line); max-width: 100%;
}
.seg-wrap { flex-wrap: wrap; }
.seg-item {
  appearance: none; border: 0; background: transparent; font: inherit; color: var(--muted);
  display: inline-flex; align-items: center; height: 32px; padding: 0 14px; border-radius: 9px; font-weight: 500; font-size: 13.5px;
  cursor: pointer; user-select: none; transition: background-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.seg-item:hover { color: var(--text); }
.seg-item:has(input:checked), .seg-item[aria-selected="true"] {
  background: var(--seg-on); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}
.seg-item:has(input:focus-visible), .seg-item:focus-visible { outline: none; box-shadow: var(--ring); }
.seg-item:has(input:disabled) { opacity: 0.5; cursor: default; }

/* ---------- Choice cards ---------- */
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.choice {
  display: grid; gap: 2px; padding: 12px 14px 12px 40px; position: relative; cursor: pointer;
  border: 1px solid var(--field-border); border-radius: 12px; background: var(--field-bg);
  transition: border-color 0.15s, background-color 0.15s, box-shadow 0.15s;
}
.choice::before {
  content: ""; position: absolute; left: 14px; top: 15px; width: 16px; height: 16px; border-radius: 50%;
  border: 1.5px solid var(--line-strong); transition: border-color 0.15s, box-shadow 0.15s;
}
.choice:hover { border-color: var(--field-hover); }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice:has(input:checked)::before { border-color: var(--accent); box-shadow: inset 0 0 0 3.5px var(--surface), inset 0 0 0 8px var(--accent); }
.choice:has(input:focus-visible) { box-shadow: var(--ring); }
.choice-title { font-weight: 600; font-size: 14px; }
.choice-text { color: var(--muted); font-size: 13px; }

.note { display: grid; gap: 2px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--accent); background: var(--accent-soft); }

/* ---------- Switch ---------- */
.switch { display: inline-flex; align-items: center; gap: 12px; cursor: pointer; user-select: none; font-size: 14px; }
.switch .track {
  flex: none; width: 40px; height: 24px; border-radius: 999px; background: var(--line-strong); position: relative;
  transition: background 0.18s, box-shadow 0.15s;
}
.switch .knob {
  position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: transform 0.18s;
}
.switch:has(input:checked) .track { background: var(--accent-fill); }
.switch:has(input:checked) .knob { transform: translateX(16px); }
.switch:has(input:focus-visible) .track { box-shadow: var(--ring); }
.switch:has(input:disabled) { opacity: 0.5; cursor: default; }

/* ---------- Drop zone, previews, progress ---------- */
.drop {
  display: grid; justify-items: center; gap: 4px; padding: 28px 18px; text-align: center; cursor: pointer;
  border: 1.5px dashed var(--line-strong); border-radius: 14px; background: var(--surface-2);
  transition: border-color 0.15s, background-color 0.15s, box-shadow 0.15s;
}
.drop:hover, .drop.dragging { border-color: var(--accent); background: var(--accent-soft); }
.drop:has(input:focus-visible) { box-shadow: var(--ring); }
.drop:has(input:disabled) { opacity: 0.5; cursor: default; }
.drop-icon { width: 26px; height: 26px; fill: none; stroke: var(--text); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.drop-title { font-weight: 600; font-size: 14px; }
.file-btn { position: relative; }

.previews { display: grid; gap: 10px; }
.previews:empty { display: none; }
.previews video { width: 100%; max-height: 440px; background: #000; border-radius: 12px; }
.previews .items { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.previews .item { display: grid; gap: 6px; font-size: 12px; min-width: 0; }
.previews .item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.previews .item img, .previews .item video, .thumb {
  width: 100%; aspect-ratio: 4 / 5; object-fit: cover; border-radius: 10px; background: var(--line);
}
.thumb { max-width: 140px; }
.previews .item .row { display: flex; gap: 4px; }
.previews .item .row .btn { flex: 1; padding: 0; }

.actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.bar { flex: 1; min-width: 140px; height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent-fill); border-radius: inherit; transition: width 0.2s; }

/* ---------- Queue ---------- */
.post { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: grid; gap: 6px; }
.post .head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: center; }
.post .head > span:last-child { display: inline-flex; align-items: center; gap: 10px; }
.post .caption { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.pill { font-size: 12px; font-weight: 600; border-radius: 999px; padding: 2px 10px; background: var(--surface-2); }
.pill.published { color: var(--ok); }
.pill.failed, .pill.canceled { color: var(--bad); }
.pill.active { color: var(--warn); }

/* ---------- Recent grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.tile { display: grid; gap: 6px; font-size: 13px; min-width: 0; align-content: start; }
.tile a { display: block; border-radius: 12px; overflow: hidden; }
.tile img, .tile .thumb { width: 100%; max-width: none; aspect-ratio: 9 / 16; object-fit: cover; display: block; background: var(--surface-2); transition: transform 0.25s; }
.tile a:hover img { transform: scale(1.02); }
.tile .meta { display: flex; justify-content: space-between; gap: 6px; font-weight: 500; }
.tile .btn { justify-self: start; }

/* ---------- Comments drawer ---------- */
body.drawer-open { overflow: hidden; }
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); backdrop-filter: blur(3px); z-index: 20; animation: fade 0.15s ease-out; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100vw); z-index: 21;
  background: var(--surface); border-left: 1px solid var(--line); box-shadow: -16px 0 48px rgba(0, 0, 0, 0.22);
  display: flex; flex-direction: column; gap: 12px; padding: 18px; overflow-y: auto; overscroll-behavior: contain;
  animation: slide-in 0.22s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; position: sticky; top: -18px; margin: -18px -18px 0; padding: 18px; background: var(--surface); border-bottom: 1px solid var(--line); z-index: 1; }
.drawer-title { display: grid; gap: 4px; min-width: 0; }
.drawer-title .muted { overflow-wrap: anywhere; }
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.comment .head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.comment { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: grid; gap: 8px; }
.comment .head strong { font-weight: 600; font-size: 14px; }
.comment .caption { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.comment .row { display: flex; gap: 6px; }
.comment.is-hidden > .caption { opacity: 0.45; }
.replies { display: grid; gap: 8px; margin-left: 14px; padding-left: 12px; border-left: 2px solid var(--line); }
.replies .comment { border: 0; padding: 4px 0; }
.reply { display: grid; gap: 8px; }
.reply .btn { justify-self: start; }

@media (prefers-reduced-motion: reduce) {
  .drawer, .backdrop { animation: none; }
}
@media (max-width: 560px) {
  .card { padding: 16px; border-radius: 16px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .seg { display: flex; }
  .seg:not(.seg-wrap) .seg-item { flex: 1; justify-content: center; }
  .auth-title { font-size: 40px; }
  .auth-head { padding: 0 20px; }
  .brand-sep, .brand .wordmark { display: none; }
}
