/* ========================================= */
/*   REAS STUDIO — polish + fluid responsive */
/* ========================================= */

html { scroll-padding-top: 84px; }

/* ---------- Preloader / page transition overlay ---------- */
html::before {
    content: "Reas.";
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: grid;
    place-items: center;
    padding-bottom: 28px;
    background: #000;
    color: #fff;
    font: 700 clamp(2rem, 8vw, 3rem) / 1 var(--font-sans, 'Inter', system-ui, sans-serif);
    letter-spacing: -0.04em;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s var(--ease, ease);
}
html::after {
    content: "";
    position: fixed;
    left: 50%;
    top: calc(50% + 34px);
    z-index: 10001;
    width: 120px;
    height: 2px;
    margin-left: -60px;
    border-radius: 2px;
    background: linear-gradient(90deg, transparent, #fff, transparent) 0 0 / 200% 100%;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s var(--ease, ease);
}
html.is-loading::before,
html.is-leaving::before { opacity: 1; pointer-events: all; }
html.is-loading::after,
html.is-leaving::after { opacity: 0.8; animation: loader-sweep 1.1s linear infinite; }
html.is-leaving::before { transition-duration: 0.25s; }

@keyframes loader-sweep {
    from { background-position: 200% 0; }
    to { background-position: -200% 0; }
}

html.is-loading body { overflow: hidden; }

/* ---------- Scroll progress ---------- */
.scroll-progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    z-index: 200;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.2), #fff);
    transform: scaleX(0);
    transform-origin: left;
    pointer-events: none;
    will-change: transform;
}

/* ---------- Back to top ---------- */
.back-to-top {
    position: fixed;
    right: max(18px, env(safe-area-inset-right));
    bottom: max(18px, env(safe-area-inset-bottom));
    z-index: 150;
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    border: 1px solid var(--border-strong, #2a2a2a);
    background: rgba(10, 10, 10, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #fff;
    opacity: 0;
    transform: translateY(12px);
    pointer-events: none;
    transition: opacity 0.3s var(--ease), transform 0.3s var(--ease), border-color 0.2s, background 0.2s;
}
.back-to-top svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.back-to-top.visible { opacity: 1; transform: none; pointer-events: auto; }
.back-to-top:hover { border-color: var(--border-hover, #3a3a3a); background: #151515; }

/* ---------- Image skeleton + fade-in ---------- */
.project-shot,
.founder-photo { background-color: #070707; }

.project-shot::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(100deg, transparent 20%, rgba(255, 255, 255, 0.05) 50%, transparent 80%) 0 0 / 200% 100%;
    animation: shimmer 1.6s linear infinite;
}
html.has-js .project-shot img { opacity: 0; transition: opacity 0.6s var(--ease), transform 0.5s var(--ease), filter 0.4s var(--ease); }
html.has-js .project-shot img.is-loaded { opacity: 1; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Project cards: reversed featured layout ---------- */
.project-card.featured.reverse { grid-template-columns: 0.9fr 1.1fr; }
.project-card.featured.reverse .project-shot { order: 2; border-right: none; border-left: 1px solid var(--border); }
.project-card.featured.reverse .project-shot img { object-position: left center; }
.project-card.featured .project-body > div[style] { flex-wrap: wrap; }

/* ---------- Founder monogram (replaces stock artwork) ---------- */
.founder-mono {
    display: grid;
    place-items: center;
    background:
        radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.09), transparent 55%),
        linear-gradient(to right, rgba(255, 255, 255, 0.03) 1px, transparent 1px) 0 0 / 36px 36px,
        linear-gradient(to bottom, rgba(255, 255, 255, 0.03) 1px, transparent 1px) 0 0 / 36px 36px,
        #070707;
}
.founder-mono .mono-letter {
    font-size: clamp(6rem, 22vw, 11rem);
    font-weight: 800;
    letter-spacing: -0.06em;
    line-height: 1;
    background: linear-gradient(180deg, #fff 0%, #5a5a5a 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}
.founder-mono .mono-letter .dot { -webkit-text-fill-color: #4ade80; }
.mono-corner {
    position: absolute;
    z-index: 3;
    font-family: var(--font-mono);
    font-size: 0.66rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-faint);
}
.mono-corner.tl { top: 22px; left: 24px; }
.mono-corner.tr { top: 22px; right: 24px; }
.mono-corner.bl { bottom: 22px; left: 24px; }
.mono-corner.br { bottom: 22px; right: 24px; }
.founder-mono::after { display: none; }

/* ---------- Micro-interactions ---------- */
.btn:active { transform: translateY(0) scale(0.98); }
.btn-primary { position: relative; overflow: hidden; }
.btn-primary::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(110deg, transparent 30%, rgba(0, 0, 0, 0.08) 50%, transparent 70%);
    transform: translateX(-120%);
    transition: transform 0.6s var(--ease);
}
.btn-primary:hover::after { transform: translateX(120%); }
.btn ion-icon { transition: transform 0.25s var(--ease); }
.btn:hover ion-icon { transform: translateX(3px); }
.nav-toggle ion-icon { transition: transform 0.3s var(--ease); }
.nav-toggle[aria-expanded="true"] ion-icon { transform: rotate(90deg); }
.footer-social a:hover { transform: translateY(-2px); }
:focus-visible { outline: 2px solid #fff; outline-offset: 3px; border-radius: 4px; }

/* Staggered reveal for grid children */
.services-grid .reveal:nth-child(2), .projects-grid .reveal:nth-child(2) { transition-delay: 0.1s; }
.services-grid .reveal:nth-child(3) { transition-delay: 0.2s; }

/* ---------- Fluid / mobile ---------- */
img, svg, video, canvas { max-width: 100%; }

.header-inner { padding-left: max(var(--container-pad), env(safe-area-inset-left)); padding-right: max(var(--container-pad), env(safe-area-inset-right)); }
.footer { padding-bottom: calc(32px + env(safe-area-inset-bottom)); }

.terminal-body { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.terminal-body::-webkit-scrollbar { display: none; }

/* Prevent grid/flex children (e.g. non-wrapping code) from widening the page */
.hero-grid, .founder, .contact-grid, .projects-grid, .services-grid { grid-template-columns: minmax(0, 1fr); }
.hero-grid > *, .founder > *, .contact-grid > *, .projects-grid > *, .services-grid > *, .project-card > * { min-width: 0; }
html, body { max-width: 100%; overflow-x: clip; }
.terminal { max-width: 100%; }
@media (min-width: 981px) {
    .hero-grid { grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr); }
    .founder { grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr); }
    .contact-grid { grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr); }
    .projects-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .services-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 721px) and (max-width: 980px) {
    .services-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

html.nav-open body { overflow: hidden; }

@media (max-width: 980px) {
    .project-card.featured.reverse { grid-template-columns: 1fr; }
    .project-card.featured.reverse .project-shot { order: 0; border-left: none; border-bottom: 1px solid var(--border); }
    .project-card.featured .project-shot { min-height: 0; aspect-ratio: 16 / 10; }
    .hero-terminal { max-width: 640px; }
}

@media (max-width: 720px) {
    .header-inner { height: 60px; }
    .nav { top: 60px; max-height: calc(100dvh - 60px); overflow-y: auto; }
    .nav-link, .nav-cta { min-height: 48px; display: flex; align-items: center; font-size: 1rem; }
    .nav-link::after { display: none; }
    .nav-toggle { width: 44px; height: 44px; margin-right: -8px; }

    .hero { padding-top: clamp(104px, 28vw, 130px); }
    .hero-title { letter-spacing: -0.032em; }
    .hero-sub { font-size: 1rem; }
    .hero-actions { margin-top: 30px; }
    .hero-actions .btn { min-height: 48px; }
    .hero-meta { margin-top: 36px; display: grid; grid-template-columns: repeat(3, auto); justify-content: space-between; gap: 16px; }
    .hero-meta-num { font-size: 1.3rem; }
    .hero-meta-label { font-size: 0.64rem; letter-spacing: 0.04em; }

    .terminal-body { min-height: 0; }
    .terminal-title { padding-right: 0; font-size: 0.7rem; }

    .service-card { padding: 24px 20px; }
    .project-body, .project-card.featured .project-body { padding: 22px 20px 24px; }
    .contact-card { padding: 22px 20px; }
    .btn { min-height: 48px; }

    .founder-photo { max-width: none; aspect-ratio: 16 / 10; }
    .founder-mono .mono-letter { font-size: clamp(5rem, 28vw, 8rem); }
    .founder-sig { flex-wrap: wrap; gap: 8px 18px; }

    .footer-grid { gap: 36px; }
    .footer-bottom { gap: 12px; }
    .back-to-top { width: 42px; height: 42px; }

    /* Touch devices: disable hover-lift that sticks after taps */
    .service-card:hover, .project-card:hover { transform: none; }
}

@media (max-width: 400px) {
    :root { --container-pad: 18px; }
    .hero-title { font-size: clamp(1.9rem, 9.4vw, 2.3rem); }
    .hero-status { font-size: 0.68rem; padding: 6px 12px; }
    .hero-actions { flex-direction: column; }
    .hero-actions .btn { width: 100%; }
    .terminal-body { font-size: 0.7rem; padding: 16px 12px 18px; }
    .t-line .ln { width: 22px; }
    .hero-meta-num { font-size: 1.15rem; }
    .section-title, .contact-title, .founder-title { overflow-wrap: anywhere; }
    .footer-legal { flex-wrap: wrap; }
}

@media (hover: none) {
    .btn-primary:hover::after { transform: translateX(-120%); }
    .project-card:hover .project-shot img { transform: none; }
}

@media (max-height: 480px) and (orientation: landscape) {
    .hero { padding-top: 96px; }
}

@media (prefers-reduced-motion: reduce) {
    html::before, html::after { transition: none !important; animation: none !important; }
    html.is-loading::before { opacity: 1; }
    .project-shot::before { animation: none; }
}
