:root {
    /* More Colorful Cartoonish Palette */
    --primary: oklch(0.75 0.18 230); /* Sky Blue */
    --primary-dark: oklch(0.65 0.22 230);
    --secondary: oklch(0.82 0.18 145); /* Grass Green */
    --accent: oklch(0.78 0.22 20); /* Bubbly Pink */
    --yellow: oklch(0.92 0.15 85); /* Butter Yellow */
    --orange: oklch(0.8 0.2 45); /* Juicy Orange */
    --purple: oklch(0.8 0.15 300); /* Soft Purple */
    
    --bg-base: #fffcf0; /* Warm Butter */
    --bg-surface: #ffffff; 
    --text-primary: #2d2d2d;
    --text-secondary: #5e5e5e;
    
    --border-dark: #2d2d2d; /* Softer dark for borders */
    --border-width: 4px;
    --radius-lg: 32px;
    --radius-md: 20px;
    
    --bouncy-easing: cubic-bezier(0.34, 1.56, 0.64, 1);
    
    /* Game Specific */
    --grid-bg: #ecfdf5; /* Fresh Mint Green */
    --tile-bg: #fffbeb; /* Warm Cream */
    --path-color: #854d0e; /* Rich Wood Path */
}

html, body {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    width: 100%;
    overflow-x: hidden;
    position: relative;
}

body {
    font-family: 'Fredoka', 'Outfit', system-ui, sans-serif;
    background-color: var(--bg-base);
    background-image: 
        radial-gradient(var(--yellow) 1px, transparent 1px),
        radial-gradient(var(--primary) 1px, transparent 1px);
    background-size: 40px 40px;
    background-position: 0 0, 20px 20px;
    color: var(--text-primary);
    line-height: 1.4;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Pure White/Light Background with subtle dots */
.mesh-bg {
    position: fixed;
    inset: 0;
    z-index: -1;
    background: linear-gradient(135deg, #fffcf0 0%, #fef2f2 100%);
    width: 100%;
    pointer-events: none;
}

.home-back-btn {
    position: relative;
    z-index: 10;
    padding: 8px 16px;
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    border-radius: 50px;
    font-family: 'Fredoka', cursive;
    margin-bottom: 15px;
    font-size: 0.85rem;
    align-self: center;
    background: #ffffff;
    border: 3px solid var(--border-dark);
    box-shadow: 4px 4px 0 var(--border-dark);
}

.home-back-btn:hover {
    transform: scale(1.05) rotate(-2deg);
    background: var(--yellow);
}

.container {
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: 15px 8px 250px;
    position: relative;
    z-index: 1;
    flex: 1;
    overflow: hidden;
}

.game-header {
    text-align: center;
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.title {
    font-size: clamp(1.5rem, 8vw, 2.5rem);
    font-weight: 800;
    color: var(--primary-dark);
    text-shadow: \
        2px 2px 0 #fff, \
        3px 3px 0 var(--border-dark);
    margin-bottom: 8px;
    width: 100%;
    text-align: center;
}

.subtitle {
    color: var(--text-primary);
    font-size: clamp(0.7rem, 3.5vw, 1rem);
    font-weight: 600;
    background: #f3f4f6;
    padding: 6px 16px;
    border-radius: 50px;
    display: inline-block;
    border: 2px solid var(--border-dark);
    max-width: 95%;
}

/* Crisp Cartoon Cards */
.glass {
    background: #ffffff;
    border: var(--border-width) solid var(--border-dark);
    border-radius: var(--radius-lg);
    box-shadow: 6px 6px 0 var(--border-dark);
    transition: transform 0.2s var(--bouncy-easing);
}

.game-layout {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    max-width: 100%;
}

@media (min-width: 950px) {
    .game-layout {
        display: grid;
        grid-template-columns: 1fr 320px;
        gap: 24px;
        align-items: start;
    }
}

/* Board */
.board-container {
    background: #fdf2f8;
    padding: 10px;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    border-radius: var(--radius-lg);
}

.grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-template-rows: repeat(6, 1fr);
    gap: 4px;
    width: 100%;
    aspect-ratio: 1/1;
    background: var(--grid-bg);
    padding: 6px;
    border-radius: var(--radius-md);
    border: 2px solid var(--border-dark);
}

.cell {
    background: #ffffff;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    cursor: pointer;
    transition: all 0.2s var(--bouncy-easing);
}

.cell:hover {
    background: #f3f4f6;
    border-color: var(--border-dark);
    transform: scale(1.05);
}

.cell.valid-move {
    background: #f0fdf4;
    border: 2px dashed var(--secondary);
}

/* Tiles */
.tile {
    width: 100%;
    height: 100%;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2.2rem;
    position: relative;
    overflow: hidden;
    animation: popIn 0.3s var(--bouncy-easing);
    border: 3px solid var(--border-dark);
    box-shadow: 0 4px 0 var(--border-dark);
}

.tile-path { background: #fef3c7; }
.tile-start { background: var(--secondary); }
.tile-treasure { background: var(--orange); }

.path-line {
    position: absolute;
    background: var(--path-color);
    z-index: 2;
    border: 2px solid var(--border-dark);
    border-radius: 2px;
}

.line-u { top: -2px; left: 50%; width: 35%; height: 60%; transform: translateX(-50%); }
.line-d { bottom: -2px; left: 50%; width: 35%; height: 60%; transform: translateX(-50%); }
.line-l { left: -2px; top: 50%; height: 35%; width: 60%; transform: translateY(-50%); }
.line-r { right: -2px; top: 50%; height: 35%; width: 60%; transform: translateY(-50%); }
.line-center { top: 50%; left: 50%; width: 35%; height: 35%; transform: translate(-50%, -50%); border: none; background: var(--path-color); }

.tile-key {
    font-size: 2.5rem;
    animation: float 2s infinite ease-in-out;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* Keys & Inventory - Transformed to Horizontal */
.inventory-card {
    padding: 8px 15px;
    margin: 0 auto 10px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 15px;
    flex-wrap: nowrap;
    width: fit-content;
    max-width: 95%;
    overflow: hidden;
    border-width: 2px;
}

.keys-tracker {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.keys-list {
    display: flex;
    gap: 8px;
}

.ogre-track-card {
    background: #fff1f2; /* Soft red for Ogre card */
}

.inventory-card {
    background: #f0fdf4; /* Light Green for Keys card */
}

.status-row {
    display: flex;
    flex-direction: row;
    gap: 12px;
    width: 100%;
    justify-content: center;
    align-items: stretch;
    margin-bottom: 12px;
}

.ogre-track-card, .inventory-card {
    padding: 12px 15px;
    margin: 0 !important;
    width: fit-content;
    min-width: 140px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border: var(--border-width) solid var(--border-dark);
    border-radius: var(--radius-md); /* Use MD for both consistently */
    box-shadow: 4px 4px 0 var(--border-dark);
    flex: 1; /* Match ratio */
}

.ogre-track-card, .inventory-card {
    padding: 10px;
    margin: 0 !important;
    width: fit-content;
    min-width: 150px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-width: 2px;
}

.ogre-track {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    width: 100%;
    justify-content: center;
    padding-bottom: 5px;
}

.track-step {
    width: 32px;
    height: 32px;
    background: #fff;
    border: 2px solid var(--border-dark);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1rem;
    box-shadow: 0 2px 0 var(--border-dark);
    transition: all 0.2s var(--bouncy-easing);
}

.track-step.active {
    background: #ef4444;
    transform: scale(1.1);
    box-shadow: 0 4px 0 var(--border-dark);
}

.key-slot {
    width: 50px;
    height: 50px;
    background: #f3f4f6;
    border: 2px solid var(--border-dark);
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    filter: grayscale(1);
    opacity: 0.3;
}

.key-slot.collected {
    filter: none;
    opacity: 1;
    background: #fbbf24;
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 4px 0 var(--border-dark);
}

.next-tile-container { text-align: center; }

.tile-preview {
    width: 100px;
    height: 100px;
    margin: 15px auto;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 3rem;
    background: #fff;
    border: 3px solid var(--border-dark);
    border-radius: 16px;
    overflow: hidden;
}

/* Buttons */
.primary-btn, .secondary-btn {
    width: 100%;
    padding: 14px;
    border: 3px solid var(--border-dark);
    border-radius: 16px;
    font-family: 'Fredoka', cursive;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.1s;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.primary-btn {
    background: #fbbf24;
    box-shadow: 0 6px 0 var(--border-dark);
    margin-bottom: 12px;
}

.primary-btn.secondary-style { background: #60a5fa; color: white; }

.primary-btn:hover, .secondary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 0 var(--border-dark);
}

.primary-btn:active, .secondary-btn:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 var(--border-dark);
}

.secondary-btn {
    background: #ffffff;
    box-shadow: 0 4px 0 var(--border-dark);
    margin-bottom: 10px;
}

/* Bottom Fixed Controls */
.bottom-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-top: 3px solid var(--border-dark);
    padding: 10px 20px 30px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}

.next-tile-fixed {
    margin-top: -55px; /* Offset to float above the footer */
    background: white;
    padding: 5px;
    border-radius: 20px;
    border: 3px solid var(--border-dark);
    box-shadow: 0 -4px 10px rgba(0,0,0,0.1);
}

.next-tile-fixed .tile-preview {
    margin: 0;
    width: 80px;
    height: 80px;
}

.main-actions {
    display: flex;
    gap: 15px;
    width: 100%;
    max-width: 500px;
}

.main-actions .primary-btn {
    flex: 1;
    margin-bottom: 0 !important;
}

.utility-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.small-btn {
    padding: 6px 14px !important;
    font-size: 0.85rem !important;
    width: auto !important;
    white-space: nowrap;
}

/* Adjust container padding to not be hidden by fixed bottom */
.container {
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px 12px 280px;
    position: relative;
    z-index: 1;
    overflow: hidden; /* Prevent container from leaking */
}

.modal-btns {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.modal-btns button {
    margin-bottom: 0 !important;
}

/* Overlay */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.8);
    backdrop-filter: blur(4px);
    z-index: 3000;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 24px;
}

.overlay.hidden { display: none; }

.overlay-content {
    max-width: 400px;
    width: 100%;
    padding: 40px;
    text-align: center;
    background: #fff;
    border: 5px solid var(--border-dark);
    border-radius: var(--radius-lg);
    box-shadow: 10px 10px 0 var(--border-dark);
}

@keyframes popIn {
    0% { transform: scale(0.6); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

@media (max-width: 600px) {
    .container { padding: 10px 4px 380px; }
    .title { font-size: 1.2rem; }
    .subtitle { font-size: 0.65rem; padding: 3px 6px; width: 100%; }

    .inventory-card {
        gap: 2px;
        padding: 5px;
        border-width: 1.5px;
        box-shadow: 2px 2px 0 var(--border-dark);
        border-radius: 10px;
        justify-content: center;
    }

    .keys-tracker h3 { font-size: 0.6rem; margin-bottom: 2px; }
    .key-slot { width: 22px; height: 22px; font-size: 0.75rem; border-width: 1px; }

    .next-tile-fixed {
        margin-top: -45px;
        border-width: 1.5px;
        padding: 2px;
    }
    .next-tile-fixed .tile-preview {
        width: 55px;
        height: 55px;
        border-width: 1.5px;
    }

    .status-row {
        gap: 8px;
        margin-bottom: 10px;
    }

    .ogre-track-card, .inventory-card { 
        padding: 8px 10px; 
        min-width: unset;
        flex: 1;
        box-shadow: 3px 3px 0 var(--border-dark);
        border-width: 2px;
        border-radius: 12px; /* Fixed radius for mobile too */
    }
    .ogre-track-card h3 { font-size: 0.7rem; }
    .ogre-track { gap: 4px; }
    .track-step { width: 18px; height: 18px; font-size: 0.6rem; border-width: 1px; }
    
    .board-container { 
        padding: 4px;
        border-width: 2px;
        box-shadow: 2px 2px 0 var(--border-dark);
        border-radius: 10px;
        width: 92vw;
        max-width: 92vw;
        margin: 0 auto;
    }
    .grid { gap: 2px; padding: 4px; border-radius: 6px; border-width: 1.5px; }
    .tile { border-width: 1.5px; font-size: 1.5rem; }
    .tile-key { font-size: 1.5rem; }

    .bottom-controls {
        padding: 5px 6px 12px;
        gap: 4px;
    }
    .main-actions { gap: 4px; }
    .primary-btn { padding: 6px; font-size: 0.75rem; border-radius: 8px; border-width: 1.5px; box-shadow: 0 2px 0 var(--border-dark); }
    .small-btn { padding: 3px 6px !important; font-size: 0.65rem !important; border-width: 1px; }
}
