/* Branching Chinese stories (/games/adventure) — growth plan D81.
   The word, ruby and popup styling is shared with the linear graded readers and lives in
   stories.css; this file is only the branching parts: the node reveal, the choice buttons, the
   path trail and the endings board. */

/* ---------- Hub cards ---------- */
.adv-card {
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.adv-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 0.6rem 1.4rem rgba(0, 0, 0, 0.14) !important;
}

.adv-card-zh {
    font-size: 1.5rem;
    line-height: 1.3;
}

/* ---------- The reader ---------- */

/* Every branch of the story is in this document; the browser shows one node at a time.
   With JavaScript off nothing would ever be revealed, so the noscript rule in the page
   overrides this and prints the whole story as one long document instead. */
.adv-node[hidden] {
    display: none;
}

.adv-node {
    animation: adv-node-in 0.32s ease both;
    /* adventure.js scrolls the revealed node to the top of the viewport when it is not already
       in view; without this the first line sits flush against the edge of the screen. */
    scroll-margin-top: 0.75rem;
}

@keyframes adv-node-in {
    from {
        opacity: 0;
        transform: translateY(0.75rem);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

/* Lines arrive one after another, which is what makes a scene feel read rather than dumped.
   --i is set on each line by the server, so the stagger costs no script. */
.adv-line {
    animation: adv-line-in 0.3s ease both;
    animation-delay: calc(var(--i, 0) * 90ms);
    padding: 0.55rem 0.2rem;
    border-bottom: 1px solid var(--bs-border-color, #dee2e6);
}

.adv-line:last-child {
    border-bottom: 0;
}

@keyframes adv-line-in {
    from {
        opacity: 0;
        transform: translateX(-0.5rem);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

/* Motion is decoration here; the reading is the content. */
@media (prefers-reduced-motion: reduce) {
    .adv-node,
    .adv-line,
    .adv-choice,
    .adv-burst span {
        animation: none !important;
        transition: none !important;
    }
}

.adv-zh {
    font-size: 1.65rem;
    line-height: 2.4;
}

.adv-nopinyin .st-word ruby rt {
    visibility: hidden;
}

.adv-en {
    font-size: 1rem;
    opacity: 0.8;
    padding-left: 0.2rem;
}

.adv-noenglish .adv-en,
.adv-noenglish .adv-choice-en {
    display: none;
}

.adv-audio-btn {
    min-width: 2.3rem;
}

/* ---------- Choices ---------- */
.adv-choices {
    display: grid;
    gap: 0.6rem;
}

.adv-choice {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.8rem 1rem;
    border-radius: 0.6rem;
    border: 2px solid var(--bs-primary, #0d6efd);
    background: transparent;
    color: inherit;
    transition: transform 0.12s ease, background-color 0.12s ease, box-shadow 0.12s ease;
    animation: adv-line-in 0.3s ease both;
    animation-delay: calc(var(--i, 0) * 90ms + 180ms);
}

.adv-choice:hover,
.adv-choice:focus-visible {
    background: rgba(13, 110, 253, 0.1);
    transform: translateX(0.25rem);
    box-shadow: 0 0.35rem 0.9rem rgba(13, 110, 253, 0.18);
}

.adv-choice:active {
    transform: scale(0.99);
}

.adv-choice-zh {
    display: block;
    font-size: 1.3rem;
    line-height: 2.2;
}

.adv-choice-en {
    display: block;
    font-size: 0.9rem;
    opacity: 0.75;
}

.adv-choice-mark {
    font-weight: 700;
    color: var(--bs-primary, #0d6efd);
    margin-right: 0.4rem;
}

/* ---------- Path trail and progress ---------- */
.adv-trail {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    min-height: 1.9rem;
}

.adv-trail-item {
    font-size: 0.8rem;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    background: var(--bs-secondary-bg, #e9ecef);
    color: var(--bs-body-color);
    max-width: 14rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    animation: adv-line-in 0.25s ease both;
}

.adv-depth {
    height: 0.4rem;
    border-radius: 999px;
    background: var(--bs-secondary-bg, #e9ecef);
    overflow: hidden;
}

.adv-depth span {
    display: block;
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--bs-primary, #0d6efd), var(--bs-info, #0dcaf0));
    transition: width 0.35s ease;
}

/* ---------- Endings ---------- */
.adv-ending-banner {
    border-radius: 0.7rem;
    padding: 1rem 1.1rem;
    margin-bottom: 1rem;
    position: relative;
    overflow: hidden;
}

.adv-ending-icon {
    font-size: 2.1rem;
    line-height: 1;
}

/* A short burst on the ending banner. Pure CSS: eight pieces, no library, no canvas. */
.adv-burst {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.adv-burst span {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 0.1rem;
    opacity: 0;
    animation: adv-burst 0.9s ease-out forwards;
}

.adv-burst span:nth-child(1) { background: #ffc107; animation-delay: 0.02s; --dx: -120px; --dy: -60px; }
.adv-burst span:nth-child(2) { background: #0dcaf0; animation-delay: 0.06s; --dx: 130px; --dy: -50px; }
.adv-burst span:nth-child(3) { background: #d63384; animation-delay: 0.10s; --dx: -90px; --dy: 55px; }
.adv-burst span:nth-child(4) { background: #198754; animation-delay: 0.14s; --dx: 100px; --dy: 60px; }
.adv-burst span:nth-child(5) { background: #fd7e14; animation-delay: 0.18s; --dx: -160px; --dy: 10px; }
.adv-burst span:nth-child(6) { background: #6f42c1; animation-delay: 0.22s; --dx: 165px; --dy: 5px; }
.adv-burst span:nth-child(7) { background: #20c997; animation-delay: 0.26s; --dx: -40px; --dy: -80px; }
.adv-burst span:nth-child(8) { background: #ffc107; animation-delay: 0.30s; --dx: 45px; --dy: 80px; }

@keyframes adv-burst {
    0% {
        opacity: 1;
        transform: translate(0, 0) rotate(0deg) scale(1);
    }

    100% {
        opacity: 0;
        transform: translate(var(--dx), var(--dy)) rotate(240deg) scale(0.4);
    }
}

.adv-ending-note {
    border-left: 3px solid var(--bs-warning, #ffc107);
    padding-left: 0.8rem;
}

/* The board of endings — the reason to read the story again. */
.adv-board {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
    gap: 0.6rem;
}

.adv-slot {
    border: 1px dashed var(--bs-border-color, #dee2e6);
    border-radius: 0.6rem;
    padding: 0.6rem;
    text-align: center;
    min-height: 5.4rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.15rem;
    transition: border-color 0.2s ease, background-color 0.2s ease, transform 0.2s ease;
}

.adv-slot .adv-slot-icon {
    font-size: 1.6rem;
    line-height: 1;
    filter: grayscale(1);
    opacity: 0.45;
}

.adv-slot .adv-slot-name {
    font-size: 0.85rem;
    font-weight: 600;
    opacity: 0.5;
}

.adv-slot .adv-slot-zh {
    font-size: 0.85rem;
    opacity: 0;
}

.adv-slot.is-found {
    border-style: solid;
    border-color: var(--bs-success, #198754);
    background: rgba(25, 135, 84, 0.08);
}

.adv-slot.is-found .adv-slot-icon {
    filter: none;
    opacity: 1;
}

.adv-slot.is-found .adv-slot-name {
    opacity: 1;
}

.adv-slot.is-found .adv-slot-zh {
    opacity: 0.75;
}

.adv-slot.is-new {
    animation: adv-pop 0.5s ease;
}

@keyframes adv-pop {
    0% { transform: scale(1); }
    45% { transform: scale(1.09); }
    100% { transform: scale(1); }
}

/* ---------- Key words ---------- */
.adv-keyword {
    font-size: 1.5rem;
    line-height: 2.1;
}

.adv-keyword ruby rt {
    font-size: 0.45em;
    opacity: 0.8;
}

@media (max-width: 575.98px) {
    .adv-zh {
        font-size: 1.4rem;
        line-height: 2.3;
    }

    .adv-choice-zh {
        font-size: 1.2rem;
    }
}
