:root {
    /* Ivory Paper Palette */
    --bg-page: #EAE6DF;
    --bg-card: #FDFCF8;
    --text-main: #2C2A26;
    --text-muted: #6B6862;
    --accent-primary: #8C4434;
    /* Muted Terracotta */
    --accent-secondary: #566D64;
    /* Muted Sage */
    --border-color: #D4D0C5;

    /* Typography */
    --font-heading: 'Noto Serif JP', 'Playfair Display', Georgia, serif;
    --font-body: 'Lora', 'Palatino Linotype', serif;

    /* Layout */
    --max-width: 900px;
}

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

body {
    background-color: var(--bg-page);
    color: var(--text-main);
    font-family: var(--font-body);
    line-height: 1.7;
    overflow-x: hidden;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    /* Subtle paper 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.05'/%3E%3C/svg%3E");
}

/* Navigation (Glassmorphism Sticky Bar) */
.navbar {
    padding: 1.5rem 2rem;
    background: rgba(234, 230, 223, 0.85);
    /* Ivory base with transparency */
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(212, 208, 197, 0.5);
    /* Subtle border */
    position: sticky;
    top: 0;
    z-index: 100;
    transition: all 0.3s ease;
}

.nav-content {
    max-width: var(--max-width);
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-family: var(--font-heading);
    font-size: 1.6rem;
    font-style: italic;
    font-weight: 600;
    text-decoration: none;
    color: var(--text-main);
    letter-spacing: 0.02em;
}

.nav-links a {
    color: var(--text-muted);
    font-family: var(--font-body);
    text-decoration: none;
    margin-left: 2rem;
    font-size: 0.95rem;
    transition: color 0.3s ease;
}

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

/* Layout Container */
.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 2rem;
    flex: 1;
    width: 100%;
}

/* Hero Section */
.hero {
    text-align: center;
    padding: 6rem 0 5rem;
    max-width: 700px;
    margin: 0 auto;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 4rem;
}

.hero-title-img {
    width: 100%;
    max-width: 600px;
    height: auto;
    margin-bottom: 0.5rem;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.1));
    /* Optional shadow for depth */
}

/* User's custom span color */
.title span {
    color: rgb(51, 47, 47);
}

.subtitle {
    font-size: 1.25rem;
    font-style: italic;
    color: var(--text-muted);
    font-weight: 400;
    max-width: 600px;
    margin-inline: auto;
}

/* Stories Grid */
.stories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 3rem;
    padding-bottom: 6rem;
}

/* Story Card */
.story-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    /* Added rounded corners */
    padding: 2.5rem;
    position: relative;
    box-shadow: inset 8px 0 16px -8px rgba(0, 0, 0, 0.06), 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    transition: transform 0.5s ease, box-shadow 0.5s ease, opacity 0.5s ease;
    /* Ensure opacity is transitioned */
    display: flex;
    flex-direction: column;
    height: 100%;
}

.story-card:hover {
    transform: translateY(-6px);
    /* Stronger lift */
    box-shadow: 0 15px 30px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -3px rgba(0, 0, 0, 0.04);
    /* More elegant, diffused shadow */
    border-color: rgba(140, 68, 52, 0.3);
    /* Subtle hint of primary accent in the border */
}

.story-tag {
    font-family: var(--font-body);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--accent-secondary);
    font-weight: 600;
    margin-bottom: 1.5rem;
    display: inline-block;
    border-bottom: 1px solid var(--accent-secondary);
    padding-bottom: 0.25rem;
}

.story-title {
    font-family: var(--font-heading);
    font-size: 1.8rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-main);
    line-height: 1.2;
}

.story-excerpt {
    color: var(--text-muted);
    font-size: 1rem;
    margin-bottom: 2.5rem;
    flex-grow: 1;
    line-height: 1.6;
}

.read-more {
    font-family: var(--font-body);
    font-style: italic;
    font-size: 1.05rem;
    color: var(--accent-primary);
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    text-align: left;
    transition: opacity 0.3s ease;
    display: inline-block;
}

.read-more::after {
    content: '';
    display: block;
    width: 0;
    height: 1px;
    background: var(--accent-primary);
    transition: width 0.3s ease;
    margin-top: 2px;
}

.story-card:hover .read-more::after {
    width: 100%;
}

/* About Section */
.about-section {
    padding: 6rem 0;
    margin-top: 2rem;
    border-top: 1px solid var(--border-color);
    position: relative;
    /* Very subtle organic vignette gradient for the bottom */
    background: radial-gradient(circle at center, transparent 0%, rgba(212, 208, 197, 0.15) 100%);
}

.about-content {
    max-width: 700px;
    margin: 0 auto;
    text-align: center;
}

.about-section h2 {
    font-family: var(--font-heading);
    font-size: 2.25rem;
    color: var(--text-main);
    margin-bottom: 2rem;
    font-weight: 600;
}

.about-text {
    font-family: var(--font-body);
    font-size: 1.15rem;
    color: var(--text-muted);
    line-height: 1.8;
}

.about-text p {
    margin-bottom: 1.5rem;
}

.about-text p:last-child {
    margin-bottom: 0;
}

/* Footer */
.footer {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: auto;
    font-family: var(--font-body);
}

/* Responsive */
@media (max-width: 768px) {
    .hero {
        padding: 4rem 0 3rem;
    }

    .stories-grid {
        grid-template-columns: 1fr;
    }

    .modal-content {
        width: 100%;
        height: 100vh;
        border-radius: 0;
        padding: 2rem 1.5rem;
    }
}

/* Story Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(44, 42, 38, 0.4);
    /* Muted slate/brown backdrop */
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--bg-card);
    width: 100%;
    max-width: 700px;
    /* Better measure for reading */
    height: 95vh;
    border-radius: 8px;
    /* Rounded corners */
    /* Book corner */
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25), inset 16px 0 32px -16px rgba(0, 0, 0, 0.08);
    /* Spine fold */
    position: relative;
    overflow-y: auto;
    padding: 3rem 4.5rem 5rem;
    transform: translateY(20px);
    transition: transform 0.5s cubic-bezier(0.165, 0.84, 0.44, 1);
    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.05'/%3E%3C/svg%3E");
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: flex-end;
    position: sticky;
    top: 0;
    background: linear-gradient(to bottom, var(--bg-card) 70%, transparent);
    padding: 1.5rem 0 1.5rem;
    z-index: 10;
    margin-top: -3rem;
    /* Offset the 3rem padding of the modal content */
}

.close-modal {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: var(--font-body);
    font-size: 0.95rem;
    cursor: pointer;
    font-style: italic;
    transition: color 0.3s ease;
}

.close-modal:hover {
    color: var(--accent-primary);
}

/* Elegant Markdown Typography */
.markdown-body {
    color: var(--text-main);
    font-family: var(--font-body);
    font-size: 1.15rem;
    line-height: 1.8;
}

.markdown-body h1 {
    font-family: var(--font-heading);
    font-size: 3rem;
    font-weight: 700;
    margin-top: 1rem;
    margin-bottom: 2rem;
    color: var(--text-main);
    line-height: 1.1;
    text-align: center;
}

.markdown-body h2 {
    font-family: var(--font-heading);
    font-size: 2rem;
    font-weight: 600;
    margin-top: 2.5em;
    margin-bottom: 1em;
    color: var(--accent-secondary);
}

.markdown-body p {
    margin-bottom: 1.5em;
    text-indent: 0;
    text-align: justify;
    hyphens: auto;
}

.markdown-body p:last-of-type {
    margin-bottom: 2em;
}

/* Drop cap images */
.drop-cap-img {
    float: left;
    height: 110px;
    width: auto;
    margin-right: 15px;
    margin-bottom: 5px;
    margin-top: 5px;
}

.markdown-body ul,
.markdown-body ol {
    margin-bottom: 2em;
    padding-left: 2em;
}

.markdown-body li {
    margin-bottom: 0.5em;
}

.markdown-body blockquote {
    border-left: none;
    padding-left: 2em;
    margin: 2em 0;
    font-style: italic;
    color: var(--accent-secondary);
    position: relative;
}

.markdown-body blockquote::before {
    content: "“";
    font-family: var(--font-heading);
    font-size: 4rem;
    position: absolute;
    left: -0.5rem;
    top: -1.5rem;
    color: rgba(86, 109, 100, 0.2);
}

.markdown-body strong {
    font-weight: 600;
}

/* Footnotes */
.markdown-body .footnotes {
    margin-top: 4rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.95rem;
    color: var(--text-muted);
}

.markdown-body .footnotes ol {
    margin-bottom: 0;
    padding-left: 1.5em;
}

.markdown-body .footnotes li {
    margin-bottom: 0.75rem;
}

.loading,
.error-msg {
    text-align: center;
    padding: 4rem;
    font-style: italic;
    color: var(--text-muted);
}

/* Custom Webkit Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-page);
}

::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background-color: var(--accent-secondary);
}