/* =======================================================
   Shared mechanics for the per-app mini-sites
   (habitsflow/, watertotter/, animewallet/).
   Each app's style.css sets the look through the
   custom properties used here.
   ======================================================= */

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

* {
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

html:has(dialog[open]) {
    overflow: hidden;
}

body {
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

img,
svg {
    display: block;
    max-width: 100%;
}

button {
    font: inherit;
    color: inherit;
    background: none;
    border: 0;
    cursor: pointer;
}

a {
    color: inherit;
}

:focus-visible {
    outline: 2px solid var(--focus-ring, currentColor);
    outline-offset: 3px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* --- Layout --- */
.wrap {
    width: 100%;
    max-width: var(--maxw, 1160px);
    margin: 0 auto;
    padding-inline: var(--gutter, clamp(16px, 5vw, 36px));
}

/* --- Scroll reveal (content is only hidden while JS is running) --- */
.js [data-reveal] {
    opacity: 0;
    transform: translateY(26px);
    transition:
        opacity 0.8s cubic-bezier(0.2, 0.7, 0.2, 1),
        transform 0.8s cubic-bezier(0.2, 0.7, 0.2, 1);
    transition-delay: var(--reveal-delay, 0s);
}

.js [data-reveal].is-visible {
    opacity: 1;
    transform: none;
}

/* --- Device frame (iPhone-like, built in CSS) --- */
.device {
    position: relative;
    display: block;
    width: min(var(--device-w, 300px), 100%);
    aspect-ratio: 1290 / 2796;
    padding: 3.4%;
    border-radius: 15% / 7%;
    background: var(--device-frame, #0c0c10);
    box-shadow:
        inset 0 0 0 1px rgba(255, 255, 255, 0.12),
        inset 0 0 0 4px rgba(0, 0, 0, 0.6),
        var(--device-shadow, 0 50px 90px -40px rgba(0, 0, 0, 0.6));
    container-type: inline-size;
}

.device-screen {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
    overflow: hidden;
    border-radius: 12% / 5.6%;
    background: var(--screen-bg, #000);
}

.device-screen > img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.device-screen::after {
    /* Dynamic Island */
    content: "";
    position: absolute;
    z-index: 5;
    top: 1.5%;
    left: 50%;
    width: 31%;
    height: 3.9%;
    transform: translateX(-50%);
    border-radius: 999px;
    background: #000;
    pointer-events: none;
}

/* --- Screenshot carousel --- */
.shots {
    display: flex;
    gap: var(--shots-gap, 22px);
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory;
    padding-block: 12px 28px;
    padding-inline: max(var(--gutter, 16px), calc((100% - var(--maxw, 1160px)) / 2 + var(--gutter, 16px)));
    scroll-padding-inline: max(var(--gutter, 16px), calc((100% - var(--maxw, 1160px)) / 2 + var(--gutter, 16px)));
    scrollbar-width: none;
}

.shots::-webkit-scrollbar {
    display: none;
}

.shot {
    flex: 0 0 auto;
    width: var(--shot-w, 236px);
    scroll-snap-align: start;
}

.shot-btn {
    display: block;
    width: 100%;
    border-radius: var(--shot-radius, 28px);
    transition: transform 0.35s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.shot-btn:hover {
    transform: translateY(-6px);
}

.shot-btn > img {
    width: 100%;
    height: auto;
    border-radius: var(--shot-radius, 28px);
}

.shot figcaption {
    margin-top: 14px;
    font-size: 0.92rem;
    line-height: 1.4;
}

.shots-nav {
    display: flex;
    gap: 10px;
}

.shots-nav[hidden] {
    display: none;
}

.shots-nav button {
    display: grid;
    width: 44px;
    height: 44px;
    place-items: center;
    border-radius: 50%;
    transition:
        opacity 0.2s,
        transform 0.2s,
        background-color 0.2s;
}

.shots-nav button:disabled {
    opacity: 0.35;
    cursor: default;
}

.shots-nav button svg {
    width: 18px;
    height: 18px;
}

/* --- Lightbox --- */
.lightbox {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    max-width: none;
    max-height: none;
    margin: 0;
    border: 0;
    background: transparent;
    color: #fff;
}

.lightbox[open] {
    display: grid;
    place-items: center;
}

.lightbox::backdrop {
    background: var(--lightbox-backdrop, rgba(4, 6, 12, 0.86));
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
}

.lightbox figure {
    display: grid;
    justify-items: center;
    gap: 14px;
    padding: 64px 16px 24px;
    pointer-events: none;
}

.lightbox img {
    width: auto;
    height: auto;
    max-width: min(92vw, 1100px);
    max-height: calc(100vh - 150px);
    border-radius: 24px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
    pointer-events: auto;
}

.lightbox figcaption {
    font-size: 0.95rem;
    opacity: 0.8;
    text-align: center;
}

.lightbox-btn {
    position: fixed;
    display: grid;
    width: 46px;
    height: 46px;
    place-items: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    transition: background-color 0.2s;
}

.lightbox-btn:hover {
    background: rgba(255, 255, 255, 0.26);
}

.lightbox-btn svg {
    width: 20px;
    height: 20px;
}

.lightbox-close {
    top: 16px;
    right: 16px;
}

.lightbox-prev,
.lightbox-next {
    top: 50%;
    transform: translateY(-50%);
}

.lightbox-prev {
    left: 16px;
}

.lightbox-next {
    right: 16px;
}

@media (max-width: 640px) {
    .lightbox-prev,
    .lightbox-next {
        top: auto;
        bottom: 20px;
        transform: none;
    }

    .lightbox-prev {
        left: calc(50% - 56px);
    }

    .lightbox-next {
        right: calc(50% - 56px);
    }

    .lightbox figure {
        padding-bottom: 84px;
    }

    .lightbox img {
        max-height: calc(100vh - 190px);
    }
}

/* --- Reduced motion --- */
@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .js [data-reveal] {
        opacity: 1;
        transform: none;
    }
}
