@font-face {
    font-family: "Edosz";
    src: url("../fonts/edosz.ttf") format("truetype");
    font-display: swap;
}

@font-face {
    font-family: "TojoCaptioner";
    src: url("../fonts/TheTojoCaptioner-Regular.ttf") format("truetype");
    font-display: swap;
}

/* ---------- Global defaults ---------- */

:root {
    color-scheme: dark;

    --color-background: #000000;
    --color-surface: #151515;
    --color-text: #f2f2f2;
    --color-muted: #aaa;
    --color-accent: #7d4071;

    --font-heading: "Edosz", serif;
    --font-body: "TojoCaptioner", sans-serif;

    --page-padding: clamp(1rem, 3vw, 3rem);
    --card-gap: clamp(0.75rem, 2vw, 1.75rem);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--color-background);
}

body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;



    color: var(--color-text);
    font-family: var(--font-body);
}

/* ---------- Main homepage container ---------- */

.archive-home {
    display: flex;
    flex-direction: column;
    align-items: center;

    width: 100%;
    min-height: 100vh;
    padding: var(--page-padding);

    overflow: hidden;
}

/* ---------- Archive heading ---------- */

.archive-header {
    position: relative;
    z-index: 1;

    display: flex;
    flex-direction: column;
    align-items: center;

    width: 100%;
    margin: 0 0 clamp(1.5rem, 4vh, 3rem);

    text-align: center;
}

.archive-title {
    width: min(100%, 42rem);
    margin: 0;
    line-height: 0;
}

.archive-subtitle {
    margin: 0.55rem 0 0;

    color: var(--color-muted);
    font-family: var(--font-body);
    font-size: clamp(0.9rem, 1.5vw, 1.15rem);
    text-align: center;

    opacity: 0;
    visibility: hidden;
    transition: opacity 900ms ease;
}

.archive-subtitle.is-visible {
    opacity: 1;
    visibility: visible;
}

@media (prefers-reduced-motion: reduce) {
    .archive-subtitle {
        transition: none;
    }
}

/* ---------- Four-cover selection layout ---------- */

.arc-selection {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: start;

    width: 100%;
    max-width: 1500px;
    margin: auto 0;

    gap: var(--card-gap);
}

/* ---------- Individual arc cards ---------- */

.arc-card {
    position: relative;
    min-width: 0;
    margin: 0;
}

.arc-link {
    position: relative;

    display: block;
    width: 100%;
    aspect-ratio: 2 / 3;

    overflow: hidden;
    isolation: isolate;

    background: var(--color-surface);
    border: 1px solid rgb(255 255 255 / 12%);
    border-radius: 3px;

    color: inherit;
    text-decoration: none;

    box-shadow:
        0 8px 24px rgb(0 0 0 / 35%),
        0 0 0 0 rgb(125 64 113 / 0%);

    transition:
        transform 220ms ease,
        border-color 220ms ease,
        box-shadow 220ms ease;
}

/* Cover image */

.arc-cover {
    position: absolute;
    inset: 0;
    z-index: -2;

    display: block;
    width: 100%;
    height: 100%;

    object-fit: cover;
    object-position: center;

    opacity: 1;

    transition:
        transform 350ms ease,
        filter 350ms ease;
}

/* Dark gradient keeps the arc title readable. */

.arc-link::after {
    position: absolute;
    inset: 0;
    z-index: -1;

    content: "";

    background: linear-gradient(
        to bottom,
        rgb(0 0 0 / 0%) 45%,
        rgb(0 0 0 / 20%) 62%,
        rgb(0 0 0 / 88%) 100%
    );

    pointer-events: none;
}

/* ---------- Arc titles ---------- */

.arc-title {
    position: absolute;
    right: 0.5rem;
    bottom: clamp(0.75rem, 2vw, 1.5rem);
    left: 0.5rem;

    margin: 0;
    padding: 0.5rem 0.25rem;

    font-family: var(--font-heading);
    font-size: clamp(1rem, 2vw, 1.8rem);
    font-weight: normal;
    line-height: 1.15;
    text-align: center;

    color: #fff;
    overflow-wrap: anywhere;

    text-shadow:
        0 2px 5px rgb(0 0 0 / 90%),
        0 0 14px rgb(0 0 0 / 70%);

    pointer-events: none;
}

/* ---------- Hover and keyboard interaction ---------- */

@media (hover: hover) and (pointer: fine) {
    .arc-link:hover {
        z-index: 2;

        transform: translateY(-6px);
        border-color: rgb(255 255 255 / 45%);

        box-shadow:
            0 16px 32px rgb(0 0 0 / 55%),
            0 0 18px rgb(181 31 43 / 12%);
    }

    .arc-link:hover .arc-cover {
        transform: scale(1.035);
    }
}

.arc-link:focus-visible {
    z-index: 3;

    outline: 3px solid var(--color-accent);
    outline-offset: 5px;
}

/* ---------- Selection state for JavaScript ---------- */

/*
   JavaScript can add .is-selected to the selected .arc-card.
   The flashing animation itself will be defined in
   animations.css and triggered by JavaScript.
*/

.arc-card.is-selected {
    z-index: 4;
}

.arc-card.is-selected .arc-link {
    border-color: var(--color-accent);
}

/* ---------- Medium screens ---------- */

@media (max-width: 900px) {
    .archive-home {
        padding: 1.5rem;
    }

    .archive-header {
        margin-bottom: 2rem;
    }

    .arc-selection {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        max-width: 680px;
        gap: 1.5rem;
    }

    .arc-title {
        font-size: clamp(1.2rem, 3vw, 1.8rem);
    }
}


/* ---------- Credits button ---------- */

.archive-footer {
    display: flex;
    justify-content: center;
    width: 100%;
    margin-top: clamp(2rem, 5vw, 4rem);
    padding: 0 1rem clamp(2rem, 4vw, 3rem);
}

.credits-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    padding: 14px 42px;

    border: 2px solid #333;
    background: #181818;
    color: #fff;

    font-family: var(--font-body);
    font-size: 24px;
    text-align: center;
    text-decoration: none;
    text-transform: uppercase;

    cursor: pointer;

    transition:
        background-color 160ms ease,
        border-color 160ms ease;
}

.credits-link:hover,
.credits-link:focus-visible {
    background: #353535;
    border-color: #888;
}

.credits-link:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 4px;
}


/* ---------- Small screens ---------- */

@media (max-width: 480px) {
    .archive-home {
        padding: 1rem;
    }

    .archive-title {
        font-size: clamp(2rem, 10vw, 3rem);
    }

    .archive-subtitle {
        font-size: 0.85rem;
        letter-spacing: 0.08em;
    }

    .arc-selection {
        gap: 0.85rem;
    }

    .arc-link {
        border-radius: 2px;
    }

    .arc-title {
        right: 0.25rem;
        bottom: 0.5rem;
        left: 0.25rem;

        font-size: clamp(0.9rem, 4vw, 1.3rem);
    }
}

/* ---------- Reduced motion accessibility ---------- */

@media (prefers-reduced-motion: reduce) {
    .arc-link,
    .arc-cover {
        transition: none;
    }
}


/* ---------- Chapter selection layout ---------- */

.arc-selection {
    transition:
        grid-template-columns 450ms ease,
        gap 450ms ease;
}

/* Keep only the chosen arc visible. */
.arc-selection.has-selection .arc-card:not(.is-selected) {
    display: none;
}

/* Selected cover stays on the left. */
.arc-selection.has-selection {
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
    align-items: center;
    gap: clamp(1.5rem, 5vw, 4rem);
}

.arc-selection.has-selection .arc-card.is-selected {
    grid-column: 1;
    width: 100%;
    max-width: 420px;
    justify-self: center;
}

/* ---------- Chapter menu ---------- */

.chapter-menu {
    grid-column: 2;
    align-self: center;

    display: flex;
    flex-direction: column;
    gap: 0.75rem;

    width: 100%;
    min-width: 0;
    max-height: min(65vh, 720px);
    overflow-y: auto;

    animation: chapter-menu-enter 350ms ease both;
}

.chapter-menu-title {
    margin: 0 0 0.5rem;

    font-family: var(--font-heading);
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    font-weight: normal;
}

.chapter-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.chapter-link,
.chapter-back {
    display: block;
    width: 100%;
    padding: 0.85rem 1rem;

    border: 1px solid rgb(255 255 255 / 22%);
    background: var(--color-surface);
    color: var(--color-text);

    font-family: var(--font-body);
    font-size: clamp(1rem, 1.5vw, 1.25rem);
    line-height: 1.4;
    text-align: left;
    text-decoration: none;

    cursor: pointer;

    transition:
        background-color 160ms ease,
        border-color 160ms ease;
}

.chapter-link:hover,
.chapter-link:focus-visible,
.chapter-back:hover,
.chapter-back:focus-visible {
    background: #292029;
    border-color: var(--color-accent);
}

.chapter-link:focus-visible,
.chapter-back:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 3px;
}

.chapter-link.is-interlude {
    padding-left: 1.5rem;
    border-left: 3px solid var(--color-accent);
    color: #d6c4d2;
}

.chapter-back {
    margin-top: 0.5rem;
    text-align: center;
}

.chapter-menu-message {
    margin: 0;
    color: var(--color-muted);
    font-size: 1.1rem;
}

@keyframes chapter-menu-enter {
    from {
        opacity: 0;
        transform: translateX(18px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ---------- Responsive chapter selection ---------- */

@media (max-width: 900px) {
    .arc-selection.has-selection {
        grid-template-columns: minmax(0, 0.75fr) minmax(0, 1.25fr);
        gap: 1.25rem;
    }

    .arc-selection.has-selection .arc-card.is-selected {
        max-width: 320px;
    }

    .chapter-menu {
        max-height: 60vh;
    }
}

@media (max-width: 600px) {
    .arc-selection.has-selection {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 1.25rem;
        margin: 1.5rem 0;
    }

    .arc-selection.has-selection .arc-card.is-selected {
        width: min(55%, 220px);
        flex: none;
    }

    .chapter-menu {
        width: 100%;
        max-height: none;
        overflow: visible;
    }

    .chapter-menu-title {
        text-align: center;
    }

    .chapter-link,
    .chapter-back {
        padding: 0.75rem;
        font-size: 1rem;
    }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
    .arc-selection,
    .chapter-menu,
    .chapter-link,
    .chapter-back {
        transition: none;
        animation: none;
    }
}

/* Revealed after menu music begins; muting preserves the loop position. */
.menu-bgm-mute {
    position: fixed;
    top: max(1rem, env(safe-area-inset-top));
    left: max(1rem, env(safe-area-inset-left));
    z-index: 10;
    padding: 0.55rem 0.8rem;
    border: 1px solid var(--color-muted);
    background: rgba(0, 0, 0, 0.85);
    color: var(--color-text);
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 600ms ease, visibility 600ms;
}

.menu-bgm-mute.is-visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.menu-bgm-mute:hover {
    border-color: var(--color-accent);
}

.menu-bgm-mute:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 4px;
}

@media (prefers-reduced-motion: reduce) {
    .menu-bgm-mute {
        transition: none;
    }
}

/* Homepage artwork supplied by the author. */
body.home-page {
    background:
        linear-gradient(rgb(0 0 0 / 15%), rgb(0 0 0 / 30%)),
        url("../images/murasaki_everywhere_promo_bg.webp") center / cover no-repeat;
}

.archive-logo {
    display: block;
    width: 100%;
    height: auto;
    filter: drop-shadow(0 3px 8px rgb(0 0 0 / 65%));
}

body.home-page .archive-subtitle {
    color: #eee;
    text-shadow: 0 1px 4px rgb(0 0 0 / 80%);
}
