:root {
    --bg-color: #f0f8ff;
    --primary-color: #4a90e2;
    --secondary-color: #f5a623;
    --accent-color: #50e3c2;
    --white: #ffffff;
    --black: #333333;
    --font-family: 'Lilita One', cursive;
    --border-radius: 15px;
}

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

html, body {
    height: 100%;
    width: 100%;
    overflow-y: auto; /* Allow vertical scrolling */
    font-family: sans-serif;
    background-color: var(--bg-color);
    color: var(--black);
    -webkit-tap-highlight-color: transparent;
}

#app-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 15px;
    min-height: 100%; /* Allow container to grow */
    display: flex;
    flex-direction: column;
    align-items: center;
}

h1, h2 {
    font-family: var(--font-family);
    color: var(--primary-color);
    text-align: center;
    margin-top: 20px; /* Add some top margin */
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
}

h1 {
    font-size: clamp(2.5rem, 8vw, 4rem);
}

h2 {
    font-size: clamp(1.5rem, 6vw, 2.5rem);
    color: var(--secondary-color);
}

.screen {
    display: none;
    width: 100%;
    flex-grow: 1; /* Allow screen to take up available space */
}

.screen.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

#vowel-selection {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 20px;
    width: 100%;
    max-width: 800px;
    padding-bottom: 20px; /* Add padding at the bottom */
}

.vowel-btn {
    background-color: var(--white);
    border: 5px solid var(--primary-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    aspect-ratio: 1 / 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px;
    position: relative;
    overflow: hidden;
    min-height: 120px; /* Ensure buttons have a minimum height */
}

.vowel-btn:hover, .vowel-btn:focus {
    transform: scale(1.05);
    box-shadow: 0 10px 20px rgba(0,0,0,0.2);
}

.vowel-btn img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 5px;
}

.vowel-btn span {
    position: absolute;
    bottom: 5px;
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--font-family);
    font-size: clamp(2rem, 8vw, 4rem);
    color: var(--white);
    text-shadow: 0 0 10px var(--black), 0 0 5px var(--black);
    line-height: 1;
}

#game-screen {
    justify-content: flex-start;
    gap: 15px;
    /* Ensure the game screen takes up the full available height */
    height: 100%;
    max-height: 100%;
    justify-content: flex-start;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 0 10px;
    flex-shrink: 0; /* Prevent header from shrinking */
}

.difficulty-selector {
    display: flex;
    align-items: center;
    gap: 10px;
}

.difficulty-selector label {
    font-family: var(--font-family);
    font-size: 1.2rem;
    white-space: nowrap;
}

#difficulty {
    padding: 5px;
    border-radius: var(--border-radius);
    font-family: var(--font-family);
    border: 2px solid var(--primary-color);
    background: var(--white);
}

.puzzle-area {
    display: flex;
    flex-direction: column; /* Stack board and pieces vertically */
    align-items: center; /* Center them horizontally */
    justify-content: flex-start; /* Align to the top */
    gap: 20px;
    width: 100%;
    flex-grow: 1;
    min-height: 0; /* Important for flexbox scrolling */
    padding-bottom: 20px; /* Add space at the bottom */
    overflow-y: auto; /* Enable vertical scrolling for the puzzle area */
}

#puzzle-board, #pieces-container {
    background-color: rgba(255, 255, 255, 0.7);
    border: 2px dashed var(--primary-color);
    border-radius: var(--border-radius);
}

#puzzle-board {
    position: relative;
    display: grid;
    aspect-ratio: 1 / 1;
    width: 100%;
    max-width: 450px;
    max-height: calc(100vh - 200px);
    flex-shrink: 0; /* Prevent board/container from shrinking */
}

#puzzle-board::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: var(--puzzle-image);
    background-size: 100% 100%;
    filter: grayscale(100%) opacity(0.3);
    z-index: 0;
    border-radius: calc(var(--border-radius) - 2px); /* Adjust for border */
}

#pieces-container {
    display: grid;
    width: 100%;
    max-width: 450px;
    aspect-ratio: 1 / 1;
    max-height: calc(100vh - 200px);
    flex-shrink: 0; /* Prevent board/container from shrinking */
}

.puzzle-piece, .placeholder {
    width: 100%;
    height: 100%;
    background-size: 400% 400%;
    border: 1px solid #ccc;
    z-index: 1;
}

.puzzle-piece {
    cursor: grab;
    transition: transform 0.1s ease-in-out, box-shadow 0.1s ease-in-out;
}

.puzzle-piece.dragging {
    cursor: grabbing;
    transform: scale(1.1);
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    z-index: 1000;
    position: absolute;
    pointer-events: none; /* Important for drop target detection */
}

.placeholder {
    background-color: rgba(0,0,0,0.05);
}

.placeholder.over {
    background-color: rgba(80, 227, 194, 0.5); /* accent color with alpha */
}

#completion-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 40px;
    border-radius: var(--border-radius);
    border: 5px solid var(--accent-color);
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    text-align: center;
    z-index: 2000;
}

#completion-message h2 {
    color: var(--primary-color);
    margin-bottom: 20px;
}

.hidden {
    display: none !important;
}

#back-button, #next-puzzle-button {
    font-family: var(--font-family);
    font-size: 1.2rem;
    padding: 10px 20px;
    border-radius: 10px;
    border: 3px solid var(--secondary-color);
    background-color: var(--secondary-color);
    color: var(--white);
    cursor: pointer;
    transition: transform 0.2s ease;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.2);
}

#back-button {
     background-color: var(--primary-color);
     border-color: var(--primary-color);
}

#back-button:hover, #next-puzzle-button:hover {
    transform: scale(1.05);
}

/* Mobile responsive styles */
@media (max-width: 768px) {
    .puzzle-area {
        /* overflow-y is now in the base style */
        /* max-height is no longer needed here, handled by flexbox */
        padding-left: 5px;
        padding-right: 5px;
    }

    #puzzle-board, #pieces-container {
        width: 90vw;
        height: 90vw;
        max-width: 400px;
        max-height: 400px;
    }
}