:root {
  --bg: #0b0b10;
  --card: #14141c;
  --text: #f4f4f8;
  --muted: #a7a7b8;
  --accent: #7c5cff;
  --accent-2: #ff5c8a;
  --chip: rgba(255, 255, 255, .12);
  --chip-active: #ffffff;
  --overlay: linear-gradient(to top, rgba(0,0,0,.92) 0%, rgba(0,0,0,.55) 38%, rgba(0,0,0,0) 70%);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --topbar-h: 56px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

/* ---------- Barra superior ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) 12px 0;
  background: linear-gradient(to bottom, rgba(0,0,0,.6), rgba(0,0,0,0));
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.brand {
  display: flex; align-items: center; gap: 7px;
  background: none; border: 0; color: var(--text);
  font-size: 19px; font-weight: 800; letter-spacing: -.02em; cursor: pointer;
  padding: 6px 4px;
}
.brand-dot {
  width: 11px; height: 11px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 14px var(--accent);
}

.chips {
  display: flex; gap: 7px; overflow-x: auto; flex: 1;
  scrollbar-width: none; margin: 0 2px;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  border: 0; border-radius: 999px;
  padding: 7px 13px; font-size: 13px; font-weight: 600;
  background: var(--chip); color: var(--text);
  cursor: pointer; transition: background .15s, color .15s, transform .1s;
  backdrop-filter: blur(8px);
}
.chip.is-active { background: var(--chip-active); color: #111; }
.chip:active { transform: scale(.94); }

.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: 50%;
  border: 0; background: rgba(255,255,255,.14); color: var(--text);
  cursor: pointer; font-size: 13px; font-weight: 700;
  backdrop-filter: blur(8px); transition: background .15s, transform .1s;
}
.icon-btn:active { transform: scale(.9); }
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; }

/* ---------- Feed ---------- */
.feed {
  height: 100%;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.card {
  position: relative;
  height: 100dvh;
  scroll-snap-align: start; scroll-snap-stop: always;
  display: flex; flex-direction: column; justify-content: flex-end;
  overflow: hidden;
}

.card-bg {
  position: absolute; inset: 0; z-index: 0;
  background-size: cover; background-position: center;
  background-repeat: no-repeat;
}
.card-bg.blur { filter: blur(28px) brightness(.55); transform: scale(1.15); }
/* Imagen nítida contenida encima del fondo desenfocado */
.card-img {
  position: absolute; inset: 0; z-index: 1;
  width: 100%; height: 100%;
  object-fit: contain;
}
.card.textcard {
  background: radial-gradient(120% 90% at 50% 0%, #241d4a 0%, #12121c 55%, #0b0b10 100%);
}
.card.textcard.trivia { background: radial-gradient(120% 90% at 50% 0%, #123a34 0%, #0f1a1c 55%, #0b0b10 100%); }
.card.textcard.numbers { background: radial-gradient(120% 90% at 50% 0%, #3a2312 0%, #1c1610 55%, #0b0b10 100%); }

.card-scrim {
  position: absolute; inset: 0; z-index: 2;
  background: var(--overlay); pointer-events: none;
}

.card-body {
  position: relative; z-index: 3;
  padding: 0 76px calc(28px + var(--safe-bottom)) 20px;
  max-width: 720px;
}
.card.textcard .card-body { padding-bottom: calc(40px + var(--safe-bottom)); }

.card-cat {
  display: inline-block; margin-bottom: 10px;
  font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: #fff; background: rgba(124,92,255,.35);
  padding: 4px 10px; border-radius: 999px; backdrop-filter: blur(4px);
}
.card-title {
  margin: 0 0 8px; font-size: clamp(22px, 6vw, 30px);
  font-weight: 800; line-height: 1.12; letter-spacing: -.02em;
  text-shadow: 0 2px 18px rgba(0,0,0,.6);
}
.card-text {
  margin: 0 0 14px; font-size: 15.5px; line-height: 1.5; color: #eaeaf2;
  text-shadow: 0 1px 12px rgba(0,0,0,.55);
}
.card.textcard .card-title { font-size: clamp(24px, 7vw, 34px); }
.card.textcard .card-text { font-size: clamp(17px, 4.5vw, 21px); color: #f4f4f8; }

.card-credit { font-size: 12px; color: var(--muted); }
.card-link {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 12px; font-size: 14px; font-weight: 700; color: #fff;
  text-decoration: none; background: rgba(255,255,255,.16);
  padding: 9px 15px; border-radius: 999px; backdrop-filter: blur(6px);
}
.card-link:active { transform: scale(.96); }

/* Quiz */
.quiz-options { display: grid; gap: 9px; margin: 4px 0 8px; }
.quiz-opt {
  text-align: left; border: 1px solid rgba(255,255,255,.2);
  background: rgba(255,255,255,.08); color: #fff;
  padding: 13px 15px; border-radius: 14px; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: background .15s, border-color .15s;
}
.quiz-opt.correct { background: rgba(46,204,113,.28); border-color: #2ecc71; }
.quiz-opt.wrong { background: rgba(231,76,60,.28); border-color: #e74c3c; }
.quiz-opt:disabled { cursor: default; }

/* ---------- Rail de acciones ---------- */
.card-rail {
  position: absolute; right: 12px; bottom: calc(40px + var(--safe-bottom)); z-index: 4;
  display: flex; flex-direction: column; gap: 18px; align-items: center;
}
.rail-btn {
  display: grid; place-items: center; gap: 3px;
  width: 46px; border: 0; background: none; color: #fff; cursor: pointer;
  font-size: 11px; font-weight: 600;
}
.rail-btn .ic {
  display: grid; place-items: center;
  width: 46px; height: 46px; border-radius: 50%;
  background: rgba(255,255,255,.16); backdrop-filter: blur(8px);
  transition: transform .12s, background .15s;
}
.rail-btn:active .ic { transform: scale(.86); }
.rail-btn svg { width: 24px; height: 24px; fill: none; stroke: #fff; stroke-width: 2; }
.rail-btn.is-saved .ic { background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.rail-btn.is-saved svg { fill: #fff; stroke: #fff; }

/* ---------- Guardados ---------- */
.saved-view {
  position: fixed; inset: 0; z-index: 40;
  background: var(--bg); overflow-y: auto;
  padding: calc(var(--safe-top) + 8px) 16px calc(var(--safe-bottom) + 24px);
}
.saved-head {
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; background: var(--bg); padding: 8px 0 14px; z-index: 2;
}
.saved-head h2 { margin: 0; font-size: 24px; font-weight: 800; }
.saved-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.saved-card {
  position: relative; border-radius: 16px; overflow: hidden;
  background: var(--card); min-height: 180px; display: flex; flex-direction: column;
  text-decoration: none; color: var(--text);
}
.saved-card .thumb { height: 110px; background-size: cover; background-position: center; background-color: #23233a; }
.saved-card.notext .thumb { height: 0; }
.saved-card .meta { padding: 10px 12px 12px; flex: 1; display: flex; flex-direction: column; }
.saved-card .st { font-size: 14px; font-weight: 700; line-height: 1.2; margin: 0 0 4px; }
.saved-card .sx { font-size: 12px; color: var(--muted); margin: 0; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.saved-card .rm {
  position: absolute; top: 8px; right: 8px; width: 30px; height: 30px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.55); color: #fff; cursor: pointer; font-size: 14px;
}
.saved-empty { text-align: center; color: var(--muted); padding: 60px 20px; }

/* ---------- Loader / banner ---------- */
.loader {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%);
  z-index: 25; display: flex; gap: 6px;
}
.loader span {
  width: 9px; height: 9px; border-radius: 50%; background: #fff; opacity: .6;
  animation: bounce 1s infinite ease-in-out;
}
.loader span:nth-child(2) { animation-delay: .15s; }
.loader span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%,80%,100% { transform: scale(.5); opacity: .3; } 40% { transform: scale(1); opacity: 1; } }

.banner {
  position: fixed; left: 50%; bottom: calc(28px + var(--safe-bottom)); transform: translateX(-50%);
  z-index: 50; background: #23233a; color: #fff; padding: 12px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 600; box-shadow: 0 8px 30px rgba(0,0,0,.5);
  display: flex; align-items: center; gap: 12px;
}
.banner button { border: 0; background: var(--accent); color: #fff; padding: 6px 12px; border-radius: 999px; font-weight: 700; cursor: pointer; }

.hint {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); z-index: 4;
  color: rgba(255,255,255,.85); font-size: 14px; text-align: center; pointer-events: none;
  animation: floaty 1.8s ease-in-out infinite;
}
@keyframes floaty { 0%,100% { transform: translate(-50%,-46%); } 50% { transform: translate(-50%,-54%); } }

/* ---------- Tema claro ---------- */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f4f8; --card: #ffffff; --text: #16161d; --muted: #6b6b7b;
    --chip: rgba(0,0,0,.08); --chip-active: #16161d;
  }
  .topbar { background: linear-gradient(to bottom, rgba(255,255,255,.7), rgba(255,255,255,0)); }
  .brand, .chip { color: #16161d; }
  .chip.is-active { color: #fff; }
  .icon-btn { background: rgba(0,0,0,.08); color: #16161d; }
  /* Las tarjetas con imagen mantienen scrim oscuro para legibilidad del texto. */
}

@media (min-width: 780px) {
  .card-body { padding-left: 40px; }
  .card-title { max-width: 620px; }
}
