/* ===== Variables ===== */
:root {
    --color-primary: #1b3a57;
    --color-primary-dark: #12283d;
    --color-accent: #3d8bd9;
    --color-bg: #f4f6f9;
    --color-surface: #ffffff;
    --color-text: #2a2f36;
    --color-muted: #5f6b7a;
    --color-border: #dfe4ea;
    --radius: 12px;
    --shadow: 0 4px 18px rgba(18, 40, 61, 0.08);
    --max-width: 1000px;
}

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

body {
    margin: 0;
    font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: var(--color-text);
    background: var(--color-bg);
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

a {
    color: var(--color-accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

h1, h2, h3 {
    line-height: 1.25;
    color: var(--color-primary);
}

/* ===== Header / navegación ===== */
body > header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px max(16px, calc((100% - var(--max-width)) / 2));
    background: var(--color-primary);
    box-shadow: var(--shadow);
}

body > header h1 {
    margin: 0;
    font-size: 1.3rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #fff;
}

nav ul {
    display: flex;
    gap: 6px;
    margin: 0;
    padding: 0;
    list-style: none;
}

nav a {
    display: block;
    padding: 8px 14px;
    border-radius: 999px;
    color: #dbe6f1;
    font-weight: 500;
    transition: background 0.2s, color 0.2s;
}

nav a:hover,
nav a[aria-current="page"] {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    text-decoration: none;
}

/* ===== Main ===== */
main {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 32px 16px 48px;
}

main > h1 {
    margin-top: 0;
    font-size: 2.2rem;
}

main > p {
    color: var(--color-muted);
}

section,
article {
    margin-bottom: 24px;
    padding: 24px 28px;
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

section h2,
article h2 {
    margin-top: 0;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--color-border);
}

section section,
section article {
    padding: 0;
    margin-bottom: 16px;
    box-shadow: none;
    background: none;
}

/* ===== Hero (Inicio) ===== */
.hero {
    display: flex;
    align-items: center;
    gap: 32px;
    padding: 32px;
    color: #fff;
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
}

.hero figure {
    flex-shrink: 0;
    margin: 0;
    text-align: center;
}

.hero img {
    width: 200px;
    height: 200px;
    object-fit: cover;
    object-position: center 25%;
    border-radius: 50%;
    border: 5px solid rgba(255, 255, 255, 0.85);
}

.hero figcaption {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
}

.hero h1 {
    margin: 0 0 4px;
    font-size: 2.4rem;
    color: #fff;
}

.hero p {
    margin: 0 0 6px;
    color: #c9d7e6;
}

.hero .role {
    font-size: 1.15rem;
    font-weight: 500;
    color: #fff;
}

/* ===== Listas ===== */
.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0;
    list-style: none;
}

.tags li {
    padding: 6px 14px;
    border-radius: 999px;
    background: #e8f0f9;
    color: var(--color-primary);
    font-size: 0.92rem;
    font-weight: 500;
}

/* ===== Timeline (experiencia / formación) ===== */
.timeline {
    margin: 0;
    padding: 0 0 0 20px;
    list-style: none;
    border-left: 2px solid var(--color-border);
}

.timeline > li {
    position: relative;
    padding: 0 0 20px 16px;
}

.timeline > li::before {
    content: "";
    position: absolute;
    left: -28px;
    top: 6px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--color-accent);
    border: 2px solid var(--color-surface);
}

.timeline h3 {
    margin: 0;
    font-size: 1.05rem;
}

.timeline .meta {
    margin: 2px 0 6px;
    font-size: 0.9rem;
    color: var(--color-muted);
}

.timeline ul {
    margin: 6px 0 0;
    padding-left: 18px;
}

/* ===== Proyectos ===== */
article header {
    margin-bottom: 8px;
}

article figure {
    margin: 16px 0 0;
}

article figure img {
    border-radius: 8px;
    border: 1px solid var(--color-border);
}

.game iframe {
    display: block;
    width: min(100%, 360px);
    aspect-ratio: 412 / 846;
    margin: 0 auto;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: #000;
}

figcaption {
    margin-top: 6px;
    font-size: 0.88rem;
    color: var(--color-muted);
    text-align: center;
}

/* ===== Formulario ===== */
form {
    display: grid;
    gap: 16px;
    margin-bottom: 24px;
    padding: 24px 28px;
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    color: var(--color-primary);
}

input,
textarea {
    width: 100%;
    padding: 10px 12px;
    font: inherit;
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: #fafbfc;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus,
textarea:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(61, 139, 217, 0.2);
}

button {
    justify-self: start;
    padding: 12px 28px;
    font: inherit;
    font-weight: 600;
    color: #fff;
    background: var(--color-primary);
    border: none;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.2s;
}

button:hover {
    background: var(--color-accent);
}

.contact-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 290px), 1fr));
    gap: 16px;
}

.contact-grid > div {
    padding: 14px 16px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
}

.contact-grid h3 {
    margin: 0 0 4px;
    font-size: 0.95rem;
}

.contact-grid p {
    margin: 0;
    white-space: nowrap;
    overflow-wrap: normal;
}

.honeypot {
    display: none;
}

/* ===== Footer ===== */
footer {
    padding: 24px 16px;
    text-align: center;
    color: #c9d7e6;
    background: var(--color-primary-dark);
}

footer p {
    margin: 0 0 10px;
    font-size: 0.9rem;
}

footer ol {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 20px;
    margin: 0;
    padding: 0;
    list-style: none;
}

footer a {
    color: #fff;
    font-weight: 500;
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
    body > header {
        justify-content: center;
    }

    .hero {
        flex-direction: column;
        text-align: center;
        padding: 24px 16px;
    }

    .hero img {
        width: 160px;
        height: 160px;
        margin: 0 auto;
    }

    .hero h1 {
        font-size: 1.9rem;
    }

    section,
    article,
    form {
        padding: 20px 16px;
    }
}

/* ===== Repositorios ===== */
.repo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
    margin-top: 16px;
}

.repo-grid > div {
    padding: 16px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.repo-grid > div:hover {
    border-color: var(--color-accent);
    box-shadow: var(--shadow);
}

.repo-grid h3 {
    margin: 0 0 6px;
    font-size: 1rem;
}

.repo-grid p {
    margin: 0 0 8px;
    font-size: 0.92rem;
}

.repo-grid .stack {
    margin: 0;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--color-muted);
}

/* ===== Galería de juegos ===== */
.games-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    margin-top: 16px;
}

.games-grid figure {
    margin: 0;
    overflow: hidden;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.games-grid figure:hover {
    border-color: var(--color-accent);
    box-shadow: var(--shadow);
}

.games-grid img {
    width: 100%;
    aspect-ratio: 16 / 10;
    object-fit: cover;
    border: none;
    border-radius: 0;
}

.games-grid figcaption {
    margin: 0;
    padding: 10px 12px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-primary);
    text-align: left;
}

.games-grid figure {
    cursor: zoom-in;
}

.games-grid figure:focus-visible {
    outline: 3px solid var(--color-accent);
    outline-offset: 2px;
}

/* ===== Lightbox ===== */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(10, 20, 32, 0.85);
    cursor: zoom-out;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.lightbox[hidden] {
    display: none;
}

.lightbox:focus {
    outline: none;
}

.lightbox figure {
    margin: 0;
    transform: scale(0.85);
    transition: transform 0.25s ease;
}

.lightbox img {
    width: min(90vw, 82vh * var(--ratio, 1.7));
    height: auto;
    max-height: 82vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.lightbox figcaption {
    margin-top: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    color: #fff;
}

.lightbox.is-open {
    opacity: 1;
}

.lightbox.is-open figure {
    transform: scale(1);
}

body.no-scroll {
    overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
    .lightbox,
    .lightbox figure {
        transition: none;
    }
}

/* ===== Selector de idioma ===== */
.lang-switch {
    display: flex;
    gap: 6px;
}

.lang-switch button {
    display: flex;
    padding: 2px;
    background: none;
    border: 2px solid transparent;
    border-radius: 50%;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s, border-color 0.2s, transform 0.2s;
}

.lang-switch button:hover {
    background: none;
    opacity: 1;
    transform: scale(1.08);
}

.lang-switch button:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.lang-switch button[aria-pressed="true"] {
    border-color: #fff;
    opacity: 1;
}

.lang-switch img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35);
}

/* Mientras se aplica un idioma guardado distinto del español */
.i18n-pending body {
    visibility: hidden;
}

/* ===== Pie de página siempre abajo (páginas cortas, como Contacto) ===== */
body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

main {
    flex: 1 0 auto;
    width: 100%;
}

/* ===== "Mi Portfolio" enlaza a la página de inicio ===== */
body > header h1 a {
    color: inherit;
    text-decoration: none;
}

/* ===== Iconos ===== */
.icon {
    display: inline-block;
    flex-shrink: 0;
    width: 18px;
    height: 18px;
}

.flag {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    box-shadow: 0 0 0 1px var(--color-border);
}

section h2 {
    display: flex;
    align-items: center;
    gap: 10px;
}

.h-icon {
    width: 24px;
    height: 24px;
}

.tags li {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.tags li .icon + .icon {
    margin-left: -4px;
}

.hero .location {
    display: flex;
    align-items: center;
    gap: 6px;
}

.hero .location .icon {
    width: 16px;
    height: 16px;
}

.timeline .meta {
    display: flex;
    align-items: center;
    gap: 6px;
}

.timeline .meta .icon {
    width: 14px;
    height: 14px;
}

/* Logotipo de la empresa o del centro a la izquierda de cada entrada */
.timeline > li.org {
    display: grid;
    grid-template-columns: 40px 1fr;
    column-gap: 14px;
}

.timeline > li.org > * {
    grid-column: 2;
}

.timeline > li.org > .org-logo {
    grid-column: 1;
    grid-row: 1 / span 2;
    align-self: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 1px solid var(--color-border);
    background: #fff;
    object-fit: cover;
}

.contact-grid h3 {
    display: flex;
    align-items: center;
    gap: 8px;
}

.phone-line {
    display: flex;
    align-items: center;
    gap: 12px;
}

.phone-line a:first-child {
    color: inherit;
}

.icon-link {
    display: inline-flex;
    transition: transform 0.2s;
}

.icon-link:hover {
    transform: scale(1.12);
}

.icon-link .icon {
    width: 22px;
    height: 22px;
}

footer a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

@media (max-width: 640px) {
    .hero .location {
        justify-content: center;
    }
}

/* ===== Estado del envío del formulario ===== */
.form-status {
    margin: 0;
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 0.95rem;
}

.form-status.is-sending {
    color: var(--color-primary);
    background: #e8f0f9;
}

.form-status.is-success {
    color: #1e6b3a;
    background: #e6f4ea;
}

.form-status.is-error {
    color: #9b2226;
    background: #fdecec;
}

.form-status a {
    color: inherit;
    font-weight: 600;
    text-decoration: underline;
}

button.is-sending {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: wait;
    opacity: 0.85;
}

button.is-sending::before {
    content: "";
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    button.is-sending::before {
        animation-duration: 2.4s;
    }
}
