:root {
    --ink: #171713;
    --muted: #6d6b62;
    --paper: #f4f1e9;
    --accent: #b95832;
    --line: rgba(23, 23, 19, 0.16);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: manipulation;
}

.login-shell,
.course-app,
.not-found-shell {
    animation: page-reveal 360ms ease-out both;
    transition: opacity 260ms ease, transform 260ms ease;
}

body.page-leaving .login-shell,
body.page-leaving .course-app,
body.page-leaving .not-found-shell {
    animation: none;
    opacity: 0;
    transform: translateY(6px);
}

@keyframes page-reveal {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

body {
    background: var(--paper);
    color: var(--ink);
    font-family: "DM Sans", sans-serif;
}

.login-shell {
    display: grid;
    grid-template-columns: minmax(390px, 43%) 1fr;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.login-panel {
    position: relative;
    z-index: 3;
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100%;
    overflow: hidden;
    padding: clamp(22px, 3.8vw, 60px);
    background:
        linear-gradient(rgba(23, 23, 19, 0.026) 1px, transparent 1px),
        linear-gradient(90deg, rgba(23, 23, 19, 0.026) 1px, transparent 1px),
        var(--paper);
    background-size: 32px 32px;
    background-position: -1px -1px;
    transform: translate3d(0, 0, 0);
    will-change: transform;
    transition: transform 650ms cubic-bezier(0.76, 0, 0.24, 1), box-shadow 650ms ease;
}

.login-shell.show-subjects .login-panel {
    transform: translate3d(-105%, 0, 0);
    box-shadow: 24px 0 60px rgba(23, 23, 19, 0.22);
}

.subjects-panel {
    --subjects-panel-padding: clamp(22px, 3.8vw, 60px);
    position: absolute;
    inset: 0 auto 0 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    width: 43%;
    min-width: 390px;
    height: 100%;
    padding: var(--subjects-panel-padding);
    overflow: hidden;
    background: #e8e2d6;
    opacity: 0;
    transform: translate3d(9%, 0, 0);
    will-change: opacity, transform;
    transition: opacity 650ms ease, transform 650ms cubic-bezier(0.76, 0, 0.24, 1);
}

.login-shell.show-subjects .subjects-panel {
    opacity: 1;
    transform: translate3d(0, 0, 0);
}

.login-shell.is-transitioning {
    pointer-events: none;
}

.subjects-header {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
}

.back-button {
    display: grid;
    width: 42px;
    height: 42px;
    padding: 0;
    place-items: center;
    border: 1px solid var(--ink);
    border-radius: 50%;
    background: transparent;
    color: var(--ink);
    font: inherit;
    font-size: 1.2rem;
    cursor: pointer;
    transition: background 180ms ease, color 180ms ease;
}

.back-button:hover,
.back-button:focus-visible {
    background: var(--ink);
    color: var(--paper);
}

.subjects-content {
    display: flex;
    min-height: 0;
    flex: 1 1 auto;
    flex-direction: column;
    width: 100%;
    margin: 0;
    padding: clamp(18px, 4vh, 42px) 0;
}

.subjects-content h2 {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin: 0;
    font-family: "Instrument Serif", Georgia, serif;
    font-size: clamp(3.1rem, min(5.4vw, 8vh), 6.2rem);
    font-weight: 400;
    letter-spacing: -0.04em;
    line-height: 0.9;
}

.subject-count {
    display: grid;
    width: 28px;
    height: 28px;
    place-items: center;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-family: "DM Sans", sans-serif;
    font-size: 0.68rem;
    letter-spacing: 0;
}

.subjects-intro {
    margin: 24px 0 28px;
    color: var(--muted);
    font-size: 0.9rem;
}

.subjects-list {
    width: calc(100% + var(--subjects-panel-padding));
    min-height: 0;
    flex: 1 1 auto;
    padding-right: var(--subjects-panel-padding);
    overflow-x: hidden;
    overflow-y: auto;
    border-top: 1px solid var(--ink);
    overscroll-behavior: contain;
    scrollbar-color: var(--accent) transparent;
    scrollbar-width: thin;
}

.subjects-list::-webkit-scrollbar {
    width: 6px;
}

.subjects-list::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: var(--accent);
}

.subject-button {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) auto;
    gap: 14px;
    align-items: center;
    min-height: 92px;
    padding: 16px 4px;
    border-bottom: 1px solid var(--line);
    color: var(--ink);
    cursor: pointer;
    transition: padding 180ms ease, background 180ms ease;
}

.subject-button:hover,
.subject-button.is-selected,
.subject-button:focus-within {
    padding-right: 12px;
    padding-left: 12px;
    background: rgba(255, 255, 255, 0.42);
}

.subject-number {
    color: var(--accent);
    font-size: 0.66rem;
    font-weight: 600;
    letter-spacing: 0.1em;
}

.subject-copy {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 6px;
}

.subject-copy strong {
    font-family: "Instrument Serif", Georgia, serif;
    font-size: clamp(1.25rem, 1.8vw, 1.75rem);
    font-weight: 400;
    line-height: 1.05;
}

.subject-title-link {
    width: fit-content;
    color: inherit;
    text-decoration: none;
}

.subject-title-link:visited {
    color: inherit;
}

.subject-title-link:hover,
.subject-title-link:focus-visible {
    color: var(--accent);
}

.subject-copy small {
    overflow: hidden;
    color: var(--muted);
    font-size: 0.7rem;
    line-height: 1.35;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.subject-action {
    display: grid;
    min-width: 46px;
    min-height: 46px;
    padding-left: 14px;
    place-items: center;
    border-left: 1px solid var(--line);
    color: var(--accent);
    font-size: 1.1rem;
    text-decoration: none;
    transition: background 180ms ease, color 180ms ease;
}

a.subject-action:visited {
    color: var(--accent);
}

a.subject-action:hover,
a.subject-action:focus-visible {
    background: var(--accent);
    color: #fff;
}

.subject-button.is-disabled {
    opacity: 0.48;
}

.subject-button.is-disabled .subject-action {
    color: var(--muted);
    font-family: "DM Sans", sans-serif;
    font-size: 0.58rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.subjects-footer {
    flex: 0 0 auto;
    margin: 0;
    padding-top: 16px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 0.65rem;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.brand-mark {
    display: flex;
    align-items: center;
    gap: 12px;
    width: fit-content;
    font-size: 0.92rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.brand-symbol {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border: 1px solid var(--ink);
    font-family: "Instrument Serif", serif;
    font-size: 1.45rem;
    font-weight: 400;
}

.brand-symbol img {
    display: block;
    width: 82%;
    height: 82%;
}

.welcome-block {
    width: min(100%, 580px);
    margin: auto 0;
    padding: clamp(24px, 7vh, 70px) 0;
}

.eyebrow {
    margin: 0 0 28px;
    color: var(--accent);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

h1 {
    margin: 0;
    font-family: "Instrument Serif", Georgia, serif;
    font-size: clamp(3rem, min(6.2vw, 10vh), 7.4rem);
    font-weight: 400;
    letter-spacing: -0.045em;
    line-height: 0.88;
}

h1 em {
    color: var(--accent);
    font-weight: 400;
}

.intro {
    max-width: 440px;
    margin: 34px 0 40px;
    color: var(--muted);
    font-size: clamp(0.95rem, 1.2vw, 1.08rem);
    line-height: 1.7;
}

.enter-button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: min(100%, 290px);
    padding: 18px 20px 18px 24px;
    border: 1px solid var(--ink);
    background: var(--ink);
    color: var(--paper);
    font-size: 0.84rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-decoration: none;
    text-transform: uppercase;
    cursor: pointer;
    transition: background 180ms ease, color 180ms ease, transform 180ms ease;
}

.enter-button:hover,
.enter-button:focus-visible {
    background: var(--accent);
    color: #fff;
    transform: translateY(-2px);
}

.enter-button:focus-visible {
    outline: 3px solid rgba(185, 88, 50, 0.28);
    outline-offset: 4px;
}

.button-arrow {
    font-size: 1.3rem;
    font-weight: 400;
}

.login-footer {
    display: flex;
    gap: 9px;
    padding-top: 20px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 0.72rem;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.author-link,
.author-link:visited {
    color: var(--accent);
    font-weight: 600;
    text-decoration: none;
}

.author-link:hover,
.author-link:focus-visible {
    text-decoration: underline;
    text-underline-offset: 4px;
}

.image-panel {
    position: relative;
    min-width: 0;
    height: 100%;
    overflow: hidden;
    background: #d8d3c9;
}

.image-panel img {
    width: 100%;
    height: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    filter: saturate(0.82) contrast(1.04);
    animation: imageReveal 900ms ease-out both;
    transition: opacity 280ms ease, transform 500ms ease;
}

.image-panel img.is-changing {
    opacity: 0.18;
    transform: scale(1.012);
}

.image-shade {
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, transparent 55%, rgba(18, 17, 13, 0.52));
    pointer-events: none;
}

.image-caption {
    position: absolute;
    right: clamp(24px, 5vw, 80px);
    bottom: clamp(28px, 5vw, 72px);
    width: min(78%, 720px);
    color: #fff;
    text-align: right;
    transition: opacity 220ms ease, transform 300ms ease;
}

.image-caption.is-changing {
    opacity: 0;
    transform: translateY(8px);
}

.caption-primary {
    max-width: 720px;
    margin: 0;
    font-family: "Instrument Serif", Georgia, serif;
    font-size: clamp(1.6rem, 2.5vw, 3rem);
    line-height: 1.05;
}

.caption-secondary {
    max-width: 520px;
    margin: 16px 0 0 auto;
    font-family: "DM Sans", sans-serif;
    font-size: clamp(0.72rem, 0.95vw, 0.9rem);
    font-weight: 500;
    letter-spacing: 0.02em;
    line-height: 1.55;
}

@keyframes imageReveal {
    from { opacity: 0; transform: scale(1.025); }
    to { opacity: 1; transform: scale(1); }
}

@media (max-width: 800px) {
    .login-shell {
        display: block;
    }

    .login-panel {
        width: 100%;
        height: 100%;
        padding: clamp(18px, 5vw, 32px);
    }

    .subjects-panel {
        --subjects-panel-padding: clamp(18px, 5vw, 32px);
        width: 100%;
        min-width: 0;
        padding: var(--subjects-panel-padding);
    }

    .image-panel {
        display: none;
    }

    .welcome-block {
        padding: 20px 0;
    }

    h1 {
        font-size: clamp(2.4rem, 9vw, 4.5rem);
    }

    .intro {
        margin: 22px 0 26px;
        font-size: 0.88rem;
        line-height: 1.5;
    }

    .image-caption {
        display: none;
    }
}

@media (max-width: 520px) {
    .login-shell {
        position: relative;
        display: block;
    }

    .login-panel {
        position: relative;
        z-index: 2;
        width: 100%;
        box-shadow: none;
    }

    .subjects-panel {
        z-index: 2;
        width: 100%;
        min-width: 0;
    }

    .subject-button {
        grid-template-columns: 26px minmax(0, 1fr) auto;
        min-height: 78px;
    }

    .subject-action {
        min-width: 40px;
        padding-left: 10px;
    }

    .brand-mark {
        font-size: 0.78rem;
    }

    .eyebrow {
        margin-bottom: 18px;
        font-size: 0.62rem;
    }

    h1 {
        font-size: clamp(2.6rem, 13vw, 4.1rem);
    }

    .login-footer {
        flex-direction: column;
        gap: 4px;
    }
}

@media (max-height: 650px) {
    .brand-symbol {
        width: 32px;
        height: 32px;
    }

    .welcome-block {
        padding: 12px 0;
    }

    .eyebrow {
        margin-bottom: 14px;
    }

    .intro {
        margin: 14px 0 18px;
        line-height: 1.35;
    }

    .enter-button {
        padding-top: 13px;
        padding-bottom: 13px;
    }

    .login-footer {
        padding-top: 12px;
    }

    .subjects-content {
        padding: 8px 0;
    }

    .subjects-intro {
        margin: 12px 0 14px;
    }

    .subject-button {
        min-height: 68px;
        padding-top: 8px;
        padding-bottom: 8px;
    }

    .subjects-footer {
        padding-top: 8px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    /* El cambio entre bienvenida e índice necesita conservar su relación
       espacial; se mantiene más corto que la animación normal. */
    .login-shell.is-transitioning .login-panel,
    .login-shell.is-transitioning .subjects-panel {
        transition-duration: 480ms !important;
    }
}
