@charset "UTF-8";

/* ============================================================================
 * Private Sun Yat-sen Memorial Hall — Main Stylesheet (style.css)
 * ============================================================================
 * COMMENTING STANDARDS
 * 1. Block comments only. Inline comments (//) are strictly prohibited.
 * 2. Section dividers use the === banner format shown above.
 * 3. All prose is written in English.
 * 4. No debugging notes, temporary workarounds, or console output in
 *    committed code.
 * ============================================================================ */

@layer page {
    /* ========================================================================
     * Global Layout & Viewport Lock
     * ======================================================================== */
    html,
    body {
        width: 100%;
        height: 100%;
        min-height: 100%;
        min-height: 100vh;
        min-height: -webkit-fill-available;
        margin: 0;
        padding: 0;
        background-color: var(--sys-bg-home, #000000);
        overflow: hidden;
    }

    @media all and (display-mode: standalone) {
        html,
        body {
            height: 100vh;
            min-height: 100vh;
            min-height: -webkit-fill-available;
        }
    }

    html.is-standalone,
    html.is-standalone body {
        height: 100vh;
        min-height: 100vh;
        min-height: -webkit-fill-available;
    }

    /* ========================================================================
     * Typography & Flexbox Foundation
     * ======================================================================== */
    body {
        color: var(--sys-text, #f5f5f7);
        font-family: var(--sys-font-family, -apple-system, BlinkMacSystemFont, "PingFang TC", "PingFang SC", "Microsoft JhengHei", sans-serif);
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        align-items: center;
        box-sizing: border-box;
        position: relative;
        padding: max(60px, 8vh) 20px calc(75px + env(safe-area-inset-bottom, 0px)) 20px;
        padding: max(60px, 8dvh) 20px calc(75px + env(safe-area-inset-bottom, 0px)) 20px;
    }

    *,
    *:before,
    *:after {
        box-sizing: inherit;
    }

    /* ========================================================================
     * Main Container
     * ======================================================================== */
    .container {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        width: 100%;
        max-width: 500px;
        margin: auto 0;
        perspective: 1000px;
    }

    /* ========================================================================
     * Portrait Frame Module
     * ======================================================================== */
    .frame-container {
        cursor: none;
        width: fit-content;
        display: flex;
        justify-content: center;
        align-items: center;
        margin: 0 auto 17px auto;
        transition: transform 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
        transform: scale(0.9816) translateZ(0);
        will-change: transform;
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
        transform-origin: center center;
        outline: none;
        -webkit-tap-highlight-color: transparent;
    }

    @media (hover: hover) and (pointer: fine) {
        .frame-container:hover {
            transform: scale(1) translateZ(0);
        }
    }

    /* ========================================================================
     * Wood Frame Material (3D Dynamic Lighting Preserved)
     * ======================================================================== */
    .wood-frame {
        display: inline-block;
        line-height: 0;
        box-sizing: border-box;
        border-radius: 4px;
        position: relative;
        padding: clamp(10px, 3.5vw, 20px);
        background: repeating-linear-gradient(90deg,
                rgba(40, 18, 9, 0.06) 0px,
                rgba(40, 18, 9, 0.06) 3px,
                rgba(70, 35, 18, 0.04) 3px,
                rgba(70, 35, 18, 0.04) 6px),
            linear-gradient(135deg, #2d140a 0%, #3f1f11 50%, #200e05 100%);
        background-blend-mode: multiply;
        border: clamp(2px, 0.8vw, 4px) solid #1a0a03;
        box-shadow: 0 clamp(10px, 3vw, 20px) clamp(20px, 6vw, 45px) rgba(0, 0, 0, 0.9),
            inset 0 0 0 clamp(1px, 0.5vw, 2px) #4d2615,
            inset 0 0 0 clamp(2px, 0.6vw, 3px) #150802,
            inset var(--sh-x, 8px) var(--sh-y, 8px) clamp(15px, 4vw, 25px) rgba(0, 0, 0, var(--sh-alpha, 0.65)),
            inset var(--hl-x, -6px) var(--hl-y, -6px) clamp(15px, 4vw, 25px) rgba(255, 255, 255, var(--hl-alpha, 0.04)),
            inset 0 0 clamp(8px, 2.5vw, 15px) rgba(0, 0, 0, 0.85);
        transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
        transform-style: preserve-3d;
        transition: transform 0.1s ease-out;
        outline: none;
        -webkit-tap-highlight-color: transparent;
    }

    /* Portrait Inner Frame */
    .wood-frame img {
        box-sizing: border-box;
        display: block;
        padding: 1px;
        background-color: #9c7210;
        border: 2px solid #150802;
        box-shadow: 0 3px 10px rgba(0, 0, 0, 0.85);
        border-radius: 1px;
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
        outline: none;
        -webkit-tap-highlight-color: transparent;
    }

    /* Portrait Image */
    .portrait-img {
        height: min(440px, 38vh);
        height: min(440px, 38dvh);
        width: auto;
        aspect-ratio: 320 / 440;
        object-fit: cover;
        border: 4px solid #140a05;
        box-shadow: 0 0 15px rgba(0, 0, 0, 0.6);
        image-rendering: -webkit-optimize-contrast;
        image-rendering: high-quality;
        transform: translateZ(0);
        will-change: transform;
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }

    /* ========================================================================
     * Attendance Counter (Apple Rounded Rectangle + Tabular SF Typography)
     * ======================================================================== */
    .attendance-box {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 4px;
        margin: 0 auto 24px auto;
        font-family: var(--sys-font-family, -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang TC", "PingFang SC", sans-serif);
        background: rgba(35, 16, 7, 0.45);
        padding: 7px 14px;
        border-radius: 10px;
        border: 1px solid rgba(138, 100, 15, 0.42);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        box-shadow: inset 0 0.5px 0 rgba(241, 196, 15, 0.10);
        text-align: center;
    }

    .attendance-label,
    .attendance-unit {
        color: #aaaaaa;
        font-size: 14px;
        font-weight: 500;
        letter-spacing: 0.2px;
        line-height: 1.2;
    }

    .attendance-count {
        color: #f1c40f;
        font-family: -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "SF Pro Display", "SF Pro Text", sans-serif;
        font-size: 14px;
        font-weight: 600;
        font-variant-numeric: tabular-nums;
        letter-spacing: 0;
        line-height: 1.2;
        margin: 0;
    }

    /* ========================================================================
     * Testament Box
     * ======================================================================== */
    .testament-box {
        margin-top: 15px;
        width: 100%;
        position: relative;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }

    .testament-text {
        writing-mode: vertical-rl;
        text-orient: mixed;
        font-family: "BiauKai", "Kaiti TC", "Kaiti SC", "標楷體", "KaiTi", "DFKai-SB", serif;
        height: min(340px, 35vh);
        height: min(340px, 35dvh);
        font-size: clamp(0.9rem, 2.2vh, 1.15rem);
        font-size: clamp(0.9rem, 2.2dvh, 1.15rem);
        text-align: start;
        word-break: break-all;
        color: #e5e5ea;
        line-height: 1.8;
        letter-spacing: 4px;
        padding: 0 15px;
        border-left: 1px rgba(255, 255, 255, 0.16) dashed;
        border-right: 1px rgba(255, 255, 255, 0.16) dashed;
        position: relative;
        width: max-content;
        left: 50%;
        transform: translateX(-50%);
        transition: transform 0.2s ease, border-color 0.2s ease, color 0.2s ease;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }

    /* Mobile Long-Press Interaction Feedback */
    .testament-text.testament-pressing {
        transform: translateX(-50%) scale(0.985);
        border-color: rgba(255, 255, 255, 0.65);
        color: #ffffff;
        text-shadow: 0 0 12px rgba(255, 255, 255, 0.35);
        transition: transform 0.15s ease, border-color 0.15s ease, text-shadow 0.15s ease;
    }

    /* Desktop spacing adaptations for typography */
    @media (min-width: 1025px) {
        .testament-text {
            height: min(280px, 30vh);
            height: min(280px, 30dvh);
            font-size: clamp(14px, 2.5vh, 18px);
            line-height: 2.1;
            letter-spacing: 6px;
            padding: 0 40px;
            margin-bottom: 10px;
        }
    }

    /* ========================================================================
     * Top Banners & Navigation
     * ======================================================================== */
    .memorial-banner,
    .status-banner {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        background-color: rgba(22, 22, 24, 0.90);
        backdrop-filter: blur(24px) saturate(180%);
        -webkit-backdrop-filter: blur(24px) saturate(180%);
        color: #f5f5f7;
        border-bottom: 0.5px solid rgba(255, 255, 255, 0.16);
        padding-top: calc(14px + env(safe-area-inset-top, 0px));
        padding-bottom: 12px;
        padding-left: 16px;
        padding-right: 16px;
        box-sizing: border-box;
        text-align: center;
        font-family: var(--sys-font-family);
        font-size: 1.05rem;
        font-weight: 600;
        letter-spacing: 5px;
        box-shadow: 0 4px 18px rgba(0, 0, 0, 0.55);
        transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1), opacity 0.3s ease;
    }

    .memorial-banner {
        z-index: 10000;
        transform: translateY(0);
        opacity: 1;
    }

    .memorial-banner.hidden {
        transform: translateY(-100%);
        opacity: 0;
    }

    .status-banner {
        z-index: 10005;
        pointer-events: none;
        transform: translateY(-100%);
        opacity: 0;
    }

    .status-banner.show {
        transform: translateY(0);
        opacity: 1;
    }

    /* Top Hover Trigger Area */
    .top-hover-trigger {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 15px;
        z-index: 20000;
    }

    /* Dropdown Navbar */
    .dropdown-nav-bar {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        background: rgba(22, 22, 24, 0.92);
        backdrop-filter: blur(24px) saturate(180%);
        -webkit-backdrop-filter: blur(24px) saturate(180%);
        border-bottom: 0.5px solid rgba(255, 255, 255, 0.14);
        padding: 12px 30px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        box-sizing: border-box;
        box-shadow: 0 6px 24px rgba(0, 0, 0, 0.65);
        transform: translateY(-100%);
        transition: transform 0.35s cubic-bezier(0.25, 1, 0.5, 1);
    }

    /* Festival Banner Text */
    .nav-festival-banner {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        color: #ffffff;
        font-family: var(--sys-font-family);
        font-weight: 600;
        font-size: clamp(12px, 3vw, 15px);
        text-align: center;
        letter-spacing: 2px;
        margin: 0;
        white-space: nowrap;
        pointer-events: none;
    }

    .nav-festival-banner[role="link"] {
        pointer-events: auto;
        transition: color 0.2s ease, letter-spacing 0.2s ease;
        -webkit-tap-highlight-color: transparent;
    }

    @media (hover: hover) and (pointer: fine) {
        .nav-festival-banner[role="link"]:hover {
            color: var(--sys-accent, #0a84ff);
            letter-spacing: 3px;
        }
    }

    .nav-festival-banner[role="link"]:active {
        opacity: 0.75;
    }

    @media (min-width: 1025px) {
        body:not(.banner-active) .top-hover-trigger:hover .dropdown-nav-bar,
        body:not(.banner-active) .dropdown-nav-bar:hover {
            transform: translateY(0);
        }
    }

    /* Navigation Links */
    .nav-link {
        color: #f5f5f7;
        text-decoration: none;
        font-family: var(--sys-font-family);
        font-size: 1.02rem;
        letter-spacing: 1px;
        transition: color 0.2s ease;
        -webkit-tap-highlight-color: transparent;
    }

    @media (hover: hover) and (pointer: fine) {
        .nav-link:hover {
            color: var(--sys-accent, #0a84ff);
        }
    }

    .nav-link:active {
        color: var(--sys-accent, #0a84ff);
    }

    /* Minguo Date Display */
    #minguo-date-display {
        color: #8e8e93;
        font-family: var(--sys-font-family);
        font-size: 1.02rem;
    }

    /* Mobile Dropdown Arrow */
    .mobile-arrow-hint {
        display: none;
    }

    @keyframes arrowBounce {
        0%,
        100% {
            transform: translateX(-50%) translateY(0);
        }

        50% {
            transform: translateX(-50%) translateY(3px);
        }
    }

    /* ========================================================================
     * Mobile Viewport Adjustments
     * ======================================================================== */
    @media (max-width: 1024px) {
        body {
            padding-top: calc(44px + env(safe-area-inset-top, 0px));
            padding-bottom: calc(56px + env(safe-area-inset-bottom, 34px));
        }

        .portrait-img {
            height: min(290px, 25vh);
            height: min(290px, 25dvh);
        }

        .attendance-box {
            margin: 10px auto 14px auto;
        }

        .testament-box {
            padding: 0 15px;
            box-sizing: border-box;
            width: 100%;
            position: relative;
            margin-top: 6px;
        }

        .testament-text {
            height: min(295px, 29vh);
            height: min(295px, 29dvh);
            font-size: clamp(11.5px, 3.3vw, 14.5px);
            line-height: 1.75;
            letter-spacing: 3.5px;
            padding: 0 12px;
            box-sizing: border-box;
            width: max-content;
            left: 50%;
            transform: translateX(-50%);
            margin-bottom: 0;
        }

        .wood-frame img {
            padding: 1px;
            background-color: #9c7210;
            border: none;
            box-shadow: 0 0 0 2px #150802, 0 3px 10px rgba(0, 0, 0, 0.9);
            border-radius: 1px;
        }

        .portrait-img {
            border: 2px solid #140a05;
            box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.95), 0 0 15px rgba(0, 0, 0, 0.8);
        }

        /* Mobile Navbar Formatting */
        .dropdown-nav-bar {
            padding: calc(12px + env(safe-area-inset-top, 0px)) 15px 12px 15px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        body.has-festival #minguo-date-display {
            display: none;
        }

        .nav-festival-banner {
            position: relative;
            left: auto;
            transform: none;
            margin: 0 0 0 auto;
            display: flex;
            align-items: center;
            font-size: clamp(11px, 2.8vw, 13px);
            white-space: nowrap;
            letter-spacing: 0px;
        }

        .nav-link {
            display: flex;
            align-items: center;
            margin-right: auto;
            font-size: clamp(11px, 2.8vw, 13px);
            white-space: nowrap;
            letter-spacing: 0px;
        }

        #minguo-date-display {
            display: flex;
            align-items: center;
            font-size: clamp(11px, 2.8vw, 13px);
            white-space: nowrap;
            letter-spacing: 0px;
        }
    }

    @media (pointer: coarse) {
        .mobile-arrow-hint {
            display: block;
            position: absolute;
            top: calc(10px + env(safe-area-inset-top, 0px));
            left: 50%;
            transform: translateX(-50%) translateY(0);
            width: 26px;
            height: 18px;
            background: rgba(28, 28, 30, 0.88);
            border: 1px solid rgba(255, 255, 255, 0.16);
            border-radius: 6px;
            color: rgba(255, 255, 255, 0.65);
            cursor: pointer;
            z-index: 19000;
            box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
            overflow: hidden;
            opacity: 1;
            visibility: visible;
            pointer-events: auto;
            transition:
                opacity 0.4s cubic-bezier(0.215, 0.610, 0.355, 1),
                transform 0.4s cubic-bezier(0.215, 0.610, 0.355, 1),
                visibility 0.4s;
            transition-delay: 0.35s;
            animation: arrowBounce 2s infinite;
        }

        .mobile-arrow-hint svg {
            width: 11px;
            height: 11px;
            display: block;
            margin: 3px auto 0 auto;
        }

        .frame-container {
            transform: none;
        }
    }

    /* Mini Screens Fallback */
    @media (max-width: 375px) {
        body {
            padding-left: 8px;
            padding-right: 8px;
        }

        .testament-text {
            line-height: 1.4;
            letter-spacing: 2px;
        }

        .attendance-box {
            margin-bottom: 15px;
            padding: 5px 12px;
        }

        .nav-link,
        #minguo-date-display,
        .nav-festival-banner {
            font-size: 11px;
        }
    }

    /* ========================================================================
     * Extremely Short Viewport Fallback (Mobile & Tablet)
     * ======================================================================== */
    @media (max-width: 1024px) and (max-height: 750px) {
        body {
            padding-top: calc(30px + env(safe-area-inset-top, 0px));
            padding-bottom: calc(52px + env(safe-area-inset-bottom, 34px));
        }

        .portrait-img {
            height: min(240px, 24vh);
            height: min(240px, 24dvh);
        }

        .attendance-box {
            margin: 6px auto 10px auto;
            padding: 4px 16px;
        }

        .testament-box {
            margin-top: 4px;
        }

        .testament-text {
            height: min(230px, 28vh);
            height: min(230px, 28dvh);
            font-size: clamp(11px, 2.8vw, 13px);
        }
    }

    /* ========================================================================
     * Gyroscope Lighting (Touch Devices Only)
     * ======================================================================== */
    @media (hover: none),
    (pointer: coarse) {
        .wood-frame {
            transition: none;
        }
    }

    /* ========================================================================
     * Light Mode Overrides (Apple Pure White & Ink Black Palette)
     * ======================================================================== */
    @media (prefers-color-scheme: light) {
        html,
        body {
            background-color: var(--sys-bg-home, #ffffff);
        }

        body {
            color: #1d1d1f;
        }

        .frame-container {
            filter: drop-shadow(0 10px 22px rgba(80, 45, 10, 0.18));
        }

        .wood-frame {
            background:
                repeating-linear-gradient(90deg,
                    rgba(60, 30, 10, 0.12) 0px,
                    rgba(60, 30, 10, 0.12) 3px,
                    rgba(90, 50, 18, 0.09) 3px,
                    rgba(90, 50, 18, 0.09) 6px),
                linear-gradient(135deg, #4a2c12 0%, #633c22 50%, #3e2510 100%);
            background-blend-mode: multiply;
            border-color: #321a08;
            box-shadow:
                0 clamp(10px, 3vw, 20px) clamp(16px, 5vw, 35px) rgba(50, 25, 5, 0.5),
                inset 0 0 0 clamp(1px, 0.5vw, 2px) #7a4e28,
                inset 0 0 0 clamp(2px, 0.6vw, 3px) #251408,
                inset var(--sh-x, 8px) var(--sh-y, 8px) clamp(15px, 4vw, 25px) rgba(0, 0, 0, var(--sh-alpha, 0.45)),
                inset var(--hl-x, -6px) var(--hl-y, -6px) clamp(15px, 4vw, 25px) rgba(220, 170, 90, var(--hl-alpha, 0.09)),
                inset 0 0 clamp(8px, 2.5vw, 15px) rgba(0, 0, 0, 0.4);
        }

        .wood-frame img {
            padding: 1px;
            background-color: #b8880e;
            border: 2px solid #251408;
            box-shadow: 0 3px 10px rgba(40, 20, 0, 0.5);
        }

        .portrait-img {
            border-color: #5a3412;
            box-shadow: 0 0 10px rgba(80, 45, 0, 0.25);
        }

        .attendance-box {
            background: rgba(196, 168, 118, 0.25);
            border-color: rgba(138, 100, 15, 0.35);
            box-shadow: inset 0 0.5px 0 rgba(255, 255, 255, 0.35);
        }

        .attendance-label,
        .attendance-unit {
            color: #6b4c35;
        }

        .attendance-count {
            color: #8a6400;
        }

        .testament-text {
            color: #1d1d1f;
            border-left-color: rgba(0, 0, 0, 0.16);
            border-right-color: rgba(0, 0, 0, 0.16);
        }

        .testament-text.testament-pressing {
            border-color: rgba(0, 0, 0, 0.55);
            color: #000000;
            text-shadow: none;
        }

        .memorial-banner,
        .status-banner {
            background-color: rgba(255, 255, 255, 0.90);
            color: #1d1d1f;
            border-bottom-color: rgba(0, 0, 0, 0.12);
            box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
        }

        .dropdown-nav-bar {
            background: rgba(255, 255, 255, 0.90);
            border-bottom-color: rgba(0, 0, 0, 0.12);
            box-shadow: 0 5px 24px rgba(0, 0, 0, 0.08);
        }

        .nav-link {
            color: #1d1d1f;
        }

        @media (hover: hover) and (pointer: fine) {
            .nav-link:hover {
                color: #007aff;
            }
        }

        .nav-link:active {
            color: #007aff;
        }

        .nav-festival-banner {
            color: #1d1d1f;
        }

        .nav-festival-banner[role="link"]:hover {
            color: #007aff;
        }

        #minguo-date-display {
            color: #6e6e73;
        }

        .mobile-arrow-hint {
            background: rgba(255, 255, 255, 0.92);
            border-color: rgba(0, 0, 0, 0.14);
            color: rgba(29, 29, 31, 0.6);
            box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12);
        }
    }

    /* ========================================================================
     * Danmaku Rendering Layer
     * ======================================================================== */
    #danmaku-container {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        pointer-events: none;
        z-index: 9000;
        overflow: hidden;
    }

    .danmaku-item {
        position: absolute;
        white-space: nowrap;
        font-size: clamp(16px, 4vw, 24px);
        font-weight: bold;
        color: #ffffff;
        text-shadow:
            -1px -1px 0 #000,
            1px -1px 0 #000,
            -1px 1px 0 #000,
            1px 1px 0 #000,
            0px 2px 4px rgba(0, 0, 0, 0.8);
        animation: danmaku-slide linear forwards;
        will-change: transform;
    }

    @keyframes danmaku-slide {
        from {
            transform: translateX(100vw);
        }
        to {
            transform: translateX(-100%);
        }
    }

    /* ========================================================================
     * Bottom Sheet Modal (iOS App Store Style)
     * ======================================================================== */
    .modal-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0);
        display: flex;
        justify-content: center;
        align-items: flex-end;
        z-index: 30000;
        visibility: hidden;
        pointer-events: none;
        transition: background-color 0.1s linear, visibility 0.1s linear;
        font-family: var(--sys-font-family);
    }

    .modal-overlay.active {
        background-color: rgba(0, 0, 0, 0.65);
        visibility: visible;
        pointer-events: auto;
    }

    /* The Sheet Container */
    .modal-sheet {
        position: relative;
        background: #f2f2f7;
        width: 100%;
        max-width: 500px;
        border-radius: 14px 14px 0 0;
        padding: 20px 16px calc(32px + env(safe-area-inset-bottom, 16px)) 16px;
        box-sizing: border-box;
        transform: translateY(100%);
        transition: transform 0.1s linear;
        box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.1);
    }

    .modal-overlay.active .modal-sheet {
        transform: translateY(0) scale(1);
        transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
    }

    @media (prefers-color-scheme: dark) {
        .modal-sheet {
            background: #1c1c1e;
            box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.5);
        }
    }

    /* Modal Header Layout */
    .sheet-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 16px;
        position: relative;
    }

    .sheet-title {
        margin: 0;
        font-size: 1.3rem;
        font-weight: 700;
        color: #1d1d1f;
        line-height: 1;
    }

    @media (prefers-color-scheme: dark) {
        .sheet-title {
            color: #f5f5f7;
        }
    }

    .sheet-close-btn {
        background: rgba(0, 0, 0, 0.08);
        border: none;
        border-radius: 50%;
        width: 30px;
        height: 30px;
        display: flex;
        justify-content: center;
        align-items: center;
        color: #3c3c43;
        cursor: pointer;
        transition: background 0.2s;
        padding: 0;
        outline: none;
    }

    .sheet-close-btn:hover {
        background: rgba(0, 0, 0, 0.12);
    }

    /* Input Area Restyling */
    .sheet-content {
        position: relative;
        background: #ffffff;
        border-radius: 14px;
        padding: 0;
        margin-bottom: 28px;
        box-shadow: none;
        overflow: hidden;
    }

    @media (prefers-color-scheme: dark) {
        .sheet-content {
            background: #2c2c2e;
        }

        .sheet-close-btn {
            background: rgba(255, 255, 255, 0.12);
            color: rgba(235, 235, 245, 0.6);
        }

        .sheet-close-btn:hover {
            background: rgba(255, 255, 255, 0.18);
        }
    }

    .ios-textarea {
        width: 100%;
        height: 90px;
        background: transparent;
        border: none;
        border-radius: 0;
        padding: 14px 16px;
        color: #1d1d1f;
        font-size: 1rem;
        resize: none;
        font-family: inherit;
        box-sizing: border-box;
    }

    .ios-textarea:focus {
        outline: none;
    }

    @media (prefers-color-scheme: dark) {
        .ios-textarea {
            color: #f5f5f7;
        }
    }

    .char-counter {
        position: absolute;
        bottom: 8px;
        right: 12px;
        font-size: 0.75rem;
        color: #8e8e93;
        pointer-events: none;
        font-family: var(--sys-font-family);
    }

    /* Footer & Buttons */
    .sheet-footer {
        display: flex;
        justify-content: center;
        padding: 0;
    }

    .ios-submit-btn {
        width: 110px;
        height: 34px;
        background: #007aff;
        color: #ffffff;
        border: none;
        border-radius: 17px;
        font-size: 0.9rem;
        font-weight: 600;
        line-height: 1;
        -webkit-appearance: none;
        cursor: pointer;
        transition: filter 0.2s;
        font-family: var(--sys-font-family);
        display: flex;
        justify-content: center;
        align-items: center;
    }

    /* Hide desktop-exclusive elements on mobile */
    .macos-cancel-btn,
    .macos-help-btn,
    .macos-popover {
        display: none;
    }

    /* History Popover (macOS Spotlight Style) */
    .history-popover {
        position: absolute;
        top: 25px;
        right: 0;
        width: 260px;
        background: rgba(255, 255, 255, 0.90);
        backdrop-filter: blur(24px);
        -webkit-backdrop-filter: blur(24px);
        border: 1px solid rgba(0, 0, 0, 0.10);
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
        border-radius: 12px;
        padding: 12px;
        z-index: 100;
        text-align: left;
        opacity: 0;
        visibility: hidden;
        transform: scale(0.95);
        transform-origin: top right;
        transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    }

    .history-popover.show {
        opacity: 1;
        visibility: visible;
        transform: scale(1);
    }

    .history-popover h4 {
        margin: 0 0 10px 0;
        font-size: 0.9rem;
        font-weight: 600;
        color: #1d1d1f;
        border-bottom: 1px solid rgba(0, 0, 0, 0.06);
        padding-bottom: 6px;
    }

    #history-list {
        max-height: 130px;
        overflow-y: auto;
        font-size: 0.85rem;
    }

    .empty-history {
        color: #8e8e93;
        text-align: center;
        padding: 10px 0;
    }

    .history-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 0;
        border-bottom: 1px solid rgba(0, 0, 0, 0.05);
        color: #1d1d1f;
    }

    .history-item:last-child {
        border-bottom: none;
    }

    .history-text {
        flex: 1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        margin-right: 10px;
    }

    .retract-btn {
        background: rgba(0, 0, 0, 0.05);
        border: none;
        border-radius: 50%;
        width: 22px;
        height: 22px;
        display: flex;
        justify-content: center;
        align-items: center;
        cursor: pointer;
        color: #6e6e73;
        transition: background 0.2s, color 0.2s;
    }

    .retract-btn:hover {
        background: rgba(0, 0, 0, 0.12);
        color: #1d1d1f;
    }

    @media (prefers-color-scheme: dark) {
        .history-popover {
            background: rgba(40, 40, 42, 0.90);
            border: 1px solid rgba(255, 255, 255, 0.12);
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
        }

        .history-popover h4 {
            color: #f5f5f7;
            border-bottom: 1px solid rgba(255, 255, 255, 0.08);
        }

        .history-item {
            color: #e5e5ea;
            border-bottom: 1px solid rgba(255, 255, 255, 0.06);
        }

        .retract-btn {
            background: rgba(255, 255, 255, 0.1);
            color: #aeaeb2;
        }

        .retract-btn:hover {
            background: rgba(255, 255, 255, 0.2);
            color: #ffffff;
        }
    }

    .ios-submit-btn:hover {
        filter: brightness(0.92);
    }

    .ios-submit-btn:disabled {
        opacity: 0.5;
        cursor: not-allowed;
    }

    @media (prefers-color-scheme: dark) {
        .ios-submit-btn {
            background: #0a84ff;
            color: #ffffff;
        }
    }

    /* ========================================================================
     * Notification Toast (Apple HIG)
     * ======================================================================== */
    .cloudflare-toast {
        position: fixed;
        bottom: -100px;
        left: 50%;
        transform: translateX(-50%);
        padding: 12px 24px;
        border-radius: 10px;
        font-size: 0.95rem;
        font-weight: 500;
        z-index: 99999;
        transition: bottom 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
        box-shadow: 0 4px 14px rgba(0, 0, 0, 0.16);
        display: flex;
        align-items: center;
        justify-content: center;
        min-width: 200px;
        text-align: center;
        font-family: var(--sys-font-family);
    }

    .cloudflare-toast.show {
        bottom: 40px;
    }

    .cloudflare-toast.success {
        background-color: #34c759;
        color: #ffffff;
    }

    .cloudflare-toast.error {
        background-color: #ff3b30;
        color: #ffffff;
    }

    .cloudflare-toast.info {
        background-color: #007aff;
        color: #ffffff;
    }

    .cloudflare-toast.system {
        background-color: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        color: #1d1d1f;
        border: 1px solid rgba(0, 0, 0, 0.10);
    }

    @media (prefers-color-scheme: dark) {
        .cloudflare-toast.system {
            background-color: rgba(28, 28, 30, 0.95);
            color: #f5f5f7;
            border: 1px solid rgba(255, 255, 255, 0.14);
        }
    }

    /* ========================================================================
     * macOS Desktop Alert Styles
     * ======================================================================== */
    @media (min-width: 600px) {
        .modal-overlay {
            align-items: center;
            background-color: rgba(0, 0, 0, 0);
        }

        .modal-overlay.active {
            background-color: rgba(0, 0, 0, 0.25);
        }

        .modal-sheet {
            width: clamp(280px, 35vw, 360px);
            border-radius: 16px;
            padding: 24px;
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(20px);
            -webkit-backdrop-filter: blur(20px);
            box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.06);
            transform: scale(0.9);
            transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.2s;
        }

        .modal-overlay.active .modal-sheet {
            transform: scale(1);
        }

        .sheet-header {
            justify-content: center;
            margin-bottom: 16px;
        }

        .sheet-title {
            font-size: 1.15rem;
            font-weight: 700;
        }

        .history-popover {
            top: 25px;
            bottom: auto;
            transform-origin: top right;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
        }

        #history-list {
            max-height: 200px;
        }

        .sheet-close-btn {
            display: flex;
            position: absolute;
            right: 0;
            top: 50%;
            transform: translateY(-50%);
        }

        .sheet-content {
            background: rgba(0, 0, 0, 0.03);
            border: 1px solid rgba(0, 0, 0, 0.1);
            box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.04);
            border-radius: 8px;
            padding: 0;
            margin-bottom: 24px;
        }

        .ios-textarea {
            height: 120px;
            font-size: 1rem;
        }

        .sheet-footer {
            display: flex;
            gap: 12px;
            width: 100%;
            justify-content: space-between;
        }

        .macos-cancel-btn {
            display: flex;
            flex: 1;
            height: 36px;
            background: #e5e5ea;
            border-radius: 8px;
            font-size: 1rem;
            font-weight: 500;
            color: #1d1d1f;
            border: 1px solid rgba(0, 0, 0, 0.06);
            box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
            justify-content: center;
            align-items: center;
            cursor: pointer;
            transition: background 0.2s;
            font-family: var(--sys-font-family);
        }

        .macos-cancel-btn:active {
            background: #d1d1d6;
        }

        .ios-submit-btn {
            flex: 1;
            width: auto;
            max-width: none;
            height: 36px;
            background: #007aff;
            border-radius: 8px;
            font-size: 1rem;
            font-weight: 500;
            color: #ffffff;
            border: none;
            box-shadow:
                0 1px 1px rgba(0, 0, 0, 0.08),
                inset 0 1px 0 rgba(255, 255, 255, 0.2);
            display: flex;
            justify-content: center;
            align-items: center;
            line-height: normal;
        }

        .ios-submit-btn:active {
            background: #0062cc;
        }
    }

    /* ========================================================================
     * macOS Desktop Dark Mode Variants
     * ======================================================================== */
    @media (min-width: 600px) and (prefers-color-scheme: dark) {
        .modal-sheet {
            background: rgba(28, 28, 30, 0.92);
            box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.14);
        }

        .sheet-title {
            color: #f5f5f7;
        }

        .sheet-close-btn {
            background: rgba(255, 255, 255, 0.15);
            color: #e5e5ea;
        }

        .sheet-content {
            background: rgba(0, 0, 0, 0.35);
            border: 1px solid rgba(255, 255, 255, 0.12);
            box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2);
        }

        .macos-cancel-btn {
            background: rgba(255, 255, 255, 0.12);
            color: #f5f5f7;
            border: 1px solid rgba(255, 255, 255, 0.08);
            box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
        }

        .macos-cancel-btn:active {
            background: rgba(255, 255, 255, 0.18);
        }

        .macos-help-btn {
            background: rgba(255, 255, 255, 0.1);
            color: #e5e5ea;
        }

        .macos-help-btn:hover {
            background: rgba(255, 255, 255, 0.15);
        }

        .macos-popover {
            background: rgba(28, 28, 30, 0.95);
            border: 1px solid rgba(255, 255, 255, 0.12);
            box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
        }

        .macos-popover h4 {
            color: #f5f5f7;
        }

        .macos-popover p {
            color: #8e8e93;
        }

        .ios-submit-btn {
            background: #0a84ff;
            box-shadow:
                0 1px 1px rgba(0, 0, 0, 0.2),
                inset 0 1px 0 rgba(255, 255, 255, 0.15);
        }

        .ios-submit-btn:active {
            background: #006ee6;
        }
    }

    /* ========================================================================
     * Captcha Modal Overlay
     * ======================================================================== */
    #captcha-modal-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0);
        visibility: hidden;
        pointer-events: none;
        z-index: 40000;
        display: flex;
        justify-content: center;
        align-items: center;
        transition: background-color 0.3s ease, visibility 0.3s ease;
    }

    #captcha-modal-overlay.active {
        background-color: rgba(0, 0, 0, 0.75);
        visibility: visible;
        pointer-events: auto;
    }

    .captcha-modal-content {
        background: transparent;
        opacity: 0;
        transform: scale(0.9);
        transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
        display: flex;
        justify-content: center;
        align-items: center;
        flex-shrink: 0;
        width: 440px;
    }

    #captcha-modal-overlay.active .captcha-modal-content {
        opacity: 1;
        transform: scale(1);
    }

    @media (max-width: 450px) {
        #captcha-modal-overlay.active .captcha-modal-content {
            transform: scale(min(1, calc(100vw / 460)));
        }
    }

    .cc-glass {
        -webkit-mask-image: -webkit-radial-gradient(white, black);
        mask-image: radial-gradient(white, black);
        transform: translateZ(0);
    }

    .clawcap-machine img {
        -webkit-user-drag: none;
        -webkit-touch-callout: none;
        user-select: none;
        pointer-events: none;
    }

    @media (max-width: 410px) {
        #captcha-modal-overlay.active .captcha-modal-content { transform: scale(0.85); }
    }

    @media (max-width: 380px) {
        #captcha-modal-overlay.active .captcha-modal-content { transform: scale(0.75); }
    }

    @media (max-width: 340px) {
        #captcha-modal-overlay.active .captcha-modal-content { transform: scale(0.65); }
    }
}

/* ============================================================================
 * Visibility & Animation State Overrides
 * ============================================================================ */
@layer overrides {
    #danmaku-container.hidden {
        display: none;
    }

    .nav-festival-banner:empty {
        display: none;
    }

    body.banner-active .dropdown-nav-bar {
        transform: translateY(-100%);
        opacity: 0;
        pointer-events: none;
    }

    .dropdown-nav-bar.force-show {
        transform: translateY(0);
    }

    .memorial-banner:not(.hidden) ~ .top-hover-trigger .mobile-arrow-hint,
    .status-banner.show ~ .top-hover-trigger .mobile-arrow-hint,
    .dropdown-nav-bar.force-show + .mobile-arrow-hint {
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
    }

    @media (pointer: coarse) {
        .memorial-banner:not(.hidden) ~ .top-hover-trigger .mobile-arrow-hint,
        .status-banner.show ~ .top-hover-trigger .mobile-arrow-hint,
        .dropdown-nav-bar.force-show + .mobile-arrow-hint,
        body.tab-navigating .mobile-arrow-hint,
        .mobile-arrow-hint.nav-hidden {
            display: block;
            opacity: 0;
            visibility: hidden;
            pointer-events: none;
            transform: translateX(-50%) translateY(-40px);
            transition: opacity 0s, transform 0s, visibility 0s;
            transition-delay: 0s;
        }
    }
}

/* ============================================================================
 * Protected Captcha Dark Mode Theme Overrides (Unlayered to override widget)
 * ============================================================================ */
@media (prefers-color-scheme: dark) {
    #captcha-root .clawcap {
        --clawcap-bg: #1c1c1e;
        --clawcap-ink: #ffffff;
        --clawcap-muted: #c7c7cc;
        --clawcap-accent: #ff5159;

        --cc-bg: #1c1c1e !important;
        --cc-ink: #ffffff !important;
        --cc-muted: #c7c7cc !important;
        --cc-line: rgba(255, 255, 255, 0.15) !important;
        --cc-fill: #2c2c2e !important;
        --cc-fill-2: #3a3a3c !important;
        --cc-accent: #ff5159 !important;
    }

    #captcha-root .clawcap-glass {
        background: linear-gradient(180deg, #242426 0%, #1c1c1e 100%) !important;
        box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05), inset 0 1px 8px rgba(0, 0, 0, 0.5) !important;
    }

    #captcha-root .cc-glass-shine {
        display: none !important;
    }

    #captcha-root .clawcap-panel {
        background: linear-gradient(180deg, #2a2a2c 0%, #202022 100%) !important;
        box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05) !important;
    }

    #captcha-root .clawcap-steps-pill {
        background: #4a4a4c !important;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3) !important;
    }

    #captcha-root .clawcap-steps li.is-active .clawcap-step-n {
        background: #ffffff !important;
        color: #1c1c1e !important;
    }

    #captcha-root .clawcap-info-n,
    #captcha-root .clawcap-info-done {
        background: #ffffff !important;
        color: #1c1c1e !important;
    }

    #captcha-root .cc-tray-door,
    #captcha-root .cc-tray-skin {
        background: linear-gradient(180deg, #3a3a3c 0%, #2c2c2e 100%) !important;
        box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), inset 0 -10px 13px -10px rgba(0, 0, 0, 0.5) !important;
    }
}
