/* ============================================================
   ARTHUR JOSÉ — PORTFÓLIO
   Camada global
   ============================================================ */

/*
 * Este arquivo é carregado antes dos arquivos das cenas.
 * Responsabilidade: reset, tokens, viewport, tipografia, cursor,
 * tema, componentes globais e comportamento responsivo comum.
 */

/* ============================================================
   VARIÁVEIS
   ============================================================ */
:root {
    --bg-color: #ffffff;
    --text-color: #000000;
    --text-muted: #6b6b6b;
    --accent: #000000;

    --cursor-default: url("../images/cursor.png") 0 0, auto;

    /* Escala fluida: evita dezenas de ajustes manuais de fonte entre breakpoints. */
    --page-gutter: max(20px, 10vw);

    /* ----- Tipografia Apple UI ----- */
    --font-ui:
        -apple-system,
        BlinkMacSystemFont,
        "SF Pro Display",
        "SF Pro Text",
        "Inter",
        "Helvetica Neue",
        Helvetica,
        Arial,
        sans-serif;

    --font-mono:
        ui-monospace,
        "SF Mono",
        "SFMono-Regular",
        Menlo,
        Monaco,
        "JetBrains Mono",
        "Cascadia Code",
        Consolas,
        monospace;
}

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

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 1s ease, color 1s ease;
    -webkit-font-smoothing: antialiased;
    touch-action: pan-x pan-y;   /* permite rolar, bloqueia pinch-zoom */
    -ms-touch-action: pan-x pan-y;
    overflow-x: hidden;
}

/* Se quiser bloquear também o "double-tap to zoom" em elementos específicos */
.scene, #viewport, canvas {
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* ============================================================
   CURSOR PERSONALIZADO
   ============================================================ */
html,
body,
#viewport,
#viewport * {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    cursor: var(--cursor-default) !important;
}

body.luva-scene,
body.luva-scene *,
body.luva-scene #viewport,
body.luva-scene #viewport * {
    cursor: none !important;
    pointer-events: none !important;
    user-select: none;
    -webkit-user-select: none;
}   

@media (hover: none) {
    html,
    body,
    #viewport,
    #viewport * {
        cursor: auto !important;
    }
}

/* ============================================================
   DARK MODE — variáveis
   ============================================================ */
body.dark-mode {
    --bg-color: #050505;
    --text-color: #f0f0f0;
    --accent: #ffffff;
    --text-muted: #a8a8a8;
}

/* ============================================================
   BASE
   ============================================================ */
.mono {
    font-family: var(--font-mono);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.06em;
    font-weight: 500;
    color: var(--text-muted);
    white-space: nowrap;
}

#viewport {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    perspective: 1000px;
    font-family: var(--font-ui);   /* ← Apple UI aplicada só aqui */
}

.scene {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100%;
    display: flex;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
}

.scene.active {
    will-change: transform, opacity;
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    will-change: transform, opacity;
}

.label {
    position: absolute;
    top: 40px;
    left: 40px;
    white-space: nowrap;
    max-width: calc(100vw - 80px);
    overflow-wrap: anywhere;
    word-break: break-word;
}

@media (max-width: 768px) {
    .label {
        top: max(16px, env(safe-area-inset-top));
        left: var(--page-gutter);
        right: var(--page-gutter);
        max-width: calc(100vw - 40px);
        font-size: 0.58rem;
        line-height: 1.45;
        letter-spacing: 0.06em;
    }
}

/* ============================================================
   GLITCH — título da cena 7
   ============================================================ */
.glitch {
    position: relative;
    display: inline-block;
    color: var(--text-color);
    isolation: isolate;
}

.glitch::before,
.glitch::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    white-space: pre-line;
    pointer-events: none;
    user-select: none;
}

.glitch::before {
    color: #00e5ff;
    text-shadow: -1px 0 #00e5ff;
    z-index: -1;
    animation: glitchShiftA 8s infinite steps(1);
}

.glitch::after {
    color: #ff2d55;
    text-shadow: 1px 0 #ff2d55;
    z-index: -2;
    animation: glitchShiftB 8s infinite steps(1);
}

@keyframes glitchShiftA {
    0%, 70%  { transform: translate(0, 0);        clip-path: inset(0 0 0 0); }
    72%      { transform: translate(-4px, 1px);   clip-path: inset(20% 0 60% 0); }
    74%      { transform: translate(2px, -2px);   clip-path: inset(60% 0 15% 0); }
    76%      { transform: translate(-6px, 0);     clip-path: inset(10% 0 75% 0); }
    78%      { transform: translate(3px, 2px);    clip-path: inset(45% 0 40% 0); }
    80%      { transform: translate(-2px, -1px);  clip-path: inset(75% 0 5% 0); }
    82%      { transform: translate(4px, 1px);    clip-path: inset(30% 0 50% 0); }
    84%      { transform: translate(-3px, -2px);  clip-path: inset(60% 0 20% 0); }
    86%      { transform: translate(5px, 0);      clip-path: inset(15% 0 70% 0); }
    88%      { transform: translate(-1px, 1px);   clip-path: inset(50% 0 30% 0); }
    90%,100% { transform: translate(0, 0);        clip-path: inset(0 0 0 0); }
}

@keyframes glitchShiftB {
    0%, 70%  { transform: translate(0, 0);        clip-path: inset(0 0 0 0); }
    72%      { transform: translate(4px, -1px);   clip-path: inset(70% 0 10% 0); }
    74%      { transform: translate(-2px, 2px);   clip-path: inset(15% 0 55% 0); }
    76%      { transform: translate(6px, 0);      clip-path: inset(55% 0 20% 0); }
    78%      { transform: translate(-3px, -2px);  clip-path: inset(5% 0 80% 0); }
    80%      { transform: translate(2px, 1px);    clip-path: inset(35% 0 45% 0); }
    82%      { transform: translate(-5px, -1px);  clip-path: inset(65% 0 15% 0); }
    84%      { transform: translate(3px, 2px);    clip-path: inset(20% 0 60% 0); }
    86%      { transform: translate(-4px, 0);     clip-path: inset(80% 0 5% 0); }
    88%      { transform: translate(2px, -1px);   clip-path: inset(40% 0 40% 0); }
    90%,100% { transform: translate(0, 0);        clip-path: inset(0 0 0 0); }
}

.glitch.glitch-burst::before {
    animation: glitchBurstA 0.7s steps(1) 1;
}

.glitch.glitch-burst::after {
    animation: glitchBurstB 0.7s steps(1) 1;
}

@keyframes glitchBurstA {
    0%   { transform: translate(-10px, 2px);  clip-path: inset(10% 0 60% 0); }
    20%  { transform: translate(8px, -3px);   clip-path: inset(70% 0 15% 0); }
    40%  { transform: translate(-14px, 0);    clip-path: inset(30% 0 55% 0); }
    60%  { transform: translate(12px, 2px);   clip-path: inset(5% 0 80% 0); }
    80%  { transform: translate(-6px, -2px);  clip-path: inset(50% 0 30% 0); }
    100% { transform: translate(0, 0);        clip-path: inset(0 0 0 0); }
}

@keyframes glitchBurstB {
    0%   { transform: translate(12px, -2px);  clip-path: inset(65% 0 15% 0); }
    20%  { transform: translate(-8px, 3px);   clip-path: inset(15% 0 60% 0); }
    40%  { transform: translate(14px, 0);     clip-path: inset(45% 0 35% 0); }
    60%  { transform: translate(-12px, -2px); clip-path: inset(0% 0 85% 0); }
    80%  { transform: translate(6px, 2px);    clip-path: inset(40% 0 40% 0); }
    100% { transform: translate(0, 0);        clip-path: inset(0 0 0 0); }
}

body.dark-mode .glitch::before,
body.dark-mode .glitch::after {
    mix-blend-mode: screen;
}

/* ============================================================
   ORB PENDURADA
   ------------------------------------------------------------
   Repouso: fica parada (sem balanço contínuo).
   Ao trocar de tema (luz acende/apaga), recebe .lamp-pull do JS
   e executa um "puxão" rápido pra baixo + retorno.
   ============================================================ */

#lamp-popup {
    position: fixed;
    top: 0;
    right: 10px;
    width: 82px;
    height: 165px;
    z-index: 120;
    pointer-events: none;
    visibility: visible;
    opacity: 1;
    overflow: visible;
    will-change: transform;
}

/* Fio — top bem acima da tela pra sobrar folga quando a lâmpada
   é puxada pra baixo (o fim visual continua idêntico em repouso). */
#lamp-popup::before {
    content: "";
    position: absolute;
    top: -60px;      /* antes: -18px */
    left: 50%;
    width: 2px;
    height: 152px;   /* antes: 110px  → -60 + 152 = 92 (mesmo ponto visual) */
    transform: translateX(-50%);
    background: #111111;
    border-radius: 999px;
}

/* Orb */
#lamp-popup::after {
    content: "";
    position: absolute;
    top: 98px;
    right: 2px;
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: #fffdf0;
    box-shadow:
        0 0 10px rgba(255, 245, 180, 0.9),
        0 0 24px rgba(255, 230, 120, 0.55),
        0 0 42px rgba(255, 220, 100, 0.25);
    transition: opacity 0.55s ease;
}

body:not(.dark-mode) #lamp-popup::after { opacity: 1; }

body.dark-mode       #lamp-popup::after { opacity: 0; }

/* ----- "Puxão" — só toca quando o tema muda ----- */
#lamp-popup.lamp-pull {
    animation: lampPull 0.78s both;
}

@keyframes lampPull {
    0% {
        transform: translateY(0);
        animation-timing-function: cubic-bezier(0.4, 0, 0.85, 1); /* cai: acelera */
    }
    38% {
        transform: translateY(22px);
        animation-timing-function: cubic-bezier(0.1, 0, 0.3, 1);  /* volta: freia */
    }
    68% {
        transform: translateY(-3px); /* leve overshoot pra cima */
        animation-timing-function: cubic-bezier(0.5, 0, 0.4, 1);
    }
    100% {
        transform: translateY(0);
    }
}

/* ============================================================
   MOBILE — LAYOUT CINEMÁTICO
   ============================================================ */
@media (max-width: 768px) {

    :root { --page-gutter: 20px; }

    html, body {
            width: 100%;
            height: 100%;
            overflow: hidden;
            overscroll-behavior: none;
        }

    #viewport {
            position: fixed;
            inset: 0;
            width: 100vw;
            height: 100dvh;
            perspective: 900px;
        }

    .scene {
            position: absolute;
            inset: 0;
            width: 100%;
            height: 100%;
            padding-left: var(--page-gutter);
            padding-right: var(--page-gutter);
        }

    .label {
            top: max(16px, env(safe-area-inset-top));
            left: var(--page-gutter);
            right: var(--page-gutter);
            max-width: calc(100vw - 40px);
            font-size: 0.58rem;
            line-height: 1.45;
            letter-spacing: 0.06em;
        }

    .mono {
            font-size: 0.62rem;
            letter-spacing: 0.06em;
        }

    /* ---------------- ORB ---------------- */
        #lamp-popup {
            top: -6px;
            right: 3px;
            width: 60px;
            height: 94px;
        }

    #lamp-popup::before {
            top: -60px;      /* antes: -8px */
            height: 104px;   /* antes: 52px  → -60 + 104 = 44 (mesmo ponto visual) */
            width: 1.5px;
        }

    #lamp-popup::after {
            top: 44px;
            right: 1px;
            width: 52px;
            height: 52px;
            box-shadow:
                0 0 7px rgba(255, 245, 180, 0.85),
                0 0 18px rgba(255, 230, 120, 0.50),
                0 0 30px rgba(255, 220, 100, 0.22);
        }
}

/* ============================================================
   CELULAR DEITADO — LANDSCAPE
   ============================================================ */
@media (max-width: 900px) and (orientation: landscape) {

    :root { --page-gutter: 6vw; }

    html, body, #viewport {
            width: 100%;
            height: 100%;
            height: 100dvh;
            min-height: 100dvh;
            overflow: hidden;
            overscroll-behavior: none;
        }

    #viewport {
            position: fixed;
            inset: 0;
            width: 100vw;
            height: 100dvh;
            perspective: 900px;
        }

    .scene {
            position: absolute;
            inset: 0;
            width: 100vw;
            height: 100dvh;
            min-height: 0;
            padding-left: 5vw;
            padding-right: 5vw;
            overflow: hidden;
        }

    .label {
            top: max(12px, env(safe-area-inset-top));
            left: var(--page-gutter);
            right: var(--page-gutter);
            max-width: calc(100vw - 40px);
            font-size: 0.52rem;
            line-height: 1.35;
            letter-spacing: 0.055em;
        }

    .mono {
            font-size: 0.56rem;
            letter-spacing: 0.055em;
        }

    /* ---------------- ORB ---------------- */
        #lamp-popup {
            top: -4px;
            right: 3px;
            width: 56px;
            height: 84px;
        }

    #lamp-popup::before {
            top: -60px;      /* antes: -6px */
            height: 102px;   /* antes: 48px  → -60 + 102 = 42 (mesmo ponto visual) */
            width: 1.5px;
        }

    #lamp-popup::after {
            top: 40px;
            right: 0;
            width: 48px;
            height: 48px;
            box-shadow:
                0 0 7px rgba(255, 245, 180, 0.85),
                0 0 18px rgba(255, 230, 120, 0.50),
                0 0 28px rgba(255, 220, 100, 0.22);
        }
}

/* ============================================================
   CELULAR DEITADO — ALTURA MUITO BAIXA
   ============================================================ */
@media (max-width: 900px)
and (orientation: landscape)
and (max-height: 430px) {

    .label { top: 9px; font-size: 0.45rem; }

    #lamp-popup { width: 48px; height: 72px; }

    #lamp-popup::before {
            top: -60px;      /* antes: herdava -6px */
            height: 96px;    /* antes: 42px  → -60 + 96 = 36 (mesmo ponto visual) */
            width: 1.5px;
        }

    #lamp-popup::after { top: 35px; width: 42px; height: 42px; }
}

/* ============================================================
   CELULARES MUITO PEQUENOS — LANDSCAPE
   ============================================================ */
@media (max-width: 700px)
and (orientation: landscape)
and (max-height: 360px) {

    :root { --page-gutter: 14px; }

    html, body, #viewport {
            width: 100%;
            height: 100%;
            height: 100dvh;
            min-height: 100dvh;
            overflow: hidden;
        }

    #viewport {
            position: fixed;
            inset: 0;
            width: 100vw;
            height: 100dvh;
            perspective: 700px;
        }

    .scene {
            width: 100vw;
            height: 100dvh;
            padding-left: 14px;
            padding-right: 14px;
            overflow: hidden;
        }

    .label {
            top: 7px;
            left: 14px;
            right: 14px;
            font-size: 0.38rem;
            line-height: 1.25;
            letter-spacing: 0.05em;
        }

    .mono { font-size: clamp(0.48rem, 1vw, 0.62rem); letter-spacing: 0.05em; }

    /* ORB */
        #lamp-popup { top: -2px; right: 1px; width: 40px; height: 60px; }

    #lamp-popup::before {
            top: -60px;      /* antes: -4px */
            height: 90px;    /* antes: 34px  → -60 + 90 = 30 (mesmo ponto visual) */
            width: 1px;
        }

    #lamp-popup::after {
            top: 30px;
            right: 0;
            width: 34px;
            height: 34px;
            box-shadow:
                0 0 5px rgba(255, 245, 180, 0.8),
                0 0 12px rgba(255, 230, 120, 0.45),
                0 0 20px rgba(255, 220, 100, 0.18);
        }
}

@media (prefers-reduced-motion: reduce) {

    *,
        *::before,
        *::after {
            animation-duration: 0.001ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.001ms !important;
            scroll-behavior: auto !important;
        }
}


/* ============================================================
   FALLBACK SEM JAVASCRIPT
   ============================================================ */
.noscript-message {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: grid;
    place-items: center;
    padding: 2rem;
    background: #ffffff;
    color: #000000;
    font-family: var(--font-ui);
    font-size: 1rem;
    line-height: 1.5;
    text-align: center;
}

.footer-credit {
    display: inline-block;
    margin-left: 1rem;
    color: inherit;
    text-decoration: none;
    opacity: 0.72;
    transition: opacity 0.2s ease;
}

.footer-credit:hover {
    opacity: 1;
}

@media (max-width: 768px) {
    .footer-credit {
        display: block;
        margin: 0.35rem 0 0;
    }
}