/* =========================================================
   CANVAS RESPONSIVE
   ========================================================= */
@media only screen and (max-width: 720px) {
    canvas {
        width: 100%;
        border: none;
    }
}

@media only screen and (max-height: 480px) {
    canvas {
        height: 100dvh;
        border: none;
    }
}


/* =========================================================
   MENU RESPONSIVE (HEADER, START OVERLAY, BUTTONS)
   ========================================================= */
@media (max-width: 500px) {
    header h2 {
        font-size: 36px;
    }

    header img {
        width: 60px;
    }

    #startoverlay {
        width: 200px;
        height: 400px;
    }

    #startoverlay button {
        width: 140px;
    }
}

@media (max-width: 380px) {
    header h2 {
        font-size: 30px;
    }
}


/* =========================================================
   CONTROL SCREEN RESPONSIVE
   ========================================================= */
@media (max-width: 720px) {
    #control {
        height: 40%;
    }

    .control-headline {
        font-size: 40px;
    }

    .control-button-style img {
        width: 19px;
    }

    button {
        font-size: 14px;
        padding: 8px 30px;
    }

    .control-container span {
        font-size: 26px;
    }

    .controls span {
        padding: 10px;
    }
}


/* =========================================================
   STORY SCREEN RESPONSIVE
   ========================================================= */
@media (max-width: 800px) {
    #story {
        width: 70%;
        height: 40%;
    }
}

@media (max-width: 680px) {
    #story {
        width: 70%;
        height: 50%;
    }
}

@media (max-width: 500px) {
    #story {
        width: 80%;
        height: 55%;
    }

    .story-headline {
        font-size: 20px;
    }

    .fullscreen-button {
        right: 8px;
        top: 170px;
    }

    .sound-button {
        right: 8px;
        top: 110px;
    }
}

@media (max-width: 380px) {
    #story {
        width: 90%;
        height: 46%;
    }

    .menu-button button {
        width: 120px;
        height: 40px;
        font-size: 14px;
        padding: 0;
    }

    .background-story p {
        font-size: 12px;
    }
}


/* =========================================================
   IMPRESSUM RESPONSIVE
   ========================================================= */
@media (max-width: 670px) {
    #impressum p,
    #impressum a {
        font-size: 16px;
    }

    #impressum {
        height: 42%;
    }
}

@media (max-width: 520px) {
    #impressum p,
    #impressum a {
        font-size: 12px;
    }

    #impressum {
        height: 37%;
    }

    .story-headline h2 {
        font-size: 24px;
    }
}

@media (max-width: 380px) {
    #impressum a {
        font-size: 10px;
    }
}


/* =========================================================
   MOBILE / TABLET LANDSCAPE: MENU + GAME
   ========================================================= */
@media screen and (max-width: 1100px) and (orientation: landscape) {

    /* Base font size */
    body {
        font-size: 16px;
    }

    /* HEADER & FOOTER (same height) */
    header,
    footer {
        height: 70px !important;
        min-height: 70px !important;
        display: flex;
        align-items: center;
        padding-inline: 8px;
        box-sizing: border-box;
    }

    header img {
        width: 60px;
        margin-left: 8px;
        margin-right: 8px;
    }

    header h2 {
        font-size: clamp(20px, 3vw, 26px);
    }

    .footer-content {
        height: 100%;
        min-height: 0;
        display: flex;
        justify-content: center;
        align-items: center;
        background-color: #B7694D;
        margin: 0;
        padding: 0;
    }

    footer img {
        width: 40px;
        height: 40px;
        margin: 0 8px 0 0;
    }

    .signature {
        font-size: 12px;
        line-height: 1.2;
        margin: 0;
        padding: 0;
    }

    .under-signature {
        margin-bottom: 3px;
        margin-top: 0;
    }

    /* CANVAS CONTAINER BETWEEN HEADER & FOOTER */
    #canvas-box {
        flex: 1 1 auto;
        height: calc(100vh - 140px);     /* 70px header + 70px footer */
        max-height: calc(100vh - 140px);
        padding: 0;
        margin: 0;
    }

    canvas {
        width: 100%;
        height: auto;
        max-width: 100%;
        border-width: 6px;
    }

    /* START OVERLAY */
    #startoverlay {
        width: 80%;
        max-width: 500px;
        height: auto;
        box-sizing: border-box;
        padding: 32px 16px 28px;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        display: flex;
        flex-direction: column;
        align-items: center;
        max-height: calc(100vh - 160px);
        min-height: 50vh;
    }

    #startoverlay .menu-main {
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 12px;
    }

    #startoverlay .menu-main button {
        width: 80%;
        max-width: 260px;
        font-size: clamp(14px, 2.4vw, 18px);
        padding: 10px 16px;
        margin: 0;
    }

    #startoverlay .impressum-button {
        align-self: center;
        margin-top: 10px;
        background: none;
        border: none;
        text-decoration: underline;
        font-size: clamp(12px, 2vw, 16px);
        padding: 0;
    }

    #game-over-overlay,
    win-over-overlay {
        height: 70%;
    }

    /* GENERIC OVERLAYS (CONTROL / STORY / IMPRESSUM) */
    #control,
    #story,
    #impressum {
        width: 90%;
        height: auto;
        max-height: 80vh;
        overflow-y: auto;
        font-size: 14px;
    }

    .story-headline,
    .control-headline {
        font-size: 24px;
        height: 56px;
        padding: 8px 0;
    }

    .background-story {
        padding: 12px 16px;
    }

    /* SOUND / FULLSCREEN BUTTONS */
    .sound-button,
    .fullscreen-button {
        right: 8px;
    }

    .sound-button {
        top: 80px;
    }

    .fullscreen-button {
        top: 130px;
    }

    .sound-button img,
    .fullscreen-button img {
        width: 30px;
        padding: 4px;
    }

    /* GAME RUNNING: FULLSCREEN CANVAS, NO SCROLLBAR */
    body.game-running {
        display: block;
        min-height: 0;
        margin: 0;
        overflow: hidden;
    }

    body.game-running header,
    body.game-running footer {
        display: none !important;
    }

    body.game-running main {
        margin: 0;
        padding: 0;
        height: 100dvh;
    }

    body.game-running #canvas-box {
        height: 100dvh;
        max-height: 100dvh;
        padding: 0;
        margin: 0;
    }

    body.game-running canvas {
        width: 100vw;
        height: 100dvh;
        max-width: none;
        max-height: none;
        border-width: 0;
        border-radius: 0;
        display: block;
    }

    body.game-running #startoverlay,
    body.game-running #control,
    body.game-running #story,
    body.game-running #impressum {
        display: none !important;
    }
}


/* =========================================================
   VERY FLAT LANDSCAPE SCREENS: COMPACT MAIN MENU
   ========================================================= */
@media screen and (max-width: 912px) and (max-height: 550px) and (orientation: landscape) {

    #startoverlay {
        padding: 16px 8px 12px;
    }

    #startoverlay .menu-main {
        gap: 8px;
    }

    #startoverlay .menu-main button {
        width: 70%;
        max-width: 220px;
        font-size: 14px;
        padding: 6px 10px;
    }

    #startoverlay .impressum-button {
        font-size: 12px;
        margin-top: 4px;
    }
}


/* =========================================================
   SMALL LANDSCAPE PHONES: SUBMENU FINE-TUNING
   (e.g. iPhone SE, small Android devices)
   ========================================================= */
@media screen and (max-width: 932px) and (max-height: 450px) and (orientation: landscape) {

    /* Shared settings for all submenus */
    #control,
    #story,
    #impressum {
        width: 60%;
        max-height: 70vh;
        font-size: 12px;
        min-width: 300px;
        min-height: 0;
    }

    .story-headline,
    .control-headline {
        font-size: 16px;
        height: 24px;
        padding: 4px 0;

        >h2 {
            font-size: 20px;
        }
    }

    /* CONTROLS SCREEN LAYOUT */
    .control-container {
        gap: 6px;
    }

    .controls {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        row-gap: 4px;
    }

    .controls .control-button-style {
        flex: 1 1 45%;
        max-width: 48%;
    }

    .control-button-style button {
        height: 20px;
        width: 132px;
        margin: 2px;
        font-size: 16px;
    }

    .control-button-style img {
        width: 16px;
    }

    .control-container span {
        font-size: 16px;
        padding: 0;
    }

    .menu-button {
        padding: 0;
        text-align: center;
    }

    .menu-button button {
        width: 140px;
        font-size: 16px;
        height: 20px;
        white-space: nowrap;
        text-align: center;
        margin-bottom: 8px;
        display: inline-flex;
        justify-content: center;
        align-items: center;
    }

    /* STORY SCREEN TEXT AREA */
    .background-story {
        padding: 8px 10px;
        max-height: calc(70vh - 90px);
        overflow-y: auto;
    }

    .background-story p {
        font-size: 16px;
        line-height: 1.3;
    }

    /* IMPRESSUM SCROLL AREA */
    #impressum p,
    #impressum a {
        margin-top: 0;
        margin-bottom: 0;
        font-size: 16px;
        line-height: 1.3;
    }

    #impressum {
        max-height: 80vh;
        overflow-y: auto;
    }
}
