/* ===== Base / Reset ligero ===== */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  padding: 0;
  font-family: "Times New Roman", Times, serif;
  color: #1a1a1a;
  line-height: 1.6;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

/* ===== Fondo animado ===== */
body::before {
  content: "";
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: -2;
  background: linear-gradient(135deg, #0a2540 0%, #0f3d6e 35%, #0066CC 70%, #0a2540 100%);
  background-size: 400% 400%;
  animation: bgGradient 18s ease infinite;
}

body::after {
  content: "";
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: -1;
  background-image:
    radial-gradient(circle at 15% 20%, rgba(0, 102, 204, 0.25) 0%, transparent 45%),
    radial-gradient(circle at 85% 80%, rgba(15, 61, 110, 0.3) 0%, transparent 45%),
    radial-gradient(circle at 50% 50%, rgba(0, 150, 255, 0.12) 0%, transparent 50%);
  animation: bgPulse 12s ease-in-out infinite;
}

@keyframes bgGradient {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@keyframes bgPulse {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50%      { opacity: 1;   transform: scale(1.05); }
}

/* ===== Tabla principal (estructura original intacta) ===== */
#table {
  width: 1000px;
  max-width: 100%;
  margin: 0 auto;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  border: 0;
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
}

#table > tbody > tr > td {
  padding: clamp(16px, 4vw, 40px);
}

/* ===== Tipografia (mismas fuentes) ===== */
h1, h2, h3, h4 {
  margin: 0.4em 0;
  font-weight: 400;
  font-family: "Instrument Serif", Georgia, "Times New Roman", Times, serif;
}

h1 { font-size: clamp(1.8rem, 5vw, 2.6rem); letter-spacing: 0.5px; }
h2 { font-size: clamp(1.4rem, 4vw, 1.9rem); }
h3 { font-size: clamp(1.05rem, 3vw, 1.3rem); }

.Estilo6 {
  font-style: italic;
  font-family: Georgia, "Times New Roman", Times, serif;
}

h1.Estilo6, h2.Estilo6, h3.Estilo6, h4.Estilo6 {
  font-family: "Instrument Serif", Georgia, "Times New Roman", Times, serif !important;
  font-style: italic !important;
}

.Estilo7 { color: #F0F0F0; }

hr {
  border: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, #0066CC, transparent);
  margin: 1.5em 0;
}

/* ===== Encabezado ===== */
#table h1.Estilo6 {
  color: #0f3d6e;
  text-shadow: 0 2px 4px rgba(0,0,0,0.08);
  font-family: "Instrument Serif", Georgia, "Times New Roman", Times, serif !important;
}

#table h3.Estilo6 {
  color: #0066CC;
  font-weight: 400;
  letter-spacing: 1px;
  margin-top: -0.3em;
  font-family: "Instrument Serif", Georgia, "Times New Roman", Times, serif !important;
}

/* ===== Menu (nav) ===== */
.menu {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin: 1.5em auto 1.2em;
  padding: 16px 0;
  max-width: 1000px;
  border-bottom: 2px solid #e0e8f5;
}

.menu-link {
  font-family: "Instrument Serif", Georgia, "Times New Roman", Times, serif;
  color: #0f3d6e;
  text-decoration: none;
  padding: 6px 0;
  background: transparent;
  text-align: center;
  font-size: clamp(0.9rem, 2.2vw, 1.05rem);
  font-weight: 500;
  letter-spacing: 0;
  flex: 0 0 auto;
  position: relative;
  transition: color 0.25s ease;
  white-space: nowrap;
}

.menu-link::after {
  content: "";
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 2px;
  background: #0066CC;
  transition: width 0.3s ease;
}

.menu-link:hover,
.menu-link:focus {
  color: #0066CC;
}

.menu-link:hover::after,
.menu-link:focus::after {
  width: 100%;
}

.menu-link.active {
  color: #0066CC;
}

.menu-link.active::after {
  width: 100%;
}

/* Enlace genérico */
a { color: #0066CC; transition: color 0.2s ease; }
a:hover { color: #0a4a8c; }

/* ===== About: tabla con imagen ===== */
#about + hr + table {
  max-width: 100%;
  border-collapse: collapse;
}
#about + hr + table td img {
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  border: 4px solid #fff;
  display: block;
  max-width: 100%;
  height: auto;
}
#about + hr + table td:first-child {
  vertical-align: middle;
}

/* ===== Skills pills ===== */
.skill-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 1em 0 1.5em;
}

.skill-pill {
  font-family: Georgia, "Times New Roman", Times, serif;
  border: 1.5px solid #c8d4e8;
  background: #fff;
  color: #0f3d6e;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.25s ease, color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

.skill-pill:hover {
  border-color: #0066CC;
  box-shadow: 0 3px 10px rgba(0, 102, 204, 0.15);
}

.skill-pill.active {
  background: #0f3d6e;
  color: #fff;
  border-color: #0f3d6e;
  box-shadow: 0 3px 12px rgba(15, 61, 110, 0.3);
}

/* ===== Skills badges ===== */
.Estilo6 img {
  display: inline-block;
  height: 28px !important;
  width: auto !important;
  border-radius: 6px;
  transition: transform 0.2s ease, filter 0.2s ease;
}
.Estilo6 a:hover img { transform: translateY(-2px); filter: brightness(1.1); }

/* Badge filtering */
.Estilo6 a[data-cat] {
  display: inline-block;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.Estilo6 a[data-cat].hidden-badge {
  display: none;
}

/* ===== Projects ===== */
#projects + p + table {
  border: 0;
  table-layout: fixed;
}
#projects + p + table td {
  width: 33.33%;
  background: #f7faff;
  border: 1px solid #e0e8f5;
  border-radius: 14px;
  padding: 18px;
  vertical-align: top;
  box-shadow: 0 4px 14px rgba(0,0,0,0.05);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}
#projects + p + table td:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 28px rgba(0,102,204,0.15);
}
#projects + p + table td h3 { color: #0f3d6e; }
#projects + p + table td p strong { color: #0066CC; }
#projects + p + table td p img { height: 22px; width: auto; }

/* ===== Contact ===== */
#contact + p + table td img {
  width: 80px;
  height: 80px;
  border-radius: 14px;
  border: 2px solid #e0e8f5;
  background: #fff;
  padding: 8px;
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.3s ease;
}
#contact + p + table td a:hover img {
  transform: scale(1.08);
  box-shadow: 0 6px 16px rgba(0,102,204,0.25);
}

/* ===== Pie ===== */
#table ~ h4, #table ~ p { color: #F0F0F0; }
#table ~ p { font-family: Georgia, "Times New Roman", Times, serif; font-style: italic; }

/* ===========================================
   RESPONSIVE
   =========================================== */
@media (max-width: 960px) {
  #table { width: 96%; border-radius: 12px; }
}

@media (max-width: 768px) {
  #table { width: 100% !important; border-radius: 0; }

  /* Todas las tablas y td internos al 100% en movil */
  #table table { width: 100% !important; }
  #table table td { width: 100% !important; }

  /* Tabla principal: la tabla interna de nav se vuelve tipo bloque amigable */
  #table > tbody > tr > td { padding: 16px; }

  /* Menu: compacto en una sola fila */
  .menu { gap: 16px; padding: 12px 0; }
  .menu-link { font-size: clamp(0.75rem, 2.8vw, 0.9rem); }

  /* About: tabla se apila (texto arriba, imagen abajo) */
  #about + hr + table { display: block !important; width: 100% !important; }
  #about + hr + table tbody { display: block; }
  #about + hr + table tr { display: flex; flex-direction: column; gap: 16px; }
  #about + hr + table td { display: block; width: 100% !important; text-align: center; }
  #about + hr + table td img { margin: 0 auto; width: 160px; height: auto; }

  /* Projects: una columna */
  #projects + p + table { display: block !important; width: 100% !important; }
  #projects + p + table tbody { display: block; }
  #projects + p + table tr { display: flex; flex-direction: column; gap: 12px; }
  #projects + p + table td { display: block; width: 100% !important; }

  /* Contact: iconos a la izquierda, texto a la derecha pero responsive */
  #contact + p + table { display: block !important; width: 100% !important; }
  #contact + p + table tbody { display: block; }
  #contact + p + table tr { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
  #contact + p + table td { display: flex; align-items: center; width: 100% !important; }
  #contact + p + table td[width="65"] { width: 80px !important; flex: 0 0 80px; }
  #contact + p + table td[width="719"] { flex: 1 1 auto; width: auto !important; }
}

@media (max-width: 480px) {
  body { font-size: 0.95rem; }
  .menu { gap: 10px; padding: 10px 0; }
  .menu-link { font-size: 0.72rem; }
  .Estilo6 img { height: 24px !important; }
  #about + hr + table td img { width: 130px; }
}

/* ===== Animaciones scroll ===== */
.reveal {
  opacity: 0;
  transform: translateY(32px);
  transition: opacity 0.7s ease, transform 0.7s ease;
}

.reveal.reveal-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Delays escalonados para cards de proyectos */
#projects + p + table td.reveal:nth-child(1) { transition-delay: 0s; }
#projects + p + table td.reveal:nth-child(2) { transition-delay: 0.15s; }
#projects + p + table td.reveal:nth-child(3) { transition-delay: 0.3s; }

/* Delays escalonados para filas de contacto */
#contact + p + table tr.reveal:nth-child(1) { transition-delay: 0s; }
#contact + p + table tr.reveal:nth-child(2) { transition-delay: 0.12s; }
#contact + p + table tr.reveal:nth-child(3) { transition-delay: 0.24s; }

/* Respetar preferencia de reduced motion */
@media (prefers-reduced-motion: reduce) {
  .reveal {
    opacity: 1;
    transform: none;
    transition: none;
  }
}

/* ===== Theme toggle ===== */
.theme-toggle {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1.5px solid #c8d4e8;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  color: #0f3d6e;
  transition: background 0.25s ease, color 0.25s ease, border-color 0.25s ease;
  margin-left: 8px;
}

.theme-toggle:hover {
  border-color: #0066CC;
  color: #0066CC;
}

.theme-toggle .icon-moon { display: none; }
.theme-toggle .icon-sun { display: block; }

body.dark .theme-toggle .icon-moon { display: block; }
body.dark .theme-toggle .icon-sun { display: none; }

/* ===== Dark mode ===== */
body.dark {
  color: #e0e0e0;
}

body.dark::before {
  background: linear-gradient(135deg, #060814 0%, #0a0f1f 35%, #111726 70%, #060814 100%);
}

body.dark::after {
  background-image:
    radial-gradient(circle at 15% 20%, rgba(126, 184, 255, 0.12) 0%, transparent 45%),
    radial-gradient(circle at 85% 80%, rgba(30, 58, 95, 0.18) 0%, transparent 45%),
    radial-gradient(circle at 50% 50%, rgba(80, 130, 200, 0.08) 0%, transparent 50%);
}

body.dark #table {
  background: #121826;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

body.dark #table > tbody > tr > td {
  color: #d0d0d0;
}

body.dark h1.Estilo6,
body.dark h2.Estilo6,
body.dark h3.Estilo6,
body.dark h4.Estilo6 {
  color: #7eb8ff !important;
}

body.dark #table h1.Estilo6 { color: #a0c4ff !important; text-shadow: 0 2px 8px rgba(0,0,0,0.3); }
body.dark #table h3.Estilo6 { color: #6aa8e8 !important; }

body.dark .menu { border-bottom-color: #1e2a3e; }
body.dark .menu-link { color: #8095ab; }
body.dark .menu-link:hover,
body.dark .menu-link:focus { color: #7eb8ff; }
body.dark .menu-link::after { background: #7eb8ff; }
body.dark .menu-link.active { color: #7eb8ff; }
body.dark .menu-link.active::after { background: #7eb8ff; }

body.dark .theme-toggle { border-color: #2a3a52; color: #8095ab; }
body.dark .theme-toggle:hover { border-color: #7eb8ff; color: #7eb8ff; }

body.dark hr { background: linear-gradient(90deg, transparent, #2a4a6e, transparent); }

body.dark .skill-pill {
  background: #1a2333;
  color: #a0c4ff;
  border-color: #2a3a52;
}
body.dark .skill-pill:hover { border-color: #7eb8ff; box-shadow: 0 3px 10px rgba(126, 184, 255, 0.15); }
body.dark .skill-pill.active { background: #1e3a5f; color: #fff; border-color: #1e3a5f; }

body.dark #projects + p + table td {
  background: #1a2333;
  border-color: #2a3a52;
  box-shadow: 0 4px 14px rgba(0,0,0,0.2);
}
body.dark #projects + p + table td:hover {
  box-shadow: 0 12px 28px rgba(126, 184, 255, 0.1);
}
body.dark #projects + p + table td h3 { color: #a0c4ff; }
body.dark #projects + p + table td p strong { color: #7eb8ff; }

body.dark #contact + p + table td img {
  border-color: #e0e8f5;
  background: #fff;
  filter: invert(1) hue-rotate(180deg);
}

body.dark a { color: #7eb8ff; }
body.dark a:hover { color: #a0c4ff; }

body.dark #table ~ h4,
body.dark #table ~ p { color: #8095ab; }

body.dark #about + hr + table td img {
  border-color: #2a3a52;
}