:root {
    --joy-color: #FFD700;
    --sadness-color: #6495ED;
    --fear-color: #9370DB;
    --disgust-color: #3CB371;
    --anger-color: #DC143C;
    --bg-color: #f0f8ff;
    --text-color: #333;
    --white: #fff;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Nunito', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    height: -webkit-fill-available; /* For mobile safari */
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}

#app-container {
    width: 100%;
    max-width: 600px;
    height: 100%;
    height: -webkit-fill-available; /* For mobile safari */
    background-color: var(--white);
    border-radius: 20px;
    box-shadow: 0 10px 20px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.screen {
    width: 100%;
    height: 100%;
    padding: 20px;
    display: none;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

#main-menu {
    justify-content: flex-start;
    overflow-y: auto;
}

.screen.active {
    display: flex;
}

.title {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

h2 {
    font-size: 1.5rem;
    margin-bottom: 20px;
}

#character-selection {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    width: 100%;
    padding: 0 10px;
}

.character-btn {
    background-color: var(--white);
    border: 3px solid var(--text-color);
    border-radius: 15px;
    cursor: pointer;
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    font-size: 1.1rem;
    font-weight: bold;
    transition: transform 0.2s, box-shadow 0.2s;
}

.character-btn:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 10px rgba(0,0,0,0.1);
}

.character-btn img {
    width: 60px;
    height: 60px;
    object-fit: contain;
}

.character-btn:last-child:nth-child(odd) {
    grid-column: 1 / -1;
    width: calc(50% - 7.5px); /* (100% / 2 columns) - (gap / 2) */
    justify-self: center;
}

.character-btn[data-character="joy"] { border-color: var(--joy-color); }
.character-btn[data-character="sadness"] { border-color: var(--sadness-color); }
.character-btn[data-character="fear"] { border-color: var(--fear-color); }
.character-btn[data-character="disgust"] { border-color: var(--disgust-color); }
.character-btn[data-character="anger"] { border-color: var(--anger-color); }

/* Game Screen */
#game-screen {
    justify-content: flex-start;
    padding-top: 15px;
}

.game-header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

#back-to-menu {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
}

#game-title {
    flex-grow: 1;
    text-align: center;
    margin: 0;
}

#game-instructions {
    margin-bottom: 20px;
    font-size: 1rem;
    padding: 0 10px;
}

#game-board {
    position: relative;
    overflow: hidden;
    background-color: #e3f2fd;
    border-radius: 10px;
    margin: 0 auto;
    width: 95%;
    max-width: 500px; /* Cap size on tablets/desktops */
    flex-shrink: 0;
}

#game-board-container {
    width: 100%;
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding-bottom: 10px;
    min-height: 0;
}

#game-info-container {
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#game-info {
    font-size: 1.2rem;
    font-weight: bold;
}

/* Modal */
.modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.modal.active {
    display: flex;
}

.modal-content {
    background-color: var(--white);
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

.modal-content h2 {
    margin-bottom: 20px;
}

.modal-content button {
    background-color: #4CAF50;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    margin: 5px;
}

.modal-content button:hover {
    opacity: 0.9;
}

/* Joy Game Specific */
#game-board.joy-board {
    display: grid;
    padding: 5px;
    background-color: var(--white);
    border: 5px solid #f0c000;
}
.maze-cell {
    width: 100%;
    aspect-ratio: 1;
}
.maze-cell.wall {
    background-color: #f0c000;
    border-radius: 2px;
}
.maze-cell.player {
    background-image: url('joy_icon.png');
    background-size: 90%;
    background-repeat: no-repeat;
    background-position: center;
}
.maze-cell.goal {
    background-image: url('bing_bong.png');
    background-size: 100%;
    background-repeat: no-repeat;
    background-position: center;
}
#maze-controls {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    margin-top: 10px;
    height: 120px; /* Fixed height for controls area */
    flex-shrink: 0;
}
.maze-btn {
    width: 50px;
    height: 50px;
    font-size: 1.5rem;
    border: 2px solid var(--joy-color);
    background-color: #fff;
    border-radius: 10px;
    cursor: pointer;
    margin: 2px;
}

/* Sadness Game Specific */
#game-board.sadness-board {
    display: grid;
    gap: 8px;
    padding: 8px;
    background-color: #dbeaff;
}
.sadness-board .card .card-front {
    background-color: var(--sadness-color);
    background-image: url('sadness_icon.png');
    background-size: 60%;
    background-repeat: no-repeat;
    background-position: center;
}
.sadness-board .card .card-back {
    background-color: #b3cde0;
}
.sadness-board .card.matched {
    opacity: 0.5;
    pointer-events: none;
}

/* Sadness Game - Level 3 Desktop Fix */
@media (min-width: 601px) {
    #game-board.sadness-board.sadness-level-3 {
        width: 80%;
        max-width: 420px;
    }
}

/* Fear Game Specific */
#game-board.fear-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    padding: 10px;
    background-color: #e9e4f0;
    width: 95%;
    aspect-ratio: 1;
    margin: 0 auto;
}
.fear-item {
    width: 100%;
    aspect-ratio: 1;
    background-size: 90%;
    background-position: center;
    background-repeat: no-repeat;
    border-radius: 10px;
    cursor: pointer;
    border: 3px solid transparent;
    transition: all 0.2s;
}
.fear-item:hover {
    background-color: #d8cde4;
}
.fear-item.selected {
    border-color: var(--fear-color);
    background-color: #d8cde4;
}
.fear-item.matched {
    border-color: var(--joy-color);
    background-color: #d1fecb;
}

@media (min-width: 600px) and (max-height: 800px) {
    #game-board.fear-board {
        max-width: 420px;
    }
}

/* Disgust Game Specific */
#game-board.disgust-board-puzzle {
    display: flex;
    flex-direction: row;
    aspect-ratio: 4/3;
    background-size: cover;
    background-position: center;
    border: 5px solid var(--disgust-color);
}
.puzzle-strip {
    width: 12.5%; /* 100 / 8 strips */
    height: 100%;
    cursor: grab;
    transition: opacity 0.2s;
}

/* Card Game Generic */
.card {
    width: 100%;
    aspect-ratio: 1;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.5s;
    cursor: pointer;
}

.card.flipped {
    transform: rotateY(180deg);
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 10px;
    overflow: hidden;
}

.card-front {
    background-color: #ccc;
}

.card-back {
    background-color: #eee;
    transform: rotateY(180deg);
}

.card-back img {
    width: 90%;
    height: 90%;
    object-fit: contain;
}

/* Anger Game Specific */
#game-board.anger-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    padding: 15px;
    aspect-ratio: 1;
}

.hole {
    aspect-ratio: 1;
    background-color: #d2b48c;
    border-radius: 50%;
    border: 5px solid #8b4513;
    position: relative;
    overflow: hidden;
}

.frustration {
    width: 80%;
    height: 80%;
    position: absolute;
    bottom: -100%;
    left: 10%;
    background-image: url('frustration.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    transition: bottom 0.2s ease-out;
    cursor: pointer;
}

.frustration.up {
    bottom: 5%;
}