:root {
    --bg-color: #2a2a2a; /* Dark Sumi-e Ink Stone */
    --text-color: #f0f0f0; /* Off-white text for contrast */
    --accent-color: #cf4545; /* Richer Vermilion */
    --page-bg: #fdfbf7;
    --page-text: #2c2c2c; /* Keep page text dark on light pages */
    --cover-bg: #4a3728;
    --cover-leather: #5c4033;
    --sidebar-bg: #161616; /* Darker, near black */
    --sidebar-text: #888;
    --sidebar-hover: #333;
    --sidebar-active: #fff;
}

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

body {
    font-family: 'Noto Sans JP', sans-serif;
    background-color: var(--bg-color);
    /* Subtle noise texture */
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.03'/%3E%3C/svg%3E");
    color: var(--text-color);
    height: 100vh;
    display: flex;
    margin: 0;
    overflow: hidden;
}

/* Sidebar Styles - Minimal Japanese Aesthetic */
.sidebar {
    width: 240px; /* Slightly wider for breathing room */
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    height: 100vh;
    display: flex;
    flex-direction: column;
    border-right: none;
    z-index: 100;
    box-shadow: 4px 0 15px rgba(0,0,0,0.1); /* Soft shadow instead of border */
}

.sidebar-header {
    padding: 2rem 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2 {
    font-family: 'Noto Serif JP', serif; /* Serif for the title */
    font-size: 1rem;
    font-weight: 300;
    color: #fff;
    margin: 0;
    letter-spacing: 2px; /* Wide tracking */
    text-transform: uppercase;
}

/* Sidebar toggle button */
.sidebar-toggle {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.1);
    color: #8e8ea0;
    cursor: pointer;
    padding: 6px;
    border-radius: 50%; /* Circular button */
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    width: 32px;
    height: 32px;
}

.sidebar-toggle:hover {
    background: #fff;
    color: #000;
    border-color: #fff;
}

/* Sidebar collapsed state */
.sidebar.collapsed {
    width: 0;
    padding: 0;
    overflow: hidden;
    border-right: none;
}

/* Sidebar open button (shown when sidebar is hidden) */
.sidebar-open-btn {
    position: fixed;
    top: 20px;
    left: 20px;
    background: var(--text-color);
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 10px;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease;
    z-index: 101;
    width: 40px;
    height: 40px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.sidebar-open-btn:hover {
    transform: scale(1.1);
    background: #000;
}

.sidebar-open-btn.visible {
    display: flex;
}

/* Smooth transition for sidebar */
.sidebar {
    transition: width 0.4s cubic-bezier(0.16, 1, 0.3, 1), padding 0.4s ease; /* Custom easing */
}

.book-list {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 1.5rem; /* More padding */
}

.book-item {
    padding: 0.8rem 0;
    cursor: pointer;
    transition: all 0.3s ease;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03); /* Very subtle separators */
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 0.8rem;
    font-weight: 300;
    color: var(--sidebar-text);
    margin-bottom: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 0.5px;
    position: relative;
    padding-left: 0; /* Reset padding */
}

.book-item:hover {
    background: transparent; /* No background change */
    color: #fff;
    padding-left: 10px; /* Slide effect */
}

.book-item.active {
    background: transparent;
    color: #fff;
    font-weight: 500;
    padding-left: 10px;
}

/* active indicator line */
.book-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 4px;
    background-color: var(--accent-color);
    border-radius: 50%;
}

/* Main Content Area */
.main-content {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    height: 100%;
    justify-content: center;
    perspective: 1500px;
}

/* Journal title above book */
.journal-title {
    font-family: 'Noto Serif JP', serif;
    font-size: 1.1rem;
    font-weight: 400;
    color: #888;
    text-align: center;
    margin: 0 0 1rem 0;
    letter-spacing: 2px;
}

.book-wrapper {
    margin-bottom: 0.5rem;
    padding: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.3s ease;
}

.book-wrapper.loading {
    opacity: 0;
}

/* Hide raw pages before PageFlip transforms them */
#book > .page {
    visibility: hidden;
}

/* Show pages once PageFlip wraps them */
.stf__parent .page,
.stf__item {
    visibility: visible !important;
}

/* Page Styles */
.page {
    background-color: var(--page-bg);
    color: var(--page-text);
    /* Remove border, use subtle shadow for depth */
    box-shadow: inset 0 0 20px rgba(0,0,0,0.05);
    overflow: hidden;
    /* Ensure pointer events work for clicking */
    pointer-events: auto; 
}

/* Remove any special active states that cause weird shadows */
.page.-active {
    box-shadow: inset 0 0 20px rgba(0,0,0,0.05);
}

/* Ensure cover pages don't have weird shadows */
.cover-front.-active,
.cover-back.-active {
    box-shadow: inset 0 0 20px rgba(0,0,0,0.05);
}

.page-content {
    width: 100%;
    height: 100%;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    position: relative;
}

/* Cover Styles - Light parchment matching inside cover */
.cover-front, .cover-back {
    background: #f5f0e1;
    background-image:
        /* Subtle aged paper texture */
        url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='paper'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.04' numOctaves='5' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23paper)' opacity='0.03'/%3E%3C/svg%3E");
    color: #555;
    /* Remove border, use shadow */
    box-shadow: inset 0 0 30px rgba(139, 119, 87, 0.2); 
}

.cover-front .page-content, .cover-back .page-content {
    justify-content: center;
    align-items: center;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.08);
    margin: 20px;
    height: calc(100% - 40px);
    width: calc(100% - 40px);
    background: transparent;
}

.cover-front h2, .cover-back h2 {
    font-family: 'Noto Serif JP', serif;
    font-size: 2.5rem;
    color: #333;
    margin-bottom: 0.75rem;
    letter-spacing: 1px;
    font-weight: 700;
}

.cover-front p {
    font-family: 'Noto Sans JP', sans-serif;
    font-weight: 400;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
    color: #666;
}

.cover-back h3 {
    font-family: 'Noto Serif JP', serif;
    font-size: 1.8rem;
    color: #333;
}

.decoration {
    width: 40px;
    height: 1px;
    background: linear-gradient(90deg, 
        transparent 0%, 
        #8e8ea0 20%, 
        #8e8ea0 80%, 
        transparent 100%);
    margin-top: 1.5rem;
}

/* Interior Page Styles */
.page-header {
    text-align: center;
    border-bottom: 1px solid #ddd;
    padding-bottom: 1rem;
    margin-bottom: 1rem;
}

.page-header h3 {
    font-family: 'Noto Serif JP', serif;
    font-size: 1.3rem;
    color: #333;
    font-weight: 600;
}

.page-text p, .page-text ul, .page-text li {
    font-family: 'Noto Serif JP', serif;
    font-size: 0.9rem;
    line-height: 1.7;
    letter-spacing: 0.3px;
}

.page-text p {
    margin-bottom: 1rem;
}

.page-text ul {
    margin-left: 2rem;
    margin-bottom: 1rem;
    list-style-type: none; /* Remove default bullets */
}

.page-text li {
    position: relative;
    margin-bottom: 0.5rem;
    padding-left: 1.5rem;
}

.page-text li::before {
    content: "•"; /* Custom bullet */
    color: var(--accent-color);
    position: absolute;
    left: 0;
    font-size: 1.2em;
    line-height: 1.4;
}

.page-image-placeholder {
    width: 100%;
    height: 150px;
    background-color: #eee;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #888;
    margin: 1rem 0;
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
}

.page-footer {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 0.7rem;
    color: #aaa;
}

/* Controls */
.controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
    z-index: 10;
}

.controls p {
    display: none; /* Hide the text instruction */
}

button {
    background: transparent;
    border: 2px solid #888;
    color: #888;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-family: 'Noto Sans JP', sans-serif;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
}

button:hover {
    background: #888;
    color: #fff;
    border-color: #888;
}

/* New styles for inside covers - aged parchment look */
.page.inside-cover {
    background-color: #f5f0e1;
    background-image: 
        /* Subtle aged paper texture */
        url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='paper'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.04' numOctaves='5' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23paper)' opacity='0.03'/%3E%3C/svg%3E");
    box-shadow: inset 0 0 40px rgba(139, 119, 87, 0.15);
}

/* Error message styling */
.error {
    padding: 2rem;
    text-align: center;
    color: #c0392b;
    font-family: 'Noto Sans JP', sans-serif;
}

/* Markdown content styling */
.page-text h1, .page-text h2, .page-text h3, .page-text h4 {
    font-family: 'Noto Serif JP', serif;
    color: #333;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.page-text h1 { font-size: 1.6rem; }
.page-text h2 { font-size: 1.3rem; }
.page-text h3 { font-size: 1.1rem; }
.page-text h4 { font-size: 0.95rem; }

.page-text strong {
    font-weight: 600;
    color: #2c2c2c;
}

.page-text em {
    font-style: italic;
}

.page-text code {
    background: #f0f0f0;
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-family: monospace;
    font-size: 0.9em;
}

.page-text pre {
    background: #f0f0f0;
    padding: 1rem;
    border-radius: 5px;
    overflow-x: auto;
    margin-bottom: 1rem;
}


/* Image styling in book pages */
.page-text img {
    max-width: 80%;
    height: auto;
    max-height: 350px;
    display: block;
    margin: 1rem auto;
    border-radius: 4px;
    object-fit: contain;
}

.page-text p:has(img) {
    text-indent: 0;
    text-align: center;
}

/* Full Screen Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 2000;
    display: none;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background-color: var(--page-bg);
    width: 90%;
    max-width: 800px;
    height: 90vh;
    padding: 3rem;
    overflow-y: auto;
    position: relative;
    border-radius: 4px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    animation: modalFadeIn 0.3s ease;
}

@keyframes modalFadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: transparent;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: #888;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
    z-index: 10;
}

.modal-close:hover {
    color: #333;
    background: transparent;
    border: none;
}

/* Adjust content for modal view */
.modal-content .page-text {
    font-size: 1.2rem; /* Slightly larger text in full screen */
    max-width: 100%;
}

/* Dark mode support for modal if the source page is dark (like covers) */
.modal-content.dark-mode {
    background: var(--sidebar-bg);
    color: #ececec;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-content.dark-mode .page-text,
.modal-content.dark-mode h1,
.modal-content.dark-mode h2,
.modal-content.dark-mode h3, 
.modal-content.dark-mode p {
    color: #ececec;
}

.modal-content.dark-mode .modal-close {
    color: #8e8ea0;
}

.modal-content.dark-mode .modal-close:hover {
    color: #fff;
}

/* Blockquote copy component styles */
.blockquote-wrapper {
    position: relative;
    margin: 1.5rem 0;
    background-color: #fafaf8;
    border: 1px solid #e0ddd9;
    border-radius: 6px;
    padding: 1rem;
}

.blockquote-wrapper blockquote {
    margin: 0;
    padding: 0;
    border: none;
    background-color: transparent;
    font-style: italic;
    color: var(--page-text);
    font-size: 0.95rem;
    line-height: 1.6;
}

.blockquote-copy-btn {
    opacity: 0;
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    padding: 0.25rem 0.5rem;
    background: none;
    border: 1px solid #d0ccc7;
    color: #999;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.65rem;
    font-weight: 500;
    transition: all 0.2s;
    z-index: 10;
}

.blockquote-wrapper:hover .blockquote-copy-btn {
    opacity: 1;
}

.blockquote-copy-btn:hover {
    background-color: #f0ebe5;
    border-color: #999;
    color: var(--page-text);
}

/* Responsive adjustments for tablets */
@media (max-width: 768px) {
    .sidebar {
        width: 180px;
    }
    
    .book-item {
        font-size: 0.75rem;
        padding: 0.4rem 0.6rem;
    }
    
    .cover-front h2 {
        font-size: 1.8rem;
    }
    
    .cover-front p {
        font-size: 0.7rem;
    }
    
    .modal-content {
        padding: 1.5rem;
        width: 95%;
    }
}

/* Mobile-specific styles */
@media (max-width: 600px) {
    body {
        flex-direction: column;
        overflow-x: hidden;
    }
    
    .journal-title {
        font-size: 0.85rem;
        margin-bottom: 0.25rem;
        letter-spacing: 1.5px;
    }
    
    /* Sidebar becomes overlay on mobile */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 280px;
        max-width: 85vw;
        height: 100vh;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
        z-index: 1000;
        box-shadow: 4px 0 20px rgba(0,0,0,0.3);
    }
    
    .sidebar:not(.collapsed) {
        transform: translateX(0);
    }
    
    .sidebar.collapsed {
        transform: translateX(-100%);
        width: 280px;
    }
    
    /* Mobile sidebar backdrop */
    .sidebar::after {
        content: '';
        position: fixed;
        top: 0;
        left: 100%;
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }
    
    .sidebar:not(.collapsed)::after {
        opacity: 1;
        pointer-events: auto;
    }
    
    .sidebar-header {
        padding: 1.5rem 1rem;
    }
    
    .sidebar-header h2 {
        font-size: 0.9rem;
    }
    
    .book-list {
        padding: 1rem;
    }
    
    .book-item {
        font-size: 0.85rem;
        padding: 0.75rem 0;
    }
    
    /* Sidebar open button always visible on mobile */
    .sidebar-open-btn {
        display: flex;
        top: 15px;
        left: 15px;
        width: 44px;
        height: 44px;
        background: var(--sidebar-bg);
        border: 1px solid rgba(255,255,255,0.1);
    }
    
    .sidebar-open-btn.visible,
    .sidebar-open-btn {
        display: flex;
    }
    
    .sidebar:not(.collapsed) + .sidebar-open-btn,
    .sidebar:not(.collapsed) ~ .sidebar-open-btn {
        display: none;
    }
    
    /* Main content adjustments */
    .main-content {
        width: 100%;
        min-height: 100vh;
        padding: 50px 10px 10px 10px;
    }
    
    .container {
        perspective: 1000px;
    }
    
    .book-wrapper {
        padding: 5px;
        margin-bottom: 0;
    }
    
    /* Book and page sizing for mobile */
    #book {
        max-width: 100%;
    }
    
    .page-content {
        padding: 1rem;
    }
    
    .page-header {
        padding-bottom: 0.5rem;
        margin-bottom: 0.5rem;
    }
    
    .page-header h3 {
        font-size: 1rem;
    }
    
    .page-text p, .page-text ul, .page-text li {
        font-size: 0.75rem;
        line-height: 1.5;
    }
    
    .page-text h1 { font-size: 1.2rem; }
    .page-text h2 { font-size: 1rem; }
    .page-text h3 { font-size: 0.9rem; }
    .page-text h4 { font-size: 0.8rem; }
    
    .page-text ul {
        margin-left: 1rem;
    }
    
    .page-text li {
        padding-left: 1rem;
    }
    
    .page-text img {
        max-width: 95%;
        max-height: 200px;
        margin: 0.5rem auto;
    }
    
    .page-footer {
        top: 0.5rem;
        right: 0.75rem;
        font-size: 0.6rem;
    }
    
    /* Cover adjustments */
    .cover-front .page-content, .cover-back .page-content {
        margin: 10px;
        height: calc(100% - 20px);
        width: calc(100% - 20px);
    }
    
    .cover-front h2, .cover-back h2 {
        font-size: 1.4rem;
        margin-bottom: 0.5rem;
    }
    
    .cover-front p {
        font-size: 0.65rem;
    }
    
    .decoration {
        width: 30px;
        margin-top: 1rem;
    }
    
    /* Navigation controls */
    .controls {
        margin-top: 0.25rem;
        gap: 2rem;
        padding: 0 1rem;
    }
    
    .controls button {
        width: 44px;
        height: 44px;
        font-size: 1.3rem;
        border-width: 2px;
    }
    
    /* Modal adjustments */
    .modal-content {
        width: 95%;
        height: 85vh;
        padding: 1rem;
        padding-top: 3rem;
    }
    
    .modal-close {
        top: 0.5rem;
        right: 0.5rem;
        width: 36px;
        height: 36px;
        font-size: 1.5rem;
    }
    
    .modal-content .page-text {
        font-size: 1rem;
    }
    
    /* Blockquote adjustments */
    .blockquote-wrapper {
        padding: 0.75rem;
        margin: 1rem 0;
    }
    
    .blockquote-wrapper blockquote {
        font-size: 0.8rem;
    }
    
    .blockquote-copy-btn {
        opacity: 1;
        font-size: 0.6rem;
        padding: 0.2rem 0.4rem;
    }
    
    /* Code blocks */
    .page-text code {
        font-size: 0.75em;
        padding: 0.15rem 0.3rem;
    }
    
    .page-text pre {
        padding: 0.75rem;
        font-size: 0.7rem;
        overflow-x: auto;
    }
}

/* Extra small devices */
@media (max-width: 380px) {
    .cover-front h2, .cover-back h2 {
        font-size: 1.2rem;
    }
    
    .page-text p, .page-text ul, .page-text li {
        font-size: 0.7rem;
    }
    
    .page-content {
        padding: 0.75rem;
    }
    
    .controls button {
        width: 44px;
        height: 44px;
        font-size: 1.2rem;
    }
}
