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

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

/* ── Noise overlay ──────────────────────────────────────── */
body::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.18;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 200px 200px;
}

#three-canvas {
    position: fixed;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;   /* prevent browser hijacking pointer events */
    cursor: grab;
}

#three-canvas:active {
    cursor: grabbing;
}

/* ── Screen overlay ─────────────────────────────────────── */
#screen-overlay {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    /* The orthographic camera's vertical extent (top/bottom) is fixed
       regardless of aspect ratio, so the touchscreen mesh's on-screen
       pixel size tracks viewport HEIGHT only — never width. A vw-based
       cap (the old min(vw, vh) here) picks a much-too-small value on
       narrow/tall viewports like an iPhone in portrait; vh alone matches
       the real projected mesh size on any aspect ratio. */
    width: calc(29vh * 946 / 542);
    aspect-ratio: 946 / 542;
    opacity: 0;
    transition: opacity 0.7s cubic-bezier(0.22, 1, 0.36, 1);
    will-change: opacity;
    pointer-events: none;
    z-index: 20;
}

#screen-overlay img {
    width: 100%;
    height: 100%;
    display: block;
    pointer-events: none;
}

/* ── Screen buttons ─────────────────────────────────────── */
.screen-btn {
    position: absolute;
    display: block;
    border-radius: 2px;
    text-decoration: none;
    cursor: pointer;
    pointer-events: none;           /* disabled until overlay is visible */
    transition: background 0.25s cubic-bezier(0.22, 1, 0.36, 1),
                outline 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

#screen-overlay.active .screen-btn {
    pointer-events: auto;
}

.screen-btn:hover {
    background: rgba(255, 255, 255, 0.35);
    outline: 1px solid rgba(255, 255, 255, 0.55);
}

/* Positions mapped to actual row positions in the PNG (946 × 542).
   Rows start at ~220 px, each row is ~65 px tall.
   Right edge stops before the scrollbar strip (~28 px from right). */
#btn-about {
    left:  0;
    right: calc(28 / 946 * 100%);
    top:   calc(220 / 542 * 100%);
    height: calc(65 / 542 * 100%);
}

#btn-portfolio {
    left:  0;
    right: calc(28 / 946 * 100%);
    top:   calc(285 / 542 * 100%);
    height: calc(65 / 542 * 100%);
}

#btn-contract {
    left:  0;
    right: calc(28 / 946 * 100%);
    top:   calc(350 / 542 * 100%);
    height: calc(65 / 542 * 100%);
}

/* ── Paper lightbox ──────────────────────────────────────── */
/* The in-scene "paper" is a small WebGL texture — great for the print
   animation, too small/soft to actually read. Once it's slid into view,
   this crossfades in a full-size DOM <img> (real browser text/image
   scaling) so the page is actually legible. */
#paper-lightbox {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(20, 18, 16, 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.6s cubic-bezier(0.22, 1, 0.36, 1);
    will-change: opacity;
    cursor: zoom-out;
}

#paper-lightbox.active {
    opacity: 1;
    pointer-events: auto;
}

#paper-lightbox img {
    max-width: 88vw;
    max-height: 88vh;
    background: #fff;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

/* ── Close button ────────────────────────────────────────── */
/* Escape backs out of 'screen'/'paper' state on desktop, but iOS has no
   Escape key — this is the only way back on touch devices. Shown for the
   whole time appState isn't 'home' (set in zoomToMesh / cleared in
   zoomOut), and steps back exactly like Escape does. */
#close-btn {
    position: fixed;
    top: 22px;
    right: 32px;
    z-index: 40;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    padding: 0;
    font-family: 'Times New Roman', Times, serif;
    font-size: 28px;
    line-height: 1;
    color: #1a1a1a;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s cubic-bezier(0.22, 1, 0.36, 1);
    -webkit-tap-highlight-color: transparent;
}

#close-btn.visible {
    opacity: 1;
    pointer-events: auto;
}

#close-btn.visible:hover {
    opacity: 0.6;
}

/* ── Site title ─────────────────────────────────────────── */
#site-title {
    position: fixed;
    top: 28px;
    left: 32px;
    font-family: 'Times New Roman', Times, serif;
    font-style: italic;
    font-weight: normal;
    font-size: 22px;
    color: #1a1a1a;
    pointer-events: none;
    z-index: 10;
}

/* ── Loading ────────────────────────────────────────────── */
#loading {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: #efefef;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    pointer-events: none;
}

#loading-label {
    font-family: 'Courier New', Courier, monospace;
    font-size: 10px;
    letter-spacing: 0.45em;
    text-transform: uppercase;
    color: #bbb;
}

#loading-track {
    width: 80px;
    height: 1px;
    background: #e0d8d0;
    overflow: hidden;
}

#loading-progress {
    height: 100%;
    width: 0%;
    background: #1a1a1a;
    transition: width 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}
