#toast {
    position: fixed;
    top: 107px;
    left: 50%;
    transform: translateX(-50%) translateY(-10px);
    padding: 10px 20px;
    border: 1px solid #d1d9c7;
    border-radius: 6px;
    background: #fffdf4ec;
    opacity: 0;
    pointer-events: none;
    transition: 0.3s;
    font-size: 12px;
    z-index: 6;
    max-width: 90vw;
    text-align: center;
}

#toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

dialog {
    background: #fbfaf3;
    border: 1px solid #cdd7c6;
    border-radius: 15px;
    max-width: 620px;
    width: calc(100% - 36px);
    padding: 40px;
    color: var(--ink);
    box-shadow: 0 30px 100px #1c3d332d;
    max-height: 86vh;
    overflow: auto;
}

dialog::backdrop {
    background: #21463845;
    backdrop-filter: blur(7px);
}

dialog h2 {
    font: 30px/1.5 Georgia, "PMingLiU", serif;
    margin: 18px 0;
}

dialog p {
    font-size: 13px;
    color: var(--muted);
}

.close {
    position: absolute;
    right: 10px;
    top: 10px;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    font-size: 25px;
    color: var(--muted);
}

.primary {
    background: var(--green);
    color: #fff7e6;
    padding: 13px 21px;
    border-radius: 5px;
    margin-top: 12px;
    font-size: 12px;
}

.fine {
    font-size: 11px !important;
    border-top: 1px solid var(--line);
    padding-top: 14px;
}

.help-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.help-grid strong {
    font-size: 13px;
}

.help-grid p {
    font-size: 12px;
}

.dialog-emblem {
    font: 50px Georgia, serif;
    color: var(--gold);
    margin-top: 25px;
}

#transitionDialog {
    text-align: center;
}

#loading {
    position: fixed;
    inset: 0;
    background: #f4f5ea;
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.7s;
}

#loading.done {
    opacity: 0;
    pointer-events: none;
}

.loading-seal {
    border: 1px solid #b49252;
    font: 25px Georgia, serif;
    color: #a58241;
    padding: 22px 12px;
    letter-spacing: 8px;
    writing-mode: vertical-rl;
}

#loading h2 {
    font: 28px Georgia, serif;
    letter-spacing: 8px;
}

#loading p {
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 2px;
}

#error {
    position: fixed;
    inset: 0;
    z-index: 30;
    background: #f8f6ed;
    padding: 20vh 10vw;
    text-align: center;
}

#error button {
    background: var(--green);
    color: white;
    padding: 12px 20px;
    border-radius: 5px;
}

dialog,
.reader-body {
    touch-action: pan-y;
}

.join-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 16px;
}

.join-form label {
    font-size: 12px;
    font-weight: 600;
    color: var(--ink);
}

.join-form input {
    width: 100%;
    min-height: 44px;
    padding: 10px 14px;
    border-radius: 7px;
    border: 1px solid var(--line);
    background: #fffef9;
    color: var(--ink);
    font: inherit;
    font-size: 16px;
}

.join-form input:focus-visible {
    outline: 3px solid #ba8b35;
    outline-offset: 2px;
}

.join-note {
    min-height: 16px;
    font-size: 11px;
    color: var(--muted);
}

.join-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 6px;
}

.join-actions .primary,
.join-actions .secondary {
    min-height: 44px;
    margin-top: 0;
}

.secondary {
    background: #eff2e8;
    color: var(--ink);
    border: 1px solid var(--line);
    padding: 12px 18px;
    border-radius: 5px;
    font-size: 12px;
}

.context-banner {
    position: fixed;
    left: 50%;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    z-index: 25;
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: calc(100vw - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
    padding: 12px 18px;
    border-radius: 10px;
    background: #fff8e7f5;
    border: 1px solid #cfa962;
    box-shadow: 0 10px 30px #1e3d3226;
    font-size: 12px;
}

.context-banner button {
    background: var(--green);
    color: #fff9e9;
    padding: 8px 14px;
    min-height: 44px;
    border-radius: 6px;
}

@media (max-width: 760px), (max-width: 960px) and (max-height: 500px) {
    .help-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    dialog {
        padding: 26px 20px;
    }

    dialog h2 {
        font-size: 24px;
    }

    #toast {
        top: calc(104px + env(safe-area-inset-top, 0px));
        font-size: 11px;
        width: max-content;
        max-width: 90vw;
    }
}

@media (max-width: 960px) and (max-height: 500px) {
    dialog {
        padding: 20px 18px;
        max-height: 90vh;
        max-height: 90dvh;
    }
}

/* -------------------------------------------------------------------------- */
/* Teleport Luminous Flash Overlay (pairs with 3D mystical light in teleport) */
/* -------------------------------------------------------------------------- */

.teleport-overlay {
    position: fixed;
    inset: 0;
    z-index: 40;
    pointer-events: all;
    opacity: 0;
    transition: opacity 0.22s ease;
}

.teleport-overlay[hidden] {
    display: none;
}

.teleport-overlay.active {
    opacity: 1;
}

.teleport-flash {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 50%, #ffffff 0%, #fff7df 48%, #d7f5ea 100%);
    opacity: 0;
    transition: opacity 0.2s ease-in;
}

.teleport-overlay.phase-flash .teleport-flash {
    opacity: 1;
}

.teleport-overlay.phase-arrive .teleport-flash {
    opacity: 0;
    transition: opacity 0.45s ease-out;
}

