body,
html {
    margin: 0;
    padding: 0;
    min-height: 100%;
    background-color: #f5f5f7;
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    overflow-x: hidden;
}

:root {
    --desk-overlap: 90px;
    --editor-min-height: 470px;
    --rip-y-offset: 80px;
}

#app-container {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    height: 100dvh;
}

#game-container {
    flex: 0 0 clamp(220px, 32vh, 380px);
    height: clamp(220px, 32vh, 380px);
    background: transparent;
    position: relative;
    z-index: 3;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Typewriter Section */
#editor-container {
    flex: 1 1 auto;
    min-height: var(--editor-min-height);
    background: #557064;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    /* Keeps typewriter wrapper against game section */
    padding-bottom: 0px;
    position: relative;
    z-index: 2;
    overflow: visible;
}

#desk-bg {
    position: absolute;
    top: calc(-1 * var(--desk-overlap));
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(100% + var(--desk-overlap));
    z-index: 1;
    pointer-events: none;
    background-image: url("assets/desk.png");
    background-repeat: repeat-x;
    background-position: left bottom;
    background-size: auto 100%;
    image-rendering: pixelated;
}

#rip-overlay {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 300px;
    width: auto;
    z-index: 2;
    transform: translateY(var(--rip-y-offset));
    pointer-events: none;
    image-rendering: pixelated;
}

#typewriter-wrapper {
    position: relative;
    width: min(900px, 96vw);
    max-width: 100%;
    /* Adjust based on your image width */
    padding-top: 150px;
    /* Creates space for the paper inside the wrapper */
    z-index: 2;
}

#save-confirm-overlay,
#game-over-overlay,
#game-win-overlay {
    position: absolute;
    inset: 0;
    z-index: 4;
    display: none;
    align-items: center;
    justify-content: center;
    padding-bottom: 140px;
    box-sizing: border-box;
}

#save-confirm-overlay.is-visible,
#game-over-overlay.is-visible,
#game-win-overlay.is-visible {
    display: flex;
}

#save-confirm-box,
#game-over-box,
#game-win-box {
    width: min(420px, calc(100% - 32px));
    min-height: 150px;
    background-color: #e0e0e0;
    border: 4px solid #000;
    box-shadow: 4px 4px 0 #000;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 26px;
    text-align: center;
    padding: 16px 20px;
    box-sizing: border-box;
}

#save-confirm-box::before,
#game-over-box::before,
#game-win-box::before {
    content: "";
    position: absolute;
    inset: -4px;
    pointer-events: none;
    border: 2px solid #000;
    clip-path: polygon(
        0 8px,
        2px 8px,
        2px 4px,
        4px 4px,
        4px 2px,
        8px 2px,
        8px 0,
        calc(100% - 8px) 0,
        calc(100% - 8px) 2px,
        calc(100% - 4px) 2px,
        calc(100% - 4px) 4px,
        calc(100% - 2px) 4px,
        calc(100% - 2px) 8px,
        100% 8px,
        100% calc(100% - 8px),
        calc(100% - 2px) calc(100% - 8px),
        calc(100% - 2px) calc(100% - 4px),
        calc(100% - 4px) calc(100% - 4px),
        calc(100% - 4px) calc(100% - 2px),
        calc(100% - 8px) calc(100% - 2px),
        calc(100% - 8px) 100%,
        8px 100%,
        8px calc(100% - 2px),
        4px calc(100% - 2px),
        4px calc(100% - 4px),
        2px calc(100% - 4px),
        2px calc(100% - 8px),
        0 calc(100% - 8px)
    );
}

#saveConfirmPrompt {
    margin: 0;
    font-family: "Courier New", Courier, monospace;
    font-size: 22px;
    font-weight: bold;
    color: #000;
}

#gameOverPrompt {
    margin: 0;
    font-family: "Courier New", Courier, monospace;
    font-size: 20px;
    font-weight: bold;
    color: #000;
}

#gameWinPrompt {
    margin: 0;
    font-family: "Courier New", Courier, monospace;
    font-size: 20px;
    font-weight: bold;
    color: #000;
}

#save-confirm-actions {
    display: flex;
    gap: 14px;
    justify-content: center;
}

#typewriter-img {
    width: 100%;
    display: block;
    position: relative;
    z-index: 2;
    /* Sits in front of the paper */
    image-rendering: pixelated;
}

#paper-area {
    position: absolute;
    top: 0;
    /* Now positioned inside the wrapper's top padding */
    left: 26%;
    right: 19%;
    height: 150px;
    /* How far down the paper goes */
    background: #ffffff;
    z-index: 1;
    /* Sits behind typewriter body */
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    padding: 30px;
    border: 1px solid #ddd;
}

#writer {
    width: 100%;
    height: 100%;
    border: none;
    outline: none;
    resize: none;
    overflow: auto;
    -ms-overflow-style: none;
    scrollbar-width: none;
    background: transparent;
    font-family: "Courier New", Courier, monospace;
    font-size: 19px;
    line-height: 1.6;
    color: #222;
}

#writer::-webkit-scrollbar {
    display: none;
}

#control-bar {
    position: absolute;
    left: 50%;
    bottom: 16px;
    transform: translateX(-50%);
    width: min(calc(100vw - 24px), 1500px);
    box-sizing: border-box;
    display: flex;
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 10px;
    overflow: visible;
    z-index: 5;
}

.control-btn {
    background-color: #e0e0e0;
    color: #000;
    font-family: "Courier New", Courier, monospace;
    font-size: 16px;
    font-weight: bold;
    padding: 10px 16px;
    border: 4px solid #000;
    box-shadow: 4px 4px 0 #000;
    cursor: pointer;
    text-transform: uppercase;
    image-rendering: pixelated;
    position: relative;
}

.control-btn::before {
    content: "";
    position: absolute;
    inset: -4px;
    pointer-events: none;
    border: 2px solid #000;
    clip-path: polygon(
        0 8px,
        2px 8px,
        2px 4px,
        4px 4px,
        4px 2px,
        8px 2px,
        8px 0,
        calc(100% - 8px) 0,
        calc(100% - 8px) 2px,
        calc(100% - 4px) 2px,
        calc(100% - 4px) 4px,
        calc(100% - 2px) 4px,
        calc(100% - 2px) 8px,
        100% 8px,
        100% calc(100% - 8px),
        calc(100% - 2px) calc(100% - 8px),
        calc(100% - 2px) calc(100% - 4px),
        calc(100% - 4px) calc(100% - 4px),
        calc(100% - 4px) calc(100% - 2px),
        calc(100% - 8px) calc(100% - 2px),
        calc(100% - 8px) 100%,
        8px 100%,
        8px calc(100% - 2px),
        4px calc(100% - 2px),
        4px calc(100% - 4px),
        2px calc(100% - 4px),
        2px calc(100% - 8px),
        0 calc(100% - 8px)
    );
}

.control-btn:hover {
    background-color: #d0d0d0;
}

.control-btn.is-selected {
    background-color: #ffd166;
    color: #000;
}

.control-btn.is-selected:hover {
    background-color: #f7c247;
}

.control-btn:active {
    transform: translate(4px, 4px);
    box-shadow: 0 0 0 #000;
}

.control-gap-after-brand {
    margin-right: 36px;
}

.control-gap-after-speed {
    margin-right: 36px;
}

.control-gap-after-time {
    margin-right: 36px;
}

@media (max-width: 1024px) {
    :root {
        --editor-min-height: 390px;
    }

    #game-container {
        flex: 1 1 auto;
        min-height: 120px;
        max-height: calc(100vh - var(--editor-min-height));
        height: auto;
    }

    #typewriter-wrapper {
        width: 100%;
        padding-top: 120px;
    }

    #paper-area {
        left: 16%;
        right: 18%;
        height: 130px;
        padding: 18px;
    }

    #writer {
        font-size: 16px;
        line-height: 1.4;
    }

    #save-confirm-box,
    #game-over-box {
        width: min(360px, calc(100% - 20px));
        min-height: 130px;
        padding: 14px 16px;
        gap: 16px;
    }

    #save-confirm-overlay,
    #game-over-overlay,
    #game-win-overlay {
        padding-bottom: 96px;
    }

    #saveConfirmPrompt,
    #gameOverPrompt,
    #gameWinPrompt {
        font-size: 17px;
    }

    #control-bar {
        bottom: 8px;
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
    }

    .control-btn {
        font-size: 13px;
        padding: 8px 10px;
        border-width: 3px;
        box-shadow: 3px 3px 0 #000;
    }

    .control-gap-after-brand,
    .control-gap-after-speed,
    .control-gap-after-time {
        margin-right: 20px;
    }
}
