/* 3D Room Camera (#516) */
.room3d-stage {
    position: absolute;
    inset: 0;
    z-index: 15;
    display: flex;
    flex-direction: column;
    background: #f9fafb;
    overflow: hidden;
}

.room3d-stage.hidden,
.room3d-empty-view.hidden,
.room3d-preview-view.hidden,
.room3d-building-view.hidden,
.room3d-viewer-view.hidden {
    display: none !important;
}

.room3d-empty-view {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem 1rem 6rem;
}

.room3d-dropzone {
    width: 100%;
    max-width: 34rem;
    border: 2px dashed #d1d5db;
    border-radius: 1.25rem;
    background: #fff;
    padding: 2rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

.room3d-dropzone:hover,
.room3d-dropzone.is-dragover {
    border-color: #b05039;
    background: #fdf6f4;
}

.room3d-saved-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.625rem;
    width: 100%;
    max-width: 34rem;
}

.room3d-saved-card {
    position: relative;
    border-radius: 0.75rem;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    background: #111827;
    aspect-ratio: 16 / 10;
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease;
}

.room3d-saved-card:hover {
    border-color: #b05039;
    transform: translateY(-1px);
}

.room3d-saved-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.room3d-saved-card span {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 0.25rem 0.5rem;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.72));
    text-align: left;
}

/* Building view */
.room3d-building-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1.5rem 6rem;
    text-align: center;
}

/* Walkable 3D Viewport */
.room3d-viewer-view {
    position: relative;
    flex: 1;
    min-height: 0;
    background: #0d1016;
    overflow: hidden;
    touch-action: none;
    user-select: none;
}

.room3d-canvas-host {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background: #0d1016;
    cursor: grab;
    pointer-events: auto;
}

.room3d-canvas-host.is-dragging {
    cursor: grabbing;
}

/* Letterboxed WebGL viewport matching active photo aspect ratio + rule-of-thirds overlay */
.room3d-viewfinder-wrap {
    position: absolute;
    inset: 0;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3.75rem 0.75rem 4.75rem;
}

@media (max-width: 1023px) {
    .room3d-viewfinder-wrap {
        padding: 3.75rem 0.5rem 8.5rem;
    }
}

.room3d-viewfinder-frame {
    position: relative;
    overflow: hidden;
    background: #0d1016;
    border: 1.5px solid rgba(255, 255, 255, 0.35);
    border-radius: 0.5rem;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
    max-width: 100%;
    max-height: 100%;
    pointer-events: auto;
}

.room3d-viewfinder-grid {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(to right, transparent 33.1%, rgba(255, 255, 255, 0.2) 33.3%, transparent 33.5%, transparent 66.4%, rgba(255, 255, 255, 0.2) 66.6%, transparent 66.8%),
        linear-gradient(to bottom, transparent 33.1%, rgba(255, 255, 255, 0.2) 33.3%, transparent 33.5%, transparent 66.4%, rgba(255, 255, 255, 0.2) 66.6%, transparent 66.8%);
}

/* Floating top bar over 3D viewport */
.room3d-viewer-topbar {
    position: absolute;
    top: 0.75rem;
    left: 0.75rem;
    right: 0.75rem;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    pointer-events: none;
}

.room3d-viewer-topbar > * {
    pointer-events: auto;
}

.room3d-topbar-left,
.room3d-topbar-right {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    min-width: 0;
}

.room3d-topbar-left {
    flex: 1 1 auto;
    overflow: hidden;
}

.room3d-topbar-right {
    flex-shrink: 0;
}

.room3d-name-wrap {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    flex: 0 1 auto;
    overflow: hidden;
}

.room3d-name-chip {
    max-width: 100%;
    min-width: 0;
}

.room3d-name-chip.hidden,
.room3d-name-input.hidden {
    display: none !important;
}

.room3d-name-input {
    width: 12rem;
    max-width: 100%;
    padding: 0.38rem 0.7rem;
    border-radius: 9999px;
    background: rgba(15, 23, 42, 0.94);
    border: 1.5px solid #b05039;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    outline: none;
}

.room3d-hud-icon-chip {
    width: 2.1rem;
    height: 2.1rem;
    padding: 0;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
}

@media (max-width: 639px) {
    .room3d-viewer-topbar {
        gap: 0.35rem;
    }
    .room3d-topbar-left,
    .room3d-topbar-right {
        gap: 0.3rem;
    }
    .room3d-hud-chip {
        padding: 0.38rem 0.6rem;
        font-size: 11px;
    }
    .room3d-hud-icon-chip {
        width: 1.9rem;
        height: 1.9rem;
        padding: 0;
    }
}

.room3d-viewer-view.is-tour-active .room3d-walk-hint {
    display: none !important;
}

.room3d-hud-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.45rem 0.75rem;
    border-radius: 9999px;
    background: rgba(17, 24, 39, 0.78);
    backdrop-filter: blur(8px);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.room3d-walk-hint {
    display: none;
}

@media (min-width: 1024px) {
    .room3d-walk-hint {
        display: inline-flex;
    }
}

button.room3d-hud-chip:hover {
    background: rgba(31, 41, 55, 0.92);
}

/* Floating bottom controls */
.room3d-viewer-bottombar {
    position: absolute;
    left: 50%;
    bottom: 1rem;
    transform: translateX(-50%);
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem;
    border-radius: 9999px;
    background: rgba(17, 24, 39, 0.82);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.16);
}

@media (max-width: 1023px) {
    .room3d-viewer-bottombar {
        bottom: 4.75rem;
    }
}

.room3d-hud-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.9rem;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
    border: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.15s ease;
}

.room3d-hud-btn:hover {
    background: rgba(255, 255, 255, 0.22);
}

.room3d-hud-btn-primary {
    background: #b05039;
}

.room3d-hud-btn-primary:hover {
    background: #97422d;
}

/* Mobile 4-button Walk D-pad */
.room3d-dpad {
    position: absolute;
    left: 0.75rem;
    bottom: 8.5rem;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(3, 2.75rem); /* 44px touch targets */
    grid-template-rows: repeat(3, 2.75rem);
    gap: 0.25rem;
    padding: 0.25rem;
    border-radius: 0.95rem;
}

@media (hover: hover) and (pointer: fine) {
    .room3d-dpad {
        display: none;
    }
}

/* Interactive 3-step 3D controls tutorial */
.room3d-tour {
    position: absolute;
    top: 3.6rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 25;
    width: min(22.5rem, calc(100% - 1.5rem));
    pointer-events: none;
}

.room3d-tour.hidden {
    display: none !important;
}

.room3d-tour-card {
    background: rgba(15, 23, 42, 0.86);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 1rem;
    padding: 0.75rem 0.9rem;
    color: #fff;
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.42);
    pointer-events: none;
    transition: border-color 0.2s ease, transform 0.2s ease;
}

.room3d-tour-card.is-step-done {
    border-color: rgba(16, 185, 129, 0.75);
}

.room3d-tour-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.room3d-tour-dots {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.room3d-tour-dots span {
    width: 0.4rem;
    height: 0.4rem;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.28);
    transition: width 0.2s ease, background-color 0.2s ease;
}

.room3d-tour-dots span.is-active {
    width: 1.2rem;
    background: #b05039;
}

.room3d-tour-dots span.is-done {
    background: #10b981;
}

.room3d-tour-skip {
    pointer-events: auto;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.72);
    font-size: 11px;
    font-weight: 600;
    padding: 0.15rem 0.4rem;
    border-radius: 0.375rem;
    cursor: pointer;
}

.room3d-tour-skip:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
}

.room3d-tour-body {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.room3d-tour-visual {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.room3d-tour-copy {
    min-width: 0;
    flex: 1;
}

.room3d-tour-title {
    font-size: 13px;
    font-weight: 700;
    line-height: 1.3;
    color: #fff;
}

.room3d-tour-desc {
    font-size: 11.5px;
    line-height: 1.4;
    color: rgba(255, 255, 255, 0.78);
    margin-top: 0.15rem;
}

.room3d-tour-check {
    flex-shrink: 0;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 9999px;
    background: #10b981;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.room3d-tour-check.hidden {
    display: none;
}

.room3d-tour-actions {
    margin-top: 0.65rem;
    display: flex;
    justify-content: flex-end;
}

.room3d-tour-actions.hidden {
    display: none;
}

.room3d-tour-done {
    pointer-events: auto;
    border: none;
    border-radius: 9999px;
    background: #b05039;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    padding: 0.4rem 0.95rem;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.room3d-tour-done:hover {
    background: #97422d;
}

/* Keycap cluster inside Step 1 */
.room3d-keycaps {
    display: grid;
    grid-template-columns: repeat(3, 1.45rem);
    grid-template-rows: repeat(2, 1.45rem);
    gap: 0.2rem;
}

.room3d-keycap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.35rem;
    border: 1px solid rgba(255, 255, 255, 0.28);
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.92);
    font-size: 11px;
    font-weight: 700;
    transition: background-color 0.12s ease, transform 0.12s ease, border-color 0.12s ease;
}

.room3d-keycap.is-target {
    border-color: #e07b63;
    background: rgba(176, 80, 57, 0.55);
    animation: room3dPulseKey 1.4s ease-in-out infinite;
}

.room3d-keycap.is-pressed {
    background: #10b981;
    border-color: #34d399;
    transform: scale(0.92);
}

/* Drag animation icon inside Step 2 */
.room3d-drag-icon {
    width: 2.75rem;
    height: 2.25rem;
    border-radius: 0.6rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.room3d-drag-icon svg {
    width: 1.35rem;
    height: 1.35rem;
    color: #fff;
    animation: room3dDragSlide 1.6s ease-in-out infinite;
}

/* Camera icon inside Step 3 */
.room3d-cam-icon {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.7rem;
    background: rgba(176, 80, 57, 0.35);
    border: 1px solid rgba(224, 123, 99, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}

/* Live spotlight ring on D-pad / Bottom bar */
.is-tour-spotlight {
    box-shadow: 0 0 0 2px rgba(224, 123, 99, 0.95), 0 0 0 7px rgba(176, 80, 57, 0.32) !important;
    animation: room3dSpotlight 1.5s ease-in-out infinite;
}

@keyframes room3dPulseKey {
    0%, 100% { box-shadow: 0 0 0 0 rgba(224, 123, 99, 0.55); }
    50% { box-shadow: 0 0 0 5px rgba(224, 123, 99, 0); }
}

@keyframes room3dDragSlide {
    0%, 100% { transform: translateX(-6px); }
    50% { transform: translateX(6px); }
}

@keyframes room3dSpotlight {
    0%, 100% { box-shadow: 0 0 0 2px rgba(224, 123, 99, 0.95), 0 0 0 4px rgba(176, 80, 57, 0.35); }
    50% { box-shadow: 0 0 0 2px rgba(224, 123, 99, 1), 0 0 0 10px rgba(176, 80, 57, 0.12); }
}

@media (prefers-reduced-motion: reduce) {
    .room3d-keycap.is-target,
    .room3d-drag-icon svg,
    .is-tour-spotlight {
        animation: none;
    }
}

.room3d-dpad-btn {
    border-radius: 0.625rem;
    background: rgba(17, 24, 39, 0.74);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
}

.room3d-dpad-btn:active {
    background: #b05039;
}

/* Sidebar pills & pin thumbnails */
.room3d-pill {
    padding: 0.45rem 0.5rem;
    border-radius: 0.5rem;
    border: 1px solid #e5e7eb;
    background: #fff;
    color: #374151;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.room3d-pill:hover {
    border-color: #d1d5db;
    background: #f9fafb;
}

.room3d-pill.is-active {
    border-color: #b05039;
    background: #fdf6f4;
    color: #97422d;
}

.room3d-pin-card {
    position: relative;
    border-radius: 0.625rem;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    background: #111827;
    aspect-ratio: 16 / 10;
    cursor: pointer;
}

.room3d-pin-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.room3d-pin-label {
    position: absolute;
    left: 0.35rem;
    bottom: 0.3rem;
    padding: 0.1rem 0.4rem;
    border-radius: 0.35rem;
    background: rgba(17, 24, 39, 0.78);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
}

.room3d-pin-remove {
    position: absolute;
    top: 0.25rem;
    right: 0.25rem;
    width: 1.35rem;
    height: 1.35rem;
    border-radius: 9999px;
    background: rgba(17, 24, 39, 0.8);
    color: #fff;
    border: none;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.room3d-pin-remove:hover {
    background: #dc2626;
}
