.scan-page {
    padding-bottom: 36px;
    overflow-x: hidden;
}

.scan-shell {
    position: relative;
}

.scan-stage {
    width: min(calc(100% - 48px), 1180px);
    padding-top: 22px;
    padding-bottom: 24px;
}

.scan-heading,
.scan-stage .camera-card,
.scan-stage .photo-drop,
.scan-stage .photo-preview,
.scan-stage > .notice-box,
.scan-stage > .cover-cta,
.camera-link-row,
.scan-error,
.scan-legal {
    width: min(100%, 1180px);
    margin-right: auto;
    margin-left: auto;
}

.scan-heading {
    margin-bottom: 26px;
}

.scan-kicker {
    margin: 0 0 8px;
    color: var(--level-aqua-deep);
    font-size: 0.69rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.scan-heading h1 {
    margin: 0;
    font-family: var(--level-font-display);
    font-size: 5.45rem;
    font-weight: 400;
    line-height: 0.9;
}

.scan-heading .intro-copy {
    max-width: 760px;
    margin: 14px 0 0;
    color: var(--level-ink-soft);
    font-size: 0.95rem;
    line-height: 1.62;
}

.scan-stage .camera-card {
    position: relative;
}

.scan-stage .camera-shell {
    position: relative;
    height: min(643px, calc(120svh - 456px));
    min-height: 466px;
    overflow: hidden;
    border: 1px solid rgba(95, 190, 186, 0.66);
    border-radius: 16px;
    background:
        radial-gradient(circle at 68% 26%, rgba(226, 245, 243, 0.9), transparent 38%),
        linear-gradient(135deg, #f7f3eb 0%, #dceeed 54%, #9cc9c7 100%);
    box-shadow: 0 18px 48px rgba(16, 43, 45, 0.12);
    transition: border-color 240ms ease, box-shadow 240ms ease;
}

.scan-stage .camera-shell.waiting::after {
    position: absolute;
    inset: 0;
    z-index: 0;
    content: "";
    background:
        linear-gradient(115deg, transparent 30%, rgba(255, 255, 255, 0.08) 48%, transparent 66%);
    background-size: 220% 100%;
    animation: cameraWaitingShimmer 8s ease-in-out infinite;
}

.scan-stage .camera-card.ready .camera-shell {
    border-color: var(--level-aqua);
    box-shadow:
        0 22px 58px rgba(16, 43, 45, 0.14),
        0 0 0 1px rgba(157, 222, 219, 0.14);
}

.scan-stage .camera-video,
.captured-frame,
.camera-canvas,
.face-map-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.scan-stage .camera-video,
.captured-frame {
    display: block;
    object-fit: cover;
    transform: scaleX(-1);
}

.scan-stage .camera-video {
    z-index: 1;
    opacity: 0;
    transition: opacity 420ms ease;
}

.scan-stage .camera-shell.active .camera-video {
    opacity: 1;
}

.camera-canvas {
    z-index: -1;
    opacity: 0;
    pointer-events: none;
}

.face-map-canvas {
    z-index: 5;
    opacity: 0;
    pointer-events: none;
    transition: opacity 300ms ease;
}

.scan-stage .camera-shell.active .face-map-canvas,
.scan-stage .camera-shell.complete .face-map-canvas {
    opacity: 1;
}

.captured-frame {
    z-index: 3;
    animation: scanStateFade 360ms ease-out both;
}

.camera-permission-state {
    position: absolute;
    inset: 0;
    z-index: 9;
    padding: 30px;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 9px;
    color: var(--level-ink);
    text-align: center;
    background:
        radial-gradient(circle at 54% 34%, rgba(255, 255, 255, 0.9), transparent 36%),
        linear-gradient(135deg, rgba(247, 243, 235, 0.96), rgba(226, 245, 243, 0.94));
    transition: opacity 300ms ease;
}

.camera-permission-icon {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(157, 222, 219, 0.48);
    border-radius: 50%;
    font-size: 1.25rem;
}

.camera-permission-state strong {
    font-family: var(--level-font-display);
    font-size: clamp(1.65rem, 3vw, 2.35rem);
    font-weight: 400;
}

.camera-permission-state p,
.camera-permission-state > span:not(.camera-permission-icon) {
    max-width: 420px;
    margin: 0;
    color: var(--level-ink-soft);
    font-size: 0.82rem;
    line-height: 1.5;
}

.camera-permission-state button,
.scan-error button {
    min-height: 42px;
    margin-top: 9px;
    padding: 0 20px;
    border: 1px solid var(--level-aqua);
    border-radius: 0;
    color: var(--level-ink);
    background: var(--level-aqua);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    cursor: pointer;
}

.camera-permission-state .permission-photo-link {
    min-height: auto;
    margin: 0;
    padding: 5px 0;
    border: 0;
    color: var(--level-ink);
    background: transparent;
    text-decoration: underline;
    text-underline-offset: 4px;
}

.scan-stage .camera-vignette {
    position: absolute;
    inset: 0;
    z-index: 4;
    pointer-events: none;
    background:
        linear-gradient(180deg, rgba(7, 27, 29, 0.06), transparent 25% 78%, rgba(7, 27, 29, 0.12)),
        radial-gradient(ellipse at center, transparent 60%, rgba(7, 27, 29, 0.1) 100%);
}

.auto-scan-grid {
    position: absolute;
    inset: 0;
    z-index: 6;
    opacity: 0.08;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(157, 222, 219, 0.34) 1px, transparent 1px),
        linear-gradient(90deg, rgba(157, 222, 219, 0.34) 1px, transparent 1px);
    background-size: 64px 64px;
}

.auto-scan-line {
    position: absolute;
    right: 4%;
    left: 4%;
    z-index: 7;
    height: 1px;
    pointer-events: none;
    background: linear-gradient(90deg, transparent, var(--level-aqua) 18% 82%, transparent);
    box-shadow: 0 0 12px rgba(157, 222, 219, 0.62);
    animation: scanLineTravel 2.7s ease-in-out infinite alternate;
}

.scan-stage .camera-status-rail {
    min-height: 46px;
    padding: 14px 1px 5px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    color: var(--level-ink-soft);
}

.scan-stage .camera-status-rail strong {
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--level-ink);
    font-size: 0.76rem;
    font-weight: 650;
}

.status-complete-mark {
    width: 22px;
    height: 22px;
    display: inline-grid;
    place-items: center;
    border-radius: 50%;
    color: var(--level-ink);
    background: var(--level-aqua);
}

.scan-stage .camera-status-rail button,
.upload-toggle {
    padding: 5px 0;
    border: 0;
    border-bottom: 1px solid var(--level-aqua-deep);
    color: var(--level-ink);
    background: transparent;
    font-size: 0.71rem;
    font-weight: 750;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
}

.scan-stage .camera-status-rail button:disabled {
    opacity: 0.45;
    cursor: default;
}

.scan-progress-wrap {
    padding-top: 7px;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 12px;
}

.auto-scan-progress {
    height: 3px;
    overflow: hidden;
    background: rgba(16, 43, 45, 0.12);
}

.auto-scan-progress > span {
    height: 100%;
    display: block;
    background: linear-gradient(90deg, var(--level-aqua-deep), var(--level-aqua), var(--level-white));
    transition: width 120ms linear;
}

.scan-progress-wrap > span {
    min-width: 34px;
    color: var(--level-ink-soft);
    font-size: 0.68rem;
    text-align: right;
}

.camera-link-row {
    padding: 18px 0 2px;
    display: flex;
    justify-content: center;
}

.scan-stage .photo-drop,
.scan-stage .photo-preview,
.scan-stage > .notice-box,
.scan-stage > .cover-cta,
.scan-error {
    margin-top: 16px;
}

.scan-stage > .cover-cta.mud-button-root {
    min-height: 52px;
    display: flex;
}

.scan-error {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.scan-error strong {
    margin: 0;
}

.scan-legal {
    margin-top: 22px;
    color: var(--level-ink-soft);
    font-size: 0.7rem;
    line-height: 1.55;
    text-align: center;
}

.scan-legal a {
    color: var(--level-ink);
    text-underline-offset: 3px;
}

.analysis-loading {
    padding-top: clamp(34px, 6vw, 76px);
    padding-bottom: clamp(50px, 8vw, 96px);
}

.analysis-loading-layout {
    display: grid;
    grid-template-columns: minmax(320px, 0.9fr) minmax(340px, 1fr);
    align-items: center;
    gap: clamp(38px, 7vw, 94px);
}

.analysis-preview {
    position: relative;
    min-height: 520px;
    overflow: hidden;
    border-radius: 8px;
    background: #071b1d;
    box-shadow: var(--level-shadow-soft);
}

.analysis-preview img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}

.analysis-preview-status {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--level-white);
    background: linear-gradient(180deg, transparent, rgba(7, 27, 29, 0.9));
}

.analysis-preview-status > span {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: var(--level-ink);
    background: var(--level-aqua);
}

.analysis-preview-status div {
    display: grid;
    gap: 2px;
}

.analysis-preview-status small {
    color: rgba(255, 255, 255, 0.66);
}

.analysis-loading-copy h1,
.analysis-loading-copy h2 {
    max-width: 560px;
    margin: 12px 0 18px;
    font-family: var(--level-font-display);
    font-size: clamp(3.1rem, 6vw, 5.8rem);
    font-weight: 400;
    line-height: 0.94;
}

.analysis-loading-copy .intro-copy {
    max-width: 470px;
}

.analysis-progress {
    --mud-palette-primary: var(--level-aqua-deep);
    height: 3px !important;
    max-width: 470px;
    margin-top: 24px;
    background: rgba(16, 43, 45, 0.12) !important;
}

@keyframes cameraWaitingShimmer {
    0%, 28% { background-position: 140% 0; }
    72%, 100% { background-position: -80% 0; }
}

@keyframes scanLineTravel {
    from { top: 9%; }
    to { top: 91%; }
}

@keyframes scanStateFade {
    from { opacity: 0; }
    to { opacity: 1; }
}

@media (max-width: 900px) {
    .scan-heading h1 {
        font-size: 4.75rem;
    }

    .scan-stage .camera-shell {
        height: min(74.4vw, calc(120svh - 396px), 624px);
        min-height: 444px;
    }

    .analysis-loading-layout {
        grid-template-columns: 1fr;
    }

    .analysis-preview {
        min-height: min(68vw, 560px);
    }
}

@media (max-width: 620px) {
    .scan-page {
        padding-bottom: 24px;
    }

    .scan-stage {
        width: calc(100% - 28px);
        padding-top: 18px;
    }

    .scan-heading h1 {
        font-size: 3.55rem;
        line-height: 0.94;
    }

    .scan-heading .intro-copy {
        font-size: 0.84rem;
    }

    .scan-stage .camera-shell {
        height: 134.4vw;
        min-height: 468px;
        max-height: 684px;
        border-radius: 12px;
    }

    .scan-stage .camera-status-rail {
        align-items: flex-start;
    }

    .scan-error {
        align-items: flex-start;
        flex-direction: column;
    }

    .analysis-loading {
        width: calc(100% - 28px);
    }

    .analysis-preview {
        min-height: 120vw;
        max-height: 580px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .scan-stage .camera-shell.waiting::after,
    .auto-scan-line,
    .captured-frame {
        animation: none;
    }

    .scan-stage .camera-video,
    .face-map-canvas,
    .auto-scan-progress > span {
        transition: none;
    }
}
