/* =========================================================
   db-gallery.css (v1.4 - Full: Header Controls + Infinite Scroll)
   ========================================================= */

/* --- 1. BODY AND LAYOUT --- */
body {
    margin: 0;
    color: var(--ink);
    background: var(--bg-db-deep);
    font-family: "Noto Sans JP", system-ui, sans-serif;
    line-height: 1.6;
    font-size: 16px;
    background-image:
        radial-gradient(1600px 800px at 50% -15%, rgba(255, 214, 170, .15), transparent 60%),
        radial-gradient(1000px 500px at 50% 120%, rgba(255, 230, 170, .12), transparent 60%);
}

:root {
    --book-shadow: 0 8px 16px rgba(0, 0, 0, 0.2), 0 0 10px rgba(0, 0, 0, 0.1);
    --header-accent: #e07a00;
}

/* --- 2. NEW HEADER CONTROLS --- */
/* These styles target the elements moved into header.php */

.header-controls {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-grow: 1;
    justify-content: flex-end; /* Push controls to the right */
    margin-left: 20px;
    max-width: 800px;
}

/* Search Box Styling */
.header-search {
    position: relative;
    flex-grow: 1; /* Expand to fill available space */
    max-width: 400px;
}

.header-search svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--header-accent);
    pointer-events: none;
}

.header-search input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    border: 1px solid #dcd1c3;
    border-radius: 20px;
    font-family: inherit;
    font-size: 0.9rem;
    background: rgba(255, 255, 255, 0.9);
    transition: all 0.2s ease;
}

.header-search input:focus {
    outline: none;
    border-color: var(--header-accent);
    box-shadow: 0 0 0 3px rgba(224, 122, 0, 0.15);
}

/* Switcher Group (Face/Back, Show/Hide) */
.switcher-group {
    display: flex;
    gap: 12px;
    flex-shrink: 0;
}

.ctrl-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid var(--header-accent);
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #5a4943;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ctrl-btn:hover {
    background: rgba(224, 122, 0, 0.1);
}

.ctrl-btn .btn-label {
    opacity: 0.7;
    font-weight: 400;
    font-size: 0.8rem;
}

.ctrl-btn .btn-state {
    color: var(--header-accent);
    font-weight: 700;
}

/* Mobile Header Adjustments */
@media (max-width: 768px) {
    .site-header {
        flex-wrap: wrap;
        gap: 10px;
    }
    .header-controls {
        display: flex;
        width: 100%;
        margin: 10px 0 0;
        justify-content: space-between;
        margin-left: 0;
        max-width: none;
    }
    .header-search {
        max-width: 100%;
        flex-grow: 1;
        margin-right: 10px;
    }
    .switcher-group {
        gap: 8px;
    }
    .ctrl-btn {
        padding: 6px 10px;
    }
    .ctrl-btn .btn-label {
        display: none; /* Save space on mobile */
    }
}

/* --- 3. MAIN LAYOUT --- */
.wrap {
    margin: 30px 0 80px;
    padding: 0 20px;
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 24px;
}

.wrap.sidebar-hidden .category-sidebar {
    display: none;
}

.wrap.sidebar-hidden .grid {
    grid-column: 1 / -1;
}

@media (max-width: 1100px) {
    .wrap {
        grid-template-columns: 1fr;
    }
    .category-sidebar {
        order: -1; /* Move sidebar above grid on tablet */
    }
}

/* --- 4. GRID & CARDS --- */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 22px;
    align-content: start;
    padding-top: 8px;
    transition: all 0.3s ease;
}

@media (max-width: 768px) {
    .grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 16px;
    }
}

/* Card Structure */
.card {
    perspective: 1200px;
    position: relative;
    padding-bottom: 15px;
}

.flip {
    position: relative;
    width: 100%;
    aspect-ratio: 10 / 14;
    border-radius: 4px;
    transform-style: preserve-3d;
    transition: transform 1.2s cubic-bezier(.6, .1, .4, 1);
    box-shadow: var(--book-shadow);
    transform: translateY(0);
    cursor: pointer;
}

.flip:focus {
    outline: 3px solid #efc95a;
    outline-offset: 2px;
}

.card:hover .flip {
    transform: translateY(-2px);
    box-shadow: 0 12px 20px rgba(0, 0, 0, 0.3), 0 0 15px rgba(0, 0, 0, 0.15);
}

.card.active .flip {
    transform: rotateY(180deg);
}

/* Faces */
.face {
    position: absolute;
    inset: 0;
    border-radius: 4px;
    overflow: hidden;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--paper);
    border: 1px solid rgba(0, 0, 0, .2);
    transform: none;
}

.face.front {
    padding: 0;
    transform: translateZ(10px);
}

.face.front img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.card:hover .face.front img {
    transform: scale(1.02);
}

.face.back {
    padding: 16px;
    gap: 10px;
    flex-direction: column;
    text-align: left;
    background: linear-gradient(135deg, var(--paper), #fffaf0);
    transform: rotateY(180deg) translateZ(10px);
}

/* Typography inside Card */
.title {
    font-family: "Noto Serif JP", serif;
    font-weight: 700;
    color: var(--ink);
    font-size: 14px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.face.back .title a {
    color: var(--ink);
    text-decoration: none;
}

.face.back .title a:hover {
    color: var(--header-accent);
    text-decoration: underline;
}

.meta {
    color: var(--ink-soft);
    font-size: 12px;
    line-height: 1.4;
}

.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: auto;
}

.tag {
    font-size: 10px;
    background: #fff0d6;
    color: #7a4d25;
    border: 1px solid rgba(0, 0, 0, .08);
    padding: .2rem .5rem;
    border-radius: 999px;
    font-weight: 500;
}

.actions {
    margin-top: 6px;
    display: flex;
    gap: 8px;
    width: 100%;
}

.actions .btn {
    flex: 1;
    font-size: 12px;
    padding: 6px 10px;
    cursor: pointer;
    border: 0;
    border-radius: 10px;
    font-weight: 600;
    background: linear-gradient(135deg, var(--header-accent), #b85110);
    color: white;
    transition: all 0.2s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .2);
    text-decoration: none;
    text-align: center;
    display: block;
}

.actions .btn:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, .3);
}

.chip {
    font-size: 11px;
    font-weight: 700;
    color: #542f18;
    background: linear-gradient(135deg, #ffe1c8, #ffd5b1);
    border: 1px solid rgba(0, 0, 0, .08);
    padding: .25rem .6rem;
    border-radius: 8px;
    align-self: flex-start;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .1);
}

/* --- 5. SIDEBAR --- */
.category-sidebar {
    background: var(--paper);
    border-radius: 14px;
    padding: 20px;
    box-shadow: var(--shadow-hard);
    height: fit-content;
    position: sticky;
    top: 90px;
    max-height: calc(100vh - 110px);
    overflow-y: auto;
}

.category-sidebar h3 {
    font-family: "Noto Serif JP", serif;
    color: var(--header-accent);
    font-size: 1.1rem;
    margin: 0 0 16px 0;
    padding-bottom: 12px;
    border-bottom: 2px solid rgba(232, 111, 36, .2);
    display: flex;
    align-items: center;
    gap: 8px;
}

.category-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.category-item {
    padding: 8px 12px;
    margin: 4px 0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--ink);
}

.category-item:hover {
    background: rgba(232, 111, 36, .1);
    color: var(--header-accent);
    padding-left: 16px;
}

.category-item.active {
    background: linear-gradient(135deg, var(--header-accent), #b85110);
    color: white;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(232, 111, 36, .3);
}

.category-item.active:hover {
    padding-left: 12px;
}

.category-count {
    font-size: 12px;
    background: rgba(0, 0, 0, .1);
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 600;
}

.category-item.active .category-count {
    background: rgba(255, 255, 255, .3);
}

/* Sidebar Language Selector Section */
.sidebar-lang-section {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px dashed rgba(232, 111, 36, 0.3);
}

.sidebar-lang-section h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    border-bottom: none;
    padding-bottom: 0;
}

.sidebar-select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 8px;
    background-color: #fff;
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--ink);
    cursor: pointer;
    /* Custom Arrow Icon */
    appearance: none; 
    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%23e07a00%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 .7em top 50%;
    background-size: .65em auto;
    padding-right: 1.5em;
}

.sidebar-select:focus {
    border-color: var(--header-accent);
    outline: none;
    box-shadow: 0 0 0 3px rgba(232, 111, 36, .1);
}

/* Scrollbar */
.category-sidebar::-webkit-scrollbar {
    width: 6px;
}
.category-sidebar::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, .05);
    border-radius: 3px;
}
.category-sidebar::-webkit-scrollbar-thumb {
    background: var(--header-accent);
    border-radius: 3px;
}
.category-sidebar::-webkit-scrollbar-thumb:hover {
    background: #b85110;
}

/* --- 6. EMPTY STATE --- */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--paper);
    opacity: 0.8;
    grid-column: 1 / -1;
}
.empty-state svg {
    width: 80px;
    height: 80px;
    margin-bottom: 20px;
    opacity: 0.5;
}

/* --- 7. MODAL --- */
.modal {
    position: fixed;
    inset: 0;
    display: none;
    place-items: center;
    background: rgba(0, 0, 0, .65);
    z-index: 200;
    animation: fadeIn 0.3s ease;
    backdrop-filter: blur(4px);
}
.modal.open { display: grid; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.dialog {
    width: min(960px, 94vw);
    max-height: 90vh;
    overflow: auto;
    background: var(--paper);
    border-radius: 18px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
    display: grid;
    grid-template-columns: 300px 1fr;
    position: relative;
    animation: slideUp 0.4s cubic-bezier(.2, .7, .2, 1);
}
@keyframes slideUp { from { transform: translateY(60px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.dialog .cover { padding: 20px; }
.dialog .cover img { width: 100%; height: auto; border-radius: 12px; box-shadow: var(--shadow-hard); }
.dialog .body { padding: 20px 24px 28px; overflow-y: auto; }
.dialog h3 { margin: 6px 0 16px; font-family: "Noto Serif JP", serif; color: var(--header-accent); font-size: 1.5rem; line-height: 1.4; }

.close {
    position: absolute;
    right: 16px;
    top: 16px;
    border: 0;
    background: rgba(0, 0, 0, .6);
    color: #fff;
    font-size: 28px;
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    line-height: 1;
    padding: 0;
}
.close:hover { background: rgba(0, 0, 0, .8); transform: rotate(90deg); }

@media (max-width: 800px) {
    .dialog { grid-template-columns: 1fr; max-height: 85vh; }
    .dialog .cover { max-width: 250px; margin: 0 auto; }
}

/* --- 8. SINGLE POST VIEW --- */
.single-dict-wrap { max-width: 1200px; margin: 40px auto; padding: 0 20px; }
.single-dict-entry { background: var(--paper); border-radius: var(--radius-main); padding: 40px; box-shadow: var(--shadow-hard); }
.entry-header { margin-bottom: 32px; padding-bottom: 24px; border-bottom: 2px solid rgba(232, 111, 36, .2); }
.entry-title { font-family: "Noto Serif JP", serif; color: var(--header-accent); font-size: 2rem; margin: 0 0 16px 0; line-height: 1.4; }
.entry-meta { display: flex; flex-wrap: wrap; gap: 20px; font-size: 14px; color: var(--ink-soft); }
.entry-meta span { display: flex; align-items: center; gap: 6px; }
.dict-details-grid { display: grid; grid-template-columns: 320px 1fr; gap: 40px; margin-bottom: 32px; }
@media (max-width: 800px) { .dict-details-grid { grid-template-columns: 1fr; } .dict-cover { max-width: 300px; margin: 0 auto; } }
.dict-cover img { width: 100%; height: auto; border-radius: 12px; box-shadow: var(--shadow-hard); }
.dict-details-list { display: grid; grid-template-columns: 120px 1fr; gap: 16px; margin: 0; }
.dict-details-list dt { color: #6b4a33; font-weight: 600; }
.dict-details-list dd { margin: 0; color: var(--ink); }
.dict-tags { margin-top: 24px; padding-top: 16px; border-top: 1px solid rgba(0, 0, 0, .1); }
.dict-tags strong { display: block; margin-bottom: 8px; color: #6b4a33; }
.entry-footer { padding-top: 24px; border-top: 1px solid rgba(0, 0, 0, .1); }
.back-to-archive { display: inline-flex; align-items: center; gap: 8px; color: var(--header-accent); text-decoration: none; font-weight: 600; transition: all 0.2s ease; }
.back-to-archive:hover { color: #b85110; transform: translateX(-4px); }

/* --- 9. FOOTER --- */
.site-footer { margin: 40px 0 40px; padding: 20px; color: #ffe9c4; text-align: center; font-size: 14px; border-top: 1px solid rgba(255, 255, 255, .1); background-color: var(--bg-db-deep) !important; }
.site-footer .footer-nav a { color: #ffe9c4 !important; }
.site-footer .footer-nav a:hover { color: #efc95a !important; background: none !important; text-decoration: underline; }
.site-footer .copyright { color: #ffe9c4 !important; opacity: 0.8; }

/* --- 10. WIDGETS --- */
.sidebar-widget-content ul { list-style: none; padding-left: 0; margin: 0; }
.sidebar-widget-content li { margin: .45rem 0; }
.sidebar-widget-content li a { color: var(--ink); text-decoration: none; font-size: 14px; }
.sidebar-widget-content li a:hover { color: var(--header-accent); text-decoration: underline; }