/* MacroFlow — paleta oficial. Superficies neutras; el cyan se usa con moderación. */
:root {
  --bg: #080D13;
  --panel: #0D151E;
  --raised: #131E29;
  --hover: #192734;
  --line: #233240;
  --control: #536779;
  --text: #EDF2F5;
  --text-2: #A4B0BC;
  --text-3: #7F909F;
  --accent: #58D5E3;
  --on-accent: #071017;
  --positive: #48C9A5;
  --negative: #F08089;
  --overlay: rgba(8, 13, 19, 0.82);

  --font: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --radius: 12px;
  --gutter: 16px;
  --sidebar-w: 264px;
  --topbar-h: 56px;
  --tabbar-h: 60px;
  --card-w: 132px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #F5F7F8;
    --panel: #FFFFFF;
    --raised: #FFFFFF;
    --hover: #EBEFF2;
    --line: #DDE3E8;
    --control: #9AA7B3;
    --text: #101820;
    --text-2: #4B5967;
    --text-3: #6B7885;
    --accent: #087E8B;
    --on-accent: #FFFFFF;
    --positive: #1E8A6B;
    --negative: #C24653;
    --overlay: rgba(245, 247, 248, 0.86);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button { font: inherit; color: inherit; }
h1, h2, h3 { font-weight: 600; letter-spacing: -0.02em; }
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.icon-sm { width: 16px; height: 16px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- Estructura ---------- */
.shell { display: flex; min-height: 100vh; min-height: 100dvh; }
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
main { flex: 1; width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 var(--gutter) 48px; outline: none; }
main.is-entering > * { animation: enter 0.28s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
@keyframes enter { from { opacity: 0; transform: translateY(6px); } }

.brand { display: flex; align-items: center; gap: 12px; min-height: 44px; }
.brand img { border-radius: 9px; flex-shrink: 0; }
.wordmark { display: grid; gap: 1px; font-family: var(--mono); line-height: 1.15; }
.wordmark-name { font-size: 17px; font-weight: 500; letter-spacing: 0.06em; color: var(--text); white-space: nowrap; }
.wordmark-by { font-size: 10px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--text-3); }
.empty { display: grid; justify-items: center; gap: 16px; padding: 72px 0; color: var(--text-2); text-align: center; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-weight: 500;
  font-size: 15px;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  transition: background-color 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn .icon { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-quiet { background: var(--raised); color: var(--text); border-color: var(--line); }
.btn-negative { color: var(--negative); }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 14px; }

/* ---------- Menú lateral (escritorio) ---------- */
.sidebar {
  display: none;
  position: sticky;
  top: 0;
  width: var(--sidebar-w);
  height: 100vh;
  height: 100dvh;
  flex-shrink: 0;
  flex-direction: column;
  padding: 20px 12px;
  border-right: 1px solid var(--line);
  overflow-y: auto;
  scrollbar-width: none;
}
.sidebar .brand { padding: 0 10px; margin-bottom: 18px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 40px;
  padding: 0 10px;
  border-radius: 8px;
  color: var(--text-2);
  font-weight: 500;
}
.nav-item.is-active { color: var(--text); background: var(--raised); }
.nav-item.is-active .icon { color: var(--accent); }
.side-heading { font-size: 13px; font-weight: 500; color: var(--text-3); margin: 28px 10px 8px; letter-spacing: 0; }
.side-series { display: flex; flex-direction: column; gap: 1px; }
.side-series a {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--text-2);
}
.side-series a.is-active { color: var(--text); background: var(--raised); }
.side-n { font-size: 12px; color: var(--text-3); }
.side-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-count { font-size: 12px; color: var(--text-3); }
.side-install { margin: 20px 10px 0; }

/* ---------- Barra superior (celular) ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) var(--gutter) 0;
  background: var(--overlay);
  backdrop-filter: saturate(140%) blur(16px);
  -webkit-backdrop-filter: saturate(140%) blur(16px);
  border-bottom: 1px solid var(--line);
}
.topbar-back { display: grid; place-items: center; width: 44px; height: 44px; margin-left: -12px; }
.topbar-title { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .btn { margin-left: auto; }

/* ---------- Barra de pestañas (celular) ---------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  padding: 4px 8px calc(4px + var(--safe-bottom));
  background: var(--overlay);
  backdrop-filter: saturate(140%) blur(16px);
  -webkit-backdrop-filter: saturate(140%) blur(16px);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 52px;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 500;
}
.tab .icon { width: 22px; height: 22px; }
.tab.is-active { color: var(--text); }
.tab.is-active .icon { color: var(--accent); }

/* ---------- Inicio ---------- */
.intro { padding: 36px 0 28px; }
.intro h1 { font-size: clamp(30px, 5.4vw, 48px); line-height: 1.06; letter-spacing: -0.035em; margin: 0 0 14px; max-width: 18ch; text-wrap: balance; }
.intro-meta { color: var(--text-3); font-size: 13px; margin: 0 0 24px; }
.intro-actions { display: flex; flex-wrap: wrap; gap: 10px; }

.resume {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px;
  margin: 0 0 36px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  max-width: 520px;
}
.resume img { width: 48px; aspect-ratio: 3 / 4; object-fit: cover; object-position: center 35%; border-radius: 6px; flex-shrink: 0; }
.resume-text { display: grid; min-width: 0; flex: 1; }
.resume-label { font-size: 12px; color: var(--accent); font-weight: 500; }
.resume-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.resume-meta { font-size: 13px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.resume-play { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--raised); border: 1px solid var(--line); flex-shrink: 0; }
.resume-play .icon { width: 14px; height: 14px; color: var(--accent); margin-left: 2px; }

/* Filas de portadas por serie */
.shelf { margin-bottom: 32px; }
.shelf-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.shelf-title { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.shelf-title h2 { font-size: 18px; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shelf-title .icon { color: var(--text-3); align-self: center; }
.shelf-n { font-size: 13px; color: var(--text-3); }
.shelf-meta { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.shelf-track {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: var(--card-w);
  gap: 10px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-padding-inline: var(--gutter);
  margin-inline: calc(var(--gutter) * -1);
  padding-inline: var(--gutter);
  padding-bottom: 4px;
  scrollbar-width: none;
}
.shelf-track::-webkit-scrollbar { display: none; }
.shelf-track > * { scroll-snap-align: start; }

.poster-card { display: grid; gap: 8px; min-width: 0; }
.poster {
  position: relative;
  display: block;
  aspect-ratio: 3 / 4;
  border-radius: 10px;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  transition: border-color 0.15s, transform 0.2s;
}
.poster img { width: 100%; height: 100%; object-fit: cover; object-position: center 35%; }
.poster-duration {
  position: absolute;
  right: 6px;
  bottom: 6px;
  padding: 1px 6px;
  border-radius: 5px;
  background: rgba(8, 13, 19, 0.78);
  color: #EDF2F5;
  font-size: 11px;
}
.poster-check {
  position: absolute;
  top: 6px;
  right: 6px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
}
.poster-check .icon { width: 12px; height: 12px; stroke-width: 2.5; }
.poster-card.is-watched img { opacity: 0.55; }
.poster-caption { display: flex; gap: 6px; min-width: 0; font-size: 13px; line-height: 1.3; }
.poster-n { color: var(--text-3); font-size: 12px; padding-top: 1px; }
.poster-title { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* ---------- Páginas ---------- */
.page-head { padding: 28px 0 20px; }
.page-head h1 { font-size: clamp(26px, 5vw, 36px); margin: 0 0 6px; line-height: 1.1; }
.page-meta { color: var(--text-3); font-size: 13px; margin: 0; }
.section-label { font-size: 14px; font-weight: 500; color: var(--text-3); margin: 0 0 4px; letter-spacing: 0; }

.list { list-style: none; padding: 0; margin: 0; }
.list li + li { border-top: 1px solid var(--line); }
.list-row { display: flex; align-items: center; gap: 14px; min-height: 68px; padding: 12px 4px; }
.list-n { font-size: 13px; color: var(--text-3); width: 22px; flex-shrink: 0; }
.list-text { display: grid; min-width: 0; flex: 1; }
.list-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-sub { font-size: 13px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-end { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.list-meta { font-size: 12px; color: var(--text-3); }

.ring { flex-shrink: 0; }
.ring circle { fill: none; }
.ring-track { stroke: var(--line); }
.ring-value { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset 0.4s; }
.ring.is-complete .ring-value { stroke: var(--positive); }

/* Serie */
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--text-3); font-size: 14px; min-height: 44px; padding-top: 16px; }
.series-head { padding: 24px 0 28px; max-width: 620px; }
.series-head h1 { font-size: clamp(28px, 5.4vw, 42px); line-height: 1.06; letter-spacing: -0.03em; margin: 4px 0 10px; }
.series-tagline { color: var(--text-2); margin: 0 0 18px; }
.series-stats { display: flex; align-items: center; gap: 12px; color: var(--text-3); font-size: 13px; margin-bottom: 20px; }
.poster-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(46%, 150px), 1fr)); gap: 18px 12px; }

/* Progreso */
.overview { display: flex; align-items: center; gap: 28px; padding: 8px 0 24px; }
.overview-ring { position: relative; display: grid; place-items: center; }
.overview-percent { position: absolute; font-size: 22px; font-weight: 500; }
.overview-stats { display: grid; gap: 14px; margin: 0; }
.overview-stats dt { font-size: 13px; color: var(--text-3); }
.overview-stats dd { margin: 0; font-size: 24px; font-weight: 500; }
.overview-stats dd span { color: var(--text-3); font-size: 16px; }
.overview-next { margin-bottom: 36px; }
.overview-next .btn { max-width: 100%; }
.overview-next .btn span { overflow: hidden; text-overflow: ellipsis; }
.danger-zone { margin-top: 32px; padding-top: 24px; border-top: 1px solid var(--line); }

/* ---------- Carga ---------- */
.skeleton { display: grid; gap: 14px; padding-top: 40px; }
.sk { display: block; border-radius: 8px; background: linear-gradient(90deg, var(--panel), var(--raised), var(--panel)); background-size: 200% 100%; animation: shimmer 1.4s infinite linear; }
.sk-title { height: 40px; width: min(80%, 420px); }
.sk-line { height: 14px; width: 200px; }
.sk-row { display: flex; gap: 10px; margin-top: 24px; }
.sk-card { width: var(--card-w); aspect-ratio: 3 / 4; flex-shrink: 0; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Varios ---------- */
.footer { text-align: center; color: var(--text-3); font-size: 12px; padding: 24px var(--gutter); }
.footer p { margin: 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  z-index: 200;
  transform: translate(-50%, 12px);
  background: var(--raised);
  border: 1px solid var(--line);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100vw - 32px);
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Celular ---------- */
@media (max-width: 899px) {
  .content { padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom)); }
  .desktop-only { display: none !important; }
}

/* ---------- Escritorio ---------- */
@media (min-width: 900px) {
  :root { --topbar-h: 0px; --tabbar-h: 0px; --gutter: 40px; --card-w: 156px; }
  .sidebar { display: flex; }
  .topbar, .tabbar { display: none; }
  .intro { padding: 64px 0 36px; }
  .page-head { padding-top: 48px; }
  .series-head { padding-top: 12px; }
  .shelf { margin-bottom: 40px; }
  .shelf-track { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 64px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 64px), transparent); }
  .poster-grid { grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); }
}

@media (hover: hover) {
  .poster-card:hover .poster { border-color: var(--control); transform: translateY(-2px); }
  .poster-card:hover .poster-title { color: var(--text); }
  .list-row:hover .list-title, .shelf-title:hover h2 { color: var(--accent); }
  .nav-item:hover, .side-series a:hover { color: var(--text); background: var(--hover); }
  .btn-quiet:hover { background: var(--hover); }
  .btn-primary:hover { filter: brightness(1.06); }
  .resume:hover { border-color: var(--control); }
  .back:hover { color: var(--text); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
