:root {
    --main-color: #ff3333; /* Red color */
    --gallery-active-color: #ff3333;
    --debug-accent: #00FFFF;
    --bg-color: #d8d8d8;
    --dynamic-tint-rgb: 216, 216, 216;
    --dynamic-tint-alpha: 0;
    --grid-size: 40px;
    --grid-line: 1px;
    --wireframe-line-width: 1.5px;
    --overlay-ui-padding: 20px;
    --side-ui-reference-offset: 40px;
    --side-ui-offset: calc((var(--overlay-ui-padding) + var(--side-ui-reference-offset)) / 2);
    --outline-nav-rest-line-width: 18px;
    --outline-nav-active-line-width: 34px;
    --outline-nav-axis-offset: calc(var(--side-ui-offset) - (var(--outline-nav-rest-line-width) / 2));
    --controls-reference-offset: 60px;
    --controls-offset: calc((var(--overlay-ui-padding) + var(--controls-reference-offset)) / 2);
    --project-frame-left: 96px;
    --project-frame-right: calc(100vw - 96px);
    --project-frame-top: 96px;
    --project-frame-bottom: calc(var(--app-height) - 96px);
    --gallery-frame-left: var(--project-frame-left);
    --gallery-frame-right: var(--project-frame-right);
    --gallery-frame-top: var(--project-frame-top);
    --gallery-frame-bottom: var(--project-frame-bottom);
    --about-frame-left: var(--project-frame-left);
    --about-frame-right: var(--project-frame-right);
    --about-frame-top: var(--project-frame-top);
    --about-frame-bottom: var(--project-frame-bottom);
    
    /* 3D Room Variables */
    --app-height: 100vh;
    --room-width: 100vw; /* Full viewport width */
    --room-height: var(--app-height); /* Synced from JS visual viewport on mobile */
    --room-depth: 1000px;
    --space-scroll: 0px;
    --back-content-offset: var(--room-height);
    --ceiling-content-offset: calc(var(--room-depth) + var(--room-height));
}

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

body {
    width: 100vw;
    height: var(--app-height);
    overflow: hidden; /* We will implement custom scroll */
    background-color: var(--bg-color);
    background-image: linear-gradient(
        rgba(var(--dynamic-tint-rgb), var(--dynamic-tint-alpha)),
        rgba(var(--dynamic-tint-rgb), var(--dynamic-tint-alpha))
    );
    font-family: 'Atkinson Hyperlegible', 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
    color: var(--main-color);
    transition: background-image 240ms ease, background-color 240ms ease, box-shadow 240ms ease;
    box-shadow: inset 0 0 0 9999px rgba(var(--dynamic-tint-rgb), calc(var(--dynamic-tint-alpha) * 0.35));
}

/* Detail projektu: bez barevného nádechu z obrázků — jen černá */
body.project-page {
    --dynamic-tint-alpha: 0;
    box-shadow: none;
}

body.about-page {
    --dynamic-tint-alpha: 0;
    box-shadow: none;
}

body.project-page.dark-mode,
:root.dark-mode body.project-page {
    background-color: #000;
    --bg-color: #000;
}

body.about-page.dark-mode,
:root.dark-mode body.about-page {
    background-color: #000;
    --bg-color: #000;
}

body.gallery-page,
body.gallery-page.dark-mode,
:root.dark-mode body.gallery-page {
    box-shadow: none;
}

/* UI Overlay */
.overlay-ui {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100;
    pointer-events: none;
    padding: var(--overlay-ui-padding);
}

.overlay-ui * {
    /* Reset pointer-events to none for containers to avoid blocking 3D scene */
    pointer-events: none;
}

.overlay-ui a,
.overlay-ui button,
.overlay-ui input,
.overlay-ui label,
.overlay-ui .toggle-btn {
    pointer-events: auto;
}

.gallery-intro {
    position: fixed;
    inset: 0;
    z-index: 160;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    pointer-events: none;
    opacity: var(--gallery-intro-opacity, 0);
    visibility: hidden;
}

.gallery-intro-title {
    color: var(--main-color);
    max-width: 92vw;
    font-size: clamp(28px, 10vw, 180px);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    line-height: 0.9;
    text-align: center;
    white-space: nowrap;
    /* translate3d(0,0,0) is a no-op that forces a compositor layer so the
       per-frame scale change doesn't re-rasterize the text (eliminates the
       sub-pixel AA flicker visible on wide viewports). */
    transform: translate3d(0, 0, 0) scale(var(--gallery-intro-scale, 1));
    transform-origin: center center;
    backface-visibility: hidden;
    opacity: 1;
}

body.gallery-intro-active .gallery-intro {
    visibility: visible;
}

/* Layer promotion hints active only during the intro animation. These
   are removed once the class is dropped in finishGalleryIntro() so
   long-lived memory isn't wasted on will-change. */
body.gallery-intro-active .gallery-intro-title {
    will-change: transform, opacity;
}

body.gallery-intro-active .scene {
    will-change: opacity;
}

body.gallery-intro-active .room {
    will-change: transform;
}

body.gallery-intro-active .wireframe-overlay {
    will-change: opacity;
}


.side-nav {
    position: absolute;
    display: flex;
    flex-direction: column;
    width: 0; /* Minimize width so container doesn't block clicks */
    white-space: nowrap; /* Keep text on one line */
    /* Create a long vertical line for the nav container if needed, but design seems minimal */
    transition: opacity 260ms ease, transform 260ms ease;
}

.side-nav-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 28px;
}

.side-nav a {
    text-decoration: none;
    color: var(--main-color);
    text-transform: lowercase;
    font-size: 14px;
    font-weight: bold;
    letter-spacing: 1px;
    /* Vertical text */
    writing-mode: vertical-rl;
    transform: rotate(180deg); /* Adjust orientation */
}

.side-nav a.side-nav-brand {
    text-transform: uppercase;
    letter-spacing: 0.14em;
}

.theme-nav {
    position: absolute;
    left: calc(var(--side-ui-offset) + 44px);
    bottom: 18px;
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
    width: auto;
    white-space: nowrap;
    transition: opacity 260ms ease, transform 260ms ease;
}

.theme-nav button {
    color: var(--main-color);
    background: transparent;
    border: none;
    padding: 0;
    font: inherit;
    cursor: pointer;
    text-decoration: none;
    text-transform: lowercase;
    font-size: 14px;
    font-weight: bold;
    letter-spacing: 1px;
    line-height: 1;
    transform: none;
}

.side-nav.left {
    left: var(--side-ui-offset);
    top: 50%;
    height: var(--outline-nav-total-max-height, calc((100vh - 96px) * 0.85));
    align-items: center;
    justify-content: space-between;
    transform: translateY(-50%);
}

body.front-view-active .side-nav.left {
    opacity: 0;
    transform: translate(-18px, -50%);
}

.side-nav.right {
    top: 50%;
    right: var(--side-ui-offset);
    align-items: center;
    gap: 100px;
    transform: translateY(-50%);
}

body.front-view-active .side-nav.right {
    opacity: 0;
    transform: translate(18px, -50%);
}

body.front-view-active .theme-nav {
    opacity: 0;
    pointer-events: none;
    transform: translate(-18px, 0);
}

.outline-nav {
    position: absolute;
    top: 50%;
    right: var(--outline-nav-axis-offset);
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: flex-start;
    height: var(--outline-nav-total-max-height, auto);
    pointer-events: auto;
    overflow: visible;
    transition: opacity 260ms ease, transform 260ms ease;
}

body.front-view-active .outline-nav {
    opacity: 0;
    pointer-events: none;
    transform: translate(18px, -50%);
}

/* Project detail: same outline column height as gallery so bottom control aligns with "categories" */
.project-page .outline-nav {
    --outline-nav-total-max-height: calc((100vh - 96px) * 0.85);
}

.project-page .outline-nav-items {
    padding-bottom: 122px;
}

a.outline-nav-footer {
    display: flex;
    text-decoration: none;
    color: inherit;
}

.outline-nav-items {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0;
    width: 100%;
    max-height: var(--outline-nav-max-height, none);
    overflow: visible;
    transform: translateY(calc(var(--outline-nav-gap, 12px) / -2));
    opacity: 1;
    transition: opacity 220ms ease, transform 220ms ease;
}

body.gallery-filter-transitioning .outline-nav-items {
    opacity: 0;
    pointer-events: none;
    transform: translateY(calc(var(--outline-nav-gap, 12px) / -2)) translateX(8px);
}

.overlay-ui .outline-nav-items,
.overlay-ui .outline-nav-items * {
    pointer-events: none;
}

.overlay-ui .outline-nav-item {
    pointer-events: auto;
}

.outline-nav-item {
    position: relative;
    width: var(--outline-nav-active-line-width);
    height: var(--outline-nav-item-hit-height, calc(12px + var(--outline-nav-gap, 12px)));
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
}

.outline-nav-line {
    position: absolute;
    top: 50%;
    right: 0;
    width: var(--outline-nav-rest-line-width);
    height: 1px;
    background: var(--main-color);
    opacity: 0.45;
    transform: translateY(-50%);
    transition: width 180ms ease, opacity 180ms ease, transform 180ms ease;
}

.outline-nav-item:hover .outline-nav-line,
.outline-nav-item:focus-visible .outline-nav-line,
.outline-nav-item.is-active .outline-nav-line {
    width: var(--outline-nav-active-line-width);
    opacity: 1;
    transform: translateY(-50%) translateX(-2px);
}

.outline-nav-item[data-outline-reveal-state="hidden"] {
    pointer-events: none;
}

.outline-nav-item[data-outline-reveal-state="hidden"] .outline-nav-line {
    opacity: 0;
    transform: translateY(-50%) translateX(8px);
}

.outline-nav-label {
    position: absolute;
    top: 50%;
    right: 42px;
    padding: 5px 8px;
    color: var(--main-color);
    background: color-mix(in srgb, var(--bg-color) 84%, transparent);
    border: 1px solid color-mix(in srgb, var(--main-color) 35%, transparent);
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    letter-spacing: 0.04em;
    text-transform: none;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    z-index: 2;
    transform: translateY(-50%) translateX(6px);
    transition: opacity 160ms ease, transform 160ms ease;
}

.outline-nav-item:hover .outline-nav-label,
.outline-nav-item:focus-visible .outline-nav-label,
.outline-nav.is-engaged .outline-nav-item.is-active .outline-nav-label {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

.outline-nav-item[data-outline-reveal-state="hidden"] .outline-nav-label {
    opacity: 0;
    transform: translateY(-50%) translateX(10px);
}

.outline-nav-item:focus-visible {
    outline: none;
}

.outline-nav-categories {
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    max-height: var(--outline-nav-max-height, none);
    opacity: 0;
    pointer-events: none;
    transform: translateX(8px);
    transition: opacity 220ms ease, transform 220ms ease;
}

.overlay-ui .outline-nav-categories,
.overlay-ui .outline-nav-categories * {
    pointer-events: none;
}

.outline-nav.is-category-open .outline-nav-items {
    opacity: 0;
    pointer-events: none;
    transform: translateY(calc(var(--outline-nav-gap, 12px) / -2)) translateX(8px);
}

.outline-nav.is-category-open .outline-nav-categories {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);
}

.overlay-ui .outline-nav.is-category-open .outline-nav-categories,
.overlay-ui .outline-nav.is-category-open .outline-nav-categories * {
    pointer-events: auto;
}

.outline-nav-category {
    width: var(--outline-nav-rest-line-width);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 0;
    border: none;
    background: transparent;
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    opacity: 0.85;
    overflow: visible;
    transition: opacity 180ms ease, transform 180ms ease;
}

.outline-nav-category-label {
    display: block;
    color: var(--main-color);
    font-family: inherit;
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
    letter-spacing: 1px;
    text-transform: lowercase;
    white-space: nowrap;
    writing-mode: vertical-rl;
    text-align: center;
    transform: rotate(0deg);
}

.outline-nav-category:hover,
.outline-nav-category:focus-visible,
.outline-nav-category.is-selected {
    opacity: 1;
    transform: rotate(0deg) translateX(-2px);
}

.outline-nav-category:focus-visible {
    outline: none;
}

.outline-nav-footer {
    position: absolute;
    right: 0;
    bottom: 0;
    width: var(--outline-nav-rest-line-width);
    display: flex;
    align-items: center;
    justify-content: center;
    height: 108px;
    flex: 0 0 auto;
    padding: 0;
    border: none;
    background: transparent;
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    opacity: 0.85;
    overflow: visible;
    transition: opacity 180ms ease, transform 180ms ease;
}

.outline-nav-selected-category {
    position: absolute;
    right: -1px;
    bottom: calc(108px + var(--outline-nav-stack-gap, 14px));
    width: var(--outline-nav-rest-line-width);
    height: 108px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    background: transparent;
    appearance: none;
    -webkit-appearance: none;
    opacity: 0;
    pointer-events: none;
    cursor: pointer;
    transform: translateX(4px);
    transition: opacity 180ms ease, transform 180ms ease;
}

.overlay-ui .outline-nav-selected-category,
.overlay-ui .outline-nav-selected-category * {
    pointer-events: none;
}

.outline-nav-selected-category.is-visible {
    opacity: 0.85;
    pointer-events: auto;
    transform: translateX(0);
}

.outline-nav-selected-category.is-visible::after {
    content: "×";
    position: absolute;
    left: 50%;
    bottom: 6px;
    color: var(--main-color);
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    transform: translateX(-50%);
    opacity: 0.85;
}

.overlay-ui .outline-nav-selected-category.is-visible,
.overlay-ui .outline-nav-selected-category.is-visible * {
    pointer-events: auto;
}

body.gallery-filter-transitioning .outline-nav-selected-category,
body.gallery-filter-transitioning .outline-nav-selected-category.is-visible {
    opacity: 0;
    pointer-events: none;
    transform: translateX(8px);
}

.outline-nav.is-category-open .outline-nav-selected-category {
    opacity: 0;
    pointer-events: none;
    transform: translateX(8px);
}

.outline-nav-selected-category-label {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--main-color);
    font-family: inherit;
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
    letter-spacing: 1px;
    text-transform: lowercase;
    white-space: nowrap;
    writing-mode: vertical-rl;
    text-align: center;
    transform: rotate(0deg);
}

.outline-nav-selected-category:hover,
.outline-nav-selected-category:focus-visible {
    opacity: 1;
    transform: translateX(-2px);
}

.outline-nav-selected-category:focus-visible {
    outline: none;
}

.outline-nav-footer-label {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--main-color);
    font-family: inherit;
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
    letter-spacing: 1px;
    text-transform: lowercase;
    white-space: nowrap;
    writing-mode: vertical-rl;
    text-align: center;
    transform: rotate(0deg);
}

.outline-nav-footer:hover,
.outline-nav-footer:focus-visible,
.outline-nav-footer.is-selected {
    opacity: 1;
    transform: rotate(0deg) translateX(-2px);
}

.outline-nav-footer:focus-visible {
    outline: none;
}

.outline-nav-flyout {
    position: fixed;
    z-index: 240;
    margin: 0;
    pointer-events: none;
}

.controls {
    position: absolute;
    bottom: 40px;
    right: var(--controls-offset);
    display: none;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    font-size: 12px;
    transition: opacity 260ms ease, transform 260ms ease;
}

body.front-view-active .controls {
    opacity: 0;
    pointer-events: none;
    transform: translateY(18px);
}

.debug-controls {
    position: absolute;
    top: 40px;
    right: var(--controls-offset);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    z-index: 120;
}

.gallery-page .debug-controls.audio-controls {
    right: calc(100vw - var(--gallery-frame-right));
}

.project-page .debug-controls.audio-controls {
    right: calc(100vw - var(--project-frame-right));
}

.debug-control-row {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--debug-accent);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.debug-control-row label {
    color: inherit;
    transform: translate(-40px, -25px);
}

.debug-control-row .toggle-btn {
    width: 24px;
    min-width: 24px;
    height: 24px;
    border: 1px solid var(--debug-accent);
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.42);
    color: var(--debug-accent);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    transform: translate(-40px, -25px);

}

.debug-control-row .toggle-btn.active {
    background: var(--debug-accent);
    color: #000;
}

.audio-toggle-btn svg {
    width: 15px;
    height: 15px;
    display: block;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

.debug-control-row .audio-toggle-btn {
    width: auto;
    min-width: 0;
    height: auto;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    color: var(--main-color);
    transform: translateY(-25px);
}

.debug-control-row .audio-toggle-btn.active {
    background: transparent;
    color: var(--main-color);
}

.debug-control-row .audio-toggle-btn svg {
    width: 22px;
    height: 22px;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.counter-buttons {
    display: flex;
    gap: 5px;
}

.counter-buttons button {
    background: transparent;
    border: 1px solid var(--main-color);
    color: var(--main-color);
    width: 20px;
    height: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.counter-buttons button:hover {
    background: var(--main-color);
    color: var(--bg-color);
}

.partition {
    position: absolute;
    top: 0;
    left: 0;
    width: var(--room-width) !important;
    height: var(--room-height) !important;
    border: var(--wireframe-line-width) solid var(--main-color) !important;
    border-left-width: var(--wireframe-line-width) !important;
    border-right-width: var(--wireframe-line-width) !important;
    background: transparent !important;
    background-color: transparent !important;
    pointer-events: none;
}

input[type=range] {
    width: 150px;
    accent-color: var(--main-color);
}

/* 3D Scene */
.scene {
    position: relative;
    width: 100vw;
    height: var(--app-height);
    perspective: var(--gallery-scene-perspective, 1200px);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.room {
    position: relative;
    z-index: 2;
    width: var(--room-width);
    height: var(--room-height);
    transform-style: preserve-3d;
    transform: translateZ(calc(var(--room-depth) / -2));
    /* Transition removed to prevent sync issues with JS scroll/depth updates */
}

.wall {
    position: absolute;
    background-color: var(--bg-color);
    /* Removed Grid Pattern */
    /* Borders will define the space now, but we want only specific lines */
    border: none; 
    opacity: 1;
}

.wall {
    position: absolute;
    background-color: var(--bg-color);
    background-image: linear-gradient(
        rgba(var(--dynamic-tint-rgb), var(--dynamic-tint-alpha)),
        rgba(var(--dynamic-tint-rgb), var(--dynamic-tint-alpha))
    );
    /* Borders added to replace wireframe in 3D */
    border: none; 
    opacity: 1;
    pointer-events: none !important; /* Ensure walls don't block clicks on content */
    transition: background-image 240ms ease, background-color 240ms ease, box-shadow 240ms ease;
    box-shadow: inset 0 0 0 9999px rgba(var(--dynamic-tint-rgb), calc(var(--dynamic-tint-alpha) * 0.8));
}

/* Wall Transforms & Borders for the "8 lines" look */

.back-wall {
    width: var(--room-width);
    height: var(--room-height);
    transform: translateZ(calc(var(--room-depth) / -2));
    z-index: -1;
    border: none;
}

.left-wall {
    width: var(--room-depth);
    height: var(--room-height);
    transform: rotateY(90deg) translateZ(calc(var(--room-width) / -2));
    left: calc(50% - var(--room-depth) / 2);
    top: 0;
    /* No borders needed here if ceiling/floor handle the corners */
}

.right-wall {
    width: var(--room-depth);
    height: var(--room-height);
    transform: rotateY(-90deg) translateZ(calc(var(--room-width) / -2));
    left: calc(50% - var(--room-depth) / 2);
    top: 0;
    /* No borders needed here if ceiling/floor handle the corners */
}

.ceiling {
    width: var(--room-width);
    height: var(--room-depth);
    transform: rotateX(-90deg) translateZ(calc(var(--room-height) / -2));
    top: calc(50% - var(--room-depth) / 2);
    left: 0;
    /* Side borders create the top-left and top-right depth lines */
    border-left: none;
    border-right: none;
}

.floor {
    width: var(--room-width);
    height: var(--room-depth);
    transform: rotateX(90deg) translateZ(calc(var(--room-height) / -2));
    top: calc(50% - var(--room-depth) / 2);
    left: 0;
    /* Side borders create the bottom-left and bottom-right depth lines */
    border-left: none;
    border-right: none;
}

/* Markers for SVG tracking */
.marker {
    position: absolute;
    width: 0;
    height: 0;
}
.marker.tl { top: 0; left: 0; }
.marker.tr { top: 0; right: 0; }
.marker.bl { bottom: 0; left: 0; }
.marker.br { bottom: 0; right: 0; }

/* SVG Wireframe */
.wireframe-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    display: block;
}

.animation-page .wireframe-overlay,
.about-page .wireframe-overlay,
.project-page .wireframe-overlay {
    z-index: 30;
}

.wireframe-overlay line,
.wireframe-overlay polygon {
    stroke: var(--main-color);
    stroke-width: var(--wireframe-line-width);
    fill: none;
    vector-effect: non-scaling-stroke;
    shape-rendering: geometricPrecision;
    stroke-linecap: square;
    stroke-linejoin: miter;
    filter: drop-shadow(0 0 1px var(--bg-color));
}

/* Zone Wrappers to position content planes */
.zone-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    transform-style: preserve-3d;
}

/* Floor Wrapper: Aligned with Floor Plane */
.floor-wrapper {
    /* Floor is rotated X 90deg. We match that. */
    /* Actually, we want to position the WRAPPER so that its content (0,0) starts at the front-left of floor? */
    /* Let's mimic the .floor transform logic but keep it independent of the wall div */
    /* Floor center is: rotateX(90deg) translateZ(height/-2) */
    /* But we want to scroll "through" it. */
    /* Easier: Position it exactly like .floor */
    transform: rotateX(90deg) translateZ(calc(var(--room-height) / -2));
    width: var(--room-width);
    height: var(--room-depth); /* Depth is height in this orientation */
    top: calc(50% - var(--room-depth) / 2);
    left: 0;
    /* The wrapper changes size with room-depth! This is good. */
}

/* Ceiling Wrapper */
.ceiling-wrapper {
    transform: rotateX(-90deg) translateZ(calc(var(--room-height) / -2));
    width: var(--room-width);
    height: var(--room-depth);
    top: calc(50% - var(--room-depth) / 2);
    left: 0;
}

/* Back Content is already inside .back-wall, so it inherits transform! */
/* Just need to position the inner container */
.back-content {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: translate3d(0, calc(var(--back-content-offset) - var(--space-scroll)), 0);
    /* Setup flex/grid for content if needed, or absolute items */
}

.floor-content {
    transform: translate3d(0, calc(0px - var(--space-scroll)), 0);
}

.ceiling-content {
    transform: translate3d(0, calc(var(--ceiling-content-offset) - var(--space-scroll)), 0);
}

.back-wall .zone-content,
.zone-wrapper .zone-content {
    pointer-events: auto;
}

.project-page .back-wall,
.about-page .back-wall,
.project-page .zone-wrapper,
.about-page .zone-wrapper {
    overflow: hidden;
}

/* Generic Zone Content Styling */
.zone-content {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    
    /* Flex Layout to prevent overlap */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 15vh; /* Reduced gap for numbers to be closer */
    padding-top: 10vh;
    padding-bottom: 10vh;
    /* GPU optimization */
    will-change: transform;
    backface-visibility: hidden;
}

/* Content Items in Zones */
.zone-content .content-item {
    position: relative; /* Changed from absolute to relative for flex flow */
    left: auto;
    top: auto;
    transform: none; /* Reset basic transform, controlled by wrapper/flex */
    width: 60%;
    text-align: center;
    backface-visibility: visible;
}

.debug-num {
    font-size: 15rem;
    font-weight: bold;
    line-height: 1;
    color: var(--main-color);
}

/* Specific adjustments per zone */

.floor-content {
    /* Floor: Items stack into depth. */
    /* Current logic showed 3 closest to camera, 1 furthest. */
    /* We want 1 closest (Start), 3 furthest (End). */
    /* So we reverse the column order. */
    flex-direction: column-reverse;
    /* Align items to the 'end' of the flex container (which is the 'start' of Y axis due to reverse?) */
    /* Flex-Start = Camera. Flex-End = Wall. */
    /* We want items to be touching the wall. */
    justify-content: flex-end;
}

.floor-content .content-item {
    transform: none; 
}

.back-content {
    /* Back Wall: Items stack vertically. */
    /* We want continuity from floor. */
    /* Floor ends, then Back Wall begins. */
    /* So first item of back wall should be at the BOTTOM. */
    justify-content: flex-end;
    /* Or reverse order? flex-direction: column-reverse */
    flex-direction: column-reverse; 
}

.ceiling-content {
    /* Ceiling: Items stack into Z. */
    /* We want symmetry with floor: 1 closest to Start (Camera), 3 closest to Wall. */
    /* So we use column-reverse (1 at Y-max/Camera, 3 at Y-min/Wall). */
    flex-direction: column-reverse;
    /* Align to Wall (Y-min). */
    justify-content: flex-end;
}

.ceiling-content .content-item {
    /* Reset rotation based on feedback "now it's reversed". */
    /* Default orientation (Top points to Wall) is correct for tunnel view. */
    transform: none;
}

/* ============================================
   DARK MODE
   ============================================ */

body.dark-mode,
:root.dark-mode body {
    --bg-color: #0a0a0a;
    --main-color: #ff3333;
}

body.dark-mode .wall,
:root.dark-mode .wall {
    background-color: var(--bg-color);
}

body.dark-mode .content-item,
:root.dark-mode .content-item {
    text-shadow: 0 0 20px rgba(255, 51, 51, 0.3);
}

body.dark-mode .falling-num,
:root.dark-mode .falling-num {
    text-shadow: 0 0 40px rgba(255, 51, 51, 0.5);
}

body.dark-mode .partition,
:root.dark-mode .partition {
    background-color: var(--bg-color);
}

/* Gallery Page Specifics */
.gallery-page .overlay-ui {
    opacity: var(--gallery-ui-opacity, 1);
    transition: opacity 320ms ease;
}

.gallery-page .side-nav.left {
    transform: translate(var(--gallery-side-nav-left-offset, 0), -50%);
    opacity: var(--gallery-ui-opacity, 1);
}

.gallery-page .theme-nav {
    transform: translateX(var(--gallery-side-nav-left-offset, 0));
    opacity: var(--gallery-ui-opacity, 1);
}

.gallery-page .outline-nav {
    transform: translate(var(--gallery-outline-nav-offset, 0), -50%);
    opacity: var(--gallery-ui-opacity, 1);
}

.gallery-page .side-nav.left,
.gallery-page .theme-nav,
.gallery-page .outline-nav {
    transition: opacity 320ms ease, transform 320ms ease;
}

.gallery-page .scene {
    opacity: var(--gallery-scene-opacity, 1);
}

.gallery-page .wireframe-overlay {
    opacity: var(--gallery-wireframe-opacity, 1);
}

.gallery-page .wireframe-overlay line,
.gallery-page .wireframe-overlay polygon {
    filter: none;
}

.gallery-card {
    position: absolute;
    /* Default centering is removed here, handled by classes */
    width: 320px;
    height: 450px;
    background: var(--bg-color);
    border: 1px solid var(--main-color);
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    padding: 20px;
    text-align: left;
    pointer-events: auto;
    text-decoration: none; /* Remove underline from anchor */
    color: var(--main-color);
    opacity: 1;
    transition: transform 0.3s ease, border-color 0.3s ease, background-color 0.3s ease, opacity 220ms ease;
    transform-style: preserve-3d; /* Key for preserving 3d context */
    overflow: hidden;
    z-index: 3;
}

.gallery-card:visited {
    color: var(--main-color);
}

body.gallery-filter-transitioning .gallery-card {
    pointer-events: none;
}

.gallery-card[data-filter-transition-state="hidden"],
.gallery-card[data-filter-transition-state="hiding"] {
    opacity: 0 !important;
    pointer-events: none;
}

.gallery-card[data-visibility-state="past"] {
    opacity: 0;
    pointer-events: none;
}

.gallery-card[data-visibility-state="active"],
.gallery-card[data-visibility-state="future"] {
    opacity: 1;
}

.gallery-card[data-visibility-state="active"] {
    border-color: var(--gallery-active-color);
    background: var(--gallery-active-color);
    color: var(--bg-color);
}

/* Positioning Classes */
.pos-center {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.pos-tl {
    top: 15%;
    left: 15%;
    transform: none;
}

.pos-tr {
    top: 15%;
    right: 15%;
    transform: none;
}

.pos-bl {
    bottom: 15%;
    left: 15%;
    transform: none;
}

.pos-br {
    bottom: 15%;
    right: 15%;
    transform: none;
}

/* Hover Effects */
.gallery-card:hover {
    border-color: var(--main-color);
    background: var(--main-color);
    color: var(--bg-color);
    cursor: pointer;
    /* Hover scale logic moved to specific modifiers below */
}

.gallery-card[data-visibility-state="active"]:hover {
    border-color: var(--gallery-active-color);
    background: var(--gallery-active-color);
    color: var(--bg-color);
}

.gallery-card:hover img,
.gallery-card:hover .gallery-card-image {
    opacity: 1;
}

/* Scale on hover must respect the initial transform */
.gallery-card.pos-center:hover {
    transform: translate(-50%, -50%) scale(1.03);
}

.gallery-card:not(.pos-center):hover {
    transform: scale(1.03);
}

.gallery-card-media-shell {
    position: relative;
    width: 100%;
    height: 320px;
    margin-bottom: 15px;
    border: 1px solid var(--main-color);
    overflow: hidden;
    background:
        linear-gradient(
            135deg,
            color-mix(in srgb, var(--bg-color) 92%, transparent),
            color-mix(in srgb, var(--main-color) 14%, var(--bg-color))
        );
}

.media-debug-overlay {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 2;
    max-width: calc(100% - 20px);
    display: inline-flex;
    align-items: flex-start;
    gap: 8px;
    pointer-events: none;
}

.media-debug-info {
    display: none;
    max-width: min(220px, calc(100vw - 96px));
    padding: 8px 10px;
    border: 1px solid var(--debug-accent);
    background: rgba(0, 0, 0, 0.72);
    color: var(--debug-accent);
    font-size: 10px;
    line-height: 1.15;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.18);
    backdrop-filter: blur(10px);
}

body.media-debug-visible .media-debug-info {
    display: grid;
    gap: 4px;
}

.media-debug-info__name,
.media-debug-info__size {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.media-debug-info__name {
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: none;
}

.media-debug-info__size {
    font-size: 8px;
    font-weight: 500;
    letter-spacing: 0.08em;
    opacity: 0.9;
}

.gallery-card-media-placeholder {
    position: absolute;
    inset: 0;
    background:
        linear-gradient(
            135deg,
            color-mix(in srgb, var(--bg-color) 88%, transparent),
            color-mix(in srgb, var(--main-color) 18%, var(--bg-color))
        );
    opacity: 0.55;
    transition: opacity 180ms ease;
}

.gallery-card img,
.gallery-card-image {
    width: 100%;
    height: 320px;
    object-fit: cover;
    opacity: 0.9;
    backface-visibility: hidden;
    image-rendering: optimizeSpeed;
    transition: opacity 180ms ease;
}

.gallery-card video {
    width: 100%;
    height: 320px;
    object-fit: cover;
    opacity: 0.9;
    backface-visibility: hidden;
    transition: opacity 180ms ease;
}

.gallery-card[data-media-ready="false"] .gallery-card-image,
.gallery-card-image[data-media-state="detached"],
.gallery-card-image:not([src]) {
    opacity: 0;
}

.gallery-card[data-media-ready="true"] .gallery-card-media-placeholder {
    opacity: 0;
}

.gallery-card-meta {
    width: 100%;
    color: inherit;
    text-align: left;
    transition: color 0.3s ease;
}

.gallery-card h2 {
    color: inherit;
    font-size: 16px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0;
    line-height: 1.3;
    transition: color 0.3s ease;
}

.gallery-card-author {
    color: inherit;
    font-size: 12px;
    font-weight: bold;
    letter-spacing: 0.04em;
    line-height: 1.25;
    margin: 4px 0 0;
    text-transform: none;
    transition: color 0.3s ease;
}

/* Override partition behavior for gallery */
.gallery-page .partition {
    /* Remove flex centering because we use absolute positioning on cards inside */
    display: block; 
    background-color: transparent !important;
    /* Keep default border from .partition unless desired otherwise */
    transform-style: preserve-3d; /* Ensure children are in 3D space */
    border-left: var(--wireframe-line-width) solid var(--main-color) !important;
    border-right: var(--wireframe-line-width) solid var(--main-color) !important;
}

.gallery-page .wall {
    background: transparent !important;
    background-image: none !important;
    box-shadow: none !important;
}

body.gallery-intro-active.gallery-page {
    --gallery-ui-opacity: 0;
    --gallery-side-nav-left-offset: -18px;
    --gallery-outline-nav-offset: 18px;
}

body.gallery-intro-active .overlay-ui,
body.gallery-intro-active .overlay-ui *,
body.gallery-intro-active .gallery-card {
    pointer-events: none !important;
}

/* Dark mode adjustment for gallery card */
body.dark-mode .gallery-card,
:root.dark-mode .gallery-card {
    background: var(--bg-color);
    box-shadow: 0 0 12px rgba(255, 51, 51, 0.14);
}

body.dark-mode .gallery-card[data-visibility-state="active"],
:root.dark-mode .gallery-card[data-visibility-state="active"] {
    border-color: var(--gallery-active-color);
    background: var(--gallery-active-color);
}

body.dark-mode .gallery-card[data-visibility-state="active"] .gallery-card-meta,
:root.dark-mode .gallery-card[data-visibility-state="active"] .gallery-card-meta {
    color: #000;
}

body.dark-mode .gallery-card:hover,
:root.dark-mode .gallery-card:hover {
    border-color: var(--main-color);
    background: var(--main-color);
}

body.dark-mode .gallery-card:hover .gallery-card-meta,
:root.dark-mode .gallery-card:hover .gallery-card-meta {
    color: #000;
}

/* ============================================
   B/W MODE (High Contrast)
   ============================================ */

body.bw-mode,
:root.bw-mode body {
    --main-color: #000000;
    --bg-color: #ffffff;
}

body.bw-mode.dark-mode,
:root.bw-mode.dark-mode body {
    --main-color: #ffffff;
    --bg-color: #000000;
}

/* Override fixed red colors and shadows */
body.bw-mode .falling-num,
body.bw-mode .falling-num:nth-child(n),
:root.bw-mode .falling-num,
:root.bw-mode .falling-num:nth-child(n) {
    color: var(--main-color) !important;
    text-shadow: none !important;
}

body.bw-mode.dark-mode .falling-num,
:root.bw-mode.dark-mode .falling-num {
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.5) !important;
}

body.bw-mode .content-item,
:root.bw-mode .content-item {
    text-shadow: none !important;
}

body.bw-mode.dark-mode .content-item,
:root.bw-mode.dark-mode .content-item {
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.5) !important;
}

body.bw-mode .gallery-card:hover,
:root.bw-mode .gallery-card:hover {
    background: var(--main-color);
    color: var(--bg-color);
}

body.bw-mode.dark-mode .gallery-card,
:root.bw-mode.dark-mode .gallery-card {
    background: rgba(0, 0, 0, 0.5);
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.2);
}

body.bw-mode .gallery-card img,
:root.bw-mode .gallery-card img {
    background-color: var(--main-color) !important;
}

/* ============================================
   PROJECT DETAIL - PROJECT CARDS
   ============================================ */

.project-page-projects {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 0;
    padding: 0;
    transition: opacity 220ms ease;
}

.about-page-projects {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 0;
    padding: 0;
}

.about-card {
    min-height: 100vh;
    overflow: visible;
}

.about-info {
    --about-text-width: min(980px, 78vw);
    --about-text-padding-inline: clamp(1rem, 3vw, 2rem);
    width: min(920px, 74vw);
    max-width: min(920px, 74vw);
    overflow: visible;
}

.project-info.about-info h2 {
    max-width: var(--about-text-width);
    margin-left: auto;
    margin-right: auto;
    margin-bottom: 2rem;
    padding-inline: var(--about-text-padding-inline);
    white-space: nowrap;
    font-size: clamp(1rem, calc((74vw - (var(--about-text-padding-inline) * 2)) / 11.8), 4rem);
    line-height: 1;
}

.about-page .left-wall,
.about-page .right-wall {
    overflow: hidden;
}

.about-side-logo-plane {
    position: absolute;
    top: var(--about-logo-plane-center-y, calc(50% + clamp(8rem, 18vh, 14rem)));
    left: 0;
    width: var(--room-depth);
    height: var(--about-logo-band-height);
    display: flex;
    align-items: center;
    overflow: hidden;
    pointer-events: none;
    transform: translateY(-50%);
}

.about-side-logo-plane--left::before {
    -webkit-mask-position-x: calc(var(--room-depth) - var(--about-logo-scroll, 0px));
    mask-position-x: calc(var(--room-depth) - var(--about-logo-scroll, 0px));
}

.about-side-logo-plane--right::before {
    -webkit-mask-position-x: calc(0px - var(--about-logo-scroll, 0px) - 100vw);
    mask-position-x: calc(0px - var(--about-logo-scroll, 0px) - 100vw);
}

.about-desc {
    max-width: var(--about-text-width);
    margin: 0 auto;
    padding-inline: var(--about-text-padding-inline);
    font-size: clamp(1rem, 1.45vw, 1.35rem);
    line-height: 1.55;
}

.about-logo-marquee,
.about-side-logo-plane {
    --about-logo-source-width: clamp(1800px, 220vw, 3200px);
    --about-logo-band-height: clamp(110px, 13vw, 190px);
}

.about-logo-marquee::before,
.about-side-logo-plane::before {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--main-color);
    -webkit-mask-image: url("../assets/loga-all.svg");
    mask-image: url("../assets/loga-all.svg");
    -webkit-mask-repeat: repeat-x;
    mask-repeat: repeat-x;
    -webkit-mask-size: var(--about-logo-source-width) auto;
    mask-size: var(--about-logo-source-width) auto;
    -webkit-mask-position-y: center;
    mask-position-y: center;
    pointer-events: none;
}

.about-logo-marquee {
    position: relative;
    width: 100vw;
    height: var(--about-logo-band-height);
    margin: clamp(3rem, 8vh, 6rem) 0 0 50%;
    overflow: hidden;
    pointer-events: none;
    transform: translateX(-50%);
}

.about-logo-marquee::before {
    -webkit-mask-position-x: calc(0px - var(--about-logo-scroll, 0px));
    mask-position-x: calc(0px - var(--about-logo-scroll, 0px));
}

.about-logo-track {
    display: flex;
    align-items: center;
    gap: clamp(72px, 10vw, 160px);
    width: max-content;
    transform: translate3d(var(--about-logo-offset, 0px), 0, 0);
    will-change: transform;
    visibility: hidden;
}

.about-credits {
    max-width: var(--about-text-width);
    margin: clamp(2rem, 6vh, 4rem) auto 0;
    padding-inline: var(--about-text-padding-inline);
    display: grid;
    gap: 1rem;
}

.about-credit-item {
    margin: 0;
    color: var(--main-color);
    font-size: clamp(0.95rem, 1.15vw, 1.05rem);
    line-height: 1.55;
    opacity: 0.9;
}

.about-credit-label {
    display: inline;
    font-weight: 700;
}

.project-card .about-logo-track img,
.about-side-logo-plane .about-logo-track img {
    display: block;
    width: clamp(1800px, 220vw, 3200px);
    max-width: none;
    max-height: none;
    height: auto;
    object-fit: contain;
    border: none;
    box-shadow: none;
    flex: 0 0 auto;
    filter: brightness(0) saturate(100%) invert(35%) sepia(99%) saturate(3050%) hue-rotate(341deg) brightness(108%) contrast(103%);
    opacity: 0.95;
}

body.bw-mode .project-card .about-logo-track img,
body.bw-mode .about-side-logo-plane .about-logo-track img,
:root.bw-mode body .project-card .about-logo-track img,
:root.bw-mode body .about-side-logo-plane .about-logo-track img {
    filter: brightness(0);
}

body.dark-mode .project-card .about-logo-track img,
body.bw-mode.dark-mode .project-card .about-logo-track img,
body.dark-mode .about-side-logo-plane .about-logo-track img,
body.bw-mode.dark-mode .about-side-logo-plane .about-logo-track img,
:root.dark-mode body .project-card .about-logo-track img,
:root.bw-mode.dark-mode body .project-card .about-logo-track img,
:root.dark-mode body .about-side-logo-plane .about-logo-track img,
:root.bw-mode.dark-mode body .about-side-logo-plane .about-logo-track img {
    filter: none;
    opacity: 1;
}

body.project-video-background-page,
body.project-video-intro-settled {
    background-color: #000;
    --bg-color: #000;
}

body.project-video-background-page .scene {
    z-index: 2;
}

body:is(.project-video-background-page, .project-video-intro-settled) .project-card--contained {
    min-height: 150vh;
    justify-content: center;
}

body:is(.project-video-background-page, .project-video-intro-settled) .project-info {
    max-width: min(760px, 72vw);
    padding: clamp(24px, 4vw, 56px);
    background: color-mix(in srgb, #000 58%, transparent);
    backdrop-filter: blur(8px);
    text-shadow: 0 0 24px rgba(0, 0, 0, 0.68);
}

body.project-video-background-page .project-page-projects {
    position: relative;
    z-index: 3;
}

.project-video-surface {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    padding: 0;
    gap: 0;
    background: #000;
    overflow: hidden;
    transform: translateZ(-2px);
    backface-visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 520ms ease;
}

body.project-video-background-page .project-video-surface {
    opacity: 1;
}

body.project-video-background-page.project-video-intro-active .project-video-surface {
    transition: opacity 900ms ease;
}

body.project-video-intro-active .project-page-projects {
    opacity: 0;
    pointer-events: none;
}

body.project-video-content-visible .project-page-projects {
    opacity: 1;
}

body.project-video-intro-restoring .project-page-projects {
    opacity: 0;
    pointer-events: none;
    transition: opacity 260ms ease;
}

body.project-video-intro-restoring .project-video-surface {
    opacity: 0;
    transition: opacity 900ms ease;
}

body.project-video-intro-transitioning .project-video-surface {
    opacity: 0;
}

body.project-media-loading .project-page-projects,
body.project-media-loading .project-video-surface {
    opacity: 0;
    pointer-events: none;
}

.project-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 40;
    width: min(36vw, 360px);
    min-width: 180px;
    color: var(--main-color);
    pointer-events: none;
    transform: translate(-50%, -50%);
    transition: opacity 220ms ease, visibility 220ms ease;
}

.project-loading[hidden],
body:not(.project-media-loading) .project-loading {
    visibility: hidden;
    opacity: 0;
}

.project-loading-label {
    display: block;
    margin-bottom: 0.65rem;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    line-height: 1;
    text-align: center;
    text-transform: uppercase;
}

.project-loading-track {
    position: relative;
    display: block;
    width: 100%;
    height: 2px;
    overflow: hidden;
    background: color-mix(in srgb, var(--main-color) 20%, transparent);
}

.project-loading-bar {
    position: absolute;
    inset: 0 auto 0 0;
    width: max(8%, calc(var(--project-loading-progress, 0) * 100%));
    background: currentColor;
    transform-origin: left center;
    animation: project-loading-pulse 900ms ease-in-out infinite alternate;
}

@keyframes project-loading-pulse {
    from {
        opacity: 0.45;
    }

    to {
        opacity: 1;
    }
}

.project-card {
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 8vh 10vw 12vh;
    gap: 5vh;
    border-bottom: none;
    /* GPU optimization */
    contain: layout style paint;
    will-change: transform;
    pointer-events: auto;
    transition: opacity 220ms ease, padding 220ms ease, min-height 220ms ease;
}

.about-page .project-card {
    contain: layout style;
}

@supports (-webkit-touch-callout: none) {
    .project-page .project-card,
    .about-page .project-card {
        contain: layout style;
        will-change: auto;
        backface-visibility: visible;
    }
}

.project-card img {
    max-width: 70%;
    max-height: 50vh;
    object-fit: contain;
    border: none;
    /* GPU optimization */
    will-change: transform;
    backface-visibility: hidden;
}

.project-card video {
    max-width: 70%;
    max-height: 50vh;
    object-fit: contain;
    border: none;
    will-change: transform;
    backface-visibility: hidden;
}

.project-card--contained {
    justify-content: center;
    padding: 6vh 10vw 10vh;
    gap: 4vh;
}

.project-media-frame {
    position: relative;
    display: block;
    width: 100%;
    pointer-events: auto;
}

.project-focus-trigger {
    cursor: zoom-in;
}

.project-focus-trigger > * {
    pointer-events: none;
}

body.project-media-focus-active .project-focus-trigger,
body.project-media-focus-active .project-links a {
    cursor: zoom-out;
}

body.project-media-focus-active .project-page-projects {
    opacity: 0;
    pointer-events: none;
}

.project-focus-source-hidden {
    opacity: 0;
}

.project-media-focus-layer {
    position: fixed;
    inset: 0;
    z-index: 60;
    pointer-events: none;
}

.project-media-focus-shell {
    position: fixed;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    transform-origin: center center;
    opacity: 1;
    transition: left 280ms ease, top 280ms ease, width 280ms ease, height 280ms ease, opacity 220ms ease;
}

.project-media-focus-shell.is-depth-syncing {
    transition: opacity 220ms ease;
}

.project-media-focus-shell.is-dissolving {
    opacity: 0;
}

.project-media-frame .project-media {
    display: block;
    pointer-events: none;
}

.project-media-grid {
    width: min(78vw, 1100px);
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 1rem;
}

.project-media-grid img {
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: 32vh;
    object-fit: cover;
}

.project-media-grid video {
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: 32vh;
    object-fit: cover;
}

.project-media-grid > :nth-child(1) {
    grid-column: span 4;
}

.project-media-grid > :nth-child(2) {
    grid-column: span 2;
}

.project-media-grid > :nth-child(3),
.project-media-grid > :nth-child(4),
.project-media-grid > :nth-child(5) {
    grid-column: span 2;
}

.project-info {
    text-align: center;
    max-width: 800px;
    pointer-events: auto;
}

.project-card--image-only {
    justify-content: center;
    min-height: auto;
    padding: 0;
    gap: 0;
}

.project-card--image-only .project-media-frame {
    max-width: min(84vw, 1120px);
    width: min(84vw, 1120px);
}

.project-card--image-only img {
    max-width: min(84vw, 1120px);
    width: min(84vw, 1120px);
    max-height: none;
    height: auto;
}

.project-card--image-only video {
    max-width: min(84vw, 1120px);
    width: min(84vw, 1120px);
    max-height: none;
    height: auto;
}

.project-info h2 {
    font-size: clamp(2rem, 5vw, 4rem);
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 1.5rem;
    color: var(--main-color);
}

.project-authors {
    font-size: clamp(0.9rem, 1.5vw, 1.2rem);
    font-weight: bold;
    margin-bottom: 0.5rem;
    color: var(--main-color);
    opacity: 0.9;
}

.project-school {
    font-size: clamp(0.8rem, 1.2vw, 1rem);
    font-style: italic;
    margin-bottom: 2rem;
    color: var(--main-color);
    opacity: 0.7;
}

.project-desc {
    font-size: clamp(0.9rem, 1.3vw, 1.1rem);
    line-height: 1.6;
    color: var(--main-color);
    opacity: 0.85;
}

.project-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.project-links a {
    color: var(--main-color);
    text-decoration: none;
    border: 1px solid currentColor;
    padding: 0.5rem 0.85rem;
    font-size: 0.85rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: zoom-in;
    pointer-events: auto;
}

.project-links a:hover,
.project-links a:focus-visible {
    background: var(--main-color);
    color: var(--bg-color);
}

.project-card--gallery-return {
    min-height: auto;
    padding-top: 6vh;
    padding-bottom: max(12vh, 4rem);
}

/*
 * Floor & ceiling zones come after .back-wall in the DOM, so in the 3D view they often paint
 * above the back wall. Each cloned card is ~100vh tall with pointer-events: auto, so large empty
 * regions steal clicks from the real “Back to gallery” control on the back wall. Disable hits on
 * floor/ceiling cards and re-enable only zoom/focus targets (not duplicate nav links).
 */
.project-page .floor-content,
.project-page .ceiling-content {
    pointer-events: none;
}

.project-page .floor-content .project-card,
.project-page .ceiling-content .project-card {
    pointer-events: none;
}

.project-page .floor-content .project-card:not(.project-card--gallery-return) .project-focus-trigger,
.project-page .floor-content .project-card:not(.project-card--gallery-return) [data-project-focus-trigger="true"],
.project-page .ceiling-content .project-card:not(.project-card--gallery-return) .project-focus-trigger,
.project-page .ceiling-content .project-card:not(.project-card--gallery-return) [data-project-focus-trigger="true"] {
    pointer-events: auto;
}

.project-back-to-gallery-actions {
    margin-top: 0;
}

.project-links .project-back-to-gallery {
    font-family: inherit;
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
    letter-spacing: 1px;
    text-transform: lowercase;
    cursor: pointer;
}

.project-links .project-back-to-gallery:hover,
.project-links .project-back-to-gallery:focus-visible,
.project-links .project-back-to-gallery.is-hover-forced {
    background: var(--main-color);
    color: var(--bg-color);
    cursor: pointer;
}

.project-page.project-return-link-hover .scene,
.project-page.project-return-link-hover .room {
    cursor: pointer;
}

.project-page.project-return-card-visible .project-outline-back {
    opacity: 0;
    pointer-events: none;
    transform: translateX(8px);
}

.project-status {
    margin-top: 1rem;
    font-size: 0.75rem;
    line-height: 1.5;
    color: var(--main-color);
    opacity: 0.75;
    max-width: 18rem;
}

.project-media-focus-asset {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    border: none;
    box-shadow: none;
}

.project-media-focus-asset--document {
    width: 100%;
    height: 100%;
    background: #fff;
}

/* Dark mode adjustments for project cards */
body.dark-mode .project-card img,
:root.dark-mode .project-card img {
    border-color: var(--main-color);
    box-shadow: 0 0 30px rgba(255, 51, 51, 0.15);
}

body.dark-mode .project-info h2,
:root.dark-mode .project-info h2 {
    text-shadow: 0 0 20px rgba(255, 51, 51, 0.3);
}

/* B/W mode adjustments */
body.bw-mode .project-card img,
:root.bw-mode .project-card img {
    border-color: var(--main-color);
}

@media (max-width: 900px) {
    .outline-nav {
        display: none;
    }

    .gallery-page .outline-nav,
    .project-page .outline-nav,
    .about-page .outline-nav {
        display: flex;
    }

    .project-page .side-nav.left {
        top: var(--project-frame-top);
        bottom: calc(var(--app-height) - var(--project-frame-bottom));
        height: auto;
        transform: none;
    }

    .project-page.front-view-active .side-nav.left {
        transform: translateX(-18px);
    }

    .project-page .outline-nav {
        top: var(--project-frame-top);
        bottom: calc(var(--app-height) - var(--project-frame-bottom));
        height: auto;
        justify-content: space-between;
        transform: none;
    }

    .project-page.front-view-active .outline-nav {
        transform: translateX(18px);
    }

    .project-page .outline-nav-items {
        flex: 1 1 auto;
        padding-bottom: 0;
    }

    .project-page .theme-nav {
        left: var(--project-frame-left);
    }

    .project-page .debug-controls.audio-controls {
        right: calc(100vw - var(--project-frame-right));
    }

    .about-page .side-nav.left {
        top: var(--about-frame-top);
        bottom: calc(var(--app-height) - var(--about-frame-bottom));
        height: auto;
        transform: none;
    }

    .about-page.front-view-active .side-nav.left {
        transform: translateX(-18px);
    }

    .about-page .outline-nav {
        top: var(--about-frame-top);
        bottom: calc(var(--app-height) - var(--about-frame-bottom));
        height: auto;
        justify-content: space-between;
        transform: none;
    }

    .about-page.front-view-active .outline-nav {
        transform: translateX(18px);
    }

    .about-page .outline-nav-items {
        flex: 1 1 auto;
        padding-bottom: 0;
    }

    .about-page .theme-nav {
        left: var(--about-frame-left);
    }

    .gallery-page .side-nav.left {
        top: var(--gallery-frame-top);
        bottom: calc(var(--app-height) - var(--gallery-frame-bottom));
        height: auto;
        transform: none;
    }

    .gallery-page .theme-nav {
        left: var(--gallery-frame-left);
    }

    .gallery-page .debug-controls.audio-controls {
        right: calc(100vw - var(--gallery-frame-right));
    }

    .gallery-card.pos-tl,
    .gallery-card.pos-tr {
        top: 12%;
        right: auto;
        left: 50%;
        transform: translateX(-50%);
    }

    .gallery-card.pos-bl,
    .gallery-card.pos-br {
        right: auto;
        bottom: 12%;
        left: 50%;
        transform: translateX(-50%);
    }

    .gallery-card.pos-tl:hover,
    .gallery-card.pos-tr:hover,
    .gallery-card.pos-bl:hover,
    .gallery-card.pos-br:hover {
        transform: translateX(-50%) scale(1.03);
    }

    .project-media-grid {
        width: min(88vw, 1120px);
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .project-media-grid > :nth-child(1),
    .project-media-grid > :nth-child(2),
    .project-media-grid > :nth-child(3),
    .project-media-grid > :nth-child(4),
    .project-media-grid > :nth-child(5) {
        grid-column: span 1;
        max-height: 24vh;
    }

    .project-card--image-only img {
        max-width: 88vw;
        width: 88vw;
        max-height: none;
    }

    .project-card--image-only .project-media-frame {
        max-width: 88vw;
        width: 88vw;
    }
}

body.bw-mode .project-info h2,
body.bw-mode .project-authors,
body.bw-mode .project-school,
body.bw-mode .project-desc,
:root.bw-mode .project-info h2,
:root.bw-mode .project-authors,
:root.bw-mode .project-school,
:root.bw-mode .project-desc {
    text-shadow: none;
}

/* ============================================
   CONTACT PAGE - VIDEO ROOM
   ============================================ */

:is(.contact-video-page, .project-video-background-page) .wall {
    overflow: hidden;
    border: none !important;
    background-color: #000;
}

:is(.contact-video-page, .project-video-background-page) .wireframe-overlay {
    z-index: 30;
}

:is(.contact-video-page, .project-video-background-page) .wireframe-overlay line,
:is(.contact-video-page, .project-video-background-page) .wireframe-overlay polygon {
    filter: drop-shadow(0 0 1px var(--bg-color)) drop-shadow(0 0 2px var(--bg-color));
}

:is(.contact-video-page, .project-video-background-page) .zone-content.video-surface {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    padding: 0;
    gap: 0;
    pointer-events: none;
    background: #000;
    overflow: hidden;
    transform: translateZ(-2px);
    backface-visibility: hidden;
}

:is(.contact-video-page, .project-video-background-page) .zone-content.video-surface::after {
    content: "";
    position: absolute;
    inset: 0;
    box-shadow: inset 0 0 0 2px #000;
    pointer-events: none;
    z-index: 2;
}

:is(.contact-video-page, .project-video-background-page) .surface-video {
    position: absolute;
    top: 50%;
    left: 50%;
    display: block;
    width: 100vw;
    height: 100vh;
    transform: translate(-50%, -50%);
    object-fit: cover;
    background: #000;
    filter: saturate(1.05) contrast(1.02);
    z-index: 1;
}

:is(.contact-video-page, .project-video-background-page) .surface-canvas {
    position: absolute;
    inset: 0;
    display: none;
    width: 100%;
    height: 100%;
    background: #000;
    z-index: 1;
}

/* Slight overscan hides subpixel seams between transformed planes. */
:is(.contact-video-page, .project-video-background-page) .surface-video.is-projected,
:is(.contact-video-page, .project-video-background-page) .surface-canvas.is-projected {
    inset: -2px;
    width: calc(100% + 4px);
    height: calc(100% + 4px);
}

:is(.contact-video-page, .project-video-background-page) .surface-video.is-projected {
    opacity: 0.92;
    mix-blend-mode: normal;
}

:is(.contact-video-page, .project-video-background-page).video-mode-copies .surface-video.is-projected {
    top: 50%;
    left: 50%;
    width: calc(100vw + 4px);
    height: calc(100vh + 4px);
    transform: translate(-50%, -50%);
    object-position: center center;
}

:is(.contact-video-page, .project-video-background-page).video-mode-perspective .surface-video.is-projected {
    display: none;
}

:is(.contact-video-page, .project-video-background-page).video-mode-perspective .surface-canvas.is-projected {
    display: block;
}

:is(.contact-video-page, .project-video-background-page).video-mode-perspective .video-surface .surface-video.is-flat {
    display: none;
}

:is(.contact-video-page, .project-video-background-page).video-mode-perspective .video-surface .surface-canvas.is-flat {
    display: block;
}

:is(.contact-video-page, .project-video-background-page) .video-surface.is-flat {
    border: none;
}

:is(.contact-video-page, .project-video-background-page) .video-surface .surface-video.is-flat {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    transform: none;
    opacity: 1;
    filter: none;
}

:is(.contact-video-page, .project-video-background-page) .left-content,
:is(.contact-video-page, .project-video-background-page) .right-content {
    width: 100%;
    height: 100%;
}

body.dark-mode:is(.contact-video-page, .project-video-background-page) .zone-content.video-surface,
body.dark-mode:is(.contact-video-page, .project-video-background-page) .surface-video,
:root.dark-mode body:is(.contact-video-page, .project-video-background-page) .zone-content.video-surface,
:root.dark-mode body:is(.contact-video-page, .project-video-background-page) .surface-video {
    background: #000;
}

body.bw-mode:is(.contact-video-page, .project-video-background-page) .surface-video,
:root.bw-mode body:is(.contact-video-page, .project-video-background-page) .surface-video {
    filter: grayscale(1) contrast(1.1);
}
