/* =========================================================
   FLUID & RESPONSIVE SIZING 
   ========================================================= */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none; /* Prevent text selection during fast taps */
}

/* PREMIUM WOOD BACKGROUND */
body {
    width: 100vw;
    height: 100vh;
    overflow: hidden; 
    font-family: "Fredoka", sans-serif; /* New Font */
    position: relative;
    background:
        radial-gradient(circle at 20% 10%, rgba(255,228,181,.18), transparent 30%),
        radial-gradient(circle at 80% 85%, rgba(60,35,18,.35), transparent 35%),
        linear-gradient(180deg, #b27d4c 0%, #9c683d 22%, #84542f 45%, #6d4427 70%, #56331d 100%);
    color: #fff4e4;
}

body::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: .65;
    background:
        repeating-linear-gradient(88deg, rgba(255,255,255,.015) 0px, rgba(255,255,255,.010) 3px, rgba(0,0,0,.015) 7px, rgba(255,255,255,.012) 12px, rgba(0,0,0,.012) 20px, rgba(255,255,255,.010) 32px, rgba(0,0,0,.010) 50px, rgba(255,255,255,.012) 80px),
        linear-gradient(90deg, transparent 0%, rgba(255,255,255,.03) 18%, transparent 40%, rgba(0,0,0,.03) 62%, transparent 100%);
    filter: blur(.4px);
    z-index: 1;
}

body::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    box-shadow: inset 0 0 250px rgba(0,0,0,.35), inset 0 0 40px rgba(255,255,255,.05);
    z-index: 1;
}

/* Typography */
h1 { 
    font-size: clamp(3rem, 10vw, 4.5rem); 
    margin-bottom: 20px; 
    text-align: center; 
    letter-spacing: 2px;
    text-shadow: 0 3px 0 #6b4322, 0 10px 20px rgba(0,0,0,.4);
}
p { 
    font-size: clamp(1.2rem, 4vw, 1.8rem); 
    margin-bottom: 30px; 
    text-align: center;
    text-shadow: 0 2px 4px rgba(0,0,0,.4);
}

/* =========================================================
   LARGE FADED PUZZLE TILES (Background Decor)
   ========================================================= */
.bg-tile {
    position: absolute;
    border-radius: 35px;
    opacity: .08;
    background: linear-gradient(145deg, #d9a167, #9c6536);
    box-shadow: 0 40px 80px rgba(0,0,0,.35), inset 0 4px 6px rgba(255,255,255,.25), inset 0 -8px 12px rgba(0,0,0,.15);
    overflow: hidden;
    z-index: 0;
    pointer-events: none;
}
.bg-tile::before {
    content: ""; position: absolute; inset: 0;
    background: repeating-linear-gradient(90deg, rgba(255,255,255,.02) 0px, rgba(255,255,255,.015) 3px, rgba(0,0,0,.015) 8px, rgba(255,255,255,.01) 15px, rgba(0,0,0,.01) 30px);
}
.bg-tile::after {
    content: ""; position: absolute; width: 90px; height: 90px; border-radius: 50%;
    background: inherit; right: -45px; top: 50%; transform: translateY(-50%); box-shadow: inherit;
}
.t1 { width: 520px; height: 520px; left: -120px; top: -120px; transform: rotate(-18deg); }
.t2 { width: 430px; height: 430px; right: -90px; bottom: -120px; transform: rotate(18deg); }
.t3 { width: 330px; height: 330px; left: 62%; top: 48%; transform: rotate(12deg); }
.t4 { width: 240px; height: 240px; top: 15%; right: 20%; transform: rotate(-12deg); }

@media(max-width: 700px) {
    .t1 { width: 320px; height: 320px; }
    .t2 { width: 300px; height: 300px; }
    .t3 { width: 220px; height: 220px; }
    .t4 { display: none; }
}

/* =========================================================
   CORE ARCHITECTURE (SPA Display Logic)
   ========================================================= */
.screen {
    display: none; 
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 20px;
    position: relative;
    z-index: 10;
}
.screen.active { display: flex; }

#winOverlay {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(45, 25, 15, 0.95); /* Darker wooden overlay */
    z-index: 100;
    display: none;
    flex-direction: column; align-items: center; justify-content: center;
}
#winOverlay.active { display: flex; }

/* =========================================================
   UI/UX: PREMIUM WOOD BUTTONS & GAME TILES
   ========================================================= */
/* Shared Wood Texture (Stacked Backgrounds so text isn't covered) */
button, .tile {
    font-family: inherit;
    font-weight: 700;
    color: #fff7ea;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    box-shadow: 0 12px 25px rgba(0,0,0,.35), inset 0 2px 2px rgba(255,255,255,.30), inset 0 -3px 5px rgba(0,0,0,.18);
    text-shadow: 0 2px 0 #6b4322, 0 4px 8px rgba(0,0,0,.3);
    background: 
        /* Highlight */
        linear-gradient(to bottom, rgba(255,255,255,.30) 0%, rgba(255,255,255,0) 40%),
        /* Wood Grain */
        repeating-linear-gradient(90deg, rgba(255,255,255,.02) 0px, rgba(255,255,255,.015) 3px, rgba(0,0,0,.012) 8px, rgba(255,255,255,.01) 18px, rgba(0,0,0,.01) 32px),
        /* Base Wood Color */
        linear-gradient(180deg, #ddb076 0%, #c98d55 30%, #a86d3d 65%, #8b552f 100%);
    transition: transform 0.1s, filter 0.1s, box-shadow 0.1s;
}

button:active, .tile:active { 
    filter: brightness(1.05);
    box-shadow: 0 6px 15px rgba(0,0,0,.4), inset 0 2px 2px rgba(255,255,255,.35), inset 0 -3px 5px rgba(0,0,0,.18);
}

/* Button Specifics */
button {
    min-width: 44px; min-height: 44px; padding: 14px 32px;
    font-size: clamp(1.2rem, 4vw, 1.5rem);
    display: flex; align-items: center; justify-content: center; gap: 10px;
    border-radius: 18px; /* Slightly rounder for UI buttons */
}
svg { width: 24px; height: 24px; fill: currentColor; }

/* Empty Tile Rule (Overrides the wood texture) */
.tile.empty {
    background: transparent;
    box-shadow: none;
    cursor: default;
}

/* =========================================================
   ORIENTATION & SCREEN ADAPTATION (Untouched Game Logic)
   ========================================================= */
#gameContainer {
    width: 100%; max-width: 100%; display: flex; flex-direction: column; align-items: center;
}

.header-stats {
    position: fixed; top: 20px; left: 0; width: 100vw; padding: 0 20px;
    display: flex; justify-content: space-between; align-items: center;
    font-size: clamp(1.2rem, 5vw, 1.8rem); font-weight: bold;
    z-index: 50; pointer-events: none;
    text-shadow: 0 2px 4px rgba(0,0,0,.5); /* Makes text readable over background */
}
.header-stats > * { pointer-events: auto; }
.stat-box { display: flex; align-items: center; gap: 8px; }

.difficulty-buttons {
    display: flex; gap: 15px; justify-content: center; flex-wrap: wrap; 
}

#board {
    display: grid; gap: 4px; 
    width: 100%; max-width: min(100vw, calc(100vh - 80px)); 
    aspect-ratio: 1 / 1; 
    margin: 60px auto 10px auto; 
    
    /* Dark recessed look for the board background */
    background: rgba(40, 20, 10, 0.4);
    box-shadow: inset 0 6px 15px rgba(0,0,0,0.6), 0 2px 4px rgba(255,255,255,0.08);
    
    padding: 6px; border-radius: 16px;
}

.tile {
    aspect-ratio: 1 / 1; 
    display: flex; align-items: center; justify-content: center;
}

/* Mobile Landscape Mode */
@media (orientation: landscape) and (max-height: 500px) {
    #gameContainer { flex-direction: row; justify-content: center; align-items: center; max-width: 100%; gap: 30px; }
    .header-stats { flex-direction: row; top: 10px; padding: 0 30px; }
    #board { height: 80vh; width: auto; aspect-ratio: 1 / 1; max-width: none; padding: 4px; margin-top: 0; }
    h1 { font-size: clamp(1.5rem, 5vw, 2.5rem); margin-bottom: 10px; }
}