
/* ===========================
   GLOBAL
=========================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    max-width: 100%;
}

body {
    font-family: "Fredoka", sans-serif;

    background-image: url("../assets/background.jpg");
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;

    color: #6D5848;

    overflow-x: hidden;
    overflow-y: hidden;
}

@media screen and (max-width: 700px) {
    body {
        background-image: url("../assets/background-mobile.jpg");
        background-attachment: scroll;
    }
}

button {
    font-family: inherit;
    cursor: pointer;
}


/* ===========================
   MAIN LAYOUT
=========================== */

.game {
    width: 100%;
    height: calc(100vh - 110px);

    padding: 20px;
    gap: 20px;

    display: grid;
    grid-template-columns: 260px minmax(0, 1fr) 380px;
}


/* ===========================
   LEFT SIDEBAR
=========================== */

.sidebar {
    background: rgba(255, 248, 242, .88);

    border: 4px solid #DCEEF8;
    border-radius: 28px;

    padding: 24px;

    display: flex;
    flex-direction: column;
    gap: 12px;

    backdrop-filter: blur(12px);

    box-shadow: 0 8px 24px rgba(110, 140, 170, .18);

    min-width: 0;
}

.sidebar h1 {
    margin-bottom: 15px;

    text-align: center;

    font-size: 2rem;

    color: #6D5848;

    letter-spacing: 1px;
}

.category {
    background: #FFFCF8;

    color: #6D5848;

    border: 2px solid #DCEEF8;

    border-radius: 18px;

    height: 54px;

    font-size: 1rem;
    font-weight: 600;

    transition: .25s;

    flex-shrink: 0;
}

.category:hover {
    background: #F8D8C8;
    border-color: #F6C98E;

    transform: translateY(-2px);
}

.category.active {
    background: #CFE7F3;
    border-color: #A7CFE3;

    color: #5D4A3A;
}


/* ===========================
   CHARACTER
=========================== */

.preview {
    min-width: 0;
    min-height: 0;

    display: flex;

    justify-content: center;
    align-items: center;

    background: rgba(255, 252, 248, 0.075);

    border-radius: 32px;

    backdrop-filter: blur(.3px);

    box-shadow: 0 10px 25px rgba(110, 140, 170, .15);

    overflow: hidden;
}

#character {
    position: relative;

    width: 450px;
    height: 700px;

    max-width: 90%;
    max-height: 90%;
}

#character img {
    position: absolute;

    width: 100%;

    left: 0;
    top: 0;

    image-rendering: auto;
}


/* ===========================
   RIGHT PANEL
=========================== */

.items {
    min-width: 0;
    min-height: 0;

    background: rgba(255, 248, 242, .88);

    border: 4px solid #DCEEF8;
    border-radius: 28px;

    padding: 24px;

    backdrop-filter: blur(12px);

    box-shadow: 0 8px 24px rgba(110, 140, 170, .18);

    overflow-y: auto;
}

.items h2 {
    margin-bottom: 25px;
}

#itemGrid {
    display: grid;

    grid-template-columns: repeat(2, minmax(0, 1fr));

    gap: 15px;
}

.item {
    min-width: 0;

    background: #FFFCF8;

    border: 2px solid #E9DDD1;

    border-radius: 18px;

    overflow: hidden;

    display: flex;
    flex-direction: column;

    transition: .2s;
}

.item img {
    width: 100%;
    height: 120px;

    object-fit: contain;

    background: #F6FBFE;
}

.item span {
    padding: 12px;

    color: #6D5848;

    font-size: .95rem;
    font-weight: 600;

    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.item:hover {
    transform: translateY(-3px);

    border-color: #F6C98E;

    box-shadow: 0 8px 18px rgba(110, 140, 170, .15);
}

.item.selected {
    border: 3px solid #F6C98E;

    background: #FFF6EA;
}


/* ===========================
   BOTTOM TOOLBAR
=========================== */

.toolbar {
    height: 74px;

    margin: 0 20px 20px;

    background: rgba(255, 248, 242, .9);

    border: 4px solid #DCEEF8;

    border-radius: 28px;

    display: flex;

    justify-content: center;
    align-items: center;

    gap: 20px;

    backdrop-filter: blur(10px);

    box-shadow: 0 8px 24px rgba(110, 140, 170, .18);

    flex-wrap: wrap;
}

.toolbar button {
    border: none;

    padding: 14px 24px;

    border-radius: 18px;

    font-size: 1rem;
    font-weight: 600;

    background: #CFE7F3;

    color: #5D4A3A;

    transition: .25s;
}

.toolbar button:hover {
    background: #F8D8C8;

    transform: translateY(-2px);
}

#revealBtn {
    background: #F6C98E;

    color: #5D4A3A;
}


/* ===========================
   RESULTS SCREEN
=========================== */

#resultsScreen {
    position: fixed;

    inset: 0;

    background: rgba(0, 0, 0, .65);

    display: flex;

    justify-content: center;
    align-items: center;

    padding: 20px;

    z-index: 999;

    overflow-y: auto;
}

.hidden {
    display: none !important;
}

.resultsCard {
    width: min(1200px, 95vw);
    height: min(700px, 90vh);

    background: #FFF8F2;

    border: 4px solid #DCEEF8;

    border-radius: 28px;

    display: grid;

    grid-template-columns: 450px minmax(0, 1fr);

    overflow: hidden;

    flex-shrink: 0;
}

.resultsCharacter {
    display: flex;

    justify-content: center;
    align-items: center;

    background: #F6FBFE;

    min-width: 0;
    min-height: 0;
}

.resultsInfo {
    padding: 50px;

    display: flex;

    flex-direction: column;

    min-width: 0;

    overflow-y: auto;
}

.resultsInfo h2 {
    color: #666;
}

.resultsInfo h1 {
    margin: 10px 0 20px;

    font-size: 3rem;
}

.resultsInfo p {
    line-height: 1.8;
}


/* ===========================
   STATS
=========================== */

.stats {
    margin-top: 40px;

    display: flex;

    flex-direction: column;

    gap: 15px;
}

.stat {
    background: #F6FBFE;

    border: 2px solid #DCEEF8;

    padding: 15px;

    border-radius: 16px;
}

.statRow {
    display: grid;

    grid-template-columns: 120px minmax(0, 1fr) 40px;

    gap: 15px;

    align-items: center;

    margin-bottom: 15px;
}

.statBar {
    width: 100%;

    height: 14px;

    background: #EAF5FA;

    border-radius: 100px;

    overflow: hidden;
}

.statFill {
    height: 100%;

    background: #A9D6EA;

    border-radius: 100px;
}

.reasonList {
    margin-top: 40px;
}

.reasonList h3 {
    margin-bottom: 15px;
}

.reasonList p {
    margin-bottom: 8px;
}


/* ===========================
   RESULT CHARACTER
=========================== */

#resultCharacter {
    position: relative;

    width: 350px;
    height: 545px;

    max-width: 90%;
    max-height: 90%;
}

#resultCharacter img {
    position: absolute;

    width: 100%;
    height: auto;

    left: 0;
    top: 0;

    image-rendering: auto;
}


/* ===========================
   DOWNLOAD / CLOSE BUTTONS
=========================== */

#downloadBtn {
    margin-top: auto;

    align-self: flex-start;

    border: none;

    padding: 16px 24px;

    border-radius: 18px;

    background: #F6C98E;

    color: #5D4A3A;

    font-size: 1rem;
    font-weight: 600;
}

#closeResultsBtn {
    margin-top: 15px;

    border: none;

    padding: 15px 24px;

    border-radius: 18px;

    background: #F6C98E;

    color: #5D4A3A;

    font-size: 1rem;
    font-weight: 600;
}

#closeResultsBtn:hover {
    background: #cfcfcf;
}


/* ===========================
   TABLET / SMALL DESKTOP
=========================== */

@media (max-width: 1400px) {

    .game {
        grid-template-columns: 220px minmax(0, 1fr) 320px;

        height: calc(100vh - 90px);

        padding: 15px;
        gap: 15px;
    }

    .sidebar {
        padding: 18px;
        border-radius: 22px;
    }

    .sidebar h1 {
        font-size: 1.6rem;
    }

    #character {
        width: min(360px, 80%);
        height: auto;

        aspect-ratio: 450 / 700;
    }

    .items {
        padding: 18px;
        border-radius: 22px;
    }

    #itemGrid {
        gap: 10px;
    }

    .item img {
        height: 100px;
    }

    .item span {
        padding: 9px;
        font-size: .85rem;
    }

    .toolbar {
        margin: 0 15px 15px;
    }

    .resultsCard {
        width: min(1100px, 92vw);
        height: min(650px, 90vh);
    }
}


/* ===========================
   TABLET
=========================== */

@media (max-width: 1000px) {

    .game {
        grid-template-columns: 180px minmax(0, 1fr);

        grid-template-rows: minmax(0, 1fr) auto;

        height: calc(100vh - 85px);
    }

    .sidebar {
        grid-column: 1;
        grid-row: 1 / 3;

        padding: 15px;
    }

    .preview {
        grid-column: 2;
        grid-row: 1;
    }

    .items {
        grid-column: 2;
        grid-row: 2;

        max-height: 220px;
    }

    #character {
        width: min(320px, 75%);
    }

    .toolbar {
        height: auto;

        min-height: 65px;

        padding: 10px;

        gap: 10px;
    }

    .toolbar button {
        padding: 11px 18px;
    }

    .resultsCard {
        width: 90vw;
        height: 90vh;

        grid-template-columns: 40% 60%;
    }

    .resultsInfo {
        padding: 30px;
    }

    .resultsInfo h1 {
        font-size: 2.3rem;
    }

    #resultCharacter {
        width: min(280px, 90%);

        height: auto;

        aspect-ratio: 350 / 545;
    }

    .statRow {
        grid-template-columns: 90px minmax(0, 1fr) 35px;

        gap: 10px;
    }
}










/* ============================================================
   MOBILE RESPONSIVENESS
   ============================================================
   Complete mobile CSS
   Latest rules are authoritative.

   Includes:
   - Mobile portrait
   - Small portrait
   - Very small portrait
   - Mobile landscape
   - Very short landscape
   - Results screen
   - Personality description layout
   ============================================================ */


/* ============================================================
   MOBILE PORTRAIT
   ============================================================ */

@media screen and (max-width: 700px) and (orientation: portrait) {

    html,
    body {
        width: 100%;
        height: 100%;
        overflow: hidden;
    }


    /* ========================================================
       MAIN GAME LAYOUT
       ======================================================== */

    .game {
        width: 100%;
        height: calc(100dvh - 58px);

        min-width: 0;
        min-height: 0;

        padding: 6px;

        display: grid;

        grid-template-columns: 1fr;

        grid-template-rows:
            auto
            minmax(0, 1fr)
            minmax(145px, 27vh);

        gap: 6px;
    }


    /* ========================================================
       CATEGORY PANEL
       ======================================================== */

    .sidebar {
        grid-column: 1;
        grid-row: 1;

        width: 100%;
        height: auto;

        min-width: 0;
        min-height: 0;

        padding: 6px;

        display: flex;
        flex-direction: row;

        align-items: center;

        gap: 5px;

        overflow-x: auto;
        overflow-y: hidden;

        scrollbar-width: none;
    }

    .sidebar::-webkit-scrollbar {
        display: none;
    }

    .sidebar h1 {
        display: none;
    }

    .category {
        flex: 0 0 auto;

        width: auto;
        min-width: 82px;

        height: 35px;
        min-height: 35px;

        margin: 0;
        padding: 0 8px;

        border-radius: 9px;

        font-size: .65rem;

        line-height: 1;

        white-space: nowrap;
    }


    /* ========================================================
       MAIN CHARACTER / PREVIEW
       ======================================================== */

    .preview {
        grid-column: 1;
        grid-row: 2;

        width: 100%;
        height: 100%;

        min-width: 0;
        min-height: 0;

        padding: 3px;

        display: flex;

        justify-content: center;
        align-items: center;

        overflow: hidden;
    }

    #character {
        position: relative;

        width: auto;

        height: min(100%, 62vh);

        aspect-ratio: 450 / 700;

        max-width: 85vw;
        max-height: 100%;
    }


    /* ========================================================
       ITEMS PANEL
       ======================================================== */

    .items {
        grid-column: 1;
        grid-row: 3;

        width: 100%;
        height: 100%;

        min-width: 0;
        min-height: 0;

        padding: 7px;

        overflow-x: hidden;
        overflow-y: auto;
    }

    .items h2 {
        margin: 0 0 6px;

        font-size: .9rem;

        line-height: 1;
    }

    #itemGrid {
        width: 100%;

        display: grid;

        grid-template-columns:
            repeat(4, minmax(0, 1fr));

        gap: 5px;
    }

    .item {
        min-width: 0;
    }

    .item img {
        width: 100%;

        height: clamp(45px, 8vh, 62px);

        object-fit: contain;
    }

    .item span {
        padding: 3px 2px;

        font-size:
            clamp(.48rem, 1.8vw, .62rem);

        line-height: 1;
    }


    /* ========================================================
       TOOLBAR
       ======================================================== */

    .toolbar {
        left: 6px;
        right: 6px;
        bottom: 6px;

        width: auto;

        height: 46px;
        min-height: 46px;

        padding: 4px 6px;

        gap: 5px;
    }

    .toolbar button {
        min-width: 0;

        padding: 7px 5px;

        border-radius: 9px;

        font-size:
            clamp(.58rem, 2vw, .72rem);

        white-space: nowrap;
    }


    /* ========================================================
       RESULTS SCREEN
       ======================================================== */

    #resultsScreen {
        position: fixed;

        inset: 0;

        width: 100vw;
        height: 100dvh;

        padding: 4px;

        display: flex;

        align-items: stretch;
        justify-content: stretch;

        overflow: hidden;

        z-index: 99999;
    }


    /* ========================================================
       RESULTS CARD
       ======================================================== */

    .resultsCard {
        position: relative;

        width: 100%;
        height: 100%;

        max-width: none;
        max-height: none;

        min-width: 0;
        min-height: 0;

        display: grid;

        grid-template-columns: 1fr;

        grid-template-rows:
            34%
            minmax(0, 66%);

        overflow: hidden;

        border-radius: 18px;
    }


    /* ========================================================
       RESULT CHARACTER
       ======================================================== */

    .resultsCharacter {
        width: 100%;
        height: 100%;

        min-width: 0;
        min-height: 0;

        padding: 2px;

        display: flex;

        justify-content: center;
        align-items: center;

        overflow: hidden;
    }

    #resultCharacter {
        display: block;

        width: auto;
        height: 100%;

        max-width: 75vw;
        max-height: 100%;

        object-fit: contain;
    }


    /* ========================================================
       RESULTS INFORMATION
       ======================================================== */

    .resultsInfo {
        width: 100%;
        height: 100%;

        min-width: 0;
        min-height: 0;

        box-sizing: border-box;

        padding: 10px 16px;

        display: flex;
        flex-direction: column;

        /*
         * Prevent the children from expanding the card.
         */
        overflow: hidden;
    }


    /* --------------------------------------------------------
       H2
       -------------------------------------------------------- */

    .resultsInfo h2 {
        flex: 0 0 auto;

        width: 100%;

        min-width: 0;
        min-height: 0;

        box-sizing: border-box;

        margin: 0 0 3px;

        font-size:
            clamp(.85rem, 3.5vw, 1.25rem);

        line-height: 1.1;

        overflow: visible;
    }


    /* --------------------------------------------------------
       H1
       -------------------------------------------------------- */

    .resultsInfo h1 {
        flex: 0 0 auto;

        width: 100%;

        min-width: 0;
        min-height: 0;

        box-sizing: border-box;

        margin: 2px 0 6px;

        font-size:
            clamp(1.8rem, 8vw, 3.2rem);

        line-height: .95;

        /*
         * IMPORTANT:
         * h1 must not shrink when p needs space.
         */
        height: auto;

        overflow: visible;
    }


    /* ========================================================
       PERSONALITY DESCRIPTION
       ========================================================
       The paragraph is the ONLY flexible element.

       It receives the remaining space after h2/h1 and before
       stats/reasons/buttons.

       It does NOT use height: 100%.
       ======================================================== */

    .resultsInfo > p {
        flex: 1 1 0%;

        width: 100%;
        max-width: none;

        min-width: 0;
        min-height: 0;

        height: auto;

        box-sizing: border-box;

        margin: 0;
        padding: 0;

        display: block;

        align-self: stretch;

        text-align: left;

        white-space: normal;

        overflow-wrap: anywhere;
        word-wrap: break-word;
        word-break: normal;

        /*
         * The description owns the scrolling area.
         */
        overflow-x: hidden;
        overflow-y: auto;

        font-size:
            clamp(.75rem, 3.5vw, 1.05rem);

        line-height: 1.3;
    }


    /* ========================================================
       STATS
       ======================================================== */

    .resultsInfo .stats {
        flex: 0 0 auto;

        width: 100%;

        min-width: 0;
        min-height: 0;

        box-sizing: border-box;

        display: flex;
        flex-direction: column;

        gap: 3px;

        overflow: hidden;
    }

    .stat {
        width: 100%;

        padding: 5px 7px;

        flex-shrink: 0;
    }

    .statRow {
        width: 100%;

        display: grid;

        grid-template-columns:
            60px
            minmax(0, 1fr)
            28px;

        gap: 6px;

        align-items: center;

        font-size: .75rem;
    }

    .statBar {
        width: 100%;

        height: 7px;
    }


    /* ========================================================
       REASONS
       ======================================================== */

    .resultsInfo .reasonList {
        flex: 0 0 auto;

        width: 100%;

        min-width: 0;
        min-height: 0;

        box-sizing: border-box;

        margin-top: 4px;

        overflow: hidden;
    }

    .reasonList h3 {
        margin: 0 0 3px;

        font-size: .82rem;
    }

    .reasonList p {
        width: 100%;

        margin: 0 0 2px;

        font-size: .68rem;

        line-height: 1.15;
    }


    /* ========================================================
       RESULT BUTTONS
       ======================================================== */

    .resultsInfo #downloadBtn,
    .resultsInfo #closeResultsBtn {
        flex: 0 0 auto;

        width: 100%;

        min-width: 0;

        box-sizing: border-box;

        margin-left: 0;
        margin-right: 0;

        border-radius: 10px;

        font-size: .88rem;

        line-height: 1;
    }

    #downloadBtn {
        min-height: 40px;

        padding: 8px 12px;

        margin-top: 5px;
    }

    #closeResultsBtn {
        min-height: 40px;

        padding: 8px 12px;

        margin-top: 4px;
    }
}


/* ============================================================
   SMALL PORTRAIT — 400PX AND BELOW
   ============================================================ */

@media screen and (max-width: 400px) and (orientation: portrait) {

    .game {
        padding: 5px;

        gap: 5px;

        grid-template-rows:
            auto
            minmax(0, 1fr)
            minmax(125px, 26vh);
    }


    /* CATEGORY */

    .sidebar {
        padding: 5px;

        gap: 4px;
    }

    .category {
        min-width: 74px;

        height: 33px;
        min-height: 33px;

        font-size: .6rem;
    }


    /* ITEMS */

    .items {
        padding: 6px;
    }

    #itemGrid {
        gap: 4px;
    }

    .item img {
        height: 46px;
    }

    .item span {
        font-size: .48rem;
    }


    /* TOOLBAR */

    .toolbar {
        left: 5px;
        right: 5px;
        bottom: 5px;

        height: 43px;
        min-height: 43px;

        padding: 4px;

        gap: 4px;
    }

    .toolbar button {
        padding: 6px 3px;

        font-size: .56rem;
    }


    /* RESULTS */

    .resultsCard {
        grid-template-rows:
            30%
            minmax(0, 70%);
    }

    .resultsCharacter {
        padding: 1px;
    }

    #resultCharacter {
        height: 100%;

        max-width: 72vw;
        max-height: 100%;
    }

    .resultsInfo {
        padding: 8px 12px;
    }

    .resultsInfo h2 {
        flex: 0 0 auto;

        font-size: .78rem;

        margin: 0 0 2px;
    }

    .resultsInfo h1 {
        flex: 0 0 auto;

        font-size: 1.7rem;

        margin: 1px 0 5px;
    }

    .resultsInfo > p {
        flex: 1 1 0%;

        width: 100%;

        min-width: 0;
        min-height: 0;

        height: auto;

        overflow-x: hidden;
        overflow-y: auto;

        font-size:
            clamp(.72rem, 3.7vw, 1rem);

        line-height: 1.25;
    }

    .stats {
        gap: 2px;
    }

    .stat {
        padding: 4px 6px;
    }

    .statRow {
        grid-template-columns:
            55px
            minmax(0, 1fr)
            25px;

        gap: 5px;

        font-size: .68rem;
    }

    .statBar {
        height: 6px;
    }

    .reasonList {
        margin-top: 3px;
    }

    .reasonList h3 {
        font-size: .74rem;
    }

    .reasonList p {
        font-size: .6rem;

        line-height: 1.1;
    }

    #downloadBtn,
    #closeResultsBtn {
        min-height: 36px;

        padding: 7px 10px;

        font-size: .78rem;
    }
}


/* ============================================================
   VERY SMALL PORTRAIT — 360PX AND BELOW
   ============================================================ */

@media screen and (max-width: 360px) and (orientation: portrait) {

    .game {
        grid-template-rows:
            auto
            minmax(0, 1fr)
            minmax(115px, 25vh);
    }

    .category {
        min-width: 68px;

        height: 31px;
        min-height: 31px;

        font-size: .56rem;
    }

    #itemGrid {
        gap: 3px;
    }

    .item img {
        height: 42px;
    }

    .item span {
        font-size: .44rem;
    }

    .toolbar {
        height: 40px;
        min-height: 40px;
    }

    .toolbar button {
        font-size: .52rem;
    }


    /* RESULTS */

    .resultsCard {
        grid-template-rows:
            27%
            minmax(0, 73%);
    }

    .resultsInfo {
        padding: 7px 10px;
    }

    .resultsInfo h2 {
        flex: 0 0 auto;

        font-size: .7rem;

        margin: 0 0 2px;
    }

    .resultsInfo h1 {
        flex: 0 0 auto;

        font-size: 1.5rem;

        margin: 1px 0 4px;
    }

    .resultsInfo > p {
        flex: 1 1 0%;

        width: 100%;

        min-width: 0;
        min-height: 0;

        height: auto;

        overflow-x: hidden;
        overflow-y: auto;

        font-size: .68rem;

        line-height: 1.2;
    }

    .stat {
        padding: 3px 5px;
    }

    .statRow {
        grid-template-columns:
            48px
            minmax(0, 1fr)
            23px;

        gap: 4px;

        font-size: .61rem;
    }

    .statBar {
        height: 5px;
    }

    .reasonList h3 {
        font-size: .68rem;
    }

    .reasonList p {
        font-size: .55rem;

        line-height: 1.05;
    }

    #downloadBtn,
    #closeResultsBtn {
        min-height: 33px;

        padding: 6px 8px;

        font-size: .7rem;
    }
}


/* ============================================================
   MOBILE LANDSCAPE
   ============================================================ */

@media screen and (max-width: 900px) and (orientation: landscape) {

    html,
    body {
        width: 100%;
        height: 100%;

        overflow: hidden;
    }


    /* ========================================================
       MAIN LANDSCAPE LAYOUT
       ======================================================== */

    .game {
        width: 100%;
        height: calc(100dvh - 52px);

        min-width: 0;
        min-height: 0;

        padding: 5px;

        display: grid;

        grid-template-columns:
            clamp(60px, 14vw, 100px)
            minmax(0, 1fr)
            clamp(90px, 20vw, 145px);

        grid-template-rows:
            minmax(0, 1fr);

        gap: 5px;
    }


    /* ========================================================
       CATEGORY SIDEBAR
       ======================================================== */

    .sidebar {
        grid-column: 1;
        grid-row: 1;

        width: 100%;
        height: 100%;

        min-width: 0;
        min-height: 0;

        padding: 5px 3px;

        display: flex;
        flex-direction: column;

        gap: 4px;

        overflow-x: hidden;
        overflow-y: auto;

        scrollbar-width: none;
    }

    .sidebar::-webkit-scrollbar {
        display: none;
    }

    .sidebar h1 {
        display: none;
    }

    .category {
        width: 100%;

        height:
            clamp(29px, 9vh, 38px);

        min-height: 28px;

        margin: 0;
        padding: 0 3px;

        border-radius: 8px;

        font-size:
            clamp(.48rem, 1.5vw, .62rem);

        line-height: 1;

        overflow: hidden;

        text-overflow: ellipsis;

        white-space: nowrap;

        flex-shrink: 0;
    }


    /* ========================================================
       MAIN CHARACTER
       ======================================================== */

    .preview {
        grid-column: 2;
        grid-row: 1;

        width: 100%;
        height: 100%;

        min-width: 0;
        min-height: 0;

        padding: 2px;

        display: flex;

        justify-content: center;
        align-items: center;

        overflow: hidden;
    }

    #character {
        position: relative;

        width: auto;

        height:
            min(94%, calc(100dvh - 70px));

        aspect-ratio: 450 / 700;

        max-width: 100%;
        max-height: 94%;
    }


    /* ========================================================
       ITEMS PANEL
       ======================================================== */

    .items {
        grid-column: 3;
        grid-row: 1;

        width: 100%;
        height: 100%;

        min-width: 0;
        min-height: 0;

        padding: 5px 4px;

        overflow-x: hidden;
        overflow-y: auto;
    }

    .items h2 {
        margin: 0 0 5px;

        font-size: .7rem;

        line-height: 1;
    }

    #itemGrid {
        display: grid;

        grid-template-columns:
            repeat(2, minmax(0, 1fr));

        gap: 4px;
    }

    .item {
        min-width: 0;

        border-radius: 7px;
    }

    .item img {
        width: 100%;

        height:
            clamp(38px, 12vh, 58px);

        object-fit: contain;
    }

    .item span {
        padding: 2px;

        font-size:
            clamp(.43rem, 1.3vw, .56rem);

        line-height: 1;
    }


    /* ========================================================
       TOOLBAR
       ======================================================== */

    .toolbar {
        left: 5px;
        right: 5px;
        bottom: 5px;

        height: 42px;
        min-height: 42px;

        padding: 3px 5px;

        gap: 4px;
    }

    .toolbar button {
        min-width: 0;

        padding: 5px 6px;

        border-radius: 8px;

        font-size:
            clamp(.52rem, 1.5vw, .65rem);
    }


    /* ========================================================
       RESULTS SCREEN — LANDSCAPE
       ======================================================== */

    #resultsScreen {
        position: fixed;

        inset: 0;

        width: 100vw;
        height: 100dvh;

        padding: 4px;

        display: flex;

        align-items: stretch;
        justify-content: stretch;

        overflow: hidden;

        z-index: 99999;
    }


    /* ========================================================
       RESULTS CARD
       ======================================================== */

    .resultsCard {
        width: 100%;
        height: 100%;

        min-width: 0;
        min-height: 0;

        display: grid;

        grid-template-columns:
            38%
            minmax(0, 62%);

        grid-template-rows:
            minmax(0, 1fr);

        overflow: hidden;

        border-radius: 17px;
    }


    /* ========================================================
       RESULT CHARACTER
       ======================================================== */

    .resultsCharacter {
        width: 100%;
        height: 100%;

        min-width: 0;
        min-height: 0;

        padding: 2px;

        display: flex;

        justify-content: center;
        align-items: center;

        overflow: hidden;
    }

    #resultCharacter {
        display: block;

        width: auto;
        height: 100%;

        max-width: 100%;
        max-height: 100%;

        object-fit: contain;
    }


    /* ========================================================
       RESULTS INFORMATION — LANDSCAPE
       ======================================================== */

    .resultsInfo {
        width: 100%;
        height: 100%;

        min-width: 0;
        min-height: 0;

        box-sizing: border-box;

        padding: 8px 13px;

        display: flex;
        flex-direction: column;

        /*
         * Stretch to the complete height of the right side.
         */
        align-self: stretch;

        overflow: hidden;
    }


    /* --------------------------------------------------------
       H2 — FIXED
       -------------------------------------------------------- */

    .resultsInfo h2 {
        flex: 0 0 auto;

        width: 100%;

        min-width: 0;
        min-height: 0;

        margin: 0 0 2px;

        font-size:
            clamp(.75rem, 2.2vw, 1.15rem);

        line-height: 1.05;

        overflow: visible;
    }


    /* --------------------------------------------------------
       H1 — FIXED
       -------------------------------------------------------- */

    .resultsInfo h1 {
        flex: 0 0 auto;

        width: 100%;

        min-width: 0;
        min-height: 0;

        margin: 1px 0 4px;

        font-size:
            clamp(1.7rem, 4.5vw, 3rem);

        line-height: .9;

        height: auto;

        overflow: visible;
    }


    /* ========================================================
       PERSONALITY DESCRIPTION — LANDSCAPE
       ======================================================== */

    .resultsInfo > p {
        flex: 1 1 0%;

        width: 100%;
        max-width: none;

        min-width: 0;
        min-height: 0;

        height: auto;

        box-sizing: border-box;

        margin: 0;
        padding: 0;

        display: block;

        align-self: stretch;

        text-align: left;

        white-space: normal;

        overflow-wrap: anywhere;
        word-wrap: break-word;
        word-break: normal;

        /*
         * The paragraph occupies all white space
         * remaining between h1 and the lower content.
         */
        overflow-x: hidden;
        overflow-y: auto;

        font-size:
            clamp(.68rem, 1.9vw, .95rem);

        line-height: 1.25;
    }


    /* ========================================================
       STATS — FIXED
       ======================================================== */

    .resultsInfo .stats {
        flex: 0 0 auto;

        width: 100%;

        min-width: 0;
        min-height: 0;

        display: flex;
        flex-direction: column;

        gap: 2px;

        overflow: hidden;
    }

    .stat {
        width: 100%;

        padding: 4px 6px;

        flex-shrink: 0;
    }

    .statRow {
        width: 100%;

        display: grid;

        grid-template-columns:
            60px
            minmax(0, 1fr)
            27px;

        gap: 5px;

        align-items: center;

        font-size: .68rem;
    }

    .statBar {
        width: 100%;

        height: 6px;
    }


    /* ========================================================
       REASONS — FIXED
       ======================================================== */

    .resultsInfo .reasonList {
        flex: 0 0 auto;

        width: 100%;

        min-width: 0;

        margin-top: 3px;

        overflow: hidden;
    }

    .reasonList h3 {
        margin: 0 0 2px;

        font-size: .72rem;
    }

    .reasonList p {
        margin: 0 0 1px;

        font-size: .58rem;

        line-height: 1.05;
    }


    /* ========================================================
       BUTTONS — FIXED
       ======================================================== */

    .resultsInfo #downloadBtn,
    .resultsInfo #closeResultsBtn {
        flex: 0 0 auto;

        width: 100%;

        min-width: 0;

        margin-left: 0;
        margin-right: 0;

        box-sizing: border-box;

        border-radius: 9px;

        font-size: .75rem;

        line-height: 1;
    }

    #downloadBtn {
        min-height: 35px;

        padding: 6px 9px;

        margin-top: 4px;
    }

    #closeResultsBtn {
        min-height: 35px;

        padding: 6px 9px;

        margin-top: 3px;
    }
}


/* ============================================================
   VERY SHORT LANDSCAPE — 430PX HEIGHT AND BELOW
   ============================================================ */

@media screen and (max-height: 430px) and (orientation: landscape) {

    .game {
        height: calc(100dvh - 46px);

        padding: 3px;

        gap: 3px;

        grid-template-columns:
            clamp(52px, 13vw, 80px)
            minmax(0, 1fr)
            clamp(72px, 18vw, 110px);
    }


    /* CATEGORY */

    .sidebar {
        padding: 3px 2px;

        gap: 2px;
    }

    .category {
        height: 26px;
        min-height: 25px;

        border-radius: 6px;

        font-size: .45rem;
    }


    /* CHARACTER */

    .preview {
        padding: 2px;
    }

    #character {
        height: 92%;

        max-height: 92%;
    }


    /* ITEMS */

    .items {
        padding: 3px 2px;
    }

    .items h2 {
        margin-bottom: 3px;

        font-size: .58rem;
    }

    #itemGrid {
        gap: 2px;
    }

    .item img {
        height: 35px;
    }

    .item span {
        padding: 1px;

        font-size: .4rem;
    }


    /* TOOLBAR */

    .toolbar {
        left: 3px;
        right: 3px;
        bottom: 3px;

        height: 38px;
        min-height: 38px;

        padding: 2px 3px;

        gap: 2px;
    }

    .toolbar button {
        padding: 4px;

        border-radius: 6px;

        font-size: .48rem;
    }


    /* ========================================================
       RESULTS
       ======================================================== */

    .resultsCard {
        grid-template-columns:
            34%
            minmax(0, 66%);

        grid-template-rows:
            minmax(0, 1fr);

        border-radius: 12px;
    }


    .resultsInfo {
        width: 100%;
        height: 100%;

        min-width: 0;
        min-height: 0;

        padding: 5px 8px;

        display: flex;
        flex-direction: column;

        overflow: hidden;
    }


    .resultsInfo h2 {
        flex: 0 0 auto;

        font-size: .65rem;

        line-height: 1.05;

        margin: 0 0 1px;
    }


    .resultsInfo h1 {
        flex: 0 0 auto;

        font-size: 1.45rem;

        line-height: .9;

        margin: 1px 0 3px;
    }


    .resultsInfo > p {
        flex: 1 1 0%;

        width: 100%;

        min-width: 0;
        min-height: 0;

        height: auto;

        margin: 0;
        padding: 0;

        overflow-x: hidden;
        overflow-y: auto;

        font-size: .62rem;

        line-height: 1.15;
    }


    /* STATS */

    .stats {
        gap: 1px;
    }

    .stat {
        padding: 3px 4px;
    }

    .statRow {
        grid-template-columns:
            50px
            minmax(0, 1fr)
            22px;

        gap: 4px;

        font-size: .54rem;
    }

    .statBar {
        height: 5px;
    }


    /* REASONS */

    .reasonList {
        margin-top: 2px;
    }

    .reasonList h3 {
        font-size: .62rem;

        margin-bottom: 1px;
    }

    .reasonList p {
        font-size: .5rem;

        line-height: 1;
    }


    /* BUTTONS */

    #downloadBtn,
    #closeResultsBtn {
        min-height: 30px;

        padding: 5px 7px;

        font-size: .65rem;
    }
}


/* ============================================================
   FINAL LANDSCAPE RESULTS OVERRIDE
   ============================================================
   This is intentionally LAST so it overrides the earlier
   landscape rules without changing portrait behavior.
   ============================================================ */

@media screen and (orientation: landscape) and (max-width: 900px) {

    /* --------------------------------------------------------
       FULL RESULTS SCREEN
       -------------------------------------------------------- */

    #resultsScreen {
        position: fixed;
        inset: 0;

        width: 100vw;
        height: 100dvh;

        padding: 0;

        display: flex;
        align-items: stretch;
        justify-content: stretch;

        overflow: hidden;
        z-index: 99999;
    }

    /* --------------------------------------------------------
       RESULTS CARD — USE THE ENTIRE LANDSCAPE SCREEN
       -------------------------------------------------------- */

    .resultsCard {
        width: 100vw;
        height: 100dvh;

        min-width: 0;
        min-height: 0;

        margin: 0;
        padding: 0;

        display: grid;
        grid-template-columns:
            minmax(0, 30%)
            minmax(0, 70%);
        grid-template-rows: minmax(0, 1fr);

        overflow: hidden;
        border-radius: 0;
    }

    /* --------------------------------------------------------
       CHARACTER
       -------------------------------------------------------- */

    .resultsCharacter {
        width: 100%;
        height: 100%;

        min-width: 0;
        min-height: 0;

        display: flex;
        align-items: center;
        justify-content: center;

        overflow: hidden;
    }

    #resultCharacter {
        width: auto;
        height: 100%;

        max-width: 100%;
        max-height: 100%;

        object-fit: contain;
    }

    /* --------------------------------------------------------
       RESULTS INFO — FULL HEIGHT
       -------------------------------------------------------- */

    .resultsInfo {
        width: 100%;
        height: 100%;

        min-width: 0;
        min-height: 0;

        box-sizing: border-box;

        padding:
            clamp(12px, 2.5vh, 24px)
            clamp(16px, 3vw, 36px);

        display: flex;
        flex-direction: column;

        align-self: stretch;
        justify-self: stretch;

        overflow: hidden;
    }

    /* --------------------------------------------------------
       H2 — LARGER
       -------------------------------------------------------- */

    .resultsInfo h2 {
        flex: 0 0 auto;

        width: 100%;
        min-width: 0;
        min-height: 0;

        margin: 0 0 clamp(4px, 1vh, 9px);

        font-size:
            clamp(1.15rem, 3.2vw, 2rem);

        line-height: 1.05;
        font-weight: 700;

        overflow: visible;
    }

    /* --------------------------------------------------------
       H1 — LARGER
       -------------------------------------------------------- */

    .resultsInfo h1 {
        flex: 0 0 auto;

        width: 100%;
        min-width: 0;
        min-height: 0;

        margin: 0 0 clamp(8px, 1.5vh, 14px);

        font-size:
            clamp(2.5rem, 7vw, 5rem);

        line-height: .92;
        font-weight: 800;

        height: auto;
        overflow: visible;
    }

    /* --------------------------------------------------------
       PERSONALITY DESCRIPTION — TAKE ALL REMAINING SPACE
       -------------------------------------------------------- */

    .resultsInfo > p {
        flex: 1 1 0%;

        width: 100%;
        max-width: none;

        min-width: 0;
        min-height: 0;

        height: auto;

        box-sizing: border-box;

        margin: 0;
        padding: 0;

        display: block;
        align-self: stretch;

        text-align: left;

        font-size:
            clamp(1.05rem, 2.8vw, 1.8rem);

        line-height: 1.35;
        font-weight: 400;

        white-space: normal;
        overflow-wrap: anywhere;
        word-wrap: break-word;
        word-break: normal;

        overflow-x: hidden;
        overflow-y: auto;
    }

    /* --------------------------------------------------------
       STATS / RESULTS INFORMATION — LARGER
       -------------------------------------------------------- */

    .resultsInfo .stats {
        flex: 0 0 auto;

        width: 100%;
        min-width: 0;
        min-height: 0;

        display: flex;
        flex-direction: column;

        gap: clamp(4px, .8vh, 8px);

        overflow: visible;
    }

    .stat {
        width: 100%;
        padding: clamp(6px, 1vh, 10px) clamp(8px, 1.2vw, 14px);
        flex-shrink: 0;
        box-sizing: border-box;
    }

    .statRow {
        width: 100%;

        display: grid;
        grid-template-columns:
            clamp(70px, 7vw, 105px)
            minmax(0, 1fr)
            clamp(32px, 4vw, 52px);

        gap: clamp(6px, 1vw, 12px);

        align-items: center;

        font-size:
            clamp(.82rem, 2vw, 1.15rem);
    }

    .statBar {
        width: 100%;
        height: clamp(8px, 1.4vh, 13px);
    }

    /* --------------------------------------------------------
       REASONS / RESULT TEXT — LARGER
       -------------------------------------------------------- */

    .resultsInfo .reasonList {
        flex: 0 0 auto;

        width: 100%;
        min-width: 0;

        margin-top: clamp(5px, 1vh, 10px);

        overflow: visible;
    }

    .reasonList h3 {
        margin: 0 0 4px;

        font-size:
            clamp(1rem, 2.3vw, 1.45rem);

        line-height: 1.1;
    }

    .reasonList p {
        width: 100%;

        margin: 0 0 3px;

        font-size:
            clamp(.78rem, 1.8vw, 1.05rem);

        line-height: 1.2;
    }

    /* --------------------------------------------------------
       RESULTS INFO BUTTONS — BIGGER
       -------------------------------------------------------- */

    .resultsInfo button,
    #resultsScreen button {
        min-height: clamp(48px, 8vh, 68px);

        padding:
            clamp(10px, 1.5vh, 15px)
            clamp(14px, 2vw, 24px);

        border-radius: 12px;

        font-size:
            clamp(.95rem, 2.2vw, 1.3rem);

        font-weight: 700;
        line-height: 1;

        box-sizing: border-box;
    }

    #downloadBtn,
    #closeResultsBtn {
        min-height: clamp(48px, 8vh, 68px);

        width: 100%;

        margin-left: 0;
        margin-right: 0;
    }

    #downloadBtn {
        margin-top: clamp(5px, 1vh, 9px);
    }

    #closeResultsBtn {
        margin-top: clamp(4px, .8vh, 8px);
    }

    /* --------------------------------------------------------
       MAIN TOOLBAR — RESULTS / REDO / SHUFFLE / SAVE
       -------------------------------------------------------- */

    .toolbar {
        height: clamp(52px, 10vh, 78px);
        min-height: clamp(52px, 10vh, 78px);

        padding:
            clamp(5px, 1vh, 9px)
            clamp(7px, 1vw, 12px);

        gap: clamp(5px, 1vw, 10px);
    }

    .toolbar button {
        min-width: 0;

        min-height: clamp(42px, 7vh, 60px);

        padding:
            clamp(8px, 1.2vh, 12px)
            clamp(10px, 1.5vw, 18px);

        border-radius: 11px;

        font-size:
            clamp(.75rem, 2vw, 1.1rem);

        font-weight: 700;
        line-height: 1;

        white-space: nowrap;
    }
}


/* ============================================================
   VERY SHORT LANDSCAPE — KEEP EVERYTHING LARGE BUT FIT
   ============================================================ */

@media screen and (orientation: landscape) and (max-width: 900px) and (max-height: 430px) {

    .resultsCard {
        grid-template-columns:
            minmax(0, 28%)
            minmax(0, 72%);
    }

    .resultsInfo {
        padding: 7px 12px;
    }

    .resultsInfo h2 {
        font-size: clamp(1rem, 3vw, 1.4rem);
        margin-bottom: 3px;
    }

    .resultsInfo h1 {
        font-size: clamp(2rem, 6vw, 3.2rem);
        margin-bottom: 6px;
    }

    .resultsInfo > p {
        font-size: clamp(.85rem, 2.5vw, 1.2rem);
        line-height: 1.25;
    }

    .statRow {
        font-size: clamp(.7rem, 1.8vw, .95rem);
    }

    .reasonList h3 {
        font-size: clamp(.85rem, 2vw, 1.1rem);
    }

    .reasonList p {
        font-size: clamp(.65rem, 1.5vw, .85rem);
    }

    .resultsInfo button,
    #resultsScreen button {
        min-height: 40px;
        padding: 7px 11px;
        border-radius: 9px;
        font-size: clamp(.75rem, 1.8vw, .95rem);
    }

    .toolbar {
        height: 48px;
        min-height: 48px;
        padding: 3px 5px;
        gap: 4px;
    }

    .toolbar button {
        min-height: 38px;
        padding: 6px 9px;
        font-size: clamp(.62rem, 1.6vw, .85rem);
    }
}