:root {
    --paper: #fdfcf6;
    --paper-warm: #fff9e9;
    --ink: #383838;
    --muted-ink: #4d4028;
    --line: #8f7f61;
    --focus-ring: 3px solid #2b2b2b;
}

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

img {
    pointer-events: none;
}

/* PWA specific styles */
@media all and (display-mode: standalone) {
    html {
        height: 100%;
        overflow-y: auto;
        overscroll-behavior-y: none;
    }

    body {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
        overscroll-behavior-y: none;
    }
}

body {
    background-image: url('/assets/ui/bg.webp');
    background-repeat: repeat;
    background-size: auto;
    background-color: var(--paper);
    margin: 0;
    padding: 0;
    font-family: "Cutive Mono", monospace;
    min-height: 100vh;
    cursor: url('/assets/cursor.webp') 0 0, auto;
}

a {
    cursor: url('/assets/pointer.webp') 0 0, pointer;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    background: radial-gradient(circle at center, rgba(255, 255, 255, 0.1), rgba(0, 0, 0, 0) 70%);
    opacity: 0.2;
    pointer-events: none;
}

body::after {
    content: "";
    position: fixed;
    inset: 0;
    background-image: url('/assets/ui/bg.webp');
    mix-blend-mode: multiply;
    opacity: 0.15;
    pointer-events: none;
}

#app {
    width: 100%;
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

.error-container,
.about-container {
    max-width: 800px;
    margin: 50px auto;
    text-align: center;
    padding: 20px;
}

#episode-container {
    position: relative;
    width: 100%;
    height: 100%;
    background-color: #FFFAE6;
    /* Match loading screen background */
    cursor: url('/assets/cursor.webp') 0 0, auto;
}

#episode-container canvas {
    cursor: url('/assets/cursor.webp') 0 0, auto;
}

#episode-back-button {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 2001;
    background: none;
    border: none;
    padding: 0;
    cursor: url('/assets/pointer.webp') 0 0, pointer;
    transition: transform 0.2s ease;
    display: block;
    line-height: 0;
    text-decoration: none;
}

#episode-back-button img {
    width: 40px;
    height: 40px;
    object-fit: contain;
}

#episode-back-button:hover {
    transform: scale(1.1);
}

#episode-back-button:active {
    transform: scale(0.95);
}

.intro-text-overlay {
    position: absolute;
    top: -60px;
    left: 72px;
    width: 400px;
    aspect-ratio: 1;
    transform: translateY(0);
    opacity: 0;
    pointer-events: none;
    z-index: 1500;
    container-type: inline-size;
    transition: opacity 800ms cubic-bezier(0.34, 1.56, 0.64, 1), transform 800ms ease;
    will-change: transform, opacity;
}

.intro-text-overlay.is-visible {
    opacity: 1;
    pointer-events: auto;
}

.intro-text-overlay.is-exiting {
    transform: translateY(-200px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 800ms ease, transform 800ms cubic-bezier(0.4, 0, 1, 1);
}

.intro-text-bg {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
}

.intro-text-line {
    position: absolute;
    color: var(--ink);
    text-align: center;
    white-space: pre-line;
    line-height: 1.2;
    text-rendering: geometricPrecision;
}

.intro-text-line-1 {
    left: 50%;
    top: 39%;
    transform: translate(-50%, -50%);
    font-family: 'Delicious Handrawn', cursive;
    font-size: 6.8cqw;
    width: 62%;
}

.intro-text-line-2 {
    left: 52%;
    top: 52%;
    transform: translate(-50%, -50%) rotate(-1deg);
    font-family: 'Cutive Mono', cursive;
    font-size: 4.8cqw;
    line-height: 1;
}

.intro-text-close-button {
    position: absolute;
    top: 25%;
    right: 9%;
    width: clamp(32px, 10.5cqw, 40px);
    height: clamp(32px, 10.5cqw, 40px);
    border: none;
    background: transparent;
    padding: 0;
    cursor: url('/assets/pointer.webp') 0 0, pointer;
    transition: transform 0.2s ease;
}

.intro-text-close-button img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.intro-text-close-button:hover {
    transform: scale(1.1);
}

.intro-text-close-button:active {
    transform: scale(0.95);
}

.episode-hint-button {
    position: absolute;
    top: 20px;
    left: 72px;
    z-index: 2001;
    width: 40px;
    height: 40px;
    border: none;
    background: none;
    padding: 0;
    cursor: url('/assets/pointer.webp') 0 0, pointer;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.episode-hint-button.is-visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.episode-hint-button img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.episode-hint-button:hover {
    transform: scale(1.1);
}

.episode-hint-button:active {
    transform: scale(0.95);
}

.interior-menu-toggle-button {
    position: absolute;
    right: max(14px, env(safe-area-inset-right));
    top: max(14px, env(safe-area-inset-top));
    z-index: 100;
    border: none;
    background: transparent;
    padding: 0;
    cursor: url('/assets/pointer.webp') 0 0, pointer;
    transition: transform 0.2s ease;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.interior-menu-toggle-button img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.interior-menu-toggle-button:hover {
    transform: scale(1.1);
}

.interior-menu-toggle-button:active {
    transform: scale(0.95);
}

.back-link {
    display: block;
    position: fixed;
    top: 20px;
    left: 20px;
    width: 70px;
    height: auto;
    cursor: url('/assets/pointer.webp') 0 0, pointer;
    transition: transform 0.2s ease;
    z-index: 1000;
}

.back-button {
    display: block;
    width: 100%;
    height: auto;
}

.back-link:hover {
    transform: scale(1.1);
}

#rotation-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

.rotation-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    color: white;
    font-size: 24px;
    text-align: center;
    padding: 20px;
    background-color: rgba(0, 0, 0, 0.6);
    border-radius: 10px;
    max-width: 80%;
}

.rotation-next-button {
    display: inline-block;
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    border: 10px solid transparent;
    border-image: url('/assets/ui/border.svg') 10 10 10 10 fill stretch stretch;
    color: #202020;
    font-family: 'Cutive Mono', monospace;
    font-size: 16px;
    padding: 0 10px;
    white-space: nowrap;
    text-decoration: none;
    cursor: url('/assets/pointer.webp') 0 0, pointer;
    transition: transform 0.2s ease;
}

.rotation-next-button:hover {
    transform: scale(1.05);
}

.rotation-next-button:active {
    transform: scale(0.98);
}

.content {
    min-height: calc(100vh - 120px);
    box-sizing: border-box;
    padding: 80px 20px;
    max-width: 1200px;
    margin: 0 auto;
}

.legal-page .about-container,
.legal-page .content {
    width: 100%;
    min-width: 0;
    max-width: none;
    min-height: 0;
    margin: 0;
    padding: clamp(72px, 9vw, 112px) clamp(12px, 3vw, 36px) 24px;
}

.legal-paper {
    position: relative;
    isolation: isolate;
    width: 100%;
    min-width: 0;
    max-width: 1120px;
    margin: 0 auto;
    padding: clamp(64px, 7vw, 112px) clamp(24px, 8vw, 112px) clamp(56px, 8vw, 112px);
    background:
        radial-gradient(circle at 16% 12%, rgba(255, 255, 255, 0.55) 0 1px, transparent 1.5px),
        radial-gradient(circle at 78% 64%, rgba(112, 86, 45, 0.07) 0 1px, transparent 1.5px),
        repeating-linear-gradient(97deg, rgba(255, 255, 255, 0.16) 0 1px, transparent 1px 8px),
        linear-gradient(105deg, rgba(255, 253, 243, 0.97), rgba(255, 255, 255, 0.86) 48%, rgba(250, 246, 229, 0.94));
    background-size: 17px 19px, 23px 27px, 100% 100%, 100% 100%;
    border: 0;
    border-radius: 1.8rem 0.3rem 2.4rem 0.8rem / 0.4rem 1.8rem 0.9rem 1.6rem;
    box-shadow: 0 10px 24px rgba(58, 46, 24, 0.08);
    color: var(--ink);
    text-align: left;
}

.legal-paper::before,
.legal-paper::after {
    position: absolute;
    content: "";
    pointer-events: none;
}

.legal-paper::before {
    inset: 8px 7px 9px 8px;
    z-index: -1;
    transform: rotate(-0.12deg);
}

.legal-paper::after {
    inset: 3px 4px 5px 3px;
    z-index: -1;
    transform: rotate(0.16deg);
}

.legal-paper>* {
    position: relative;
    z-index: 1;
}

.legal-paper h1,
.legal-paper h2,
.legal-paper h3,
.legal-paper p,
.legal-paper ul,
.legal-paper a {
    max-width: 78ch;
    overflow-wrap: anywhere;
}

.legal-paper h1 {
    margin: 0 0 clamp(1.75rem, 4vw, 3rem);
    font-size: clamp(2rem, 4vw, 3rem);
    line-height: 1.05;
}

.legal-paper h2 {
    margin: clamp(2rem, 5vw, 3rem) 0 1rem;
    font-size: clamp(1.25rem, 2.5vw, 1.8rem);
    line-height: 1.2;
}

.legal-paper h3 {
    margin: 2.25rem 0 1rem;
    font-size: clamp(1.2rem, 2.2vw, 1.5rem);
}

.legal-paper p,
.legal-paper li {
    line-height: 1.65;
    overflow-wrap: anywhere;
    hyphens: auto;
}

.legal-paper p {
    margin: 0 0 1rem;
}

.legal-paper ul {
    padding-left: 1.4rem;
}

.legal-paper li+li {
    margin-top: 0.75rem;
}

.legal-page .back-link {
    top: max(16px, env(safe-area-inset-top));
    left: max(16px, env(safe-area-inset-left));
}

.legal-page .footer {
    min-height: 80px;
    height: auto;
    padding: 12px 20px max(20px, env(safe-area-inset-bottom));
    flex-wrap: wrap;
}

.legal-page #me-image {
    position: absolute;
    top: 24px;
    right: clamp(24px, 6vw, 72px);
    z-index: 2;
    width: clamp(76px, 13vw, 160px);
    height: auto;
}

.legal-page.imprint-page #me-image {
    transform: rotate(8deg);
}

.about-section {
    display: flow-root;
}

.concept-gallery {
    width: min(34%, 340px);
    margin: 0 0 1.5rem 2rem;
    float: right;
    clear: right;
}

.concept-gallery img {
    display: block;
    width: 100%;
    height: auto;
}

.concept-gallery figcaption {
    margin-top: 0.4rem;
    font-size: 0.9em;
    line-height: 1.35;
    text-align: center;
}

h1 {
    font-family: 'Delicious Handrawn', cursive;
    font-size: 2.5rem;
    margin-bottom: 2rem;
}

h2 {
    font-size: 1.8rem;
    margin: 1.5rem 0;
}

h3 {
    font-family: 'Delicious Handrawn', cursive;
}

p {
    line-height: 1.6;
    margin-bottom: 1rem;
}

.footer {
    height: 80px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 30px;
    bottom: 0;
    width: 100%;
}

.footer .nav-link {
    margin: 0;
    background-color: transparent;
    color: var(--ink);
    font-family: 'Delicious Handrawn', cursive;
    font-size: 24px;
    padding: 8px 15px;
    transition: all 0.3s ease;
    text-decoration: none;
    border: none;
    cursor: url('/assets/pointer.webp') 0 0, pointer;
}

.footer .nav-link:hover {
    background-color: transparent;
    color: var(--ink);
    transform: scale(1.2);
}

.footer .secondary-button {
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    color: #4d4028;
    border: 10px solid transparent;
    border-image: url('/assets/ui/border_white.svg') 10 10 10 10 fill stretch stretch;
    padding: 0px 10px;
    white-space: nowrap;
}

.footer .secondary-button:hover {
    background: transparent;
    color: #4d4028;
    transform: scale(1.05);
}

.progress-reset-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-y: auto;
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 2100;
}

.progress-reset-modal.is-visible {
    opacity: 1;
    pointer-events: auto;
}

.progress-reset-dialog {
    position: relative;
    flex: 0 0 auto;
    border: 10px solid transparent;
    border-image: url('/assets/ui/border.svg') 10 10 10 10 fill stretch stretch;
    padding: 26px 30px;
    max-width: 420px;
    width: min(90vw, 420px);
    text-align: center;
}

.progress-reset-warning {
    position: absolute;
    top: -28px;
    left: -28px;
    width: 59px;
    height: 59px;
    object-fit: contain;
    pointer-events: none;
    z-index: 1;
}

.progress-reset-dialog h3 {
    font-size: 30px;
    margin: 0 0 10px;
    color: var(--ink);
}

.progress-reset-dialog p {
    margin: 0 0 20px;
    color: var(--muted-ink);
    font-size: 18px;
}

.progress-reset-actions {
    display: flex;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
}

.progress-reset-actions button {
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    border: 10px solid transparent;
    border-image: url('/assets/ui/border_primary.svg') 10 10 10 10 fill stretch stretch;
    font-family: 'Cutive Mono', monospace;
    font-size: 16px;
    padding: 0 10px;
    white-space: nowrap;
    cursor: url('/assets/pointer.webp') 0 0, pointer;
    transition: transform 0.2s ease;
}

.progress-reset-cancel {
    color: #fff9e9;
}

.progress-reset-confirm {
    color: #4d4028;
    border-image: url('/assets/ui/border_white.svg') 10 10 10 10 fill stretch stretch !important;
}

.progress-reset-actions button:hover {
    transform: scale(1.05);
}

.progress-reset-actions button:active {
    transform: scale(0.98);
}

.info-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 2100;
}

.info-modal.is-visible {
    opacity: 1;
    pointer-events: auto;
}

.info-modal-dialog {
    position: relative;
    border: 10px solid transparent;
    border-image: url('/assets/ui/border.svg') 10 10 10 10 fill stretch stretch;
    padding: 24px 26px 22px;
    max-width: 520px;
    width: min(92vw, 520px);
    text-align: center;
}

.info-modal-icon {
    width: clamp(70px, 20vw, 120px);
    height: auto;
    margin-bottom: 10px;
}

.info-modal-dialog h3 {
    font-size: clamp(24px, 4.2vw, 34px);
    margin: 0 0 8px;
    color: var(--ink);
}

.info-modal-dialog p {
    margin: 0 0 18px;
    color: var(--muted-ink);
    font-size: clamp(16px, 3.2vw, 20px);
}

.info-modal-close {
    position: absolute;
    top: -25px;
    right: -18px;
    width: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    padding: 0;
    cursor: url('/assets/pointer.webp') 0 0, pointer;
    transition: transform 0.2s ease;
    border-radius: 50%;
}

.info-modal-close img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.info-modal-close:hover {
    transform: scale(1.05);
}

.info-modal-close:active {
    transform: scale(0.98);
}

#level-selector {
    text-align: center;
    padding: 20px;
}

.level-grid {
    position: relative;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 60px;
    max-width: 1000px;
    margin: 0 auto;
    padding: 40px;
    z-index: 3;
}

.level-card {
    position: relative;
    background: white;
    text-decoration: none;
    color: var(--ink);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    padding: 15px 15px 60px 15px;
    width: 100%;
    box-sizing: border-box;
}

/* Fixed rotations for cards */
.level-card:nth-child(1) {
    transform: rotate(-12deg);
}

.level-card:nth-child(2) {
    transform: rotate(8deg);
}

.level-card:nth-child(3) {
    transform: rotate(2deg);
}

.level-card:hover {
    transform: scale(1.02) rotate(0deg);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
    z-index: 1;
}

.level-card img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    margin-bottom: 10px;
    border: none;
}

.wide-screen-only-icon {
    display: none;
}

.level-card-placeholder {
    display: grid;
    place-items: center;
    width: 100%;
    aspect-ratio: 1;
    margin-bottom: 10px;
    background: #b7d77b;
    color: #345321;
    font-family: 'Cutive Mono', monospace;
    font-size: 1.1rem;
    letter-spacing: 0.12em;
}

.level-card h2 {
    position: absolute;
    bottom: 20px;
    left: 0;
    right: 0;
    margin: 0;
    padding: 0 20px;
    font-family: 'Delicious Handrawn', cursive;
    font-size: 2rem;
    color: var(--ink);
}

/* Random text alignments */
.level-card:nth-child(1) h2 {
    text-align: left;
    transform: rotate(-3deg);
}

.level-card:nth-child(2) h2 {
    text-align: right;
    transform: rotate(2deg);
}

.level-card:nth-child(3) h2 {
    text-align: center;
    transform: rotate(-1deg);
}

.level-card:first-child::before {
    content: "";
    position: absolute;
    top: -25px;
    left: -25px;
    width: 70px;
    height: 70px;
    background-image: url('/assets/ui/go.webp');
    background-size: contain;
    background-repeat: no-repeat;
    z-index: 1;
}

.level-card:first-child::after {
    content: "";
    position: absolute;
    bottom: 70px;
    left: -170px;
    width: 300px;
    height: 60px;
    background: url('/assets/ui/startHere.webp') center / contain no-repeat;
    transform: rotate(-90deg);
    z-index: -1;
    pointer-events: none;
}

@media (max-width: 768px) {
    #episode-back-button {
        top: 10px;
        left: 10px;
    }

    #episode-back-button img {
        width: 32px;
        height: 32px;
    }

    .episode-hint-button {
        top: 10px;
        left: 52px;
        width: 32px;
        height: 32px;
    }

    .content {
        padding: 60px 15px;
    }

    h1 {
        font-size: 2rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    .footer {
        height: 60px;
        gap: 15px;
    }

    .footer .nav-link {
        font-size: 16px;
        padding: 6px 12px;
    }

    .legal-paper {
        padding: 58px clamp(20px, 6vw, 48px) 56px;
    }

    .legal-paper h1 {
        margin-bottom: 2rem;
    }

    .legal-page #me-image {
        top: 16px;
        right: 20px;
        width: clamp(72px, 22vw, 120px);
    }

    .legal-page.imprint-page #me-image {
        transform: none;
    }

    .concept-gallery {
        width: min(42%, 220px);
        margin: 0 0 1.5rem 1.25rem;
        float: right;
        clear: right;
    }

    .progress-reset-dialog {
        padding: 20px 22px;
    }

    .progress-reset-dialog h3 {
        font-size: 24px;
    }

    .progress-reset-dialog p {
        font-size: 16px;
    }

    .back-button {
        width: 40px;
        height: auto;
        top: 15px;
        left: 15px;
    }

    .level-grid {
        grid-template-columns: 1fr;
        gap: 40px;
        padding: 20px;
        max-width: 400px;
        margin-top: -70px;
    }

    .level-card {
        padding: 10px 10px 50px 10px;
    }

    .level-card .wide-screen-only-icon {
        display: block;
        position: absolute;
        top: 5px;
        left: -14px;
        width: clamp(56px, 18vw, 90px);
        height: auto;
        aspect-ratio: auto;
        object-fit: contain;
        margin: 0;
        z-index: 2;
    }

    .level-card h2 {
        padding: 0 15px;
        font-size: 1.6rem;
        bottom: 15px;
    }

    .level-card:first-child::before {
        width: 30px;
        height: 30px;
        top: 20px;
        left: 20px;
    }

    /* Adjust rotation angles for better mobile display */
    .level-card:nth-child(1) {
        transform: rotate(-8deg);
    }

    .level-card:nth-child(2) {
        transform: rotate(5deg);
    }

    .intro-text-overlay {
        top: -10px;
        left: 52px;
    }

}

@media (max-width: 768px) {
    .intro-text-overlay {
        top: 8px;
        left: 50%;
        width: min(86vw, 520px);
        transform: translateX(-50%);
    }

    .intro-text-overlay.is-exiting {
        transform: translate(-50%, -200px);
    }

    .intro-text p {
        padding: 0 30px;
    }
}

@media (max-width: 480px) {
    .content {
        padding: 50px 10px;
    }

    h1 {
        font-size: 1.8rem;
    }

    h2 {
        font-size: 1.3rem;
    }

    .legal-page .about-container,
    .legal-page .content {
        padding-right: 20px;
        padding-left: 20px;
    }

    .legal-paper {
        padding: 52px 18px 42px;
        border-radius: 1.5rem 0.25rem 2rem 0.65rem / 0.35rem 1.5rem 0.75rem 1.35rem;
    }

    .legal-paper h1 {
        font-size: clamp(1.85rem, 10vw, 2.4rem);
    }

    .legal-paper h2 {
        font-size: 1.3rem;
    }

    .concept-gallery {
        width: min(42%, 180px);
    }

    .concept-gallery figure {
        max-width: 360px;
        margin-right: auto;
        margin-left: auto;
    }

    .info-modal-close {
        top: -29px;
        right: -2px;
    }
}

@media (orientation: portrait) {
    #rotation-overlay {
        display: flex;
        opacity: 1;
        pointer-events: auto;
    }

    #rotation-overlay.portrait-allowed {
        display: none;
        opacity: 0;
        pointer-events: none;
    }
}

:where(a, button, [tabindex]):focus-visible {
    outline: var(--focus-ring);
    outline-offset: 4px;
}