:root {
  /* Surfaces — near-black tinted toward the accent's own hue, not warm-by-default */
  --bg:            oklch(0.165 0.008 285);
  --surface:       oklch(0.212 0.010 285);
  --inset:         oklch(0.145 0.008 285);
  --border:        oklch(0.295 0.012 285);
  --border-strong: oklch(0.380 0.016 285);

  /* Ink — all verified ≥4.5:1 on --surface */
  --ink:        oklch(0.960 0.004 285);
  --ink-muted:  oklch(0.760 0.010 285);
  --ink-subtle: oklch(0.660 0.012 285);

  /* Accent doubles as fill and as text-on-dark, so it can't be darkened for
     white button text (that fails 4.5:1). Dark ink on the vivid fill instead;
     hover goes lighter, which is also the right direction on a dark UI. */
  --accent:       oklch(0.640 0.185 285);
  --accent-hover: oklch(0.700 0.180 285);
  --accent-soft:  oklch(0.640 0.185 285 / 0.14);
  --accent-ink:   oklch(0.175 0.015 285);

  --danger:  oklch(0.700 0.185 22);
  --success: oklch(0.760 0.150 155);

  --r-sm: 6px;
  --r-md: 9px;
  --r-lg: 13px;

  --s1: 0.25rem;
  --s2: 0.5rem;
  --s3: 0.75rem;
  --s4: 1rem;
  --s5: 1.5rem;
  --s6: 2rem;

  --ease: cubic-bezier(0.22, 1, 0.36, 1); /* ease-out-quart */
  --dur: 180ms;
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  margin: 0;
  padding: var(--s6) var(--s4) var(--s6);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- Masthead ---------- */

.masthead {
  display: flex;
  align-items: center;
  gap: var(--s3);
  margin-bottom: var(--s5);
}
.logo { flex-shrink: 0; display: block; }
.session-box {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex-shrink: 0;
}
.session-user {
  font-size: 0.8125rem;
  color: var(--ink-muted);
}
.session-box button { margin-top: 0; }

.login-page { display: grid; place-items: center; min-height: 100vh; }
.login-main { width: 100%; max-width: 380px; }
.login-main .card > form > :last-child { margin-bottom: 0; }
.masthead-text { min-width: 0; }
h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.subtitle {
  margin: 2px 0 0;
  color: var(--ink-muted);
  font-size: 0.875rem;
}

/* ---------- Cards & sections ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s5);
  margin-bottom: var(--s4);
}
.card[hidden] { display: none; }

h2 {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin: 0 0 var(--s4);
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--ink);
}
.step {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---------- Forms ---------- */

label {
  display: block;
  margin-bottom: var(--s1);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--ink-muted);
}
.hint {
  font-weight: 400;
  color: var(--ink-subtle);
}

.media-preview {
  margin-bottom: var(--s4);
}
.media-preview[hidden] { display: none; }
.media-preview video,
.media-preview img {
  display: block;
  width: 100%;
  max-height: 360px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--inset);
  object-fit: contain;
}

input, select, textarea {
  display: block;
  width: 100%;
  padding: 0.55rem 0.7rem;
  margin-bottom: var(--s4);
  background: var(--inset);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--ink);
  font-size: 0.9375rem;
  font-family: inherit;
  line-height: 1.45;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
textarea { resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--ink-subtle); }

input:hover:not(:disabled),
select:hover:not(:disabled),
textarea:hover:not(:disabled) { border-color: var(--border-strong); }

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input[type="file"] {
  padding: 0.4rem 0.5rem;
  color: var(--ink-muted);
  font-size: 0.875rem;
}
input[type="file"]::file-selector-button {
  margin-right: var(--s3);
  padding: 0.35rem 0.7rem;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  color: var(--ink);
  font: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: background var(--dur) var(--ease);
}
input[type="file"]::file-selector-button:hover { background: var(--border); }

.row { display: flex; gap: var(--s3); flex-wrap: wrap; }
.field { flex: 1 1 180px; min-width: 0; }

.brand-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s3);
}

.subpanel {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: color-mix(in oklab, var(--inset) 60%, transparent);
  padding: var(--s4);
  margin-bottom: var(--s4);
}
.subpanel[hidden] { display: none; }
.subpanel > :last-child { margin-bottom: 0; }

/* ---------- Channel toggles ---------- */

#platform-list {
  display: grid;
  /* wide enough that a full account name fits beside the badged avatar */
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--s2);
  margin-bottom: var(--s4);
}
.analyze-row { margin-bottom: var(--s4); }

.platform-check {
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-width: 0;              /* lets the name truncate instead of overflowing */
  margin: 0;
  padding: 0.5rem 0.7rem;
  background: var(--inset);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.platform-check:hover { border-color: var(--border-strong); }
.platform-check:has(:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.platform-check:has(:focus-visible) {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
  border-color: var(--accent);
}
.platform-check input {
  width: auto;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--accent);
}
.avatar {
  position: relative;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: block;
}
.avatar-img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--border);
  display: block;
}
/* Platform logo badged on the corner of the account avatar */
.avatar-badge {
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 0 0 1.5px var(--inset);
  object-fit: contain;
  display: block;
}
.platform-check:has(:checked) .avatar-badge { box-shadow: 0 0 0 1.5px var(--accent-soft); }

.platform-text { min-width: 0; }   /* stacked so the name gets the full chip width */
.platform-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tag {
  display: block;
  color: var(--ink-subtle);
  font-size: 0.6875rem;
  font-weight: 400;
  line-height: 1.3;
}

/* ---------- Buttons ---------- */

button {
  background: var(--accent);
  color: var(--accent-ink);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: 0.6rem 1.1rem;
  font-size: 0.9375rem;
  font-family: inherit;
  font-weight: 550;
  cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              opacity var(--dur) var(--ease);
}
button:hover:not(:disabled) { background: var(--accent-hover); }
button:active:not(:disabled) { transform: translateY(1px); }
button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}
button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
button[aria-busy="true"] { cursor: progress; }

.btn-secondary {
  background: var(--inset);
  color: var(--ink);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) { background: var(--border); }

.btn-ghost {
  background: transparent;
  color: var(--ink-muted);
  border-color: var(--border);
  padding: 0.3rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 500;
}
.btn-ghost:hover:not(:disabled) {
  background: var(--inset);
  color: var(--ink);
}

/* ---------- Status ---------- */

.status {
  margin: var(--s2) 0 0;
  min-height: 1.25em;
  font-size: 0.8125rem;
  color: var(--ink-muted);
}
.status:empty { margin: 0; min-height: 0; }
.status a { color: var(--accent); text-underline-offset: 2px; }
.status.is-error { color: var(--danger); }
.status.is-done { color: var(--success); }
.status.is-busy::after {
  content: "";
  display: inline-block;
  width: 0.5em; height: 0.5em;
  margin-left: 0.45em;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.1s var(--ease) infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.25; }
  50%      { opacity: 1; }
}

.error { color: var(--danger); }

/* ---------- Captions ---------- */

.caption-block { margin-bottom: var(--s4); }
.caption-block:last-child { margin-bottom: 0; }
.caption-block textarea { margin-bottom: 0; }
.caption-head {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin-bottom: var(--s1);
}
.caption-platform {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--ink);
  text-transform: capitalize;
}
.char-count {
  margin-left: auto;
  font-size: 0.6875rem;
  color: var(--ink-subtle);
  font-variant-numeric: tabular-nums;
}
.char-count.is-over { color: var(--danger); font-weight: 600; }
/* Block labels can't push a counter right with margin-left:auto — needs flex. */
.label-row { display: flex; align-items: baseline; gap: 0.35rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  button:active:not(:disabled) { transform: none; }
}

@media (max-width: 480px) {
  body { padding: var(--s4) var(--s3); }
  .card { padding: var(--s4); }
  button { width: 100%; }      /* comfortable touch targets on narrow screens */
  .btn-ghost { width: auto; }
}
