:root {
    color-scheme: dark;
    --story-button-size: clamp(44px, 4vw + 1vh, 88px);
    --story-button-icon-size: clamp(18px, 1.8vw + 0.4vh, 34px);
    --story-control-size: clamp(30px, 2.8vw + 0.6vh, 68px);
    --story-control-arrow-size: clamp(7px, 0.9vw + 0.16vh, 16px);
    --story-close-font-size: clamp(0.82rem, 0.62rem + 0.7vw, 1.18rem);
    --story-close-padding-y: clamp(6px, 0.9vh, 12px);
    --story-close-padding-x: clamp(14px, 3.2vw, 28px);
    --story-blur: blur(18px);
    --story-border-color: rgba(148, 163, 184, 0.28);
    --story-hover-border-color: rgba(148, 163, 184, 0.5);
    --story-surface-gradient: linear-gradient(145deg, rgba(30, 41, 59, 0.92), rgba(15, 23, 42, 0.78));
    --story-surface-gradient-hover: linear-gradient(150deg, rgba(51, 65, 85, 0.98), rgba(17, 24, 39, 0.82));
    --story-elevated-shadow:
        0 14px 32px rgba(15, 23, 42, 0.45),
        inset 0 1px 0 rgba(255, 255, 255, 0.12);
    --story-elevated-shadow-hover:
        0 18px 36px rgba(15, 23, 42, 0.55),
        inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

canvas {
    display: block;
    margin: 0 auto;
    width: min(60vw, 960px);
    max-width: 100%;
    height: auto;
    aspect-ratio: 4 / 3;
}

@media (max-width: 768px) {
    body {
        padding: clamp(16px, 5vh, 48px) clamp(12px, 5vw, 20px);
    }

    canvas {
        width: 100%;
    }
}

.story-button {
    position: fixed;
    top: clamp(12px, 3vw, 18px);
    left: clamp(12px, 3vw, 18px);
    width: var(--story-button-size);
    height: var(--story-button-size);
    border-radius: 20px;
    border: 1px solid var(--story-border-color);
    background: var(--story-surface-gradient);
    color: #cbd5f5;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    cursor: pointer;
    z-index: 1100;
    box-shadow: var(--story-elevated-shadow);
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease,
        background 0.2s ease;
    backdrop-filter: var(--story-blur);
    -webkit-backdrop-filter: var(--story-blur);
    overflow: hidden;
}

.story-button::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(160deg, rgba(255, 255, 255, 0.1), rgba(15, 23, 42, 0));
    pointer-events: none;
}

.story-button:hover,
.story-button:focus-visible {
    transform: translateY(-1px);
    border-color: var(--story-hover-border-color);
    background: var(--story-surface-gradient-hover);
    box-shadow: var(--story-elevated-shadow-hover);
}

.story-button:focus-visible {
    outline: none;
    box-shadow:
        0 0 0 3px rgba(99, 102, 241, 0.35),
        var(--story-elevated-shadow-hover);
}

.story-button__icon {
    width: var(--story-button-icon-size);
    height: var(--story-button-icon-size);
}

.story-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at top, rgba(15, 23, 42, 0.35), rgba(10, 12, 24, 0.08));
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease-in-out;
    z-index: 1200;
    padding: 20px;
    backdrop-filter: blur(12px);
}

.story-overlay--visible {
    opacity: 1;
    pointer-events: auto;
}

.story-overlay__content {
    width: min(90vw, 720px);
    max-height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.story-overlay__content:focus,
.story-overlay__content:focus-visible {
    outline: none;
}

.story-episode {
    display: none;
    line-height: 1.8;
    color: #e2e8f0;
}

.story-episode--active {
    display: block;
}

.story-episode__heading {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.story-modal {
    position: relative;
    width: 100%;
    padding: 32px clamp(24px, 5vw, 40px);
    border-radius: 24px;
    background: linear-gradient(135deg, rgba(26, 34, 56, 0.55), rgba(15, 17, 34, 0.35));
    box-shadow:
        0 30px 60px rgba(0, 0, 0, 0.45),
        0 4px 12px rgba(15, 23, 42, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.12);
    backdrop-filter: var(--story-blur);
    color: #f8fafc;
}

.story-modal__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
}

.story-modal__titles {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.story-modal__episode-label {
    margin: 0;
    font-size: clamp(1rem, 1.6vw, 1.6rem);
    letter-spacing: 0.2em;
    color: rgba(248, 250, 252, 0.92);
    text-shadow: 0 0 12px rgba(148, 163, 184, 0.45);
}

.story-modal__title {
    margin: 0;
    font-size: clamp(1.25rem, 2.4vw, 2.4rem);
    font-weight: 600;
    letter-spacing: 0.05em;
}

.story-modal__footer-actions {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 12px;
}

.story-modal__control {
    width: var(--story-control-size);
    height: var(--story-control-size);
    border-radius: 50%;
    border: 1px solid rgba(148, 163, 184, 0.5);
    background: linear-gradient(145deg, rgba(148, 163, 184, 0.24), rgba(71, 85, 105, 0.16));
    color: #f8fafc;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
    backdrop-filter: var(--story-blur);
}

.story-modal__control::before {
    content: "";
    display: block;
    width: var(--story-control-arrow-size);
    height: var(--story-control-arrow-size);
    border-top: 2px solid currentColor;
    border-right: 2px solid currentColor;
    transform: rotate(45deg);
}

.story-modal__control--prev::before {
    transform: rotate(225deg);
}

.story-modal__control:focus-visible,
.story-modal__control:hover {
    transform: translateY(-2px);
    border-color: rgba(148, 163, 184, 0.8);
    background: linear-gradient(145deg, rgba(248, 250, 252, 0.3), rgba(148, 163, 184, 0.22));
}

.story-modal__body {
    margin-top: 24px;
    max-height: calc(70vh - 120px);
    overflow-y: auto;
    padding-right: 6px;
}

.story-modal__body::-webkit-scrollbar {
    width: 6px;
}

.story-modal__body::-webkit-scrollbar-thumb {
    background-color: rgba(148, 163, 184, 0.4);
    border-radius: 9999px;
}

.story-modal__body p {
    margin: 0 0 0.85rem;
    font-size: clamp(0.9rem, 1.8vw, 1.35rem);
    letter-spacing: 0.02em;
}

.story-modal__footer {
    margin-top: 24px;
}

.story-modal__close {
    padding: var(--story-close-padding-y) var(--story-close-padding-x);
    font-size: var(--story-close-font-size);
    border-radius: 9999px;
    border: none;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    color: #f8fafc;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(59, 130, 246, 0.35);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.story-modal__close:hover,
.story-modal__close:focus-visible {
    transform: translateY(-1px);
    box-shadow: 0 14px 30px rgba(37, 99, 235, 0.45);
}

@media (max-width: 640px) {
    .story-modal {
        padding: 24px 20px;
        border-radius: 20px;
    }

    .story-modal__header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .story-modal__footer-actions {
        flex-wrap: wrap;
        justify-content: flex-start;
        gap: 16px;
    }

    .story-modal__body {
        max-height: calc(70vh - 80px);
    }
}

.buttons {
    display: none;
}

@media screen and (max-width: 1368px) and (orientation: landscape) {
    canvas {
        display: block;
        margin: 0 auto;
        width: 40vw;
        height: 30vw;
    }
  
    .buttons {
        display: grid;
        grid-template-columns: 5vw 5vw 5vw 5vw 60vw 5vw 5vw 5vw 5vw;
        grid-template-rows: auto 5vw 5vw 5vw auto;
    }

    .UpButton {
        grid-row: 2;
        grid-column: 3;
        background-image: url('./button_images/UpButton.png');
        background-size: cover;
        background-repeat: no-repeat;
        background-position: center;
    }
   
    .LeftButton {
        grid-row: 3;
        grid-column: 2;
        background-image: url('./button_images/LeftButton.png');
        background-size: cover;
        background-repeat: no-repeat;
        background-position: center;
    }
   
    .RightButton {
        grid-row: 3;
        grid-column: 4;
        background-image: url('./button_images/RightButton.png');
        background-size: cover;
        background-repeat: no-repeat;
        background-position: center;
    }
   
    .DownButton {
        grid-row: 4;
        grid-column: 3;
        background-image: url('./button_images/DownButton.png');
        background-size: cover;
        background-repeat: no-repeat;
        background-position: center;
    }
   
    .AButton {
        grid-row: 3;
        grid-column: 6;
        background-image: url('./button_images/AButton.png');
        background-size: cover;
        background-repeat: no-repeat;
        background-position: center;
    }
   
    .SButton {
        grid-row: 4;
        grid-column: 7;
        background-image: url('./button_images/SButton.png');
        background-size: cover;
        background-repeat: no-repeat;
        background-position: center;
    }
  
}

@media screen and (max-width: 1024px) and (orientation: portrait) {
    canvas {
        display: block;
        margin: 0 auto;
        width: 100vw;
        height: 75vw;
        image-rendering: pixelated;
    }
 
    .buttons {
        display: grid;
        grid-template-columns: 12.5vw 12.5vw 12.5vw 12.5vw 12.5vw 12.5vw 12.5vw 12.5vw;
        grid-template-rows: auto 12.5vw 12.5vw 12.5vw auto;
    }

    .UpButton {
        grid-row: 2;
        grid-column: 3;
        background-image: url('./button_images/UpButton.png');
        background-size: cover;
        background-repeat: no-repeat;
        background-position: center;
    }

    .LeftButton {
        grid-row: 3;
        grid-column: 2;
        background-image: url('./button_images/LeftButton.png');
        background-size: cover;
        background-repeat: no-repeat;
        background-position: center;
    }

    .RightButton {
        grid-row: 3;
        grid-column: 4;
        background-image: url('./button_images/RightButton.png');
        background-size: cover;
        background-repeat: no-repeat;
        background-position: center;
    }

    .DownButton {
        grid-row: 4;
        grid-column: 3;
        background-image: url('./button_images/DownButton.png');
        background-size: cover;
        background-repeat: no-repeat;
        background-position: center;
    }

    .AButton {
        grid-row: 3;
        grid-column: 6;
        background-image: url('./button_images/AButton.png');
        background-size: cover;
        background-repeat: no-repeat;
        background-position: center;
    }

    .SButton {
        grid-row: 4;
        grid-column: 7;
        background-image: url('./button_images/SButton.png');
        background-size: cover;
        background-repeat: no-repeat;
        background-position: center;
    }

 }