:root {
    --color-sunlight: #D4D1B8;
    --color-wall: #E2DFCA;
    --color-oak-light: #C5B08A;
    --color-oak-dark: #6D4C41;
    --color-magic-blue: #546E7A;
    --color-leaf-green: #4CAF50;
    --color-ink: #3E2723;
    --color-parchment: #F5E6D3;
    --shelf-thickness: 30px;
    --font-heading: 'Georgia', serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, sans-serif;
    background-color: var(--color-sunlight);
    background-image: url('/assets/bg-image.png');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

header {
    background-color: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    border-bottom: 2px solid var(--color-oak-light);
    padding: 1rem 0;
    flex: 0 0 auto;
    z-index: 1000;
    position: relative; /* Anchor for shelf actions */
}

nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 100px;
    width: 100%;
}

.brand { font-family: var(--font-heading); font-size: 1.8rem; font-weight: bold; color: var(--color-oak-dark); text-decoration: none; }
.nav-links {
    /* Removed relative positioning to allow actions to key off header */
}

.nav-links a { color: var(--color-ink); text-decoration: none; font-weight: 600; }

#shelfActionContainer {
    position: absolute;
    top: 100%; /* Align top of buttons to bottom of header */
    right: 20px; /* Just inside the page edge */
    transform: translateY(-50%); /* Center vertically on the border line */
    display: flex;
    gap: 0.5rem;
    z-index: 2000;
}

.header-btn {
    position: relative; /* Reset from fixed */
    width: 48px;
    height: 48px;
    border-radius: 50%; /* Circle */
    display: flex;
    align-items: center;
    justify-content: center;
    color: white !important;
    text-decoration: none;
    border: 3px solid rgba(255,255,255,0.3);
    cursor: pointer;
    font-size: 1.4rem;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    transition: transform 0.2s;
}

.header-btn:hover { transform: translateY(-2px); }
.add-game-toggle { background-color: var(--color-leaf-green) !important; }
.filter-toggle { background-color: var(--color-oak-dark) !important; }

main { 
    flex: 1; 
    display: flex; 
    flex-direction: column; 
    justify-content: center; 
    position: relative; 
    overflow: hidden; 
    background: var(--color-wall);
}

/* --- Shelf Experience --- */
.shelf-container {
    position: relative;
    width: 100%;
    margin: 0; 
    padding: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 100%;
}

.shelf-inner {
    display: flex;
    align-items: flex-end;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 4px;
    padding: 0 100px; 
    height: 75vh; /* Increased from 60vh to allow space above games */
    min-height: 600px; /* Ensure enough room for 380px games + title */
    max-height: 900px;
    position: relative;
    scrollbar-width: none;
    z-index: 10;
    scroll-snap-type: x mandatory;
    width: 100%;
    /* The Shelf Board */
    background: 
        linear-gradient(to top, 
            var(--color-oak-light) 0%, 
            var(--color-oak-light) 40px, 
            transparent 40px
        );
    border-bottom: var(--shelf-thickness) solid var(--color-oak-dark);
    padding-bottom: 0px;
    margin-bottom: 130px; /* Reserve floor space for Plaque */
}

.shelf-inner::-webkit-scrollbar { display: none; }

.shelf-title-box {
    position: absolute;
    left: 0;
    margin-left: 450px;
    top: 18%; /* Moved further down to clear header buttons */
    z-index: 5;
    pointer-events: none;
    white-space: nowrap;
    opacity: 0.4;
    text-align: left;
}

.wall-title {
    font-family: var(--font-heading);
    font-size: clamp(3rem, 10vw, 5rem);
    color: var(--color-oak-dark);
    text-shadow: 3px 3px 0px white;
    margin: 0;
    white-space: nowrap;
}

.edit-shelf-name {
    font-size: 0.3em; /* Shrink the pencil */
    vertical-align: middle;
    margin-left: 10px;
    cursor: pointer;
    pointer-events: auto; /* Re-enable clicking on the pencil */
    color: var(--color-oak-dark);
    opacity: 0.7;
    transition: opacity 0.2s;
}

.edit-shelf-name:hover {
    opacity: 1;
}

/* Spatial Units */
.bookend {
    flex: 0 0 auto;
    height: 380px; /* Taller bookends */
    z-index: 20;
    display: flex;
    align-items: flex-end;
    scroll-snap-align: start;
    margin-bottom: -5px;
}
.bookend img { height: 100%; filter: drop-shadow(5px 0 10px rgba(0,0,0,0.3)); }
.bookend--right img { transform: scaleX(-1); }

.curio { 
    flex: 0 0 auto; 
    height: 220px; 
    align-self: flex-end; 
    z-index: 15; 
    scroll-snap-align: start; 
    margin: 0 20px; 
    margin-bottom: 10px; /* Sit on shelf */
}
.curio img { height: 100%; filter: drop-shadow(2px 2px 5px rgba(0,0,0,0.2)); }

/* Game Items & Spines */
.game-item {
    flex: 0 0 auto;
    width: var(--game-width, 110px);
    height: var(--game-height, 380px);
    background-color: var(--color-parchment);
    position: relative;
    overflow: visible; /* Allow pop-out */
    box-shadow: 2px 0 10px rgba(0,0,0,0.25);
    border-radius: 2px;
    scroll-snap-align: start;
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
    transform-origin: bottom center;
}

.game-item:hover { 
    transform: translateY(-5px) scale(1.02); 
    z-index: 100; 
    box-shadow: 0 10px 30px rgba(0,0,0,0.4); 
}

/* Real Image Spine */
.game-item img.box-art {
    width: var(--game-height, 380px);
    height: var(--game-width, 110px);
    object-fit: cover;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(90deg);
    display: block;
    z-index: 1;
}

/* Procedural Spine (Fallback) */
.procedural-spine {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(to right, #5D4037, #795548, #5D4037);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.1);
}

.spine-text {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    font-family: var(--font-heading);
    color: #FFF8E1;
    font-size: 1.2rem;
    font-weight: bold;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
    white-space: nowrap;
    max-height: 90%;
}

.spine-logo {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    opacity: 0.8;
}

/* Leans */
.game-item--leaning-left { transform: rotate(-2deg); margin-right: 5px; }
.game-item--leaning-right { transform: rotate(2deg); margin-left: 5px; }
.game-item--leaning-left:hover, .game-item--leaning-right:hover { transform: rotate(0deg) translateY(-10px) scale(1.02); }

/* Stacks */
.game-item--stacked {
    margin-bottom: -10px;
    background: transparent;
    box-shadow: none;
    overflow: visible;
}

.game-item--stacked img.box-art {
    width: 100%; height: 100%;
    position: static;
    transform: none;
    object-fit: cover;
}

/* Spatial Columns (The Grid System) */
.shelf-column {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    height: 100%;
    scroll-snap-align: start;
    z-index: 10;
    position: relative;
    flex: 0 0 auto;
    /* Debug: border: 1px solid red; */
}

/* Wall Layer (Signs) */
.wall-sign {
    margin-bottom: auto; /* Push to top of column */
    margin-top: 10%;     /* Spacing from very top */
    width: max-content;
    z-index: 5;
    pointer-events: none;
    transition: transform 0.3s ease;
}

.wall-sign img { max-width: 180px; max-height: 120px; filter: drop-shadow(4px 4px 8px rgba(0,0,0,0.25)); }

/* Decor Layer (Meeples) */
.decor-layer {
    position: absolute;
    bottom: -20px; /* Lowered to sit in front of game on the shelf lip */
    left: 50%;
    transform: translateX(-50%);
    z-index: 200; /* In front of games */
    pointer-events: none;
}

.meeple-decor {
    height: 120px; /* 300% larger */
    filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.4));
}

.stack-container {
    display: flex;
    flex-direction: column-reverse;
    justify-content: flex-start;
    align-items: center;
    height: 100%;
    scroll-snap-align: start;
    margin: 0 12px;
    flex: 0 0 auto;
}

/* Edit Mode */
.delete-btn {
    position: absolute;
    top: -15px;
    right: -15px;
    width: 30px;
    height: 30px;
    background: #D32F2F;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    z-index: 300;
    opacity: 0;
    transform: scale(0);
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

[data-edit-mode="true"] .delete-btn {
    opacity: 1;
    transform: scale(1);
}

[data-edit-mode="true"] .game-item {
    animation: shake 3s infinite ease-in-out;
}

@keyframes shake {
    0% { transform: rotate(0deg); }
    2% { transform: rotate(-1deg); }
    4% { transform: rotate(1deg); }
    6% { transform: rotate(0deg); }
    100% { transform: rotate(0deg); }
}

/* Plaque - Aged Bronze Luster */
.plaque {
    position: fixed;
    bottom: 10px; /* Lowered from 30px */
    left: 50%;
    transform: translateX(-50%);
    width: min(500px, 95vw);
    background-color: #C5B08A !important;
    background: linear-gradient(135deg, #C5B08A 0%, #A68D60 100%) !important;
    padding: 1.5rem;
    border: 5px solid #3E2723 !important;
    z-index: 4000;
    opacity: 0;
    pointer-events: none;
    text-align: center;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border-radius: 4px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}

.plaque.visible { opacity: 1 !important; pointer-events: auto; transform: translateX(-50%) translateY(-10px); }
.plaque h2 { margin: 0 0 0.5rem 0; font-family: var(--font-heading); color: #3E2723; border-bottom: 2px solid rgba(0,0,0,0.1); padding-bottom: 0.5rem; }
.plaque p { margin: 0; font-size: 1.1rem; color: #3E2723; line-height: 1.4; font-weight: 500; }

.filter-panel {
    position: fixed;
    top: -400px; /* Hide completely */
    left: 0;
    width: 100%;
    background: rgba(245, 230, 211, 0.98); /* Parchment color, almost opaque */
    border-bottom: 2px solid var(--color-oak-dark);
    padding: 130px 2rem 1.5rem 2rem; /* Clear header generously */
    z-index: 900;
    display: flex;
    justify-content: center;
    align-items: flex-end; /* Align inputs and button */
    gap: 1.5rem;
    transition: top 0.4s cubic-bezier(0.19, 1, 0.22, 1);
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.filter-panel.open { top: 0; }

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.filter-group label {
    font-family: var(--font-heading);
    font-weight: bold;
    color: var(--color-oak-dark);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-left: 4px;
}

.filter-group select {
    appearance: none;
    background-color: rgba(255, 255, 255, 0.6);
    border: 1px solid var(--color-oak-light);
    border-radius: 8px;
    padding: 0.6rem 2.2rem 0.6rem 0.8rem;
    font-family: system-ui, sans-serif;
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-ink);
    cursor: pointer;
    min-width: 140px;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%236D4C41%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 0.8em top 50%;
    background-size: 0.65em auto;
    transition: all 0.2s;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.05);
}

.filter-group select:hover {
    background-color: rgba(255, 255, 255, 0.9);
    border-color: var(--color-leaf-green);
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.filter-group select:focus {
    outline: none;
    border-color: var(--color-leaf-green);
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.2);
}

.reset-btn {
    width: 38px;
    height: 38px;
    border-radius: 8px; /* Matching corner radius */
    background: var(--color-oak-dark); /* Match theme */
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    margin-bottom: 2px; /* Align visually */
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.reset-btn:hover { 
    transform: rotate(-90deg); 
    background: var(--color-ink);
}

.container { max-width: 1200px; margin: 0 auto; padding: 0 20px; width: 100%; }
.text-center { text-align: center; }
.grid { display: grid; gap: 2rem; }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }

.section { padding: 4rem 0; }

.feature-card {
    background: white;
    padding: 2.5rem;
    border-radius: 12px;
    border: 3px solid var(--color-oak-light);
    text-align: center;
    box-shadow: 0 10px 20px rgba(0,0,0,0.05);
    transition: transform 0.3s ease;
}

.feature-card:hover { transform: translateY(-10px); }
.feature-card i { font-size: 3rem; color: var(--color-oak-dark); margin-bottom: 1.5rem; }
.feature-card h3 { font-family: var(--font-heading); margin-bottom: 1rem; }

.login-btn {
    display: inline-block;
    padding: 1rem 2.5rem;
    background: var(--color-oak-dark);
    color: white !important;
    text-decoration: none;
    border-radius: 8px;
    font-weight: bold;
    font-size: 1.2rem;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    transition: all 0.2s;
    border: none;
    cursor: pointer;
}

.login-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.3); }

/* Footer */
footer {
    background-color: var(--color-ink);
    color: var(--color-sunlight);
    padding: 4rem 0;
    margin-top: auto;
}

.footer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 3rem;
}

.footer-col h4 {
    color: var(--color-oak-light);
    margin-bottom: 1.5rem;
    font-family: 'Georgia', serif;
}

.footer-col ul { list-style: none; padding: 0; }
.footer-col ul li { margin-bottom: 0.8rem; }

.footer-col a {
    color: var(--color-sunlight);
    text-decoration: none;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.footer-col a:hover { opacity: 1; }

@media (max-width: 900px) {
    nav { padding: 0 20px; }
    .brand { font-size: 1.3rem; }
    .hero h1 { font-size: 3rem; }
    .shelf-container { padding: 0; }
    
    .header-btn {
        width: 36px;
        height: 36px;
        font-size: 1rem;
        /* top removed to respect relative positioning */
    }

    /* Mobile Shelf Scaling */
    .shelf-inner {
        height: 50vh; /* Dynamic height for mobile */
        min-height: 350px; /* Override desktop min-height */
        max-height: 500px;
        padding: 0 20px;
        margin-bottom: 100px; /* Reduced floor space */
    }

    .shelf-title-box {
        margin-left: 20px;
        top: 10px; /* Reset to top */
        bottom: auto;
    }
    
    .wall-title {
        font-size: 2.5rem;
    }

    .bookend { height: 200px; } /* Scaled down */

    .curio { height: 120px; }

    /* Scale games using calc on the inline variables */
    .game-item {
        width: calc(var(--game-width) * 0.6) !important;
        height: calc(var(--game-height) * 0.6) !important;
    }

    .game-item img {
        width: calc(var(--game-height) * 0.6) !important;
        height: calc(var(--game-width) * 0.6) !important;
    }

    .game-item--stacked {
        margin-bottom: -3px;
    }
    
    /* Wall signs need to move down */
    .wall-sign {
        bottom: auto; 
        top: -40px; /* Position relative to column top */
        margin-top: 0;
    }
    .wall-sign img {
        max-width: 100px;
        max-height: 80px;
    }

    /* Mobile Meeples */
    .decor-layer { bottom: -10px; }
    .meeple-decor { height: 70px; }

    /* Plaque adjustments for mobile */
    .plaque {
        width: 95%;
        bottom: 10px;
        padding: 1rem;
    }
    .plaque h2 { font-size: 1.1rem; }
    .plaque p { font-size: 0.8rem; }
}
