:root {
    --primary: #4338ca;
    --primary-dark: #312e81;
    --bg-body: #f1f5f9;
    --bg-shelf: #3e2723;
    /* Dark Wood */
    --font-heading: "Noto Serif JP", serif;
    --font-body: "Noto Sans JP", sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-body);
    color: #333;
}

a {
    text-decoration: none;
    color: inherit;
}

/* Header */
header {
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    padding: 1rem 0;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.header-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.site-brand {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.5rem;
    color: var(--primary);
}

.main-nav ul {
    display: flex;
    gap: 1.5rem;
    list-style: none;
}

.main-nav a {
    font-weight: 500;
    color: var(--text-light);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: inline-block;
    position: relative;
}

.main-nav a:hover {
    color: var(--primary);
}

/* Bookshelf Area */
.library {
    margin: 0 auto;
    /* Removed top margin completely */
    max-width: 900px;
    padding: 0.5rem 1rem 1.5rem;
    /* Minimal top/bottom padding */
    background-color: #fdfbf7;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
}

.shelf-title {
    text-align: center;
    font-family: var(--font-heading);
    font-size: 2rem;
    margin-top: 0;
    /* Remove default browser margin */
    margin-bottom: 0;
    color: #1e293b;
}

.shelf-description {
    text-align: center;
    color: #475569;
    margin-top: 0.2rem;
    /* Ultra tight to title */
    margin-bottom: 0.5rem;
    line-height: 1.6;
    font-size: 1.1rem;
}

/* The Shelf Grid */
.shelf {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 2rem;
    align-items: end;
    border-bottom: 15px solid #8d6e63;
    /* Shelf wood */
    padding-bottom: 0px;
    margin-bottom: 3rem;
}

/* Book Spines */
/* Book Covers (Face-out Display) */
.book {
    height: 300px;
    width: 100%;
    max-width: 210px;
    /* Standard Aspect Ratio */
    border-radius: 2px 6px 6px 2px;
    box-shadow: 2px 5px 15px rgba(0, 0, 0, 0.15);
    display: block;
    /* It's an image block now, not a flex interaction */
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    transition: transform 0.3s, box-shadow 0.3s;
    position: relative;
    cursor: pointer;
    margin: 0 auto;
}

.book:hover {
    transform: translateY(-8px) scale(1.03);
    box-shadow: 0 20px 30px rgba(0, 0, 0, 0.25);
    z-index: 10;
}

/* Specific Book Images */
.book-nishida {
    background-image: url('images/nishida.png');
}

.book-schrodinger {
    background-image: url('images/schrodinger.png');
}

.book-yamamoto {
    background-image: url('images/yamamoto.png');
}

/* Hide text since we have real covers */
.book-title,
.book-author {
    display: none;
}

/* Add a subtle sheen overlay */
.book::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to right, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0) 20%, rgba(0, 0, 0, 0.1) 100%);
    pointer-events: none;
    border-radius: 2px 6px 6px 2px;
}

/* Footer of Library */
.library-footer {
    text-align: center;
    font-size: 0.9rem;
    color: #94a3b8;
    margin-top: 4rem;
}

/* Book TOC Page Styles */
.book-info {
    text-align: center;
}

.book-cover-large img {
    width: 200px;
    border-radius: 4px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    margin-bottom: 1.5rem;
}

.book-detail-title {
    font-family: var(--font-heading);
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.book-detail-author {
    color: var(--text-light);
    margin-bottom: 2rem;
}

.book-progress {
    background: #fff;
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-light);
}

.progress-bar {
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
}

.toc-heading {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    border-bottom: 2px solid var(--border);
    padding-bottom: 0.5rem;
    margin-bottom: 2rem;
}

.chapter-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.chapter-item {
    display: flex;
    align-items: center;
    background: #fff;
    padding: 1.5rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    transition: transform 0.2s, var(--primary) 0.2s;
}

.chapter-item:hover {
    transform: translateX(5px);
    border-color: var(--primary);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}

.chapter-number {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary);
    margin-right: 1.5rem;
    opacity: 0.5;
}

.chapter-content {
    flex-grow: 1;
}

.chapter-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.chapter-meta {
    font-size: 0.8rem;
    color: var(--text-light);
}

.chapter-arrow {
    color: var(--border);
    font-size: 1.5rem;
    margin-left: 1rem;
}

.chapter-item:hover .chapter-arrow {
    color: var(--primary);
}

/* Reading Mode (Single Article) */
.reading-container {
    max-width: 720px;
    /* Optimal reading width */
    margin: 1rem auto 4rem;
    padding: 0 1.5rem;
    font-family: "Noto Serif JP", serif;
    /* Serif for book feel */
    color: #2d3748;
    background-color: #fff;
    /* Paper white */
}

/* Article Header */
.reading-header {
    text-align: center;
    margin-bottom: 0px;
    /* Gapless */
    padding-bottom: 1rem;
    border-bottom: 1px solid #e2e8f0;
}

.reading-breadcrumbs {
    font-family: var(--font-body);
    font-size: 0.8rem;
    color: #94a3b8;
    margin-bottom: 0.5rem;
    /* Reduced from 1.5rem */
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.reading-title {
    font-size: 1.6rem;
    /* Slightly reduced to ensure single line fit */
    font-weight: 700;
    line-height: 1.4;
    margin-bottom: 0.2rem;
    color: #1a202c;
    font-feature-settings: "palt";
}

.reading-meta {
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: #64748b;
}

/* Article Body */
.reading-body {
    font-size: 1.15rem;
    line-height: 2.1;
    text-align: justify;
}

/* Remove ALL vertical margins from the first element */
.reading-body>*:first-child {
    margin-top: 0 !important;
    margin-bottom: 0 !important;
}

/* General paragraph spacing (applies to subsequent paragraphs) */
.reading-body p {
    margin-bottom: 1rem;
}

.reading-body h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 1rem 0 0.5rem;
    /* Further reduced heading margins */
    padding-bottom: 0.2rem;
    border-bottom: 2px solid var(--primary);
    display: inline-block;
}

/* Blockquote */
.reading-body blockquote {
    background-color: #f8fafc;
    border-left: none;
    padding: 2rem 3rem;
    margin: 3rem 0;
    font-style: italic;
    color: #475569;
    position: relative;
    border-radius: 4px;
}

.reading-body blockquote::before {
    content: "“";
    font-family: serif;
    font-size: 4rem;
    color: #e2e8f0;
    position: absolute;
    top: -10px;
    left: 10px;
    line-height: 1;
}

/* Reading Memo (Note style) */
.reading-memo {
    background-color: #fffbeb;
    /* Post-it yellow/cream */
    border: 1px solid #fcd34d;
    padding: 1.5rem;
    margin: 3rem 0;
    border-radius: 2px;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.05);
    font-family: var(--font-body);
    /* Sans-serif for notes */
    font-size: 0.95rem;
    color: #78350f;
    position: relative;
}

.reading-memo::before {
    content: "📝 MEMO";
    display: block;
    font-weight: 700;
    font-size: 0.8rem;
    margin-bottom: 0.5rem;
    opacity: 0.7;
    border-bottom: 1px dashed #d97706;
    padding-bottom: 0.3rem;
}

/* Footer Navigation */
.reading-footer-nav {
    margin-top: 5rem;
    padding-top: 3rem;
    border-top: 1px solid #e2e8f0;
    text-align: center;
}

.btn-back {
    display: inline-block;
    border: 1px solid #cbd5e1;
    padding: 0.8rem 2rem;
    border-radius: 50px;
    color: #64748b;
    font-family: var(--font-body);
    font-size: 0.9rem;
    transition: all 0.2s;
}

.btn-back:hover {
    border-color: var(--primary);
    color: var(--primary);
    background-color: #f8fafc;
}

/* Extended Click Area for Article Cards */
.article-card {
    position: relative;
    /* establish positioning context */
}

/* Ensure the link covers the entire card */
.article-card a {
    display: flex;
    flex-direction: column;
    height: 100%;
    text-decoration: none;
    color: inherit;
    position: static;
}

.article-card a::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* Ensure inner links (if any, like categories) are still clickable above the card link */
.article-card .article-meta a {
    position: relative;
    z-index: 2;
}

/* Navigation Active/Hover "Up" Effect */
.main-nav a {
    font-weight: 500;
    color: var(--text-light);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: inline-block;
    position: relative;
}

.main-nav a:hover,
.main-nav a.active {
    color: var(--primary);
    transform: translateY(-4px) scale(1.15);
    font-weight: 800;
    text-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}


/* --- Final Refined Navigation UI --- */
.main-nav a {
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) !important;
    display: inline-block !important;
    text-decoration: none !important;
}

.main-nav a:hover,
.main-nav a.active {
    transform: translateY(-5px) scale(1.15) !important;
    font-weight: 800 !important;
    text-shadow: 0 4px 15px rgba(0, 0, 0, 0.1) !important;
}





/* --- New Compact Article List Style --- */
.article-item {
    background: #fff;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    margin-bottom: 0.5rem;
    transition: all 0.2s ease;
    overflow: hidden;
}

.article-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    border-color: var(--primary);
}

.article-item a {
    display: flex;
    align-items: center;
    padding: 1rem 1.5rem;
    text-decoration: none;
    color: inherit;
    gap: 1.5rem;
}

.item-meta-group {
    display: flex;
    flex-direction: column;
    width: 120px;
    flex-shrink: 0;
    text-align: center;
    /* Center for chapter num */
}

.item-meta {
    font-size: 0.8rem;
    color: var(--text-light);
}

.item-logo-row {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 0.25rem;
}

.item-logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    opacity: 0.5;
}

.item-click-hint {
    display: none;
    /* Hide for this compact view if not needed */
}

.item-title-box {
    flex-grow: 1;
}

.item-title-box h3 {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    margin-bottom: 0.25rem;
    line-height: 1.4;
    color: #1e293b;
}

.item-excerpt {
    font-size: 0.9rem;
    color: var(--text-light);
}

@media (max-width: 640px) {
    .article-item a {
        flex-direction: row;
        /* Keep row for chapter num */
        align-items: center;
        gap: 1rem;
    }

    .item-meta-group {
        width: auto;
        margin-right: 0.5rem;
    }

    .item-logo {
        font-size: 1.2rem;
    }
}

/* Single Article Header Styling (Refined) */
.single-post header.bg-styled {
    padding: 1.5rem 2rem;
    background: transparent !important;
    border: none !important;
    margin-bottom: 2rem;
    border-bottom: 1px solid #e2e8f0 !important;
}

.single-post header h1 {
    font-family: var(--font-heading);
    font-size: 1.8rem;
    font-weight: 700;
    margin: 0.5rem 0;
    line-height: 1.4;
    color: #1e293b;
}

.breadcrumb {
    font-size: 0.9rem;
    color: #64748b;
    margin-bottom: 1rem;
}

/* Category/Book Colors */
/* Nishida: Indigo/Purple */
.text-nishida {
    color: #4f46e5;
}

.bg-nishida {
    border-top: 4px solid #4f46e5 !important;
}

/* Schrodinger: Teal/Green */
.text-schrodinger {
    color: #0d9488;
}

.bg-schrodinger {
    border-top: 4px solid #0d9488 !important;
}

/* Yamamoto: Red/Orange */
.text-yamamoto {
    color: #e11d48;
}

.bg-yamamoto {
    border-top: 4px solid #e11d48 !important;
}