:root {
  --bg: #0b0d12;
  --card: #12151d;
  --text: #f2f4f8;
  --muted: #9aa3b2;
  --accent: #ff3b5c;
  --accent2: #4f8cff;
  --chip: rgba(255,255,255,.09);
  --chip-active: #ffffff;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

/* ── Barra superior ─────────────────────────────────────────────── */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 30;
  padding: calc(var(--safe-top) + 8px) 10px 6px;
  background: linear-gradient(to bottom, rgba(11,13,18,.92), rgba(11,13,18,.55) 70%, transparent);
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }
.tb-row { display: flex; align-items: center; gap: 8px; }

#btnLocation svg { fill: var(--accent); }

.tabs { display: flex; gap: 2px; flex: 1; justify-content: center; min-width: 0; overflow: hidden; }
.tab {
  background: none; border: none; color: var(--muted);
  font-size: 13.5px; font-weight: 600; padding: 6px 7px;
  border-radius: 16px; cursor: pointer; white-space: nowrap;
  min-width: 0; overflow: hidden; text-overflow: ellipsis; max-width: 42%;
}
.tab.active { color: #fff; }
.tab.active::after {
  content: ''; display: block; height: 2.5px; border-radius: 2px;
  background: #fff; margin-top: 2px;
}

.icon-btn {
  background: rgba(255,255,255,.1); border: none; border-radius: 50%;
  width: 34px; height: 34px; display: grid; place-items: center;
  cursor: pointer; flex-shrink: 0;
}
.icon-btn svg { width: 18px; height: 18px; fill: #fff; }

.chips {
  display: flex; gap: 6px; overflow-x: auto; margin-top: 8px;
  scrollbar-width: none; padding-bottom: 4px;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  background: var(--chip); color: #dfe4ec; border: none;
  font-size: 12px; font-weight: 500; padding: 5px 12px;
  border-radius: 14px; cursor: pointer; white-space: nowrap;
  backdrop-filter: blur(6px);
}
.chip.active { background: var(--chip-active); color: #10131a; font-weight: 700; }

/* ── Ticker de cotizaciones ─────────────────────────────────────── */
.rates {
  display: flex; gap: 6px; overflow-x: auto; margin-top: 6px;
  scrollbar-width: none; padding-bottom: 4px; cursor: pointer;
}
.rates::-webkit-scrollbar { display: none; }
.rate {
  display: flex; align-items: center; gap: 5px;
  background: rgba(10,14,20,.55); backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,.08);
  font-size: 11.5px; padding: 4px 10px; border-radius: 12px;
  white-space: nowrap; flex-shrink: 0;
}
.rate .rl { color: var(--muted); font-weight: 600; }
.rate .rv { color: #7ee2a8; font-weight: 700; font-variant-numeric: tabular-nums; }
.rate.hot .rl { color: #ffd166; }

/* ── Feed con snap vertical ─────────────────────────────────────── */
.feed {
  height: 100dvh;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
}
.feed::-webkit-scrollbar { display: none; }

.card {
  position: relative;
  height: 100dvh;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background: var(--card);
  cursor: pointer;
}
.card-bg {
  position: absolute; inset: 0;
  background-size: cover; background-position: center top;
  filter: brightness(.85);
  transform: scale(1.02);
}
.card-bg.noimg {
  background: radial-gradient(120% 100% at 20% 0%, #263149 0%, #141824 55%, #0b0d12 100%);
}
.card-bg.noimg::after {
  content: '📰';
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: 64px; opacity: .18;
}
.card-shade {
  position: absolute; inset: 0;
  background: linear-gradient(to top, rgba(5,6,10,.96) 0%, rgba(5,6,10,.82) 26%, rgba(5,6,10,.25) 55%, rgba(5,6,10,.15) 100%);
  pointer-events: none;
}

.card-content {
  position: relative;
  padding: 0 74px calc(var(--safe-bottom) + 30px) 16px;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.card-content .card-open { pointer-events: auto; }

/* Galería de varias imágenes/videos: swipe horizontal dentro de la noticia */
.card-gal {
  position: absolute; inset: 0;
  display: flex; overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}
.card-gal::-webkit-scrollbar { display: none; }
.gal-slide {
  flex: 0 0 100%; height: 100%;
  scroll-snap-align: start; scroll-snap-stop: always;
  background-size: cover; background-position: center top;
  background-color: #12151d;
}
.gal-slide.gal-video { display: grid; place-items: center; background: #000; }
.gal-slide video, .gal-slide iframe {
  width: 100%; height: 62%; max-height: 62dvh; border: 0; background: #000;
}
.gal-dots {
  display: flex; gap: 5px; margin-bottom: 4px;
}
.gal-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: rgba(255,255,255,.35);
}
.gal-dots span.vid { border-radius: 2px; }
.gal-dots span.on { background: #fff; }
.card-toprow { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.card-storychip {
  background: rgba(79,140,255,.22); border: 1px solid rgba(79,140,255,.55);
  color: #cfe0ff; font-size: 11px; font-weight: 700;
  padding: 3px 9px; border-radius: 10px; cursor: pointer;
  pointer-events: auto;
}

/* Línea de tiempo */
.tl-list { overflow-y: auto; flex: 1; padding: 6px 4px 10px; min-height: 120px; }
.tl-item {
  position: relative; padding: 0 0 18px 22px;
  border-left: 2px solid rgba(255,255,255,.15);
  margin-left: 8px; cursor: pointer;
}
.tl-item:last-child { border-left-color: transparent; padding-bottom: 4px; }
.tl-item::before {
  content: ''; position: absolute; left: -6px; top: 3px;
  width: 10px; height: 10px; border-radius: 50%; background: var(--accent2);
}
.tl-item.current::before { background: var(--accent); box-shadow: 0 0 0 4px rgba(255,59,92,.25); }
.tl-date { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.tl-title { font-size: 14.5px; font-weight: 700; line-height: 1.3; margin: 2px 0; }
.tl-src { font-size: 12.5px; color: var(--muted); line-height: 1.4; }

.card-cat {
  align-self: flex-start;
  font-size: 11px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase;
  color: #fff; background: var(--accent);
  padding: 3px 9px; border-radius: 10px;
}
.card-cat[data-cat="economia"] { background: #2e9e5b; }
.card-cat[data-cat="deportes"] { background: #4f8cff; }
.card-cat[data-cat="politica"] { background: #b6541f; }
.card-cat[data-cat="policiales"] { background: #c0392b; }
.card-cat[data-cat="espectaculos"] { background: #9b59b6; }
.card-cat[data-cat="tecnologia"] { background: #16a2b8; }
.card-cat[data-cat="internacional"] { background: #5b6b8f; }
.card-cat[data-cat="salud"] { background: #27ae60; }
.card-cat[data-cat="ciencia"] { background: #7d6bd6; }
.card-cat[data-cat="cultura"] { background: #d4a017; }
.card-cat[data-cat="clima"] { background: #3498db; }
.card-cat[data-cat="sociedad"] { background: #808b9b; }
.card-cat[data-cat="otros"] { background: #6b7280; }

.card-title {
  font-size: clamp(20px, 5.6vw, 28px);
  font-weight: 800; line-height: 1.18;
  text-shadow: 0 1px 8px rgba(0,0,0,.5);
}
.card-summary {
  font-size: clamp(14px, 3.9vw, 16px);
  line-height: 1.45; color: #e6eaf1;
  display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-summary.expanded { -webkit-line-clamp: 16; }
.card-meta {
  display: flex; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--muted);
}
.card-meta b { color: #cfd6e2; font-weight: 600; }
.card-open {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 13px; font-weight: 600; color: var(--accent2);
  margin-top: 2px;
}
.card-open svg { width: 13px; height: 13px; fill: var(--accent2); }

/* Rail de acciones */
.rail {
  position: absolute;
  right: 8px; bottom: calc(var(--safe-bottom) + 40px);
  display: flex; flex-direction: column; gap: 16px;
  align-items: center; z-index: 5;
}
.rail-btn {
  background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: #fff; font-size: 11.5px; font-weight: 600;
}
.rail-btn .ric {
  width: 46px; height: 46px; border-radius: 50%;
  background: rgba(20,23,32,.55); backdrop-filter: blur(8px);
  display: grid; place-items: center;
  transition: transform .12s;
}
.rail-btn:active .ric { transform: scale(1.18); }
.rail-btn svg { width: 24px; height: 24px; fill: #fff; }
.rail-btn.on-like svg { fill: var(--accent); }
.rail-btn.on-save svg { fill: #ffd166; }

/* Barra de búsqueda */
.searchbar { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.searchbar input {
  flex: 1; min-width: 0;
  background: rgba(255,255,255,.12); border: none; border-radius: 18px;
  padding: 9px 14px; color: #fff; font-size: 14px; outline: none;
  backdrop-filter: blur(6px);
}
.searchbar .sb-go {
  background: var(--accent); color: #fff; border: none; border-radius: 16px;
  font-size: 13px; font-weight: 700; padding: 8px 14px; cursor: pointer;
}
.searchbar .sb-x {
  background: none; border: none; color: var(--muted); font-size: 15px; cursor: pointer; padding: 4px;
}

/* Tarjeta de publicidad */
.ad-card { display: grid; place-items: center; cursor: default; }
.ad-box { width: 92%; max-width: 420px; position: relative; z-index: 2; }
.ad-tag {
  display: block; text-align: center; font-size: 10.5px; color: var(--muted);
  letter-spacing: .12em; text-transform: uppercase; margin-bottom: 8px;
}

/* Estado vacío / cargando */
.feed-msg {
  position: fixed; inset: 0; z-index: 5;
  display: flex; flex-direction: column; gap: 14px;
  align-items: center; justify-content: center;
  color: var(--muted); text-align: center; padding: 0 40px;
  pointer-events: none;
}
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.15); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Sheets (comentarios / perfil) ──────────────────────────────── */
.backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,.5);
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  background: #161a23;
  border-radius: 18px 18px 0 0;
  padding: 10px 16px calc(var(--safe-bottom) + 16px);
  max-height: 72dvh;
  display: flex; flex-direction: column;
  animation: slideup .22s ease-out;
}
@keyframes slideup { from { transform: translateY(40%); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet-handle {
  width: 40px; height: 4px; border-radius: 2px;
  background: rgba(255,255,255,.25); margin: 2px auto 12px;
}
.sheet h3 { font-size: 16px; margin-bottom: 10px; }

.comments-list { overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 12px; padding-bottom: 10px; min-height: 80px; }
.comment { display: flex; flex-direction: column; gap: 2px; }
.comment .c-head { font-size: 12.5px; color: var(--muted); }
.comment .c-head b { color: #dfe4ec; }
.comment .c-body { font-size: 14.5px; line-height: 1.4; }

.comment-form { display: flex; gap: 8px; padding-top: 10px; border-top: 1px solid rgba(255,255,255,.08); }
.comment-form input {
  flex: 1; background: rgba(255,255,255,.08); border: none; border-radius: 20px;
  padding: 10px 14px; color: #fff; font-size: 14px; outline: none;
}

.menu-item {
  display: block; width: 100%; text-align: left;
  background: rgba(255,255,255,.06); border: none; color: #fff;
  font-size: 15px; padding: 13px 14px; border-radius: 12px;
  margin-top: 8px; cursor: pointer;
}
.menu-item.danger { color: #ff6b81; }

.lang-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin: 10px 0 4px; font-size: 14px; color: #dfe4ec;
}
.lang-row select {
  background: rgba(255,255,255,.08); color: #fff;
  border: 1px solid rgba(255,255,255,.15); border-radius: 10px;
  padding: 8px 12px; font-size: 14px; outline: none; min-width: 130px;
}

/* ── Modales ────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.6);
  display: grid; place-items: center; padding: 20px;
}
.modal-card {
  position: relative; width: 100%; max-width: 360px;
  background: #171b25; border-radius: 16px; padding: 24px 20px 20px;
  max-height: 86dvh; overflow-y: auto;
}
.modal-x {
  position: absolute; top: 10px; right: 12px;
  background: none; border: none; color: var(--muted);
  font-size: 16px; cursor: pointer; padding: 4px;
}
.pane h3 { margin-bottom: 14px; font-size: 18px; }
.pane form { display: flex; flex-direction: column; gap: 10px; }
.pane input, .pane textarea {
  background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px; padding: 11px 13px; color: #fff; font-size: 15px; outline: none;
  font-family: inherit; resize: vertical;
}
.pane input:focus, .pane textarea:focus { border-color: var(--accent2); }

.btn-primary {
  background: var(--accent); color: #fff; border: none;
  font-size: 15px; font-weight: 700; padding: 11px 18px;
  border-radius: 10px; cursor: pointer;
}
.btn-ghost {
  background: none; color: #fff; border: 1px solid rgba(255,255,255,.25);
  font-size: 15px; font-weight: 600; padding: 11px 18px;
  border-radius: 10px; cursor: pointer; margin-top: 8px;
}
.wide { width: 100%; }
.hint { font-size: 13px; color: var(--muted); margin: 8px 0; line-height: 1.4; }
.hint.center { text-align: center; }
.hint a { color: var(--accent2); text-decoration: none; }

/* ── Intereses ──────────────────────────────────────────────────── */
.sub-h { font-size: 12.5px; color: var(--muted); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .05em; }
.int-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.int-chips .chip { backdrop-filter: none; }
.int-chips .chip.ai-topic { background: rgba(155,89,182,.35); color: #e8d5f2; }
.int-chips .chip.ai-topic.active { color: #e8d5f2; }
.topic-form { display: flex !important; flex-direction: row !important; gap: 8px; margin-bottom: 8px; }
.topic-form input { flex: 1; min-width: 0; }
.topic-form .btn-primary { padding: 8px 16px; }

/* ── Visor de fotos con zoom ────────────────────────────────────── */
.card { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }

.pviewer {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(0, 0, 0, .97);
  display: flex; flex-direction: column;
  animation: pvin .18s ease-out;
  overscroll-behavior: contain;
}
@keyframes pvin { from { opacity: 0; } to { opacity: 1; } }
.pv-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 3;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(var(--safe-top) + 10px) 14px 10px;
  background: linear-gradient(to bottom, rgba(0,0,0,.55), transparent);
}
.pv-counter { font-size: 13px; font-weight: 700; color: #fff; }
.pv-btn {
  background: rgba(255,255,255,.14); border: none; color: #fff;
  width: 36px; height: 36px; border-radius: 50%;
  font-size: 16px; cursor: pointer; display: grid; place-items: center;
}
.pv-nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 3;
  font-size: 26px; width: 40px; height: 40px;
}
.pv-prev { left: 8px; }
.pv-next { right: 8px; }
.pv-nav.hidden { display: none; }
.pv-stage {
  flex: 1; display: grid; place-items: center;
  overflow: hidden; touch-action: none;
}
.pv-stage img {
  max-width: 100vw; max-height: 100dvh;
  object-fit: contain;
  transform-origin: center center;
  transition: transform .16s ease-out;
  will-change: transform;
}
.pv-stage img.pinching { transition: none; }
.pv-caption {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 3;
  padding: 14px 16px calc(var(--safe-bottom) + 16px);
  background: linear-gradient(to top, rgba(0,0,0,.65), transparent);
  font-size: 13.5px; color: #dfe4ec; line-height: 1.35;
  pointer-events: none;
}

/* ── Cookies y legales ──────────────────────────────────────────── */
.cookiebar {
  position: fixed; left: 12px; right: 12px;
  bottom: calc(var(--safe-bottom) + 12px);
  z-index: 70;
  background: #171b25; border: 1px solid rgba(255,255,255,.12);
  border-radius: 14px; padding: 14px 16px;
  box-shadow: 0 6px 30px rgba(0,0,0,.5);
  animation: slideup .25s ease-out;
  max-width: 430px; margin: 0 auto;
}
.cookiebar p { font-size: 13px; color: #cfd6e2; line-height: 1.45; margin-bottom: 10px; }
.cookiebar a { color: var(--accent2); }
.cb-actions { display: flex; gap: 8px; }
.cb-actions .btn-primary, .cb-actions .btn-ghost { flex: 1; margin: 0; padding: 9px 10px; font-size: 13.5px; }
.legal-links { text-align: center; font-size: 12px; color: var(--muted); margin-top: 14px; }
.legal-links a { color: var(--muted); text-decoration: underline; }

/* ── Toast ──────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 30px);
  transform: translateX(-50%);
  background: #fff; color: #10131a;
  font-size: 14px; font-weight: 600;
  padding: 10px 18px; border-radius: 22px;
  z-index: 60; max-width: 86vw; text-align: center;
  animation: slideup .2s ease-out;
  box-shadow: 0 4px 24px rgba(0,0,0,.4);
}

/* Pantallas grandes: el feed se ve como teléfono centrado */
@media (min-width: 700px) {
  body { background: #05070b; }
  .feed { max-width: 460px; margin: 0 auto; box-shadow: 0 0 60px rgba(0,0,0,.6); }
  #topbar, .feed-msg {
    max-width: 460px; width: 100%;
    left: 50%; right: auto; transform: translateX(-50%);
  }
  .sheet { max-width: 460px; margin: 0 auto; }
  .toast { bottom: 40px; }
}
