/* ============================================
   VARIABLES
   ============================================ */
:root {
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, Roboto, 'Helvetica Neue', Arial, sans-serif;
  --bg:        #0d1117;
  --panel:     #161b22;
  --panel-2:   #1c2430;
  --elev:      #21262d;
  --line:      rgba(255, 255, 255, 0.06);
  --line-hi:   rgba(255, 255, 255, 0.12);
  --tx-0: #ffffff;
  --tx-1: #e6edf3;
  --tx-2: #8b949e;
  --tx-3: #6e7681;
  --yellow:   #f5c518;
  --red:      #f85149;
  --blue:     #58a6ff;
  --green:    #42db42;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --sidebar-w: 130px;
  --sidebar-mini-w: 64px;
}

body.light {
  --bg:        #ffffff;
  --panel:     #f6f8fa;
  --panel-2:   #eaeef2;
  --elev:      #e1e4e8;
  --line:      rgba(27, 31, 36, 0.1);
  --line-hi:   rgba(27, 31, 36, 0.18);
  --tx-0: #1f2328;
  --tx-1: #24292f;
  --tx-2: #57606a;
  --tx-3: #6e7781;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--tx-1);
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.5;
}

a { text-decoration: none; }

.app { display: flex; width: 100%; min-height: 100vh; }

/* ============================================
   SCROLLBAR
   ============================================ */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--line-hi) transparent;
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line-hi);
  border-radius: 10px;
  border: 2px solid transparent;
  background-clip: padding-box;
  transition: background 0.2s ease;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--tx-3);
  background-clip: padding-box;
  border: 2px solid transparent;
}
::-webkit-scrollbar-corner { background: transparent; }

/* ============================================
   CUERPO DE LA APP
   ============================================ */
.app-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

/* ============================================
   BARRA SUPERIOR
   ============================================ */
.topbar-global {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.5rem;
  height: 60px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex-shrink: 0;
  z-index: 100;
}

.school-topbar-logo {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--tx-0);
  letter-spacing: -0.025em;
  flex-shrink: 0;
}

.topbar-global .search-wrap { flex: 1; margin: 0 auto; }
.topbar-global .mode-switch { margin-left: auto; }

/* ============================================
   DISPOSICIÓN DE REPRODUCCIÓN
   ============================================ */
.play-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  width: 100%;
  flex-wrap: nowrap;
  align-items: stretch;
}

/* ============================================
   BARRA LATERAL
   ============================================ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 0.85rem 0.075rem;
  gap: 0.25rem;
  overflow: hidden;
  flex-shrink: 0;
  transition: width 0.22s var(--ease);
}

.sb-nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  width: 100%;
}

.sb-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 0.75rem;
  text-decoration: none;
  color: var(--tx-2);
  height: 40px;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 400;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
  border: none;
  background: transparent;
  position: relative;
  text-align: left;
  white-space: nowrap;
}

.sb-item:hover { background: var(--panel-2); color: var(--tx-0); }

.sb-item.active {
  background: var(--panel-2);
  color: var(--tx-0);
  font-weight: 700;
}

.sb-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 2px;
  height: 40px;
  background: var(--yellow);
}

.sb-ico {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  flex-shrink: 0;
  color: inherit;
}

.sb-text {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sb-count {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--tx-3);
  background: var(--elev);
  padding: 0.15rem 0.5rem;
  border-radius: 100px;
  display: none;
  min-width: 26px;
  text-align: center;
  flex-shrink: 0;
}

.sb-item.active .sb-count {
  background: var(--yellow);
  color: #0d1117;
}

/* Barra lateral mini */
.sidebar-mini {
  width: var(--sidebar-mini-w);
  padding: 0.85rem 0.5rem;
  transition: width 0.22s var(--ease);
  overflow: hidden;
  z-index: 50;
}
.sidebar-mini .sb-item {
  padding: 0.7rem 0;
  justify-content: center;
  gap: 0;
}
.sidebar-mini .sb-text,
.sidebar-mini .sb-count { display: none; }
.sidebar-mini:hover { width: 120px; }
.sidebar-mini:hover .sb-item {
  padding: 0.6rem 0.75rem;
  justify-content: flex-start;
  gap: 0.75rem;
}
.sidebar-mini:hover .sb-text { display: block; }
.sidebar-mini:hover .sb-count { display: inline-block; }

/* ============================================
   PRINCIPAL
   ============================================ */
.main {
  flex: 1;
  padding: 1rem 1rem 2rem;
  overflow-y: auto;
  min-width: 0;
}

/* ============================================
   BÚSQUEDA
   ============================================ */
.search-wrap {
  position: relative;
  display: flex;
  max-width: 405px;
}

.search-input {
  width: 100%;
  padding: 0.65rem 1.15rem;
  border-radius: 10px;
  border: 1px solid var(--line-hi);
  background: var(--panel);
  color: var(--tx-0);
  outline: none;
  max-width: 405px;
  font-size: 0.875rem;
  font-family: inherit;
  transition: border-color 0.15s var(--ease);
}

.search-input::placeholder { color: var(--tx-3); }
.search-input:focus { border-color: var(--yellow); }

/* ============================================
   CAMBIO DE MODO
   ============================================ */
.mode-switch {
  display: inline-flex;
  background: var(--panel-2);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
  flex-shrink: 0;
}

.mode-btn {
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--tx-2);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s var(--ease);
  white-space: nowrap;
}

.mode-btn:hover { color: var(--tx-0); }

.mode-btn.active {
  background: var(--panel);
  color: var(--tx-0);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

body.light .mode-btn.active {
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--tx-1);
  font-size: 1rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all 0.15s var(--ease);
  flex-shrink: 0;
}

.icon-btn:hover { border-color: var(--yellow); color: var(--yellow); }

/* ============================================
   HERO
   ============================================ */
.hero-banner {
  background: linear-gradient(135deg, #1f2a3a 0%, #161b22 100%);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem 1.5rem;
  margin-bottom: 1.5rem;
}

body.light .hero-banner {
  background: linear-gradient(135deg, #eef2f7 0%, #f6f8fa 100%);
}

.hero-title {
  font-size: 2.2rem;
  font-weight: 900;
  color: var(--tx-0);
  letter-spacing: -0.035em;
  line-height: 1.1;
}

.hero-sub {
  color: var(--tx-2);
  font-size: 0.9rem;
  margin-top: 0.5rem;
  max-width: 620px;
}

/* ============================================
   CUADRÍCULA
   ============================================ */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  grid-auto-rows: minmax(110px, auto);
  gap: 1rem;
  grid-auto-flow: dense;
}

.grid-loading {
  grid-column: 1 / -1;
  padding: 3rem;
  text-align: center;
  color: var(--tx-3);
  font-size: 0.9rem;
}

/* ============================================
   TARJETA
   ============================================ */
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: var(--tx-1);
  transition: transform 0.2s var(--ease);
}

.card:hover { transform: translateY(-3px); }

.card-img-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  overflow: hidden;
  background: var(--panel-2);
  border: 1px solid var(--line);
  transition: border-color 0.15s var(--ease);
}

.card:hover .card-img-wrap { border-color: var(--yellow); }

.card-img-wrap img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s var(--ease);
}

.card:hover .card-img-wrap img { transform: scale(1.05); }

.card-img-wrap.no-img::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--panel-2);
}

/* ============================================
   DESTACADO (2x2)
   ============================================ */
.card-featured {
  grid-column: span 2;
  grid-row: span 2;
}

.card-featured .card-img-wrap {
  aspect-ratio: auto;
  flex: 1;
  min-height: 0;
}

/* ============================================
   DETALLE
   ============================================ */
.viewer-wrap { margin-bottom: 2rem; }

.preview {
  display: flex;
  align-items: center;
  gap: 2rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 2rem;
}

.preview-img {
  width: 220px; height: 220px;
  border-radius: 12px;
  object-fit: cover;
  background: var(--panel-2);
  flex-shrink: 0;
}

.preview-info { flex: 1; min-width: 0; }

.preview-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: #fff;
  background: var(--red);
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  margin-bottom: 0.75rem;
}

.preview-title {
  font-size: 1.9rem;
  font-weight: 900;
  color: var(--tx-0);
  letter-spacing: -0.035em;
  line-height: 1.1;
  margin-bottom: 0.5rem;
}

.preview-sub {
  color: var(--tx-2);
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}

.btn-play {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.9rem 1.75rem;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 800;
  color: #0d1117;
  background: var(--yellow);
  border: none;
  cursor: pointer;
  transition: all 0.15s var(--ease);
  box-shadow: 0 8px 20px -8px rgba(245, 197, 24, 0.55);
}

.btn-play:hover { background: #ffd633; transform: translateY(-1px); }

.viewer {
  display: none;
  width: 100%;
  height: calc(100vh - 120px);
  max-height: calc(100vh - 120px);
  background: #000;
  border-radius: 14px;
  overflow: hidden;
  position: relative;
}

.viewer.active { display: block; }
.viewer iframe { width: 100%; height: 100%; border: 0; display: block; }

.btn-fs {
  position: absolute;
  bottom: 16px; right: 16px;
  background: rgba(255, 255, 255, 0.95);
  color: #0d1117;
  border: none;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  display: none;
}

.similar-title {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--tx-0);
  letter-spacing: -0.025em;
  margin: 2rem 0 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--line);
}

/* ============================================
   DETALLE — CARRIL DE ANUNCIO DERECHO
   ============================================ */
.detail-ad-rail {
  width: 300px;
  min-width: 300px;
  max-width: 300px;
  flex-shrink: 0;
  padding: 1rem 1rem 2rem 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background: var(--bg);
  height: 100vh;
  overflow: hidden;
}

.detail-ad-rail .kutu {
  width: 300px;
  height: 600px;
  margin-bottom: 0;
  flex-shrink: 0;
}

.detail-ad-rail .kutu:empty { display: none; }

@media (max-width: 1280px) {
  .detail-ad-rail { display: none; }
}

/* ============================================
   DISPOSICIÓN DE ESTUDIO
   ============================================ */
.school-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  width: 100%;
}

.school-sidebar {
  width: var(--sidebar-w);
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 0.85rem 0.075rem;
  gap: 0.25rem;
  overflow: hidden;
  flex-shrink: 0;
  transition: width 0.22s var(--ease);
}

.school-nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  width: 100%;
}

.school-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 0.75rem;
  text-decoration: none;
  color: var(--tx-2);
  height: 40px;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 400;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
  border: none;
  background: transparent;
  position: relative;
  text-align: left;
  white-space: nowrap;
}

.school-item:hover { background: var(--panel-2); color: var(--tx-0); }

.school-item.active {
  background: var(--panel-2);
  color: var(--tx-0);
  font-weight: 700;
}

.school-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 2px;
  height: 40px;
  background: var(--yellow);
}

.school-footer {
  margin-top: auto;
  padding: 0.85rem 0.075rem 0;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}

.school-clear {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 0.75rem;
  width: 100%;
  height: 40px;
  border-radius: 0;
  background: transparent;
  border: none;
  color: var(--tx-2);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 400;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.school-clear:hover { background: var(--panel-2); color: var(--tx-0); }
.school-clear svg { flex-shrink: 0; width: 18px; height: 18px; }

.school-content {
  flex: 1;
  padding: 2rem;
  overflow-y: auto;
  background: var(--bg);
}

.school-title {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--tx-0);
  letter-spacing: -0.03em;
  outline: none;
  margin-bottom: 2rem;
}

.school-note {
  font-size: 1rem;
  line-height: 1.8;
  color: var(--tx-1);
  outline: none;
  min-height: 400px;
  max-width: 800px;
}

.school-note:empty::before {
  content: attr(data-placeholder);
  color: var(--tx-3);
  pointer-events: none;
}

.school-note h2 {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--tx-0);
  margin: 1.5rem 0 0.75rem;
  letter-spacing: -0.02em;
}
.school-note h2:first-child { margin-top: 0; }

.school-note p {
  margin-bottom: 0.85rem;
  color: var(--tx-1);
}

.school-note ul {
  margin: 0 0 1rem 1.25rem;
  padding: 0;
}

.school-note li {
  margin-bottom: 0.35rem;
  color: var(--tx-1);
  line-height: 1.7;
}

.school-note strong { color: var(--tx-0); font-weight: 700; }

/* ============================================
   CONSEJO DE ESTUDIO (flecha)
   ============================================ */
.study-tip {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.35s ease, transform 0.35s ease;
  color: var(--yellow);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  width: 170px;
}

.study-tip.show {
  opacity: 1;
  transform: translateY(0);
}

.study-tip.show .study-tip-arrow {
  animation: studyTipBounce 1.6s ease-in-out infinite;
}

.study-tip-close {
  pointer-events: auto;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--yellow);
  background: var(--panel);
  color: var(--yellow);
  display: grid;
  place-items: center;
  position: absolute;
  top: -14px;
  cursor: pointer;
  padding: 0;
  transition: background 0.15s ease, transform 0.15s ease;
  flex-shrink: 0;
  left: 40px;
}

.study-tip-close:hover {
  background: var(--yellow);
  color: #0d1117;
  transform: scale(1.1);
}

.study-tip-label {
  pointer-events: auto;
  background: var(--yellow);
  color: #0d1117;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  white-space: nowrap;
  box-shadow: 0 6px 16px -6px rgba(245, 197, 24, 0.6);
  margin-right: 4px;
}

.study-tip-arrow {
  width: 190px;
  height: 90px;
  color: var(--yellow);
  filter: drop-shadow(0 4px 10px rgba(245, 197, 24, 0.35));
  margin-top: 0;
  left: 90px !important;
  position: absolute;
  top: -10px;
}

.study-tip-arrow svg {
  width: 100%;
  height: 100%;
  display: block;
}

@keyframes studyTipBounce {
  0%, 100% { transform: translateY(0) translateX(0); }
  50%      { transform: translateY(-6px) translateX(4px); }
}

/* ============================================
   KUTU (caja de anuncios)
   ============================================ */
.kutu {
  min-height: 0;
  margin-bottom: 0.5rem;
}
.kutu:empty { display: none; }

/* ============================================
   ANIMACIÓN DE TARJETA
   ============================================ */
@keyframes cardFadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card {
  animation: cardFadeUp 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* ============================================
   BOTÓN VOLVER EN DETALLE
   ============================================ */
#detailBack .sb-ico svg {
  transition: transform 0.2s var(--ease);
}
#detailBack:hover .sb-ico svg {
  transform: translateX(-3px);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 900px) {
  :root { --sidebar-w: 64px; }

  .sb-text, .sb-count { display: none; }
  .sb-item { justify-content: center; padding: 0.6rem; }

  .school-item,
  .school-clear { justify-content: center; padding: 0.6rem; }

  .topbar-global { gap: 0.6rem; padding: 0 1rem; }
  .topbar-global .search-wrap { max-width: 100%; }
  .school-topbar-logo { font-size: 0.95rem; }

  .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 0.75rem; }
  .hero-title { font-size: 1.7rem; }
  .hero-banner { padding: 1.5rem; }

  .preview { flex-direction: column; text-align: center; padding: 1.5rem; gap: 1.25rem; }
  .preview-img { width: 180px; height: 180px; }
  .preview-title { font-size: 1.5rem; }

  .school-content { padding: 2rem; }
  .school-title { font-size: 1.4rem; }
}

@media (max-width: 700px) {
  .study-tip { display: none; }
}

@media (max-width: 600px) {
  .main { padding: 1rem; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 0.6rem; }

  .topbar-global { height: 56px; padding: 0 0.75rem; gap: 0.5rem; }
  .school-topbar-logo { font-size: 0.85rem; }
  .mode-btn { padding: 0.45rem 0.7rem; font-size: 0.75rem; }
  .icon-btn { width: 34px; height: 34px; font-size: 0.9rem; }

  .school-item,
  .school-clear { font-size: 0.82rem; padding: 0.5rem 0.75rem; }
  .school-content { padding: 1.5rem; }
  .school-title { font-size: 1.25rem; }
  .school-note { font-size: 0.9rem; }
}

/* ============================================
   RESULTADOS DE BÚSQUEDA DESPLEGABLE
   ============================================ */
.search-wrap {
  position: relative;
  display: flex;
  max-width: 405px;
  flex: 1;
}

.search-results {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 420px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line-hi);
  border-radius: 12px;
  padding: 0.4rem;
  box-shadow: 0 20px 40px -12px rgba(0, 0, 0, 0.6);
  z-index: 200;
}

.search-results.show {
  display: block;
}

.search-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  text-decoration: none;
  color: var(--tx-1);
  transition: background 0.12s;
}

.search-item:hover,
.search-item.active {
  background: var(--panel-2);
  color: var(--tx-0);
}

.search-thumb {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--elev);
  flex-shrink: 0;
}

.search-info {
  min-width: 0;
  flex: 1;
}

.search-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--tx-0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-meta {
  font-size: 0.7rem;
  color: var(--tx-3);
  margin-top: 0.1rem;
}

.search-empty {
  padding: 1.5rem;
  text-align: center;
  color: var(--tx-3);
  font-size: 0.82rem;
}