:root {
  --bg: #0f1020;
  --bg2: #171933;
  --panel: #1d2040;
  --line: #2f3366;
  --text: #eceefb;
  --muted: #9aa0cc;
  --accent: #ff5d8f;
  --accent2: #7c5cff;
  --ok: #3ddc97;
  --warn: #ffb84d;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
h1, h2, h3 { margin: 0 0 .4em; }
code { background: var(--bg2); padding: 1px 5px; border-radius: 5px; }

button, select, input, textarea {
  font: inherit; color: var(--text);
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
}
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--accent2); outline-offset: 1px;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent2); }
button.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); border: 0; font-weight: 600; }
button.danger { border-color: #7a2f45; color: #ff9db6; }
button.big { padding: 14px 20px; font-size: 1.05rem; }
textarea { width: 100%; min-height: 140px; resize: vertical; }

/* ===== Barra superior ===== */
#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 10px 14px; background: rgba(15,16,32,.92);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
#topbar #search { flex: 1 1 220px; min-width: 140px; }
.screen { min-height: 100vh; }
#topbar:not(.hidden) ~ .screen { min-height: calc(100vh - 58px); }

/* ===== Bienvenida ===== */
#screen-welcome { position: relative; overflow: hidden; display: grid; place-items: center; padding: 20px; }
#poster-wall {
  position: absolute; inset: -10%; display: flex; gap: 14px; transform: rotate(-6deg);
  opacity: .35; pointer-events: none;
}
.wall-col { flex: 1; display: flex; flex-direction: column; gap: 14px; animation: wall 60s linear infinite; }
.wall-col:nth-child(even) { animation-direction: reverse; animation-duration: 75s; }
.wall-col img { width: 100%; aspect-ratio: 2/3; object-fit: cover; border-radius: 10px; }
@keyframes wall { from { transform: translateY(0); } to { transform: translateY(-50%); } }
.welcome-card {
  position: relative; z-index: 1; text-align: center; max-width: 520px; width: 100%;
  background: rgba(15,16,32,.82); border: 1px solid var(--line);
  padding: 32px 24px; border-radius: 20px; backdrop-filter: blur(10px);
}
.welcome-card h1 { font-size: 2rem; }
.welcome-actions { display: grid; gap: 10px; margin-top: 22px; }

/* ===== Mosaico ===== */
#screen-grid { padding: 14px; }
#grid-info { margin: 4px 2px 12px; }
#grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
.card { cursor: pointer; position: relative; }
.card .cover {
  position: relative; aspect-ratio: 2/3; border-radius: var(--radius); overflow: hidden;
  background: var(--panel); border: 1px solid var(--line);
  transition: transform .15s, border-color .15s;
}
.card:hover .cover { transform: translateY(-3px); border-color: var(--accent); }
.card .cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .no-poster { display: grid; place-items: center; height: 100%; font-size: 2.4rem; color: var(--muted); }
.card .badge {
  position: absolute; top: 8px; left: 8px; font-size: .72rem; padding: 2px 8px; border-radius: 20px;
  background: rgba(15,16,32,.88); border: 1px solid var(--line);
}
.card .badge.viendo { color: var(--warn); } .card .badge.completado { color: var(--ok); }
.card .bar { position: absolute; left: 0; right: 0; bottom: 0; height: 5px; background: rgba(0,0,0,.5); }
.card .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); }
.card .t { margin-top: 7px; font-weight: 600; font-size: .9rem; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .y { color: var(--muted); font-size: .82rem; }
.empty { text-align: center; padding: 60px 10px; color: var(--muted); }

/* ===== Ficha ===== */
#screen-detail { padding: 14px; }
.detail-wrap { max-width: 1100px; margin: 0 auto; display: grid; grid-template-columns: 260px 1fr; gap: 22px; }
.poster-col img.poster {
  width: 100%; aspect-ratio: 2/3; object-fit: cover; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--panel);
}
.poster-col img.poster.zoom { cursor: zoom-in; }
.poster-col .no-poster { aspect-ratio: 2/3; display: grid; place-items: center; font-size: 3rem;
  background: var(--panel); border-radius: var(--radius); border: 1px dashed var(--line); }
.poster-col .stack { margin-top: 10px; }
.stack { display: grid; gap: 8px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > input { flex: 1; }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.detail-head h2 { font-size: 1.6rem; }
.detail-head .sub { color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 14px 0; overflow-x: auto; }
.tabs button { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none; padding: 10px 14px; white-space: nowrap; }
.tabs button.active { border-bottom-color: var(--accent); color: var(--accent); font-weight: 600; }

.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px 14px; }
.field label { display: block; font-size: .78rem; color: var(--muted); margin-bottom: 3px; }
.field input, .field select, .field textarea { width: 100%; }
.field.full { grid-column: 1 / -1; }
.field .val { padding: 2px 0; word-break: break-word; white-space: pre-wrap; }
.field .val.empty-val { color: var(--line); }
.chips { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 5px; }
.chip { font-size: .75rem; padding: 2px 9px; border-radius: 20px; border: 1px solid var(--line); background: var(--bg2); cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.chip.static { cursor: default; border-color: var(--accent2); }

.list-rows { display: grid; gap: 8px; }
.list-row { display: flex; gap: 8px; }
.list-row input { flex: 1; min-width: 0; }
.cast-table { width: 100%; border-collapse: collapse; }
.cast-table th { text-align: left; color: var(--muted); font-weight: 500; font-size: .8rem; padding: 4px 8px; }
.cast-table td { padding: 6px 8px; border-top: 1px solid var(--line); }

.progress-box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.progress-bar { height: 10px; background: var(--bg); border-radius: 10px; overflow: hidden; margin: 8px 0; }
.progress-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); }
.counter { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.counter b { font-size: 1.4rem; min-width: 3ch; text-align: center; }

.lookup { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 14px; }
.lookup .row select { flex: 0 0 auto; }
.results { display: grid; gap: 6px; margin-top: 10px; max-height: 380px; overflow: auto; }
.result { display: flex; gap: 10px; align-items: center; padding: 6px; border-radius: 8px; border: 1px solid var(--line); cursor: pointer; background: var(--bg2); }
.result:hover { border-color: var(--accent); }
.result img { width: 42px; height: 60px; object-fit: cover; border-radius: 5px; background: var(--panel); flex: none; }
.result .src { font-size: .7rem; padding: 1px 7px; border-radius: 20px; border: 1px solid var(--accent2); color: var(--accent2); margin-left: 6px; }
.notice { color: var(--warn); font-size: .85rem; margin-top: 6px; }

/* ===== Modales ===== */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(5,6,16,.75); display: grid; place-items: center; padding: 16px; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 22px; width: min(520px, 100%); max-height: 90vh; overflow: auto; }
.modal-actions { display: flex; justify-content: flex-end; margin-top: 16px; }
#fields-list { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 6px; }
#fields-list li { display: flex; justify-content: space-between; align-items: center; background: var(--bg2); padding: 6px 6px 6px 12px; border-radius: 8px; }
.file-btn { display: block; text-align: center; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg2); cursor: pointer; }
.file-btn:hover { border-color: var(--accent2); }
#lightbox { cursor: zoom-out; }
#lightbox img { max-width: 100%; max-height: 100%; border-radius: 10px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100;
  background: var(--panel); border: 1px solid var(--accent2); padding: 10px 18px; border-radius: 10px; max-width: 92vw; }
#toast.err { border-color: #c4456a; }

/* ===== Móvil ===== */
@media (max-width: 760px) {
  .detail-wrap { grid-template-columns: 1fr; }
  .poster-col { max-width: 220px; margin: 0 auto; width: 100%; }
  #grid { grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); gap: 10px; }
  #topbar { padding: 8px; }
  #topbar select { flex: 1 1 120px; }
  .welcome-card h1 { font-size: 1.6rem; }
}

.chip.active { border-color: var(--accent); color: var(--accent); background: rgba(255,93,143,.12); font-weight: 600; }
.progress-box .chips { margin-top: 0; }
.field a, .val a { color: var(--accent); }
