/* ============================================================
   Cinema Timeline — hoja de estilos
   Tema oscuro cinematográfico, pantalla completa.
   ============================================================ */

:root {
  --bg: #0b0e14;
  --bg-2: #10141d;
  --bg-3: #161b26;
  --line: #232a38;
  --text: #e8ecf3;
  --text-dim: #9aa5b8;
  --text-faint: #5d6878;
  --accent: #f5c518;
  --panel-w: 380px;
  --topbar-h: 58px;
  --axis-h: 42px;
  --font: "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "SF Mono", "Cascadia Code", Consolas, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
}

button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- Barra superior ---------- */

#topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
  background: linear-gradient(180deg, #12161f 0%, #0d1119 100%);
  border-bottom: 1px solid var(--line);
  z-index: 40;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  white-space: nowrap;
  flex-shrink: 0;
}
.brand-icon { font-size: 20px; }
.brand-name {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.4px;
  background: linear-gradient(90deg, #f5c518, #ff8a3d);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.brand-sub {
  font-size: 11px;
  color: var(--text-dim);
  font-style: italic;
}

/* Buscador */
.search-box {
  position: relative;
  flex: 0 1 340px;
}
#search {
  width: 100%;
  padding: 7px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}
#search:focus { border-color: var(--accent); }
#search::placeholder { color: var(--text-dim); }

/* Selector de idioma */
#lang-switch {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-3);
  flex-shrink: 0;
}
.lang-btn {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  padding: 5px 10px;
  border-radius: 999px;
  transition: all 0.15s;
}
.lang-btn:hover { color: var(--text); }
.lang-btn.active {
  background: var(--accent);
  color: #10141d;
}


#search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 320px;
  overflow-y: auto;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
  z-index: 60;
}
.search-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.search-item:last-child { border-bottom: none; }
.search-item:hover, .search-item.active { background: rgba(245, 197, 24, 0.08); }
.search-item .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}
.search-item .si-name { font-weight: 600; font-size: 13px; }
.search-item .si-meta { font-size: 11px; color: var(--text-dim); }
.search-item .si-kind {
  margin-left: auto;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
  flex-shrink: 0;
}

/* ---------- Eje de años ---------- */

#axis {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  right: 0;
  width: 100%;
  height: var(--axis-h);
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  z-index: 30;
}

/* ---------- Escenario ---------- */

#stage {
  position: fixed;
  inset: calc(var(--topbar-h) + var(--axis-h)) 0 0 0;
  overflow: hidden;
  background:
    radial-gradient(1200px 500px at 70% -10%, rgba(56, 189, 248, 0.05), transparent 60%),
    radial-gradient(900px 500px at 15% 110%, rgba(225, 29, 72, 0.05), transparent 60%),
    var(--bg);
  cursor: grab;
}
#stage.dragging { cursor: grabbing; }

#world { width: 100%; height: 100%; display: block; }

#empty-hint {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: var(--text-dim);
  background: rgba(16, 20, 29, 0.85);
  border: 1px solid var(--line);
  padding: 7px 14px;
  border-radius: 999px;
  pointer-events: none;
  transition: opacity 0.6s;
}

/* ---------- Elementos del mundo SVG ---------- */

.era-line { stroke: rgba(255, 255, 255, 0.05); stroke-width: 1; }
.era-label {
  fill: var(--text-faint);
  font-size: 10px;
  font-family: var(--mono);
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

.family-band { fill: rgba(255, 255, 255, 0.018); }
.family-band.alt { fill: rgba(255, 255, 255, 0.04); }
.family-label {
  fill: var(--text-faint);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  opacity: 0.55;
}

.edge {
  fill: none;
  stroke-width: 1.4;
  opacity: 0.28;
  transition: opacity 0.15s, stroke-width 0.15s;
}
.edge.lit { opacity: 0.95; stroke-width: 2.4; }

.node { cursor: pointer; }
.node rect {
  stroke-width: 1.2;
  transition: filter 0.15s;
}
.node text {
  pointer-events: none;
  user-select: none;
}
.node .n-name {
  fill: #fff;
  font-size: 11px;
  font-weight: 600;
}
.node .n-year {
  fill: rgba(255, 255, 255, 0.65);
  font-size: 9px;
  font-family: var(--mono);
}
.node:hover rect { filter: brightness(1.25); }
.node.selected rect { stroke-width: 2.4; filter: brightness(1.3) drop-shadow(0 0 6px rgba(255,255,255,0.35)); }

/* Estados de atenuación */
#world.has-focus .node { opacity: 0.18; }
#world.has-focus .node.focus { opacity: 1; }
#world.has-focus .edge { opacity: 0.06; }
#world.has-focus .edge.lit { opacity: 0.95; }

#world.family-filter .node { opacity: 0.12; }
#world.family-filter .node.in-family { opacity: 1; }
#world.family-filter .edge { opacity: 0.04; }
#world.family-filter .edge.in-family { opacity: 0.5; }

/* ---------- Panel lateral ---------- */

#panel {
  position: fixed;
  top: calc(var(--topbar-h) + var(--axis-h));
  right: 0;
  bottom: 0;
  width: var(--panel-w);
  background: linear-gradient(180deg, #131824 0%, #0e121b 100%);
  border-left: 1px solid var(--line);
  box-shadow: -16px 0 40px rgba(0, 0, 0, 0.45);
  z-index: 50;
  overflow-y: auto;
  transform: translateX(0);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
#panel.hidden { display: block !important; transform: translateX(105%); }

#panel-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--text-dim);
  font-size: 13px;
  z-index: 2;
}
#panel-close:hover { color: var(--text); border-color: var(--text-dim); }

#panel-content { padding: 22px 20px 40px; }

.p-family {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 4px 11px;
  border-radius: 999px;
  margin-bottom: 12px;
}
.p-family .dot { width: 8px; height: 8px; border-radius: 50%; }

.p-title {
  font-size: 24px;
  font-weight: 800;
  line-height: 1.15;
  margin-bottom: 4px;
}
.p-year {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 14px;
}
.p-desc {
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--text-dim);
  margin-bottom: 20px;
}

.p-section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 18px 0 8px;
}

.p-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.p-chip {
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}
.p-chip:hover { border-color: var(--accent); color: var(--accent); }

.p-films { list-style: none; }
.p-films li {
  display: flex;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  align-items: baseline;
}
.p-films li:last-child { border-bottom: none; }
.p-films .f-year {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
  flex-shrink: 0;
  width: 38px;
}
.p-films .f-body { flex: 1; min-width: 0; }
.p-films .f-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  display: inline;
  text-align: left;
  border: 0;
  background: transparent;
}
.p-films .f-title:hover { color: var(--accent); text-decoration: underline; }
.p-films .f-title:focus-visible,
.p-back:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
.p-films .f-dir {
  display: block;
  font-size: 11.5px;
  color: var(--text-dim);
  margin-top: 2px;
}

.p-back {
  margin: 0 0 18px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-3);
  color: var(--text-dim);
  font-size: 12px;
}
.p-back:hover { color: var(--accent); border-color: var(--accent); }

.film-detail {
  display: grid;
  grid-template-columns: minmax(96px, 132px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.film-poster-wrap {
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg-3);
}
.film-poster {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.film-poster-placeholder {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  min-height: 160px;
  padding: 12px;
  color: var(--text-faint);
  font-size: 12px;
  text-align: center;
}
.film-detail-copy { min-width: 0; }
.film-detail-copy .p-section-title { display: block; margin-top: 0; }
.film-detail-copy .p-title { font-size: 20px; overflow-wrap: anywhere; }
.film-detail-copy .p-year { margin-bottom: 12px; }
.film-credits { font-size: 12px; }
.film-credits > div { margin-top: 9px; }
.film-credits dt {
  margin-bottom: 2px;
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.film-credits dd { color: var(--text-dim); line-height: 1.5; }
.film-detail-copy .p-wiki { margin-top: 15px; }
.film-image-credit {
  margin-top: 9px;
  color: var(--text-faint);
  font-size: 10px;
  line-height: 1.5;
}
.film-image-credit a { color: var(--text-dim); }
.film-image-credit a:hover { color: var(--accent); }

.p-wiki {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 22px;
  padding: 9px 14px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--text-dim);
  font-size: 12.5px;
  text-decoration: none;
  transition: all 0.15s;
}
.p-wiki:hover { color: var(--accent); border-color: var(--accent); }

.p-center {
  margin-top: 10px;
  width: 100%;
  padding: 9px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text-dim);
  font-size: 12.5px;
  transition: all 0.15s;
}
.p-center:hover { color: var(--text); border-color: var(--text-dim); }

/* ---------- Controles de zoom ---------- */

#controls {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 40;
}
#controls button {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(19, 24, 36, 0.9);
  color: var(--text);
  font-size: 17px;
  backdrop-filter: blur(6px);
  transition: all 0.15s;
}
#controls button:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Estadísticas ---------- */

#stats {
  position: fixed;
  left: 16px;
  bottom: 16px;
  font-size: 11.5px;
  color: var(--text-dim);
  background: rgba(19, 24, 36, 0.9);
  border: 1px solid var(--line);
  padding: 7px 13px;
  border-radius: 999px;
  backdrop-filter: blur(6px);
  z-index: 40;
  pointer-events: none;
  max-width: calc(100vw - 76px);
}
#stats b { color: var(--text); font-weight: 700; }

/* ---------- Tooltip ---------- */

#tooltip {
  position: fixed;
  pointer-events: none;
  background: rgba(13, 17, 25, 0.95);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 12px;
  font-size: 12px;
  z-index: 70;
  max-width: 260px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
#tooltip .tt-name { font-weight: 700; margin-bottom: 2px; }
#tooltip .tt-meta { color: var(--text-dim); font-size: 11px; }

/* ---------- Scrollbars ---------- */

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #2e3748; }

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .brand-sub { display: none; }
  #panel { width: min(var(--panel-w), 92vw); }
}

@media (max-width: 520px) {
  #stats { font-size: 9.5px; padding: 5px 9px; }
}
