@font-face {
    font-family: 'iAWriterDuoV';
    src: url('./fonts/iAWriterDuoV.woff2') format('woff2'),
         url('./fonts/iAWriterDuoV.ttf') format('truetype');
    font-weight: 100 900;
    font-style: normal;
}

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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000000;
}

:root {

    --unlock-mask-radius: 0px;
    --unlock-mask-hole-alpha: 1;
    --unlock-mask-fade: 3;
    --ui-edge-padding: clamp(14px, 4vw, 28px);
    --scene-perspective: 620px;
    --lock-clock-size: min(100vmin, 800px);
    --clock-lens-blur: 26px;
    --lock-feedback-blur-boost: 0px;
    --clock-sharp-core: 56%;
    --clock-lens-warp: 1.08;
    --lock-feedback-lens-boost: 0;
    --unlock-duration: 1400ms;
    --unlock-zoom-scale: 3.6;
    --unlock-start-scale: 1;
    --unlock-end-scale: var(--unlock-zoom-scale);
    --lock-feedback-scale: 1;
    --px: 0;
    --py: 0;
}

body {
    text-transform: lowercase;
}

.lock-screen {
    position: fixed;
    inset: 0;
    z-index: 1800;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(circle at 35% 26%, rgba(255, 255, 255, 0.07) 0%, transparent 42%),
        radial-gradient(circle at 70% 72%, rgba(255, 255, 255, 0.04) 0%, transparent 45%),
        #000000;
    opacity: 1;
    visibility: visible;
    transition: opacity var(--unlock-duration) cubic-bezier(0.2, 0.6, 0.08, 1), visibility 0s linear var(--unlock-duration);
    -webkit-mask-image: radial-gradient(
        circle var(--unlock-mask-radius) at center,
        rgba(255, 255, 255, var(--unlock-mask-hole-alpha)) calc(100% - var(--unlock-mask-fade) * 1%),
        white 100%
    );
    -webkit-mask-repeat: no-repeat;
    -webkit-mask-mode: alpha;
    mask-image: radial-gradient(
        circle var(--unlock-mask-radius) at center,
        rgba(255, 255, 255, var(--unlock-mask-hole-alpha)) calc(100% - var(--unlock-mask-fade) * 1%),
        white 100%
    );
    mask-repeat: no-repeat;
    mask-mode: alpha;
}

.lock-clock-shell {
    width: var(--lock-clock-size);
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: scale(var(--lock-feedback-scale));
    will-change: transform, opacity, filter;
}

@keyframes lock-zoom-through {
    0% {
        opacity: 1;
        transform: scale(var(--unlock-start-scale));
    }
    100% {
        opacity: 0;
        transform: translate(0, 0) scale(var(--unlock-end-scale));
    }
}

body.state-unlocking .lock-screen {
    pointer-events: none;
    /* opacity stays 1 — mask handles the visual transition */
}

body.state-unlocking .lock-clock-shell {
    /* zoom-through removed — mask circle replaces it */
}

body.state-home .lock-screen {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    -webkit-mask-image: none;
    mask-image: none;
    transition: none; /* instant hide — no flash when mask is removed */
}

body.state-home .lock-clock-shell {
    opacity: 0;
    transform: translate(0, 0) scale(var(--unlock-end-scale));
}

.lock-clock {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    overflow: hidden;
    isolation: isolate;
    box-shadow:
        inset 0 -8px 24px rgba(255, 255, 255, 0.07),
        inset 0 16px 28px rgba(255, 255, 255, 0.1),
        0 36px 64px rgba(0, 0, 0, 0.65);
}

.watchface-container {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    overflow: hidden;
    z-index: 1;
}

.watchface-container canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}

body.state-lock .card-stack-container {
    opacity: 0;
    transform: scale(0.94);
    filter: none;
    pointer-events: none;
}

body.state-lock.portal-preview .card-stack-container {
    opacity: 1;
    transform: scale(1);
    transition: none;
}

body.state-unlocking .card-stack-container {
    opacity: 1;
    transform: scale(1);
    filter: none;
    pointer-events: none;
    transition: none;
}

/* During unlock stacking, flatten card depth layers to avoid transient z-fighting shimmer. */
body.state-unlocking .card {
    transform-style: flat;
}

body.state-unlocking .card-slice {
    display: none;
}

/* Keep mobile-sensitive card layers flattened until reveal motion fully settles. */
body.unlock-render-stabilizing .card {
    transform-style: flat;
}

body.unlock-render-stabilizing .card-slice {
    display: none;
}

body.state-home .card-stack-container {
    opacity: 1;
    transform: scale(1);
    filter: none;
    pointer-events: auto;
}

body.state-lock .top-nav,
body.state-lock .card-info {
    opacity: 0 !important;
    pointer-events: none !important;
}

.blur-debug {
    position: fixed;
    top: clamp(14px, 3vh, 30px);
    left: clamp(14px, 3vw, 28px);
    z-index: 2200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(340px, calc(100vw - 28px));
    max-height: min(78vh, 560px);
    overflow: auto;
    padding: 12px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(10, 10, 10, 0.58);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    font-family: 'iAWriterDuoV', -apple-system, BlinkMacSystemFont, sans-serif;
    color: rgba(255, 255, 255, 0.9);
    opacity: 0;
    pointer-events: none;
    transform: translateY(-8px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

body.debug-settings-visible .blur-debug {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

body.state-home .blur-debug {
    opacity: 0 !important;
    pointer-events: none !important;
    transform: translateY(-8px) !important;
}

.blur-debug-head {
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: lowercase;
    opacity: 0.82;
}

.blur-debug-row {
    display: grid;
    grid-template-columns: 52px 1fr 44px;
    align-items: center;
    gap: 10px;
}

.blur-debug-label {
    font-size: 12px;
    letter-spacing: 0.02em;
    text-transform: lowercase;
    opacity: 0.82;
}

.blur-debug-slider {
    width: 100%;
}

.blur-debug-row.blur-primary-row .blur-debug-label,
.blur-debug-row.blur-primary-row .blur-debug-value {
    font-size: 13px;
    font-weight: 700;
}

.blur-debug-row.blur-primary-row .blur-debug-slider {
    height: 28px;
}

.blur-debug-value {
    font-size: 12px;
    min-width: 36px;
    text-align: right;
    opacity: 0.92;
}

/* Top Navigation */
.top-nav {
    position: fixed;
    top: 8%;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0 var(--ui-edge-padding);
    z-index: 1000;
    transition: opacity 0.3s ease;
}

.nav-btn {
    background: none;
    border: none;
    font-family: 'iAWriterDuoV', -apple-system, BlinkMacSystemFont, sans-serif;
    font-weight: 400;
    font-size: clamp(14px, 2vw, 18px);
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    transition: color 0.2s ease;
    padding: 0;
    transform: scale(1.2);
}

.nav-btn:hover {
    color: #ffffff;
}

.card-stack-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    perspective: var(--scene-perspective);
    transition: opacity 0.35s ease, transform 0.45s ease;
    will-change: transform;
}

/* Disable transform easing in grid camera mode to avoid gyro input latency */
.card-stack-container.grid-camera-active {
    transition: opacity 0.35s ease;
}

/* Wrapper: stable hit area for pointer events, never tilts */
.card-wrapper {
    position: absolute;
    width: var(--card-width, 400px);
    height: var(--card-height, 400px);
    cursor: grab;
    user-select: none;
    touch-action: none;
    will-change: transform;
    perspective: var(--scene-perspective);
}

.card {
    position: relative;
    width: 100%;
    height: 100%;
    --card-radius: calc(var(--card-width, 300px) * 0.15);
    --card-border-width: 2px;
    border-radius: var(--card-radius);
    --card-thickness: clamp(1.11px, calc(var(--card-width, 300px) * 0.00443), 2.33px);
    --depth-layers: 5;
    --slice-step: calc(var(--card-thickness) / var(--depth-layers));
    --depth-reactivity: 0.0089;
    will-change: transform;
    --mouse-x: 50%;
    --mouse-y: 50%;
    --tilt-x: 0;
    --tilt-y: 0;
    --shine-angle: 180deg;
    --shine-opacity: 0;
    transform-style: preserve-3d;
    overflow: visible;
    pointer-events: none;
}

.card-slice {
    position: absolute;
    inset: 0;
    border-radius: var(--card-radius);
    background-color: var(--card-edge-color, #2f3440);
    transform: translate3d(
        calc(var(--slice-index) * var(--tilt-y) * var(--depth-reactivity) * -1px),
        calc(var(--slice-index) * var(--tilt-x) * var(--depth-reactivity) * 1px),
        calc(var(--slice-index) * var(--slice-step) * -1)
    );
    backface-visibility: hidden;
    pointer-events: none;
}

.card-front {
    position: absolute;
    inset: 0;
    --card-inner-radius: max(0px, calc(var(--card-radius) - var(--card-border-width)));
    border-radius: var(--card-radius);
    border: var(--card-border-width) solid var(--card-edge-color, #2f3440);
    /* Slightly larger Z offset reduces front-face shimmer during reveal on mobile GPUs. */
    transform: translateZ(1px);
    overflow: hidden;
    backface-visibility: hidden;
    box-shadow:
        0 4px 6px rgba(0, 0, 0, 0.025),
        0 10px 20px rgba(0, 0, 0, 0.04),
        0 20px 40px rgba(0, 0, 0, 0.05);
}

/* Ambient overhead light — linear gradient that shifts with tilt angle, masked to top half */
.card-front::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: var(--card-inner-radius);
    background: linear-gradient(
        var(--shine-angle),
        rgba(255, 255, 255, var(--shine-opacity)) 0%,
        rgba(255, 255, 255, calc(var(--shine-opacity) * 0.3)) 40%,
        transparent 80%
    );
    -webkit-mask-image: linear-gradient(to bottom, black 0%, rgba(0,0,0,0.6) 30%, rgba(0,0,0,0.2) 55%, transparent 75%);
    mask-image: linear-gradient(to bottom, black 0%, rgba(0,0,0,0.6) 30%, rgba(0,0,0,0.2) 55%, transparent 75%);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    transform: none;
    z-index: 2;
}

.card.tilt-active .card-front::before {
    opacity: 1;
}

/* Cursor-following specular highlight */
.card-front::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: var(--card-inner-radius);
    background: radial-gradient(
        circle at var(--mouse-x) var(--mouse-y),
        rgba(255, 255, 255, 0.25) 0%,
        rgba(255, 255, 255, 0.08) 30%,
        transparent 60%
    );
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    transform: none;
}

.card.tilt-active .card-front::after {
    opacity: 1;
}

body.unlock-render-stabilizing .card-front {
    transform: none;
}

body.unlock-render-stabilizing .card-front::before,
body.unlock-render-stabilizing .card-front::after {
    opacity: 0 !important;
    transition: none !important;
}

/* Static shadow — dynamic calc(var(--tilt-y)...) forces software re-raster every frame on mobile */
.card-front {
    box-shadow:
        0 2px 4px rgba(0, 0, 0, 0.1),
        0 8px 16px rgba(0, 0, 0, 0.12),
        0 16px 32px rgba(0, 0, 0, 0.15),
        0 24px 48px rgba(0, 0, 0, 0.12);
}

.card-wrapper:active {
    cursor: grabbing;
}

.card-wrapper.dragging {
    cursor: grabbing;
}

.card-wrapper.dragging .card-front {
    box-shadow:
        0 10px 20px rgba(0, 0, 0, 0.05),
        0 20px 40px rgba(0, 0, 0, 0.06),
        0 40px 80px rgba(0, 0, 0, 0.075);
}

.card-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: calc(var(--card-width, 300px) * 0.08);
    pointer-events: none;
}

.card-cover-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: var(--card-inner-radius);
    pointer-events: none;
}

.card-content {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: var(--card-inner-radius);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.9);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 24px;
    font-weight: 600;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.card-number {
    font-size: 64px;
    font-weight: 700;
    opacity: 0.3;
}

/* Card Info Text Display */
.card-info {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    padding-bottom: 3%;
    padding-top: 150px;
    text-align: center;
    z-index: 1000;
    pointer-events: none;
    transition: opacity 0.3s ease;
    background: linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0) 0%,
        rgba(0, 0, 0, 1) 100%
    );
}

.card-info-inner {
    opacity: 0;
    -webkit-transition: opacity 0.25s ease-out;
    transition: opacity 0.25s ease-out;
    -webkit-transform: translate3d(0, -80%, 0);
    transform: translate3d(0, -60%, 0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    will-change: opacity;
}

.card-info-inner.visible {
    opacity: 1;
}

.card-info-inner.fade-out {
    opacity: 0;
}


.card-info-title {
    font-family: 'iAWriterDuoV', -apple-system, BlinkMacSystemFont, sans-serif;
    font-weight: 700;
    font-size: calc(clamp(23px, 3.8vw, 40px) / 1.4);
    color: #ffffff;
    margin-bottom: 0;
    line-height: 1.12;
    letter-spacing: -0.02em;
}

.card-info-description {
    font-family: 'iAWriterDuoV', -apple-system, BlinkMacSystemFont, sans-serif;
    font-weight: 400;
    font-size: calc(clamp(13px, 1.9vw, 17px) / 1.4);
    color: rgba(255, 255, 255, 0.6);
    width: min(400px, calc(100% - (var(--ui-edge-padding) * 2)));
    margin: 0 auto;
    line-height: 1.5;
}

.grid-camera-vignette {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, transparent 30%, rgba(0, 0, 0, 0.4) 100%);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 200;
}

.grid-camera-vignette.active {
    opacity: 1;
}
