* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-color: #080808;
    --panel-bg: #121212;
    --text-color: #ffffff;
    --accent-color: rgba(255, 255, 255, 0.15);
}

body {
    min-height: 100dvh;
    background: var(--bg-color);
    color: var(--text-color);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.comic-player {
    width: 100vw;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background: var(--bg-color);
    overflow: hidden;
}

/* --- Top Navigation Bar --- */
.top-bar {
    height: 48px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: var(--panel-bg);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    z-index: 20;
}

.top-bar h1 {
    font-size: clamp(13px, 3.5vw, 16px);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.page-number {
    font-size: 13px;
    color: #888888;
    font-weight: 500;
    white-space: nowrap;
}

/* --- Main Canvas Viewing Area --- */
.comic-area {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: clamp(4px, 1.5vw, 16px);
    position: relative;
    overflow: hidden;
    width: 100%;
}

.comic-book {
    position: relative;
    aspect-ratio: 2 / 1;
    /* Dynamically calculate maximum height considering top and bottom controls */
    width: min(100%, calc((100dvh - 140px) * 2));
    height: auto;
    max-height: calc(100dvh - 140px);
    background: #000000;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.8);
    touch-action: pan-y;
    overflow: hidden;
}

/* --- Video & Overlay Split Layers --- */
.layer {
    position: absolute;
    top: 0;
    height: 100%;
}

.video-layer-left,
.static-left-layer {
    left: 0;
    width: 50%;
    overflow: hidden;
}

.video-layer-right,
.static-right-layer {
    right: 0;
    width: 50%;
    overflow: hidden;
}

.static-left-layer,
.static-right-layer {
    z-index: 2;
    display: none;
    pointer-events: none;
}

/* Ensure left and right videos completely fill their split halves */
.video-layer-left video {
    width: 200% !important;
    height: 100% !important;
    object-fit: cover !important;
    object-position: left center !important;
}

.video-layer-right video {
    width: 200% !important;
    height: 100% !important;
    object-fit: cover !important;
    object-position: right center !important;
    position: absolute;
    right: 0;
}

/* Single page 1:1 image captures */
/* Single page 1:1 image captures - match video scaling */
.static-left-layer img,
.static-right-layer img {
    width: 100%;
    height: 100%;
    object-fit: cover !important;
    object-position: center;
    position: absolute;
    top: 0;
    left: 0;
}

/* --- WebGL Overlay --- */
#paperCanvasContainer {
    position: absolute;
    inset: 0;
    z-index: 10;
    pointer-events: none;
}

#paperCanvasContainer canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

img:not([src]),
img[src=""] {
    display: none !important;
}

/* --- Controls & Progress Bar --- */
.controls {
    height: 48px;
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: clamp(10px, 3vw, 16px);
    z-index: 20;
}

.control-button {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: #ffffff;
    font-size: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, background 0.15s ease;
}

.control-button:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

/* Forward button stays unavailable until the current video is completed. */
.control-button:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none !important;
    pointer-events: none;
}

.play-button {
    width: 44px;
    height: 44px;
    font-size: 16px;
    background: var(--accent-color);
}

.progress-section {
    height: 32px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 16px 8px;
    color: #888888;
    font-size: 12px;
    font-weight: 500;
    z-index: 20;
}

#progressBar {
    flex: 1;
    height: 4px;
    accent-color: #ffffff;
    cursor: pointer;
}

/* --- AR Button & Overlay Popup --- */
.ar-button {
    display: none;
    align-self: center;
    margin-bottom: 4px;
    padding: 6px 14px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 20px;
    background: #1e1e1e;
    color: #ffffff;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

/* --- AR Popup --- */

.ar-popup {
    display: none;
    position: fixed;
    inset: 0;

    z-index: 1000;

    align-items: center;
    justify-content: center;

    padding: 20px;

    background: rgba(0, 0, 0, 0.72);

    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}


.ar-popup-box {
    width: min(88vw, 390px);

    padding: 30px 26px 24px;

    background: #181818;

    border: 1px solid rgba(255, 255, 255, 0.12);

    border-radius: 22px;

    text-align: center;

    box-shadow:
        0 25px 70px rgba(0, 0, 0, 0.55);

    animation: arPopupIn 0.22s ease-out;
}


/* AR icon */

.ar-popup-box::before {
    content: "✨";

    display: flex;
    align-items: center;
    justify-content: center;

    width: 58px;
    height: 58px;

    margin: 0 auto 18px;

    border-radius: 50%;

    background: #292929;

    font-size: 26px;
}


/* Heading */

.ar-popup-box h2 {
    margin: 0 0 10px;

    color: #ffffff;

    font-size: 24px;
    font-weight: 600;

    line-height: 1.25;
}


/* Description */

.ar-popup-box p {
    max-width: 300px;

    margin: 0 auto 26px;

    color: #999999;

    font-size: 14px;

    line-height: 1.5;
}


/* Buttons */

.start-ar-button,
.close-ar-button {
    width: 100%;

    padding: 13px 18px;

    border: none;

    border-radius: 12px;

    font-size: 14px;

    font-weight: 600;

    cursor: pointer;

    transition:
        transform 0.15s ease,
        background 0.15s ease;
}


/* Start AR */

.start-ar-button {
    margin-bottom: 9px;

    background: #ffffff;

    color: #111111;
}

.start-ar-button:hover {
    background: #eeeeee;
}

.start-ar-button:active {
    transform: scale(0.97);
}


/* Not Now */

.close-ar-button {
    background: #292929;

    color: #aaaaaa;
}

.close-ar-button:hover {
    background: #333333;

    color: #ffffff;
}

.close-ar-button:active {
    transform: scale(0.97);
}


/* Popup entrance animation */

@keyframes arPopupIn {

    from {
        opacity: 0;
        transform: scale(0.94) translateY(8px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* --- Mobile Landscape / Fullscreen Mode --- */
@media (max-width: 920px) and (orientation: landscape) {
    .top-bar, 
    .progress-section {
        display: none !important;
    }

    .comic-area {
        padding: 0;
        width: 100vw;
        height: 100dvh;
    }

    .comic-book {
        width: min(100vw, calc(100dvh * 2));
        height: min(100dvh, calc(100vw / 2));
        max-width: 100vw;
        max-height: 100dvh;
        border-radius: 0;
        border: none;
        box-shadow: none;
    }

    .controls {
        position: absolute;
        bottom: 10px;
        right: 10px;
        z-index: 50;
        height: auto;
        gap: 6px;
        background: transparent !important;
    }

    .control-button {
        width: 34px;
        height: 34px;
        font-size: 12px;
        background: rgba(0, 0, 0, 0.6) !important;
        border: 1px solid rgba(255, 255, 255, 0.2);
    }
}


/* --- Mobile Landscape Launch / Welcome Overlay --- */

.landscape-overlay {
    display: none;
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100dvh;

    background: #080808;

    z-index: 100000;

    justify-content: center;
    align-items: center;

    padding: 24px;
}

.landscape-overlay-box {
    width: min(88vw, 420px);

    text-align: center;

    display: flex;
    flex-direction: column;
    align-items: center;
}

.landscape-overlay-box h2 {
    margin: 0 0 12px;

    color: #ffffff;

    font-size: clamp(24px, 6vw, 34px);
    font-weight: 600;
    line-height: 1.2;

    letter-spacing: -0.5px;
}

.landscape-overlay-box p {
    margin: 0 0 26px;

    color: #999999;

    font-size: 15px;
    line-height: 1.5;
}

#enterFullscreenBtn {
    min-width: 170px;

    padding: 13px 26px;

    border: none;
    border-radius: 30px;

    background: #ffffff;
    color: #000000;

    font-size: 14px;
    font-weight: 700;

    letter-spacing: 0.3px;

    cursor: pointer;

    transition:
        transform 0.15s ease,
        background 0.15s ease;
}

#enterFullscreenBtn:active {
    transform: scale(0.96);
}

#enterFullscreenBtn:hover {
    background: #eeeeee;
}

/* Force elements to expand completely when in Native Fullscreen */
:fullscreen .comic-player,
:-webkit-full-screen .comic-player {
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
}

:fullscreen .comic-book,
:-webkit-full-screen .comic-book {
    width: min(100vw, calc(100vh * 2)) !important;
    height: min(100vh, calc(100vw / 2)) !important;
}


#arButton {
    position: absolute;
    bottom: 25px;
    left: 50%;
    transform: translate(-50%, -90%); 
    z-index: 50;
    
    background: rgba(0, 0, 0, 0.8);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 8px 18px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    
    transition: opacity 0.2s ease, transform 0.2s ease;
}

#arButton:hover {
    background: rgba(0, 0, 0, 0.95);
    transform: translateX(-50%) scale(1.05);
}

