* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;

    font-family: "Trebuchet MS", "Segoe UI", sans-serif;

    background: #f5f5f5;

    display: flex;
    justify-content: center;

}


.game {
    width: min(100%, 1100px);
    text-align: center;
}


.game-header h1 {
    margin-bottom: 5px;
}


#progress {
    font-size: 1.1rem;
    font-weight: bold;
}


.screen {
    margin-top: 25px;
}


.hidden {
    display: none;
}


/* -------------------------
   MYSTERY BOARD
------------------------- */

#mystery-board {
    position: relative;

    width: min(70vw, 70vh, 600px);
    aspect-ratio: 1 / 1;

    margin: 0 auto;

    overflow: hidden;
}


#mystery-image {
    position: absolute;

    inset: 0;

    width: 100%;
    height: 100%;

    object-fit: cover;
}


#tile-grid {
    position: absolute;

    inset: 0;

    display: grid;

    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
}


.tile {
    border: 3px solid white;

    background: #6d6d6d;

    color: white;

    font-size: 2rem;
    font-weight: bold;

    cursor: pointer;

    transition:
        transform 0.15s ease,
        opacity 0.4s ease;
}


.tile:hover {
    transform: scale(0.96);
}


.tile.revealed {
    opacity: 0;
    pointer-events: none;
}

.tile.revealing {
    animation: revealTile 2.2s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    pointer-events: none;
    z-index: 10;
}

@keyframes revealTile {

    0% {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }

    15% {
        opacity: 1;
        transform: scale(1.08) rotate(0deg);
    }

    100% {
        opacity: 0;
        transform: scale(0.6) rotate(360deg);
    }
}

/* -------------------------
   QUESTIONS
------------------------- */

#question-text {
    font-size: 2rem;
    margin-bottom: 35px;
}

.question-highlight {
    background-color: #fff3a6;
    padding: 0.1em 0.2em;
    border-radius: 0.25em;
    font-weight: bold;
}

#answers {
    display: grid;

    grid-template-columns:
        repeat(2, minmax(220px, 1fr));

    gap: 20px;

    max-width: 850px;

    margin: 0 auto;
}


.answer-button,
.main-button {
    padding: 20px;

    border: none;
    border-radius: 14px;

    font-size: 1.3rem;
    font-weight: bold;

    cursor: pointer;
}


.answer-button {
    background: white;

    border: 3px solid #333;
}


.answer-button:hover {
    transform: scale(1.02);
}


.main-button {
    margin-top: 25px;

    padding-left: 40px;
    padding-right: 40px;
}


/* -------------------------
   SMALLER SCREENS
------------------------- */

@media (max-width: 650px) {

    body {
        padding: 15px;
    }

    #answers {
        grid-template-columns: 1fr;
    }

    #mystery-board {
        width: 90vw;
    }

}

/* -------------------------
   FEEDBACK POP-UP
------------------------- */

.modal {
    position: fixed;

    inset: 0;

    background: rgba(0, 0, 0, 0.45);

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 20px;

    z-index: 1000;
}


.modal-card {
    width: min(90%, 450px);

    background: white;

    border-radius: 24px;

    padding: 40px;

    text-align: center;

    box-shadow:
        0 15px 40px rgba(0, 0, 0, 0.25);
}


.modal-card h2 {
    margin-top: 0;

    font-size: 2.2rem;
}


.modal-card p {
    font-size: 1.3rem;
}


/* Keep this AFTER .modal */
.modal.hidden {
    display: none !important;
}

.modal:not(.hidden) {
    display: flex;
}

/* HOME SCREEN */

.home-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: space-between;

    background: linear-gradient(
        to bottom,
        #85d477,
        #fff7c7
    );
}

.home-content {
    text-align: center;
    position: relative;
    width: 60%;
    margin: 0 auto;
    top: 40px;
}

.home-milo {
    width: clamp(140px, 20vw, 300px);
    position: absolute;
    left: 15%;
    top: 15%;
    pointer-events: none;
}

.home-poppy {
    width: clamp(140px, 20vw, 300px);
    position: absolute;
    right: 17%;
    top: 60%;
    pointer-events: none;
}

.brand-title {
    font-size: 24px;
    margin: 0;
}

.game-title {
    font-size: clamp(32px, 4vw, 48px);
    margin: 10px 0;
}

.game-subtitle {
    font-size: 32px;
    margin: 0;
}

.start-game-button {
    font-size: 36px;
    padding: 35px 55px;
    font-weight: bold;
    background-color: #dfff00;
    font-family: "Dreaming Outloud";
    clip-path: polygon(
    50% 0%,
    58% 22%,
    72% 5%,
    74% 28%,
    96% 18%,
    82% 40%,
    100% 50%,
    82% 60%,
    96% 82%,
    74% 72%,
    72% 95%,
    58% 78%,
    50% 100%,
    42% 78%,
    28% 95%,
    26% 72%,
    4% 82%,
    18% 60%,
    0% 50%,
    18% 40%,
    4% 18%,
    26% 28%,
    28% 5%,
    42% 22%
);
position: relative;
z-index: 10;
}

.home-screen.hidden {
    display: none;
}

/* BOARD SCREEN */

#board-screen {
    min-height: 100vh;
    background: linear-gradient(
        to bottom,
        #85d477, 
        #fff7c7
    );
    position: relative;
    margin-top: 0;
    overflow: hidden;
}

/* responsive on tablet screens about 650px*/

@media (max-width: 650px) {

    .home-content {
        width: 90%;
    }

}

/* responsive on mobile screens about 400px

@media (max-width: 400px) {

    .home-milo {
        display: none;
    }

    .home-poppy {
        display: none;
    }
} */


/* lives*/
.heart {
    position: relative;
    display: inline-block;
    color: black;
}

.heart-fill {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(0.78);
    color: #ff0000; 
}

.timer-warning {
    font-weight: 900;
    font-size: 1.4em;
    animation: timer-pulse 0.5s ease-in-out infinite alternate;
}

@keyframes timer-pulse {
    from {
        transform: scale(1);
    }

    to {
        transform: scale(1.15);
    }
}

/* ---------------------------------
   KEYBOARD FOCUS
--------------------------------- */

button:focus-visible,
input:focus-visible,
summary:focus-visible {
    outline: 4px solid #000000;
    outline-offset: 4px;
}
.start-game-button:focus-visible {
    outline: none;

    box-shadow:
        inset 0 0 0 6px #000000;
}

/* ---------------------------------
   SHORT TABLET SCREENS
--------------------------------- */

@media (max-height: 800px) {

    .home-content {
        top: 0;
    }

    .brand-title {
        font-size: 18px;
    }

    .game-title {
        font-size: clamp(28px, 4vw, 38px);
        margin: 5px 0;
    }

    .game-subtitle {
        font-size: 26px;
    }

    .instructions {
        margin-top: 8px;
        margin-bottom: 8px;
    }

    .instructions-content p {
        margin: 5px 0;
    }

    .timer-settings {
        margin-top: 8px;
        margin-bottom: 8px;
    }

    .timer-settings p {
        margin: 5px 0;
    }

    .start-game-button {
        font-size: 28px;
        padding: 25px 42px;
    }
}

/* ---------------------------------
   HALLOWEEN HOME DECORATIONS
--------------------------------- */

.home-screen {
    position: relative;
}

.theme-decorations {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.theme-decoration {
    position: absolute;
    font-size: clamp(1.4rem, 3vw, 2.5rem);
    opacity: 0.75;
    user-select: none;
}

.decoration-1 {
    top: 8%;
    left: 8%;
}

.decoration-2 {
    top: 12%;
    right: 10%;
}

.decoration-3 {
    bottom: 12%;
    left: 12%;
}

.decoration-4 {
    bottom: 10%;
    right: 10%;
}

/* =====================================
   MILO & POPPY - WORKINGS AREA
===================================== */

.workings-area {
    width: min(90%, 680px);
    margin: 20px auto;
    padding: 15px;
    background: #f5faff;
    border: 3px solid #377bd1;
    border-radius: 18px;
    box-sizing: border-box;
}

.workings-area summary {
    cursor: pointer;
    font-size: 1.2rem;
    font-weight: bold;
    color: #174a9c;
    text-align: center;
    padding: 10px;
}

.workings-content {
    padding: 15px 0;
    text-align: center;
}

.workings-content p {
    margin-bottom: 15px;
}

.workings-toolbar {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 15px;
}

.workings-toolbar button {
    padding: 10px 15px;
    border: 2px solid #377bd1;
    border-radius: 10px;
    background: white;
    cursor: pointer;
    font-weight: bold;
}

.workings-toolbar button:hover {
    background: #deebff;
}

#workings-canvas {
    display: block;
    width: 100%;
    height: auto;
    background: white;
    border: 2px solid #aac8e9;
    border-radius: 10px;
    cursor: crosshair;
    touch-action: none;
    box-sizing: border-box;
}

/* ============================================
   MILO & POPPY - QUESTION / WORKINGS LAYOUT
============================================ */

/* Question stays above the working area */
#question-screen {
    width: 100%;
    max-width: 1300px;
    margin: 0 auto;
    box-sizing: border-box;
}

/* Keep the question visible */
#question-text {
    text-align: center;
    margin: 15px auto 25px;
    max-width: 1100px;
}

/* Default answers: 2 columns */
#answers {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
    width: 100%;
}

/* When workings are open, use a two-column layout */
#question-screen:has(.workings-area[open]) {
    display: grid;
    grid-template-columns: minmax(220px, 40%) minmax(0, 60%);
    column-gap: 20px;
    align-items: start;
}

/* Question spans both columns */
#question-screen:has(.workings-area[open]) #question-text {
    grid-column: 1 / -1;
}

/* Four answers in one vertical column */
#question-screen:has(.workings-area[open]) #answers {
    grid-column: 1;
    grid-row: 2;

    grid-template-columns: 1fr;
    gap: 12px;
}

/* Workings area on the right */
#question-screen:has(.workings-area[open]) .workings-area {
    grid-column: 2;
    grid-row: 2;

    width: 100%;
    max-width: none;
    max-height: 65vh;
    margin: 0;
    overflow-y: auto;
}

/* Keep buttons manageable */
#question-screen:has(.workings-area[open]) .answer-button {
    width: 100%;
    min-height: 65px;
    padding: 12px;
}

/* Smaller screens */
@media (max-width: 750px) {

    #question-screen:has(.workings-area[open]) {
        grid-template-columns: 1fr;
    }

    #question-screen:has(.workings-area[open]) #question-text,
    #question-screen:has(.workings-area[open]) #answers,
    #question-screen:has(.workings-area[open]) .workings-area {
        grid-column: 1;
        grid-row: auto;
    }

    #question-screen:has(.workings-area[open]) #answers {
        grid-template-columns: 1fr;
    }

    #question-screen:has(.workings-area[open]) .workings-area {
        max-height: 50vh;
    }
}

#question-screen.hidden {
    display: none !important;
}

/* ==========================================
   MILO & POPPY — HOME SCREEN IMPROVEMENTS
========================================== */

/* Keep the home screen within the available width */
#home-screen {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    box-sizing: border-box;
}

/* Keep navigation buttons above decorative images */
#home-collection-button,
#collection-button {
    position: relative;
    z-index: 20;
}

/* Keep decorative character images behind controls */
#home-screen img {
    z-index: 1;
}

/* Ensure buttons remain accessible */
#home-screen button,
#home-screen a {
    position: relative;
    z-index: 20;
}

/* Home screen viewport adjustments */

#home-screen {
    margin-top: 0;
    min-height: 100vh;
    min-height: 100dvh;
}

/* Keep controls accessible on smaller screens */

@media (max-width: 650px) {

    #home-screen .home-milo,
    #home-screen .home-poppy {
        display: none;
    }

    #home-screen .home-content {
        width: 94%;
        top: 0;
    }
}

/* Collection navigation: centred beneath LET'S PLAY, clear of Poppy. */
#home-collection-button {
    display: block;
    width: fit-content;
    max-width: 100%;
    margin: 12px auto 0;
    padding: 10px 16px;
    border: 2px solid #174a9c;
    border-radius: 12px;
    background: #fff;
    color: #174a9c;
    font: 700 1rem Arial, sans-serif;
    text-decoration: none;
    position: relative;
    z-index: 30;
}
#home-collection-button.hidden,
#collection-button.hidden {
    display: none !important;
}
#collection-button:not(.hidden) {
    display: inline-block;
    background: #fff;
    border: 2px solid #174a9c;
    color: #174a9c;
    text-decoration: none;
    margin-top: 12px;
}

/* MILO & POPPY — RESPONSIVE MOBILE LAYOUT

/* Mobile characters hidden on desktop */
.mobile-home-characters {
    display: none;
}

/* ==========================================
   MILO & POPPY — MOBILE LAYOUT
   Home Screen + Mystery Board
========================================== */

@media (max-width: 650px) {

    /* GENERAL MOBILE SETTINGS */

    body {
        margin: 0;
        padding: 0;
    }

    .game {
        width: 100%;
        max-width: 100%;
    }

    #home-screen,
    #board-screen {
        width: 100%;
        height: 100dvh;
        min-height: 0;
        box-sizing: border-box;

        background: linear-gradient(
            to bottom,
            #85d477,
            #fff7c7
        );
    }

    #home-screen.hidden,
    #board-screen.hidden {
        display: none !important;
    }


    /* ======================================
       HOME SCREEN
    ====================================== */

    #home-screen {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;

        padding: 8px 12px;
        margin: 0;

        overflow-y: auto;
    }

    #home-screen .home-content {
        position: relative;

        width: 100%;
        max-width: 500px;

        margin: auto;
        padding: 0;

        top: 0;
        text-align: center;
    }


    /* ======================================
       CHARACTER POSITIONING
    ====================================== */

    /* Hide original desktop characters */

    #home-screen > .home-milo,
    #home-screen > .home-poppy {
        display: none !important;
    }

    /* Display mobile characters */

    #home-screen .mobile-home-characters {
        display: flex !important;

        flex-direction: row;
        justify-content: space-evenly;
        align-items: center;

        width: 100%;
        gap: 12px;

        margin: 5px auto 8px;
    }

    /* Reset desktop character positioning */

    #home-screen .mobile-home-characters img {
        display: block !important;

        position: static !important;
        inset: auto !important;

        width: auto;
        max-width: 44%;
        max-height: 20dvh;

        height: auto;
        object-fit: contain;

        transform: none;
    }


    /* ======================================
       HEADINGS
    ====================================== */

    #home-screen .brand-title {
        font-size: clamp(14px, 2.4dvh, 19px);
        line-height: 1.15;

        margin: 0 0 5px;
    }

    #home-screen .game-title {
        font-size: clamp(23px, 4.2dvh, 35px);
        line-height: 1.1;

        margin: 5px 0;
    }

    #home-screen .game-subtitle {
        font-size: clamp(20px, 3.5dvh, 28px);
        line-height: 1.1;

        margin: 5px 0;
    }


    /* ======================================
       INSTRUCTIONS
    ====================================== */

    #home-screen .instructions {
        margin: 5px auto;
        padding: 0;
    }

    #home-screen .instructions summary {
        font-size: clamp(16px, 2.6dvh, 21px);
        cursor: pointer;
    }

    #home-screen .instructions-content {
        margin-top: 4px;
    }

    #home-screen .instructions-content p {
        font-size: clamp(14px, 2.2dvh, 18px);
        line-height: 1.15;

        margin: 4px 0;
    }


    /* ======================================
       TIMER SETTINGS
    ====================================== */

    #home-screen .timer-settings {
        margin: 5px auto;
        font-size: clamp(15px, 2.5dvh, 20px);
    }

    #home-screen .timer-settings p {
        margin: 4px 0;
    }


    /* ======================================
       LET'S PLAY BUTTON
    ====================================== */

    #home-screen .start-game-button {
        font-size: clamp(20px, 3.3dvh, 27px);

        padding: 17px 30px;
        margin: 6px auto;

        max-width: 100%;
    }


    /* ======================================
       EXPANDED INSTRUCTIONS
       Automatically compact the layout
    ====================================== */

    #home-screen:has(.instructions[open]) {
        padding: 5px 10px;
    }

    #home-screen:has(.instructions[open])
    .mobile-home-characters {
        margin: 2px auto 4px;
    }

    #home-screen:has(.instructions[open])
    .mobile-home-characters img {
        max-height: 14dvh;
    }

    #home-screen:has(.instructions[open])
    .brand-title {
        font-size: clamp(12px, 2dvh, 16px);
        margin-bottom: 2px;
    }

    #home-screen:has(.instructions[open])
    .game-title {
        font-size: clamp(21px, 3.5dvh, 29px);
        margin: 2px 0;
    }

    #home-screen:has(.instructions[open])
    .game-subtitle {
        font-size: clamp(18px, 3dvh, 25px);
        margin: 2px 0;
    }

    #home-screen:has(.instructions[open])
    .instructions {
        margin: 2px auto;
    }

    #home-screen:has(.instructions[open])
    .instructions-content p {
        font-size: clamp(13px, 2dvh, 16px);
        line-height: 1.1;
        margin: 3px 0;
    }

    #home-screen:has(.instructions[open])
    .timer-settings {
        margin: 3px auto;
    }

    #home-screen:has(.instructions[open])
    .start-game-button {
        font-size: clamp(19px, 3dvh, 25px);
        padding: 13px 25px;
        margin: 4px auto;
    }


    /* ======================================
       MYSTERY BOARD SCREEN
    ====================================== */

    #board-screen {
        display: flex;
        flex-direction: column;

        justify-content: center;
        align-items: center;

        padding: 10px;
        margin: 0;

        overflow-y: auto;
    }

    #board-screen h1,
    #board-screen h2 {
        margin: 5px auto 8px;
        line-height: 1.15;
    }

    #board-screen #progress {
        margin: 6px auto;
    }

    #mystery-board {
        width: min(88vw, 48dvh, 450px);
        max-width: 100%;

        aspect-ratio: 1 / 1;

        margin: 12px auto;
        flex-shrink: 0;
    }
}


/* ==========================================
   EXTRA COMPACT — SHORT PHONES
========================================== */

@media (max-width: 650px) and (max-height: 700px) {

    #home-screen .mobile-home-characters img {
    display: block !important;
    position: static !important;

    width: 42%;
    height: 16dvh;

    max-width: none;
    max-height: none;

    object-fit: contain;
    transform: none;
}

    #home-screen:has(.instructions[open])
    .mobile-home-characters img {
        height: 12dvh;
        max-height: none;
    }

    #home-screen .brand-title {
        font-size: 14px;
    }

    #home-screen .game-title {
        font-size: 24px;
    }

    #home-screen .game-subtitle {
        font-size: 21px;
    }

    #home-screen:has(.instructions[open])
    .instructions-content p {
        font-size: 13px;
    }

    #home-screen:has(.instructions[open])
    .start-game-button {
        font-size: 20px;
        padding: 10px 24px;
    }

    #mystery-board {
        width: min(92vw, 55dvh, 450px);
    }
}

