:root {
    --active-color: #6bb4fd;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    overflow-x: clip;
}

body {
    background-color: var(--active-color);
    font-family: 'Arial Rounded MT Bold';
    display: flex;
    flex-direction: column;
    height: 100vh;
    background-image: url("https://transparenttextures.com/patterns/ps-neutral.png");
    transition: background-color .15s linear;
}

menu {
    margin: 0;
    display: flex;
    height: 64px;
    padding-inline: 16px;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 20;
}

/* Buttons */
button.open-button,
button.close-button {
    height: 44px;
    border: 0;
    border-radius: 24px;
    padding-inline: 16px;
    font-size: 16px;
    font-family: 'Arial Rounded MT Bold';
    border-bottom: 4px solid #ba2222;
    background-color: #ff3333;
    color: white;
    text-shadow: rgba(0, 0, 0, 0.133) 0px 2px 0px;
    cursor: pointer;
    transition: transform 0.2s ease, background-color 0.3s ease;
    margin-bottom: 0;
    padding-block: 0;
}

button:hover {
    transform: scale(1.05);
    background-color: #eee;
}

menu h1 {
    color: #587e9c;
}

menu button.open-button {
    margin-left: auto;
}

dialog {
    height: 100%;
    width: 100%;
    border: 0;
    background-image: url("https://transparenttextures.com/patterns/ps-neutral.png");
    padding: 0;
}

dialog menu {
    padding: 24px;
    background-color: white;
    border-bottom: 3px solid #eee;
    z-index: 10;
}

dialog #story-list {
    margin: 24px auto 48px;
    display: flex;
    flex-direction: column;
    width: 100%;
    padding-inline: 24px;
}

dialog button {
    padding: 24px;
    margin-bottom: 16px;
    border-radius: 16px;
    font-size: 24px;
    background-color: white;
    color: #587e9c;
    border: 0;
    border-bottom: 3px solid #ddd;
    cursor: pointer;
    font-family: 'Arial Rounded MT Bold';
    position: relative;
    overflow: hidden;
    transition: transform 0.2s ease;
}

dialog button:hover {
    transform: scale(1.05);
}

dialog button .marker {
    width: 10px;
    height: 100%;
    background-color: #ddd;
    position: absolute;
    left: 0;
    top: 0;
}

main {
    flex: 1;
    display: flex;
    align-items: center;
    padding-inline: 16px;
}

.container {
    display: flex;
    align-items: center;
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
}

/* Navigation Buttons */
#next, #previous {
    height: 44px;
    width: 44px;
    border-radius: 100%;
    flex-shrink: 0;
    border: 0;
    border-bottom: 4px solid lightgray;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--active-color);
    cursor: pointer;
    background-color: white;
    z-index: 10;
    transition: transform 0.2s ease;
}

#next:hover, #previous:hover {
    transform: scale(1.1);
}

#next[disabled],
#previous[disabled] {
    opacity: .4;
    pointer-events: none;
}

#app {
    padding: 16px;
    width: 100%;
}

/* Story Wrapper */
.story-wrapper {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Story Image with GPU Acceleration Fix */
.story-image {
    height: 200px;
    width: 200px;
    border-radius: 100%;
    position: relative;
    background-color: color-mix(in oklab, var(--active-color), 40% black);
    cursor: pointer;
    border: 0;

    /* Prevent iOS flickering */
    will-change: transform, opacity;
    transform: translateZ(0);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.story-image.stabilized {
    /* Ensure stable rendering after animation frame */
    transform: scale(1);
}

/* Improved Image Toggle with Opacity */
.image-wrapper {
    width: 100%;
    height: 100%;
    overflow: hidden;
    border-radius: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;

    /* Force GPU acceleration */
    will-change: transform, opacity;
    transform: translateZ(0);
    user-select: none;
}

.image-wrapper img {
    position: absolute;
    transition: opacity 0.3s ease, transform 0.3s ease;
    opacity: 0;
    pointer-events: none;
    opacity: 1;
}

.image-wrapper img.active {
    opacity: 1;
    pointer-events: all;
    transform: scale(1.05);
}

/* Interaction Effects */
.action-text,
.active-image {
    display: none;
}

.action-text {
    position: absolute;
    z-index: 20;
    background-color: white;
    color: gray;
    padding: 12px;
    width: fit-content;
    top: 0;
    border-radius: 40px;
    left: calc(100% - 32px);
    min-width: 135px;
    transition: opacity 0.3s ease;
    user-select: none;
}

.action-text:before {
    content: "";
    background-color: white;
    height: 20px;
    width: 20px;
    border-radius: 50%;
    position: absolute;
    bottom: -10px;
    left: -10px;
}

.story-image.active img, 
.story-image:focus-visible img {
    visibility: hidden;
}

.story-image.active .active-image, 
.story-image:focus-visible .active-image {
    visibility: visible;
    display: block;
}

.story-image.active .action-text, 
.story-image:focus-visible .action-text {
    display: block;
    opacity: 1;
}

/* Smooth image transitions */
.image-wrapper .active-image {
    position: absolute;
    transition: opacity 0.3s ease;
    user-select: none;
}

.image-wrapper img {
    position: absolute;
    bottom: 0;
    transition: bottom 0.5s ease;
    user-select: none;
}

h2.story-title {
    font-size: 40px;
    margin-block: 24px;
    color: white;
    text-shadow: rgba(0, 0, 0, 0.133) 0px 2px 0px;
}

/* Story Pages */
.story-wrapper .story {
    border-radius: 24px;
    background-color: white;
    height: 40vh;
    overflow-y: scroll;
    color: gray;
    line-height: 1.5;
    width: 100%;
    text-align: left;
    display: flex;
    flex-direction: column;
    scroll-snap-type: y mandatory; 
    border: 2px solid color-mix(in oklab, var(--active-color), 10% black);
}
    
.page {
    width: 100%;
    height: 100%;
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    padding: 24px;
    align-items: center;
    flex-shrink: 0;
    scroll-snap-align: start;
    position: relative;
    counter-increment: page-number; 
}

.page::after {
    content: "Page " counter(page-number);
    position: absolute;
    bottom: 10px;
    right: 16px;
    font-size: 14px;
    color: gray;
    opacity: 0.7;
}

/* Utilities */
.accent {
    color: var(--active-color);
}

#splash-screen {
    display: none;
}

@media all and (display-mode: standalone) {
    body {
        background-color: var(--active-color);  /* Ensure color consistency */
        background-image: url("https://transparenttextures.com/patterns/ps-neutral.png");
        transition: background-color .15s linear;
    }
    #splash-screen {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: var(--active-color);
        background-image: url("https://transparenttextures.com/patterns/ps-neutral.png");
        color: #fff;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        z-index: 9999;
        transition: opacity 0.75s ease-in-out;
    }
    
    #splash-screen img {
        width: 150px;
        height: auto;
        animation: fadeIn 1s ease-in-out;
        border-radius: 100%;
    }
    
    #splash-screen h1 {
        font-size: 2rem;
        animation: fadeIn 1.5s ease-in-out;
        text-shadow: rgba(0, 0, 0, 0.133) 0px 2px 0px;
    }
}