/* main.css */
/* Purpose: Global variables, root theming, resets, typography, and base layout definitions. */

/* ==========================================================================
   ROOT VARIABLES & THEMING
   ========================================================================== */
:root {
    /* Fonts */
    --font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
    --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;

    /* Base Colors */
    --color-white: #FFFFFF;
    --color-black: #000000;
    --color-bg: #FFFFFF;
    --color-player-bg: #101218;
    --color-card-bg: #F2F2F7;
    --color-card-border: rgba(0, 0, 0, 0.05);
    --color-kbd-border: rgba(0, 0, 0, 0.15); /* A11Y: Subtle border for keyboard shortcuts */
    --color-tooltip-kbd-border: rgba(255, 255, 255, 0.2); /* A11Y: Inverted for dark tooltips */

    /* Gray Scale */
    --color-gray-dark: #323232;
    --color-gray-med: #777777;
    --color-gray-light: #B2B2B2;
    --color-gray-xlight: #D9D9D9;

    /* Semantic & Accent Colors */
    --color-accent: #2B71F0;
    --color-success: #34C759;
    --color-error: #FF3B30;
    --color-error-alt: #d73a49;
    --color-overlay-dark: rgba(0, 0, 0, 0.85);
    --color-overlay-light: rgba(255, 255, 255, 0.1);
    --color-glass-bg: rgba(235, 235, 240, 0.6);

    /* Spacing Scale */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 24px;
    --space-xxl: 32px;
    --space-xxxl: 40px;
    --space-xxxxl: 80px;
    --space-xxxxxl: 100px;
    --page-padding: 8vw;
    --header-offset-y: 15vh; /* Added to manage absolute header positioning */
    --gallery-safe-top: calc(var(--header-offset-y) + 120px); /* A11Y: Dynamic safe zone to prevent title occlusion */
    --gallery-safe-bottom: 77px; /* A11Y: Generous breathing room above the footer */
    --gallery-meta-width: 200px; /* Controls the maximum width of the text/pills under thumbnails */

    /* Border Radii */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-pill: 100px;
    --radius-circle: 50%;

    /* Speeds & Easing */
    --speed-fast: 0.2s;
    --speed-normal: 0.3s;
    --speed-slow: 0.4s;
    --speed-main: 1s;
    --ease-standard: ease;
    --ease-fluid: cubic-bezier(0.16, 1, 0.3, 1);

    /* Z-Index Scale */
    --z-base: 10;
    --z-above: 20;
    --z-dropdown: 50;
    --z-fixed: 100;
    --z-overlay: 1000;
    --z-modal: 2000;
    --z-max: 10000;

    /* Device Measurements (Defaults) */
    --device-aspect-ratio: 1 / 2.03;
    --device-h-gallery: 60vh;
    --device-h-case: 75vh;
    --device-h-player: 85vh;
    --device-max-h-gallery: 700px;
    --device-max-h-case: 700px;
    --device-max-h-player: 800px;
    --device-w-ratio: -0.49261;
}

/* ==========================================================================
   DEVICE VARIATIONS
   ========================================================================== */
.iphone-17 {
    --device-aspect-ratio: 1 / 2.15;
    --device-h-gallery: 55vh;
    --screen-w: 91%;
    --screen-h: 92%;
    --screen-r: 10%;
    --device-offset-y: var(--space-md);
    --device-w-ratio: -0.465116;
}

.apple-watch {
    --device-aspect-ratio: 1 / 1.6;
    --device-h-gallery: 30vh;
    --device-h-case: 50vh;
    --screen-w: 74%;
    --screen-h: 46%;
    --screen-r: 18%;
    --device-offset-y: 30px;
    --device-w-ratio: -0.625;
}

.iphone-12 {
    --device-aspect-ratio: 1 / 2.1;
    --device-h-gallery: 48vh;
    --screen-w: 105%;
    --screen-h: 100%;
    --screen-r: 9%;
    --device-offset-y: 15px;
    --device-w-ratio: -0.47619;
}

.iphone-x {
    --device-aspect-ratio: 1 / 2.1;
    --device-h-gallery: 55vh;
    --screen-w: 87%;
    --screen-h: 92%;
    --screen-r: 9%;
    --device-offset-y: var(--space-sm);
    --device-w-ratio: -0.47619;
}

.iphone-8 {
    --device-aspect-ratio: 1 / 1.8;
    --device-h-gallery: 49vh;
    --device-h-case: 70vh;
    --screen-w: 83%;
    --screen-h: 72%;
    --screen-r: 1%;
    --device-offset-y: 23px;
    --device-w-ratio: -0.55555;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--color-bg);
    color: var(--color-black);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    transition: background-color var(--speed-slow) var(--ease-standard);
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

body.player-active {
    background-color: var(--color-player-bg);
}

html,
body,
button,
a,
.nav-link,
.case-thumb-wrapper {
    touch-action: manipulation;
}

h1 {
    font-weight: 500;
    font-size: 38px;
    letter-spacing: -0.04em;
    line-height: 0.8;
    color: var(--color-black);
}

h2 {
    font-weight: 600;
    font-size: 38px;
    letter-spacing: -0.02em;
    line-height: 1.0;
    color: var(--color-black);
}

h3 {
    font-weight: 600;
    font-size: 20px;
    letter-spacing: -0.02em;
    line-height: 1.0;
    color: var(--color-black);
}

h4 {
    font-weight: 250;
    font-size: 22px;
    letter-spacing: -0.04em;
    line-height: 0.8;
    color: var(--color-gray-med);
}

.p1 {
    font-weight: 400;
    font-size: 18px;
    letter-spacing: -0.02em;
    line-height: 1.1;
    color: var(--color-black);
}

.p2 {
    font-weight: 300;
    font-size: 17px;
    letter-spacing: -0.02em;
    line-height: 0.8;
    color: var(--color-gray-med);
}

.p3 {
    font-weight: 500;
    font-size: 13px;
    letter-spacing: 0em;
    line-height: 1.0;
    color: var(--color-gray-xlight);
    text-decoration: none;
}

/* ==========================================================================
   LAYOUT BASE
   ========================================================================== */
#app-container {
    width: 100vw;
    padding: 0 0 0px; /* Removed 15vh top padding to prevent flex clipping */
    height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
}

header {
    position: absolute; /* Extracts header from document flow */
    top: var(--header-offset-y); 
    left: 0;
    right: 0;
    width: 100%;
    max-width: 1440px;
    margin: 0 auto; /* Removed bottom margin since it is absolute */
    padding: 0 var(--page-padding);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: var(--z-dropdown); /* Elevated to float above the gallery */
    transition: opacity 0.1s var(--ease-standard);
    view-transition-name: main-header-view;
    pointer-events: none; /* Prevents invisible box from blocking mouse/touch events on gallery */
}

.header-left, .header-right {
    pointer-events: auto; /* A11Y: Re-enables clicking and keyboard focus on header contents */
}

.header-left h1 {
    margin-bottom: var(--space-md);
}

.header-right {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    text-align: left;
}

header.hidden-header {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}

.nav-link {
    cursor: pointer;
    transition: color var(--speed-fast) var(--ease-standard);
    text-decoration: none;
}

.nav-link:hover {
    color: var(--color-black);
}

.header-divider {
    width: 2px;
    height: 18px;
    background: var(--color-gray-med);
    opacity: 0.3;
    margin: 0 var(--space-sm);
    border-radius: 2px;
}

.about-label {
    font-size: 13px;
    font-weight: 500;
}

.about-avatar {
    width: 22px;
    height: 22px;
    border-radius: var(--radius-circle);
    object-fit: cover;
}

footer {
    position: fixed;
    bottom: 20px;
    left: 0;
    width: 100%;
    text-align: center;
    pointer-events: none;
    transition: opacity var(--speed-normal) var(--ease-fluid), visibility var(--speed-normal) var(--ease-standard);
    view-transition-name: footer-view;
}

footer.hidden-footer {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}

footer p {
    font-size: 12px;
    color: var(--color-gray-light);
    padding: 0 var(--page-padding);
}

.view-section {
    flex-grow: 1;
    display: none;
    height: 100%;
    position: relative;
}

.view-section.active {
    display: block;
}

.hidden-default {
    display: none;
}

/* ==========================================================================
   ABOUT VIEW
   ========================================================================== */
#view-about.active {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--color-bg);
    z-index: var(--z-above);
}

.about-layout {
    display: flex;
    gap: 100px;
    align-items: center;
    justify-content: center;
    padding: 0 var(--page-padding);
    height: 100%;
    max-width: 1280px;
    margin: 0 auto;
    flex-direction: row-reverse;
}

#view-about .about-content {
    max-width: 450px;
}

#view-about .p1 {
    margin-bottom: var(--space-xl);
}

.about-links {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    margin-top: var(--space-xl);
}

.about-image-container {
    flex: 0 0 auto;
    width: 402px;
    height: 279px;
    overflow: hidden;
}

#about-photo {
    height: 100%;
    width: 100%;
    object-fit: cover;
    border-radius: var(--radius-sm);
}

/* Visibility Overrides for leaving states */
body.player-active .floating-about-btn,
body.player-active .floating-lang-btn,
body.player-active .floating-ai-btn,
body.player-active .header-divider,
body[data-active-view="about"] .header-divider {
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
    transform: translateY(-10px);
}

/* ==========================================================================
   VIEW TRANSITIONS (ELEVATOR EFFECT)
   ========================================================================== */
::view-transition-old(root),
::view-transition-new(root) {
    animation-duration: 0.7s;
    animation-timing-function: var(--ease-fluid); /* Using your new variable for cubic-bezier(0.16,1,0.3,1) */
}

html.slide-up-transition::view-transition-old(root) { 
    animation-name: fadeOutUp; 
}
html.slide-up-transition::view-transition-new(root) { 
    animation-name: fadeInFromBottom; 
}

html.slide-down-transition::view-transition-old(root) { 
    animation-name: fadeOutDown; 
}
html.slide-down-transition::view-transition-new(root) { 
    animation-name: fadeInFromTop; 
}

@keyframes fadeOutUp {
    to { transform: translateY(-10%); opacity: 0; }
}

@keyframes fadeInFromBottom {
    from { transform: translateY(15%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeOutDown {
    to { transform: translateY(15%); opacity: 0; }
}

@keyframes fadeInFromTop {
    from { transform: translateY(-10%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ==========================================================================
   MOBILE RESPONSIVENESS (LAYOUT & CORE)
   ========================================================================== */
@media (max-width: 768px) {
    :root {
        --device-h-player: 55vh;
    }

    #app-container {
        padding: 0 !important;
        height: 100dvh;
        display: block;
        position: relative;
        overflow: hidden !important;
        overscroll-behavior: none;
    }

    header {
        position: absolute;
        top: 10vh;
        left: 0;
        width: 100%;
        padding: 0 var(--page-padding);
        z-index: var(--z-dropdown);
        display: flex !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: var(--space-md);
    }

    .header-left h1 {
        font-size: 28px;
        margin-bottom: 2px !important;
        line-height: 1.1;
    }

    .header-left h4 {
        font-size: 17px;
        line-height: 1.3 !important;
        max-width: 85%;
    }

    .header-right {
        display: flex !important;
        flex-direction: row !important;
        gap: var(--space-xl) !important;
    }

    .view-section {
        height: 100dvh;
        width: 100vw;
        display: none;
        flex-direction: column;
        align-items: center;
        overflow: hidden;
    }

    #view-about.active {
        display: flex !important;
        flex-direction: column;
        justify-content: flex-start;
        overflow-y: auto;
        padding-top: 0vh;
        padding-bottom: 60px;
    }

    .about-layout {
        flex-direction: column-reverse;
        gap: var(--space-xxxl);
        padding: 0 var(--page-padding);
        max-width: 90%;
    }

    #view-about .about-content {
        max-width: 100% !important;
        text-align: left;
    }

    .about-image-container {
        width: 100% !important;
        height: auto !important;
        aspect-ratio: 402 / 279;
        border-radius: 0px;
    }

    #view-about .p1 {
        font-size: 16px !important;
        line-height: 1.3 !important;
        margin-bottom: var(--space-lg) !important;
    }

    #view-about .about-links .p2 {
        font-size: 14px !important;
    }
}