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

body {
    background-color: #ffffff;
    font-family: 'Courier Prime', 'Courier New', monospace;
    overflow: hidden;
    color: #000;
    /* Prevent text selection when dragging */
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    overscroll-behavior: none;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.gallery-container {
    width: 100vw;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* --- Top Right Controls --- */
.top-right-controls {
    position: absolute;
    top: 40px;
    right: 40px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
    z-index: 50;
}

.menu-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
}

.expandable-controls {
    display: flex;
    gap: 8px;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateX(20px);
    transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.4s;
}

.expandable-controls.open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateX(0);
}

.icon-btn,
.control-btn {
    position: relative;
    border: none;
    background: transparent;
    color: #000;
    font-family: 'Courier Prime', 'Courier New', monospace;
    cursor: pointer;
    z-index: 1;
    display: flex;
    justify-content: center;
    align-items: center;
}

.icon-btn::before,
.control-btn::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(240, 240, 240, 0.6);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    z-index: -1;
    border-radius: 8px;
    transition: background-color 0.2s;
}

.icon-btn {
    width: 48px;
    height: 48px;
    font-size: 20px;
}

.control-btn {
    padding: 12px 24px;
    font-size: 14px;
    font-weight: 400;
}

.control-btn.active {
    font-weight: 400;
}

.control-btn.active::before {
    background-color: rgba(200, 200, 200, 0.8);
}

.icon-btn:hover::before,
.control-btn:hover:not(.active)::before {
    background-color: rgba(220, 220, 220, 0.7);
}

/* --- Scene and Carousel --- */
.scene {
    width: 100%;
    height: 100%;
    perspective: 1800px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.carousel-container {
    width: 200px;
    height: 280px;
    position: relative;
    transform-style: preserve-3d;
    transform: rotateX(-10deg);
}

.carousel {
    width: 100%;
    height: 100%;
    position: absolute;
    transform-style: preserve-3d;
}

.carousel__cell {
    position: absolute;
    width: 150px;
    height: 220px;
    left: 25px;
    top: 30px;
    border-radius: 0;
    overflow: hidden;
    background-color: #f5f5f5;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    backface-visibility: visible;
    transition: filter 0.3s ease, margin-top 0.4s cubic-bezier(0.25, 1, 0.5, 1), box-shadow 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}

.carousel__cell.active {
    margin-top: -20px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.carousel__cell img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
}

.carousel__cell:hover {
    filter: brightness(1.1);
}

/* Camera Container */
.camera-container {
    position: absolute;
    bottom: 40px;
    right: 40px;
    width: 240px;
    height: 180px;
    display: none;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
    z-index: 20;
    background: #000;
}

#webcam,
#hands-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: scaleX(-1);
    object-fit: cover;
}

/* --- Intro Screen --- */
.intro-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 100;
    display: flex;
    transition: opacity 0.5s ease, visibility 0.5s;
}

.intro-container.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.intro-panel {
    width: 45%;
    max-width: 600px;
    min-width: 400px;
    height: 100%;
    position: relative;
    padding: 40px 50px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.intro-panel::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(245, 245, 245, 0.55);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    z-index: -1;
    border-right: 1px solid rgba(255, 255, 255, 0.4);
}

.intro-overlay {
    flex-grow: 1;
    cursor: pointer;
}

.intro-header {
    display: flex;
    flex-direction: column;
}

.intro-title {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 150px;
    font-weight: 400;
    letter-spacing: -3px;
    line-height: 0.8;
    margin-left: -5px;
    /* Visual alignment */
    margin-bottom: 5px;
}

.intro-subtitle {
    display: flex;
    justify-content: space-between;
    font-size: 24px;
    margin-top: 0;
    font-weight: 500;
}

.intro-middle {
    text-align: center;
    font-size: 22px;
    cursor: pointer;
}

.intro-middle p {
    margin-bottom: 20px;
}

.intro-arrow {
    font-size: 32px;
    display: inline-block;
    transition: transform 0.3s;
}

.intro-middle:hover .intro-arrow {
    transform: translateX(10px);
}

.intro-bottom {
    display: flex;
    justify-content: center;
}

.intro-icon {
    width: 90px;
    height: auto;
}

/* --- Modals --- */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(255, 255, 255, 0.05);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    backdrop-filter: blur(0px);
    -webkit-backdrop-filter: blur(0px);
    transition: opacity 0.6s ease, visibility 0.6s ease, backdrop-filter 0.6s ease, -webkit-backdrop-filter 0.6s ease;
}

.modal.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
}

.modal-content {
    padding: 40px 30px;
    max-width: 650px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    color: #000;
    text-align: center;
    border-radius: 8px;
    touch-action: pan-y;
    overscroll-behavior: contain;
    background-color: rgba(245, 245, 245, 0.75);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
}

.modal-content::before {
    display: none;
}

.modal-content * {
    font-weight: 400 !important;
}

.modal-content h2 {
    margin-bottom: 24px;
    font-size: 28px;
}

.modal-content p,
.modal-content ul {
    font-size: 16px;
    line-height: 1.6;
    margin-bottom: 16px;
    color: #333;
    text-align: left;
}

.modal-content ul {
    padding-left: 20px;
}

.close-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    font-size: 32px;
    cursor: pointer;
    color: #666;
    transition: color 0.2s, transform 0.2s;
    line-height: 1;
}

.close-btn:hover {
    color: #000;
    transform: scale(1.1);
}

/* Photo Modal */
.photo-modal {
    background: radial-gradient(circle, rgba(255, 255, 255, 0.7) 40%, rgba(0, 0, 0, 0.3) 150%);
}

.photo-modal::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: transparent;
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    z-index: -1;
}

.back-btn {
    position: absolute;
    top: 40px;
    left: 40px;
    font-size: 32px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: #000;
    z-index: 101;
    font-family: 'Courier Prime', 'Courier New', monospace;
}

/* Hide global back button when text view is active to prevent duplicates */
#text-view:not([style*="display: none"])~.back-btn {
    display: none;
}

.text-view-header {
    display: flex;
    align-items: center;
    gap: 40px;
    margin-bottom: 50px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    padding-bottom: 10px;
}

.info-panel {
    position: fixed;
    bottom: 40px;
    left: 40px;
    z-index: 50;
    font-family: 'Courier Prime', monospace;
    color: rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    gap: 5px;
    pointer-events: none;
    transition: opacity 0.3s, color 0.3s;
    max-width: 260px;
}

body.dark-theme .info-panel {
    color: rgba(255, 255, 255, 0.6);
}

.info-panel span {
    display: block;
    font-size: 14px;
}

#history-number {
    font-weight: bold;
    font-size: 16px;
    color: #000;
    transition: color 0.3s;
}

body.dark-theme #history-number {
    color: #fff;
}

.mobile-only-info {
    font-family: 'Courier Prime', monospace;
    font-size: 12px;
    color: rgba(0, 0, 0, 0.5);
    margin-top: 15px;
    text-align: center;
    max-width: 260px;
    line-height: 1.5;
    display: none;
}

@media (max-width: 768px) {
    .info-panel {
        display: flex;
        left: 50%;
        transform: translateX(-50%);
        text-align: center;
        align-items: center;
        max-width: 80vw;
    }

    .mobile-only-info {
        display: none;
    }
}

.back-btn-inline {
    display: none;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 32px;
    font-family: 'Courier Prime', monospace;
    padding: 0;
    margin: 0;
    line-height: 1;
}

.text-view-header h2 {
    margin: 0;
    font-size: 32px;
}

.photo-modal-inner {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transform: scale(0.9);
    transition: transform 0.6s cubic-bezier(0.25, 1, 0.5, 1);
}

.modal.visible .photo-modal-inner {
    transform: scale(1);
}

.photo-modal-inner img {
    max-width: 80%;
    max-height: 75vh;
    object-fit: contain;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    margin-bottom: 25px;
}

.read-action {
    font-family: 'Courier Prime', monospace;
    font-size: 18px;
    cursor: pointer;
    text-decoration: underline;
    color: #000;
    transition: color 0.2s;
}

.read-action:hover {
    color: #555;
}

#text-view {
    justify-content: flex-start;
    align-items: flex-start;
    padding-top: 100px;
    padding-left: 80px;
    padding-right: 80px;
    padding-bottom: 100px;
    overflow-y: auto;
    touch-action: pan-y;
    overscroll-behavior: contain;
}

.full-text-content {
    text-align: left;
    max-width: 900px;
    font-size: 20px;
    line-height: 1.3;
    color: #000;
}

.full-text-content h2 {
    font-size: 36px;
    font-weight: 400;
    margin-bottom: 40px;
}

.full-text-content p {
    margin-bottom: 24px;
}

/* --- Dark Theme --- */
body.dark-theme {
    background-color: #121212;
    color: #ffffff;
}

body.dark-theme .icon-btn,
body.dark-theme .control-btn {
    color: #aaa;
}

body.dark-theme .icon-btn.active,
body.dark-theme .control-btn.active {
    color: #fff;
}

body.dark-theme .icon-btn::before,
body.dark-theme .control-btn::before {
    background-color: rgba(30, 30, 30, 0.6);
}

body.dark-theme .icon-btn.active::before,
body.dark-theme .control-btn.active::before {
    background-color: rgba(60, 60, 60, 0.8);
}

body.dark-theme .icon-btn:hover::before,
body.dark-theme .control-btn:hover:not(.active)::before {
    background-color: rgba(45, 45, 45, 0.7);
}

body.dark-theme .carousel__cell {
    background-color: #222;
}

body.dark-theme .intro-panel::before {
    background-color: rgba(18, 18, 18, 0.4);
}

body.dark-theme .modal-content {
    color: #fff;
    background-color: rgba(20, 20, 20, 0.8);
}

body.dark-theme .modal-content::before {
    display: none;
}

body.dark-theme .modal-content p,
body.dark-theme .modal-content ul {
    color: #ccc;
}

body.dark-theme .close-btn {
    color: #aaa;
}

body.dark-theme .close-btn:hover {
    color: #fff;
}

body.dark-theme .photo-modal {
    background: radial-gradient(circle, rgba(18, 18, 18, 0.85) 50%, rgba(255, 255, 255, 0.05) 150%);
}

body.dark-theme .photo-modal::before {
    background-color: transparent;
}

body.dark-theme .back-btn {
    color: #fff;
}

body.dark-theme .full-text-content {
    color: #fff;
}

body.dark-theme .read-action {
    color: #fff;
}

body.dark-theme .read-action:hover {
    color: #aaa;
}

.mobile-read-btn {
    display: none;
}

/* --- Mobile Adaptation --- */
@media (max-width: 768px) {
    .intro-panel {
        width: 100%;
        max-width: none;
        min-width: 100%;
        padding: 10vh 5vw;
        border-right: none;
    }

    .intro-title {
        font-size: 26vw;
        letter-spacing: normal;
        margin-left: 0;
    }

    .intro-subtitle {
        font-size: 5vw;
    }

    .intro-middle {
        font-size: 5vw;
    }

    /* Top Menu Controls Adaptation */
    .top-right-controls {
        top: 20px;
        right: 20px;
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        gap: 15px;
    }

    .menu-wrapper {
        display: flex;
        flex-direction: column-reverse;
        align-items: flex-end;
    }

    #sound-btn {
        display: none !important;
    }

    .camera-container {
        position: fixed;
        top: 20px;
        left: 20px;
        bottom: auto;
        right: auto;
        width: 150px;
        height: 100px;
        border-radius: 8px;
        z-index: 100;
    }

    .expandable-controls {
        position: absolute;
        top: 60px;
        right: 0;
        flex-direction: column;
        align-items: flex-end;
        transform: translateY(-10px);
        margin-right: 0;
        transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.4s;
    }

    .expandable-controls.open {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
    }

    .control-btn {
        padding: 1.5vh 4vw;
        font-size: 4vw;
    }

    #help-btn {
        position: fixed;
        bottom: 5vh;
        right: 5vw;
        top: auto;
    }

    .mobile-read-btn {
        display: none;
        position: fixed;
        bottom: 12vh;
        left: 50%;
        transform: translateX(-50%);
        font-family: 'Courier Prime', 'Courier New', monospace;
        font-size: 5vw;
        font-weight: 400;
        cursor: pointer;
        z-index: 40;
        color: #000;
        background: transparent;
        padding: 0;
        border-radius: 0;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }

    body.dark-theme .mobile-read-btn {
        color: #fff;
        background: transparent;
    }

    #text-view {
        padding-top: 15vh;
        padding-left: 8vw;
        padding-right: 8vw;
        padding-bottom: 15vh;
        overflow-y: auto;
    }

    .back-btn {
        top: 5vh;
        left: 40px;
        font-size: 8vw;
    }

    .full-text-content h2 {
        font-size: 7vw;
        margin-bottom: 4vh;
    }

    .full-text-content p {
        font-size: 4.5vw;
        margin-bottom: 3vh;
    }
}