/*
 * Escrito a mano y sin build a proposito: la imagen de produccion no tiene Node, y el
 * CSS que un build compraba (anidamiento, capas, color-mix) ya lo resuelve el navegador.
 * Estila elementos antes que clases, asi las vistas siguen siendo HTML semantico.
 *
 * Blanco y tinta: el color lo ponen las portadas, que traen cada una el suyo, y la obra
 * esta pintada sobre papel blanco. El unico acento es el bermellon del sello, y solo en
 * el boton que hace avanzar la compra; si aparece en otro lado deja de senalar algo.
 * Solo modo claro por lo mismo: en oscuro las portadas y la obra quedarian como
 * rectangulos encendidos.
 */

@layer reset, base, components, pages;

@font-face {
    font-family: 'Cormorant Garamond';
    src: url('../fonts/cormorant-garamond.woff2') format('woff2');
    font-weight: 300 700;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Cormorant Garamond';
    src: url('../fonts/cormorant-garamond-italic.woff2') format('woff2');
    font-weight: 300 700;
    font-style: italic;
    font-display: swap;
}

@layer reset {
    *, *::before, *::after { box-sizing: border-box; }
    html { -webkit-text-size-adjust: 100%; }
    body, h1, h2, h3, p, ul, ol, figure { margin: 0; }
    img { display: block; max-width: 100%; height: auto; }
}

@layer base {
    :root {
        --paper: #ffffff;
        --ink: #0d0a0a;
        --ink-2: #4a4646;
        --ink-3: #6f6a6a;
        --line: #e6e3e1;
        --wash: #f6f4f2;
        --alert: #a3352b;
        --accent: #b5412b;
        --accent-hover: #9a3522;

        --font-title: 'Cormorant Garamond', 'Iowan Old Style', Georgia, serif;
        --font-body: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

        --width: 72rem;
        --narrow: 40rem;
        --gutter: clamp(1rem, 4vw, 3rem);
        --shadow-cover: 0 1px 2px rgb(13 10 10 / .08), 0 12px 28px -8px rgb(13 10 10 / .22);

        color-scheme: light;
    }

    body {
        min-height: 100vh;
        display: flex;
        flex-direction: column;
        background: var(--paper);
        color: var(--ink);
        font: 1.0625rem/1.7 var(--font-body);
    }

    main { flex: 1; }

    h1, h2, h3 {
        font-family: var(--font-title);
        font-weight: 500;
        line-height: 1.15;
        text-wrap: balance;
    }

    h1 { font-size: clamp(2.25rem, 5vw, 3.5rem); margin-bottom: .75rem; }
    h2 { font-size: clamp(1.6rem, 3vw, 2rem); margin-bottom: .5rem; }
    h3 { font-size: 1.4rem; }

    p { margin-bottom: 1rem; }
    p, li { text-wrap: pretty; }

    a { color: inherit; text-underline-offset: .2em; text-decoration-thickness: 1px; }
    a:hover { color: var(--ink-2); }

    small { color: var(--ink-3); }

    :focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
}

@layer components {
    /* Rotulo: mayusculas chicas y espaciadas, para lo que ordena y no se lee. */
    .label {
        font: 500 .75rem/1.4 var(--font-body);
        letter-spacing: .12em;
        text-transform: uppercase;
        color: var(--ink-3);
    }

    .lead { font-size: 1.125rem; color: var(--ink-2); max-width: var(--narrow); }
    .meta { color: var(--ink-3); font-size: .95rem; }
    /* Cormorant trae numeros de estilo antiguo; en precios y datos se leen desparejos. */
    .price, .specs strong { font-variant-numeric: lining-nums; }
    .price { font-family: var(--font-title); font-weight: 600; font-size: 1.6rem; line-height: 1.2; }

    .narrow {
        width: 100%;
        max-width: calc(var(--narrow) + 2 * var(--gutter));
        margin: 0 auto;
        padding: clamp(2rem, 6vw, 4.5rem) var(--gutter) 4rem;
    }

    .narrow > .label { display: block; margin-bottom: .5rem; }

    .prose > * + * { margin-top: 1rem; }
    .prose p { margin-bottom: 0; }
    .prose ul, .prose ol { padding-left: 1.2rem; }
    .prose li + li { margin-top: .25rem; }

    /* Cabecera y pie */

    .site-header {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: .75rem 2rem;
        width: 100%;
        max-width: var(--width);
        margin: 0 auto;
        padding: 1.25rem var(--gutter);
    }

    .brand img { height: 2.25rem; width: auto; }

    @media (min-width: 48rem) {
        .brand img { height: 3.25rem; }
    }

    .site-header nav { display: flex; gap: 1.5rem; margin-left: auto; }
    .site-header nav a { text-decoration: none; }
    .site-header nav a:hover { color: var(--ink); }

    .country label { display: flex; align-items: center; gap: .5rem; margin: 0; font-size: .85rem; font-weight: 400; color: var(--ink-3); }
    .country select { width: auto; margin: 0; padding: .3rem .5rem; }

    .site-footer {
        width: 100%;
        max-width: var(--width);
        margin: 0 auto;
        padding: 2.5rem var(--gutter) 3rem;
        border-top: 1px solid var(--line);
        color: var(--ink-3);
        font-size: .9rem;
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        gap: .5rem 2rem;
    }

    .site-footer p { margin: 0; }

    /* Portada de un producto: un objeto sobre el papel, no una foto mas. */

    .cover img, .cover-fallback { width: 100%; box-shadow: var(--shadow-cover); }

    .cover-fallback {
        aspect-ratio: 5 / 7;
        display: grid;
        place-items: center;
        padding: 1.5rem;
        background: var(--wash);
        font: 500 1.5rem/1.2 var(--font-title);
        text-align: center;
    }

    /* Tarjetas: las de curso, que no cambian en esta etapa */

    .cards {
        list-style: none;
        margin: 1.5rem 0 0;
        padding: 0;
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr));
        gap: 1rem;
    }

    .card {
        border: 1px solid var(--line);
        padding: 1.5rem;
        margin-top: 1rem;
    }

    .cards .card { margin-top: 0; display: flex; flex-direction: column; }
    .cards .card > .button { margin-top: auto; align-self: flex-start; }
    .card h2 a { text-decoration: none; }

    /* Formularios */

    label { display: block; margin: 0 0 1rem; font-weight: 500; }

    input[type='email'], input[type='text'], select {
        display: block;
        width: 100%;
        margin-top: .35rem;
        padding: .7rem .8rem;
        font: inherit;
        color: var(--ink);
        background: var(--paper);
        border: 1px solid #cfcac6;
        border-radius: 2px;
    }

    label.checkbox { display: flex; gap: .6rem; align-items: center; font-weight: 400; }

    details { margin: 0 0 1rem; }
    summary { cursor: pointer; color: var(--ink-2); }
    details[open] summary { margin-bottom: .75rem; }

    button, .button {
        display: inline-block;
        padding: 1rem 1.75rem;
        font: 600 .95rem/1 var(--font-body);
        letter-spacing: .03em;
        color: var(--paper);
        background: var(--accent);
        border: 1px solid var(--accent);
        border-radius: 0;
        text-decoration: none;
        cursor: pointer;
    }

    button:hover, .button:hover { color: var(--paper); background: var(--accent-hover); border-color: var(--accent-hover); }

    .button.secondary { background: transparent; color: var(--ink); border-color: var(--ink); }
    .button.secondary:hover { background: var(--wash); color: var(--ink); border-color: var(--ink); }

    button.link {
        padding: 0;
        background: none;
        border: 0;
        color: inherit;
        font-weight: 400;
        letter-spacing: 0;
        text-decoration: underline;
        text-underline-offset: .2em;
    }

    button.link:hover { background: none; color: inherit; opacity: .75; }

    .field-error { color: var(--alert); margin-top: -.5rem; }

    /* Avisos */

    .notice {
        width: calc(100% - 2 * var(--gutter));
        max-width: var(--width);
        margin: 1rem auto;
        padding: .9rem 1.1rem;
        border-left: 2px solid var(--ink);
        background: var(--wash);
    }

    .narrow .notice { width: 100%; }
    .notice.error { border-left-color: var(--alert); }
    .notice ul { margin: 0 0 1rem; padding-left: 1.25rem; }
    .notice > :last-child { margin-bottom: 0; }

    /*
     * Lista de productos con portada chica: el resumen del checkout y la biblioteca de
     * mis accesos. La portada ancla la fila; sin ella (un curso) el texto toma su lugar.
     */

    .lines { list-style: none; margin: 1.5rem 0 0; padding: 0; border-top: 1px solid var(--line); }

    .lines li {
        display: grid;
        grid-template-columns: 4.5rem minmax(0, 1fr) auto;
        gap: 0 1.25rem;
        align-items: start;
        padding: 1.25rem 0;
        border-bottom: 1px solid var(--line);
    }

    .lines li:not(:has(.cover)) > div { grid-column: 1 / 3; }

    /* Todas a 3:4 y del mismo ancho, como en el estante: lado a lado, las proporciones
       distintas de cada portada se ven como libros de tamanos distintos. */
    .lines .cover { width: 4.5rem; aspect-ratio: 3 / 4; }
    .lines .cover img, .lines .cover-fallback { width: 100%; height: 100%; aspect-ratio: auto; object-fit: cover; }
    .lines .cover-fallback { padding: .25rem; font-size: .7rem; }
    .lines strong { display: block; font: 500 1.3rem/1.25 var(--font-title); }
    .lines small { display: block; margin-top: .2rem; font-size: .85rem; }
    .lines form { margin-top: .4rem; }
    .lines button.link { font-size: .85rem; color: var(--ink-3); }
    .lines .price { font: 400 1rem/1.7 var(--font-body); font-variant-numeric: lining-nums; }
    .lines p { margin: .75rem 0 0; }

    .library li { grid-template-columns: 4.5rem minmax(0, 1fr); }
    .library .button { margin-top: 1rem; padding: .8rem 1.4rem; }

    /* Indice plegable de la ficha */

    details.toc { border-block: 1px solid var(--line); padding: 1rem 0; margin: 2rem 0 0; }
    details.toc summary { list-style: none; display: flex; justify-content: space-between; color: var(--ink); }
    details.toc summary::-webkit-details-marker { display: none; }
    details.toc summary::after { content: '+'; font-size: 1.1rem; line-height: 1; }
    details.toc[open] summary::after { content: '−'; }
    details.toc ol, details.toc ul { color: var(--ink-2); margin: 0; padding-left: 1.25rem; }

    /*
     * La barra de seleccion: persistente, abajo, en tinta para que no se confunda con
     * la pagina. En el telefono no tapa el contenido porque es sticky, no fixed.
     */

    .selection-bar {
        position: sticky;
        bottom: 0;
        display: flex;
        flex-wrap: wrap;
        align-items: flex-start;
        gap: .75rem 1.5rem;
        padding: .9rem var(--gutter);
        background: var(--ink);
        color: var(--paper);
    }

    .selection-bar details { flex: 1; min-width: 14rem; margin: 0; }
    .selection-bar summary { display: flex; gap: .75rem; flex-wrap: wrap; align-items: baseline; color: var(--paper); }
    .selection-bar summary span { color: #c9c4c0; }

    /* El flex se come el triangulo del summary; sin una pista no se sabe que se despliega. */
    .selection-bar summary::after { content: 'Ver detalle'; color: #c9c4c0; text-decoration: underline; text-underline-offset: .2em; }
    .selection-bar details[open] summary::after { content: 'Ocultar'; }

    .selection-bar ul { list-style: none; margin: 0; padding: 0; }

    .selection-bar li {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        gap: .25rem 1rem;
        padding: .6rem 0;
        border-top: 1px solid #3a3434;
    }

    .selection-bar li > span:first-child { flex: 1; min-width: 10rem; }
    .selection-bar li small { display: block; color: #c9c4c0; }
    .selection-bar form { margin: 0; }
    .selection-bar .button { padding: .8rem 1.4rem; }
}

@layer pages {
    /* Home: la obra arriba, vertical en el telefono y horizontal en escritorio */

    .hero img { width: 100%; aspect-ratio: 4 / 5; object-fit: cover; }

    @media (min-width: 48rem) {
        .hero img { aspect-ratio: 21 / 9; }
    }

    .hero figcaption {
        max-width: var(--width);
        margin: .5rem auto 0;
        padding: 0 var(--gutter);
        color: var(--ink-3);
        font-size: .8rem;
    }

    .intro {
        max-width: var(--width);
        margin: 0 auto;
        padding: clamp(2.5rem, 8vw, 6rem) var(--gutter) 0;
        display: grid;
        gap: 1.5rem 4rem;
    }

    @media (min-width: 48rem) {
        .intro { grid-template-columns: 1fr 1.3fr; }
    }

    .intro h1 { font-size: clamp(2.1rem, 4.5vw, 3.25rem); line-height: 1.15; margin: .75rem 0 0; }
    .intro p { color: var(--ink-2); max-width: 36rem; }
    .intro p:last-child { color: var(--ink); }

    .shelf {
        max-width: var(--width);
        margin: 0 auto;
        padding: clamp(3rem, 9vw, 7rem) var(--gutter);
    }

    .shelf > .label { display: block; padding-bottom: 1rem; border-bottom: 1px solid var(--line); margin-bottom: 2.5rem; }
    .shelf + .shelf { padding-top: 0; }

    /* Seis libros: dos columnas en el telefono y tres en escritorio, filas parejas. */
    .books {
        list-style: none;
        margin: 0;
        padding: 0;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 2.5rem 1rem;
    }

    /*
     * Las portadas vienen con proporciones distintas (de 0,72 a 0,80) y lado a lado se
     * ven de tamanos distintos. En el estante van todas a 3:4: el recorte es de 3% por
     * lado como mucho, y no toca titulo, logo ni autora en ninguna. La ficha muestra la
     * portada entera.
     */
    .book .cover img, .book .cover-fallback { aspect-ratio: 3 / 4; object-fit: cover; }

    @media (min-width: 48rem) {
        .books { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4.5rem 3rem; }
    }

    .book a { display: block; text-decoration: none; }
    .book a:hover { color: inherit; }
    .book .cover img, .book .cover-fallback { transition: transform .3s; }
    .book a:hover .cover img, .book a:hover .cover-fallback { transform: translateY(-4px); }
    .book h2 { font-size: clamp(1.15rem, 2.4vw, 1.4rem); line-height: 1.25; margin: 1.25rem 0 .15rem; }
    .book .subtitle { color: var(--ink-2); font-style: italic; margin: 0; }
    .book .facts { color: var(--ink-3); font-size: .85rem; margin: .5rem 0 0; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0 1rem; }
    .book .facts .price { color: var(--ink); font: 400 1rem/1.7 var(--font-body); font-variant-numeric: lining-nums; }

    @media (max-width: 47.99rem) {
        .book .facts { flex-direction: column; }
    }

    /* Ficha del ebook: portada fija a la izquierda en escritorio */

    .product {
        max-width: var(--width);
        margin: 0 auto;
        padding: clamp(1.5rem, 5vw, 4rem) var(--gutter) 5rem;
        display: grid;
        gap: 2.5rem 4rem;
    }

    @media (min-width: 48rem) {
        .product { grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); align-items: start; }
        .product > .cover { position: sticky; top: 2rem; }
    }

    .product h1 { margin: .5rem 0 .25rem; line-height: 1.05; }
    .product .subtitle { color: var(--ink-2); font-family: var(--font-title); font-style: italic; font-size: 1.35rem; margin: 0 0 1.75rem; }

    .buy { padding: 1.25rem 0; border-block: 1px solid var(--line); margin-bottom: 2rem; }
    .buy .price { font-size: 2rem; margin-bottom: 1rem; }
    .buy details { margin: 0 0 1.25rem; }
    .buy .meta { margin: 1rem 0 0; font-size: .875rem; }

    .specs { list-style: none; margin: 0 0 2rem; padding: 0; display: flex; flex-wrap: wrap; gap: 1rem 2.5rem; }
    .specs li { border-left: 1px solid var(--line); padding-left: .75rem; }
    .specs strong { display: block; font: 500 1.6rem/1.2 var(--font-title); font-variant-numeric: lining-nums; }
    .specs span { color: var(--ink-3); font-size: .8rem; }

    .product .prose { color: var(--ink-2); }

    /*
     * Checkout: el resumen y el pago, uno debajo del otro en el telefono y lado a lado
     * en escritorio, con el formulario a la derecha a la altura del titulo de la lista.
     */

    .checkout {
        max-width: var(--width);
        margin: 0 auto;
        padding: clamp(2rem, 6vw, 4.5rem) var(--gutter) 5rem;
        display: grid;
        gap: 0 4rem;
    }

    .checkout > header .label { display: block; margin-bottom: .5rem; }
    .checkout .notice { width: 100%; margin: 1rem 0; }

    @media (min-width: 48rem) {
        .checkout { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
        .checkout > header, .checkout > .notice { grid-column: 1 / -1; }
        .checkout .pay { position: sticky; top: 2rem; margin-top: 1.5rem; }
    }

    .total {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        margin: 1.25rem 0 1.5rem;
    }

    .total .price { font-size: 2rem; }

    .pay { padding: 1.5rem; background: var(--wash); align-self: start; }
    .pay button { width: 100%; margin-top: .5rem; }
    .pay .meta { font-size: .875rem; }
}
