:root {
    --bg-color: #121212;
    --card-bg: #1e1e1e;
    --text-main: #ffffff;
    --text-dim: #b3b3b3;
    --accent: #FFCC01; /* Premium Cricket Gold */
}

body {
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    margin: 0;
    padding: 20px;
}

.header-controls {
    position: relative;
    background-color: #121212;
    padding: 0px 0 20px 0;
    z-index: 100;
    text-align: center;
    border-bottom: none !important;
}

/* Back link + title row: flexbox, no absolute positioning,
   so the two can never overlap at any screen width. */
.header-controls > .site-header-row {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 10px !important;
    width: 100% !important;
    height: auto !important;
    margin-bottom: 15px;
}

.site-title {
    margin: 0;
    font-size: 1.7rem;
    color: white;
    letter-spacing: 1.5px;
    text-align: center;
}

.back-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 400;
    font-size: 1.0em;
    line-height: 1;
    white-space: nowrap;
}

@media screen and (max-width: 600px) {
    .back-link {
        font-size: 0.8em;
    }
}

#searchInput {
    width: 280px;
}

.search-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.search-wrapper:hover #clearSearch {
    color: var(--accent);
}

.mobile-column {
    display: contents;
}

.controls-row {
    display: contents;
}

#counter {
    display: block !important;
    text-align: center !important;
    width: 100%;
    font-family: sans-serif;
    font-size: 14px;
    color: var(--text-dim);
    margin: 5px 0 !important;
    padding-bottom: 0px !important;
}

/* ==========================================
   MAIN MAIN GRID (index.html)
   ========================================== */

#bookGrid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 220px));
    gap: 25px;
    padding: 20px;
    max-width: 1600px;
    margin: 0 auto;
    justify-content: center; 
    border-top: none !important;
    padding-top: 10px;
    margin-top: 0 !important;
}

.book-card {
    width: 100%;
    max-width: 220px;
    margin: 0 auto;
    background-color: var(--card-bg);
    border-radius: 8px;
    overflow: hidden;
    transition: transform 0.2s;
    cursor: pointer;
    border: none;
    text-align: left;
}

.book-card:hover {
    transform: translateY(-5px);
}

/* Keeps index.html thumbnails uniform without clipping or bloating */
.grid-img {
    width: 100% !important;
    aspect-ratio: 2 / 3 !important; 
    object-fit: cover !important;
    display: block;
    background-color: #282828;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease-in;
}

.grid-img[src] {
    opacity: 1;
}

.card-content { 
    padding: 12px; 
}

.card-author {
    display: block;
    font-weight: bold;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-title {
    display: block;
    font-size: 12px;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 8px;
}

/* ==========================================
   ALPHABET NAVIGATION BAR
   ========================================== */

.alphabet-bar {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    z-index: 1000;
    background-color: #121212;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 2px;
    width: 100%;
    padding-top: 5px !important;
    padding-bottom: 5px !important;
}

.letter-btn,
.alphabet-bar button {
    background: none;
    border: none;
    color: #888;
    font-size: 19px;
    font-weight: bold;
    cursor: pointer;
    padding: 4px 6px 2px 6px !important;
    margin: 0;
    line-height: 1;
    height: auto !important;
    display: inline-block;
    transition: color 0.2s;
    border-radius: 4px;
}

.letter-btn:hover {
    color: var(--accent);
    background: rgba(255, 255, 255, 0.1);
}

.letter-btn.active {
    color: #000;
    background: var(--accent);
}

.sticky-nav {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    z-index: 1000;
    background-color: #121212;
    border-top: none !important;
    border-bottom: none !important;
    padding: 0 !important;
    margin: 0;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

/* ==========================================
   DESKTOP CONTROL LAYOUT
   ========================================== */

.header-controls > div {
    display: flex !important;
    flex-wrap: nowrap !important;
    flex-direction: row !important;
    justify-content: center !important;
    align-items: center !important;
    gap: 10px !important;
    width: 100% !important;
    height: auto !important; 
}

#searchType,
#categoryInput {
    min-width: 120px;
}

#categoryInput, 
#sortInput {
    height: 45px !important; 
    min-height: 45px !important;
    max-height: 45px !important;
    box-sizing: border-box !important;
    margin: 0 !important;
}

/* ==========================================
   BOOK VIEW PROFILE PAGE (details.html)
   ========================================== */

.page-wrapper {
    max-width: 900px;
    margin: -10px auto 0 auto;
    padding: 0 0px 10px 0px;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    background: #1e1e1e;
    padding: 15px 10px 30px 10px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

.top-container {
    display: flex; 
    gap: 30px; 
    flex-wrap: wrap; 
    margin-bottom: 30px;
    align-items: flex-start;
}

.details-box {
    flex: 1; 
    min-width: 300px; 
    background: #282828; 
    padding: 15px 20px; 
    border-radius: 8px; 
    border: 1px solid #414141;
    display: flex; 
    flex-direction: column;
}

.image-box {
    flex: 0 0 300px; 
    max-width: 100%;
}

.image-box img {
    width: 100%; 
    display: block; 
    border-radius: 8px; 
    box-shadow: 0 8px 25px rgba(0,0,0,0.6);
    margin-bottom: 0px !important;
}

.notes-section {
    margin-top: 15px;
    padding: 20px;
    background: #282828;
    border-radius: 8px;
    font-size: 1.0em;
    color: #ccc;
    border: 1px solid #414141;
}

.loading {
    text-align: center;
    padding: 50px;
    font-style: italic;
    color: #888;
}


/* Fixes the desktop and layout alignment for the Book Title and Author headers */
.book-title h1, 
.book-title h2,
.details-page h1,
.details-page h2 {
    text-align: left !important;
    margin-left: 20px !important; 
    padding-left: 0 !important;
}

.book-title h1,
.details-page h1 {
    margin-bottom: 2px !important;
    margin-top: -5px !important;
    color: #FFCC01 !important; /* Premium Cricket Gold */
}

.book-title h2,
.details-page h2 {
    margin-top: 0 !important;
    color: #eee !important;
}

/* ==========================================
   DYNAMIC RESPONSIVE MEDIA QUERIES
   ========================================== */

/* Universal Header Alignment for Desktop Profile Headers */
@media screen and (min-width: 601px) {
    h1 {
        --mobile-gate: 0px !important;
    }
    
    .book-detail h1, #bookDetail h1 {
        text-align: left !important;
        margin-left: 20px !important;
        margin-top: 15px !important;
        display: block !important;
    }

    .book-detail h2, #bookDetail h2 {
        text-align: left !important;
        margin-left: 20px !important;
        margin-top: 0 !important;
    }
}

/* Mobile & Smart Devices (Under 600px breakpoint) */
@media screen and (max-width: 600px) {
    h1 {
        --mobile-gate: 20px !important;
        margin-top: -5px !important;
        margin-bottom: 0px !important;
    }
    
    h2 {
        margin-bottom: -10px !important;
    }

    body {
        padding-top: 14px !important;
    }

    .header-controls {
        padding-top: 0 !important;
    }

    .mobile-column {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        width: 100%;
        padding: 0 10px;
        box-sizing: border-box;
    }

    .controls-row {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        width: 100%;
        gap: 5px;
        box-sizing: border-box;
        margin: 0 !important;
        padding: 0 !important;
    }

    input[type="text"], select {
        margin: 0 !important;
    }

    .header-controls > div {
        padding: 0 !important;
        display: flex !important;
        flex-wrap: nowrap !important;
        flex-direction: row !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 10px !important;
        width: 100% !important;
        height: auto !important;
    }

    /* Input Element Responsive Scaling Rules */
    .search-wrapper {
        width: 100% !important;
        max-width: none !important;
        flex: 1 !important;
        height: 45px !important;
    }

    #searchInput {
        width: 100% !important;
    }

    #searchType,
    #categoryInput,
    #sortInput {
        flex: 1 !important;
        width: 0 !important;
        min-width: 0 !important;
        height: 45px !important;
    }

    #resetBtn {
        flex-shrink: 0 !important;
        width: 90px !important;
        margin-top: 0 !important;
    }

    /* Mobile 3-Column Card Architecture */
    #bookGrid, .grid-container {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important; 
        gap: 8px !important; 
        padding: 10px !important;
    }

    .book-card img {
        width: 100% !important;
        height: auto !important;
        border-radius: 4px !important; 
    }

    .card-content {
        font-size: 11px !important; 
        line-height: 1.2 !important;
    }

    /* Safe Sticky Boundary Execution For Filter Views */
    div[class*="header"], 
    .search-wrapper, 
    .sticky-header {
        position: static !important;
    }

    #alphabetRow {
        position: -webkit-sticky !important;
        position: sticky !important;
        top: 0 !important;
        z-index: 9999 !important;
        background-color: #121212 !important;
        display: block !important;
    }

    /* Mobile Stack & Space Logic for Details Page */
    .top-container {
        display: grid !important;
        grid-template-columns: 100% !important;
        row-gap: 0px !important; 
        margin-left: -10px !important;
        margin-right: -10px !important;
    }

    .image-box {
        width: calc(100% - 24px) !important;
        margin: -8px 12px 10px 12px !important; 
        order: 1 !important;
        background-color: var(--card-bg) !important; 
        border-radius: 12px !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        padding: 15px 0 !important; 
        height: auto !important;
        min-height: 0 !important;
    }

    .image-box img {
        max-width: 85% !important; 
        max-height: 400px !important; 
        width: auto !important;
        height: auto !important;
        display: block !important;
        border-radius: 8px;
        box-shadow: 0 8px 25px rgba(0,0,0,0.6);
        object-fit: contain;
    }

    .details-box {
        width: calc(100% - 24px) !important; 
        margin: -5px 12px 0 12px !important;
        box-sizing: border-box;
        order: 2 !important;
    }

    .notes-section {
        width: calc(100% - 5px) !important;
        margin: 15px -5px 0 3px !important;
        box-sizing: border-box;
    }

    .container {
        margin: 0 -1px 0 -7px !important;
    }
}