:root {
  --bg: #f6f5f9;
  --surface: #ffffff;
  --surface-2: #f0eef6;
  --text: #1d1b26;
  --muted: #6b6878;
  --border: #e4e1ec;
  --accent: #6d5dfc;
  --accent-text: #ffffff;
  --accent-soft: #ece9ff;
  --ok: #16875a;
  --ok-soft: #e3f5ec;
  --warn: #9a6400;
  --warn-soft: #fff4dc;
  --danger: #c23a3a;
  --danger-soft: #fdeaea;
  --info: #2563c9;
  --info-soft: #e6effd;
  --shadow: 0 1px 2px rgba(20, 16, 40, 0.06), 0 2px 8px rgba(20, 16, 40, 0.04);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121117;
    --surface: #1c1a24;
    --surface-2: #25222f;
    --text: #f1eff7;
    --muted: #a19db0;
    --border: #2f2b3b;
    --accent: #8b7fff;
    --accent-text: #0f0d18;
    --accent-soft: #2a2548;
    --ok: #4ccf93;
    --ok-soft: #173327;
    --warn: #f0b545;
    --warn-soft: #3a2c10;
    --danger: #ff7b7b;
    --danger-soft: #3d1a1d;
    --info: #7fb0ff;
    --info-soft: #1a2640;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #121117;
  --surface: #1c1a24;
  --surface-2: #25222f;
  --text: #f1eff7;
  --muted: #a19db0;
  --border: #2f2b3b;
  --accent: #8b7fff;
  --accent-text: #0f0d18;
  --accent-soft: #2a2548;
  --ok: #4ccf93;
  --ok-soft: #173327;
  --warn: #f0b545;
  --warn-soft: #3a2c10;
  --danger: #ff7b7b;
  --danger-soft: #3d1a1d;
  --info: #7fb0ff;
  --info-soft: #1a2640;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.35rem; margin: 0.4rem 0 1rem; }
h2 { font-size: 1rem; margin: 0; }

/* ---------- barra superior ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); white-space: nowrap; }
.brand::before { content: "▶"; color: var(--accent); margin-right: 6px; font-size: 0.85em; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
  padding: 6px 10px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.93rem;
  white-space: nowrap;
}
.topbar nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.topbar nav a:hover { text-decoration: none; color: var(--text); }

.wrap { max-width: 720px; margin: 0 auto; padding: 14px 16px 48px; }

/* ---------- chips y pestañas ---------- */
.chips, .tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 -16px 12px;
  padding: 0 16px;
}
.chips::-webkit-scrollbar, .tabs::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
}
.chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.chip:hover, .tab:hover { text-decoration: none; }
.tabs { border-bottom: 1px solid var(--border); gap: 2px; }
.tab {
  flex: none;
  padding: 8px 10px 10px;
  color: var(--muted);
  font-size: 0.93rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.count {
  display: inline-block;
  min-width: 20px;
  padding: 0 6px;
  margin-left: 4px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}
.tab.on .count { background: var(--accent); color: var(--accent-text); }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none; }

/* ---------- tarjetas ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
}
.list { list-style: none; margin: 0; padding: 0; }
.item-card { display: flex; gap: 12px; padding: 10px; }
.thumb {
  flex: none;
  width: 68px;
  height: 120px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.8rem;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.item-card .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.meta { color: var(--muted); font-size: 0.82rem; }
.meta .dot { vertical-align: 0; margin-right: 5px; }
.caption {
  color: var(--text);
  font-size: 0.95rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.caption:hover { text-decoration: none; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: auto; }
.actions form { margin: 0; }
.stage { color: var(--muted); font-size: 0.85rem; display: flex; align-items: center; gap: 8px; }
.error-text { color: var(--danger); font-size: 0.85rem; }

/* ---------- estados ---------- */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
}
.s-nuevo { background: var(--info-soft); color: var(--info); }
.s-en_cola, .s-procesando { background: var(--warn-soft); color: var(--warn); }
.s-listo { background: var(--ok-soft); color: var(--ok); }
.s-error { background: var(--danger-soft); color: var(--danger); }
.s-subido { background: var(--accent-soft); color: var(--accent); }

/* ---------- botones ---------- */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 8px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.success { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); background: transparent; }
.btn.sm { min-height: 34px; padding: 5px 12px; font-size: 0.88rem; border-radius: 10px; }
.btn.big { width: 100%; min-height: 50px; font-size: 1.02rem; }
.btn.copied { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn[disabled] { opacity: 0.6; cursor: default; }

/* ---------- formularios ---------- */
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > input { flex: 1; min-width: 0; }
label, .label { font-weight: 600; font-size: 0.9rem; }
.label { margin: 6px 0 0; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 2px 0 0; }
input[type="text"], input[type="url"], input[type="password"], input:not([type]), textarea, select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
input[type="color"] { width: 52px; height: 42px; padding: 3px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
input[type="file"] { font: inherit; max-width: 100%; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.channel-buttons { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.btn.channel {
  min-height: 58px;
  border: 2px solid var(--c);
  background: color-mix(in srgb, var(--c) 12%, var(--surface));
  color: var(--text);
  white-space: normal;
  text-align: center;
  line-height: 1.2;
}

/* ---------- avisos ---------- */
.alert { border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; font-size: 0.93rem; }
.alert p { margin: 4px 0 0; }
.alert.warn { background: var(--warn-soft); color: var(--text); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); }
.alert.error { background: var(--danger-soft); color: var(--text); border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); }
.alert.ok { background: var(--ok-soft); color: var(--text); border: 1px solid color-mix(in srgb, var(--ok) 35%, transparent); }
.alert.small { font-size: 0.86rem; padding: 9px 12px; margin: 10px 0 0; }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty strong { display: block; color: var(--text); font-size: 1.05rem; margin-bottom: 6px; }

/* ---------- detalle ---------- */
.back { display: inline-block; margin-bottom: 8px; color: var(--muted); font-size: 0.92rem; }
.item-head { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.media { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 14px; }
.media video, .media .poster {
  width: 100%;
  max-width: 320px;
  max-height: 70vh;
  border-radius: var(--radius);
  background: #000;
  display: block;
  object-fit: contain;
}
.small { font-size: 0.86rem; }
.tiny { font-size: 0.78rem; color: var(--muted); }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card > h2 { margin-bottom: 8px; }
.card textarea { margin-bottom: 10px; }
.counter { color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.counter.over { color: var(--danger); font-weight: 700; }
.saved-flag { color: var(--ok); font-size: 0.8rem; opacity: 0; transition: opacity 0.2s; }
.saved-flag.on { opacity: 1; }
.options { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.options li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-2);
}
.options li span { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: 0.95rem; }
.facts { display: grid; gap: 8px; font-size: 0.93rem; }
.facts .k { display: block; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 700; }
.progress { display: flex; align-items: center; gap: 12px; font-weight: 600; }
.bottom-actions { display: flex; flex-direction: column; gap: 10px; margin: 18px 0; }
details.card > summary { cursor: pointer; font-weight: 600; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: "▾"; float: right; color: var(--muted); }
details.card[open] > summary { margin-bottom: 12px; }
details.card .stack + form, details.card form + form { margin-top: 12px; }

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2.5px solid color-mix(in srgb, var(--warn) 30%, transparent);
  border-top-color: var(--warn);
  animation: spin 0.8s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* ---------- login / mensajes centrados ---------- */
.center-card { max-width: 380px; margin: 12vh auto 0; }
.center-card h1 { text-align: center; }
.success-mark {
  width: 64px;
  height: 64px;
  margin: 12px auto;
  border-radius: 50%;
  background: var(--ok-soft);
  color: var(--ok);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 700;
}
.center { text-align: center; }

/* ---------- lista de canales ---------- */
.channel-row { display: flex; align-items: center; gap: 12px; }
.channel-row .grow { flex: 1; min-width: 0; }
.channel-row .name { font-weight: 700; }
.fields { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }

ol.steps { padding-left: 1.3rem; }
ol.steps li { margin-bottom: 10px; }
code, .code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86em;
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 6px;
  overflow-wrap: anywhere;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.92rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 420px) {
  .topbar nav a { padding: 6px 8px; font-size: 0.88rem; }
  .brand span { display: none; }
}

/* ---------- comparación a ciegas ---------- */
.compare-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  color: var(--text);
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
  font-size: 0.9rem;
}
.compare-banner:hover { text-decoration: none; }
.compare-banner span:last-child { color: var(--accent); font-weight: 600; white-space: nowrap; }
.variant.chosen { border-color: var(--ok); }
.titles { margin: 4px 0 10px; padding-left: 1.3rem; display: flex; flex-direction: column; gap: 6px; }
.titles li { overflow-wrap: anywhere; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin: 4px 0 6px; }
.variant form { margin-top: 10px; }
table.results { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
table.results th, table.results td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.results th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
table.results td.num, table.results th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.results tr.winner td:first-child { font-weight: 700; }
.table-wrap { overflow-x: auto; }

.rank-badge {
  min-width: 36px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  text-align: center;
}
.variant.ranked { border-color: var(--accent); }
.rank-bar {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin: 0 -16px 12px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
}

/* ---------- contenido del post (carruseles) ---------- */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-2);
}
.tile.current { border-color: var(--ok); }
.tile img, .tile-empty, .tile video { width: 100%; aspect-ratio: 4 / 5; object-fit: cover; display: block; }
.tile video { object-fit: contain; background: #000; }
.tile-empty { display: flex; align-items: center; justify-content: center; color: var(--muted); font-weight: 700; }
.tile-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
}
.tile-actions { padding: 8px; display: flex; justify-content: center; min-height: 50px; align-items: center; gap: 6px; }
.tile-actions form { margin: 0; flex: 1; }
.tile-actions .btn { flex: 1; width: 100%; }
.tile-actions .btn.dl { flex: 0 0 auto; width: auto; padding: 5px 10px; }
.media-actions { justify-content: center; }
