/* Reset & Base */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #E8EDE9;
    --bg-secondary: #DFE5E0;
    --surface: #FFFFFF;
    --accent: #8B7D6B;
    --accent-dark: #5C4F3D;
    --accent-light: #A89B8C;
    --accent-bg: rgba(139, 125, 107, 0.1);
    --text-primary: #5C4F3D;
    --text-secondary: #8B7D6B;
    --text-tertiary: #A0ADB8;
    --border: #DDD5CA;
    --shadow-card: 0 4px 20px rgba(92, 79, 61, 0.08);
    --shadow-card-hover: 0 8px 30px rgba(92, 79, 61, 0.14);
    --shadow-nav: 0 4px 24px rgba(92, 79, 61, 0.1);
    --nav-bg: rgba(232, 237, 233, 0.85);
    --radius-card: 12px;
    --radius-pill: 100px;
}

[data-theme="dark"] {
    --bg: #1A1815;
    --bg-secondary: #222018;
    --surface: #2A2721;
    --accent: #C4B59A;
    --accent-dark: #E0D5C0;
    --accent-light: #8A7E6D;
    --accent-bg: rgba(196, 181, 154, 0.1);
    --text-primary: #E0D8CC;
    --text-secondary: #9B917F;
    --text-tertiary: #5A5347;
    --border: #3A352D;
    --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-card-hover: 0 8px 30px rgba(0, 0, 0, 0.5);
    --shadow-nav: 0 4px 24px rgba(0, 0, 0, 0.4);
    --nav-bg: rgba(26, 24, 21, 0.88);
}

html, body { height: 100%; overflow: hidden; }

body {
    font-family: 'Geist', -apple-system, BlinkMacSystemFont, 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    transition: background 0.4s, color 0.4s;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: url('assets/bg-lake.png') center/cover no-repeat;
    z-index: -2;
    pointer-events: none;
}

body::after {
    content: '';
    position: fixed;
    inset: 0;
    background: var(--bg);
    opacity: 0.78;
    z-index: -1;
    pointer-events: none;
    transition: background 0.4s, opacity 0.4s;
}

[data-theme="dark"] body::after { opacity: 0.82; }

.app-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* =============================================
   FLOATING THEME TOGGLE - top right
   ============================================= */
.theme-btn-float {
    position: fixed;
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    border-radius: 20px;
    background: var(--nav-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-nav);
    transition: all 0.3s;
    z-index: 200;
}

.theme-btn-float:hover {
    color: var(--accent);
    border-color: var(--accent);
}

.theme-btn-float .icon-sun, .theme-btn-float .icon-moon { width: 18px; height: 18px; }
.theme-btn-float .icon-sun { display: none; }
.theme-btn-float .icon-moon { display: block; }
[data-theme="dark"] .theme-btn-float .icon-sun { display: block; }
[data-theme="dark"] .theme-btn-float .icon-moon { display: none; }

/* =============================================
   CALENDAR STRIP
   ============================================= */
.calendar-strip {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    z-index: 10;
    padding: 8px 0 12px;
    background: var(--nav-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
}

.calendar-strip::-webkit-scrollbar { display: none; }

.calendar-track {
    display: flex;
    gap: 6px;
    padding: 0 24px;
    width: max-content;
    margin: 0 auto;
}

.cal-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 52px;
    height: 64px;
    border: none;
    border-radius: 14px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    font-family: inherit;
    padding: 6px 8px;
}

.cal-cell:hover { background: var(--bg-secondary); }

.cal-cell.selected {
    background: var(--accent);
    color: var(--bg);
    box-shadow: 0 2px 12px rgba(139, 125, 107, 0.25);
}

[data-theme="dark"] .cal-cell.selected { box-shadow: 0 2px 12px rgba(196, 181, 154, 0.15); }

.cal-cell.future { color: var(--text-tertiary); opacity: 0.5; cursor: pointer; }
.cal-cell.future.selected { opacity: 1; color: var(--bg); }
.cal-cell.no-data { opacity: 0.4; }

.cal-weekday { font-size: 0.6rem; font-weight: 600; letter-spacing: 0.5px; line-height: 1; }
.cal-day { font-size: 1.1rem; font-weight: 700; line-height: 1; }

.cal-today-dot {
    width: 4px; height: 4px; border-radius: 50%;
    background: var(--accent);
    position: absolute; bottom: 5px;
}

.cal-cell.selected .cal-today-dot { background: var(--bg); }

/* =============================================
   CONTENT AREA
   ============================================= */
.content-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 24px 60px;
    transition: opacity 0.25s ease;
}

.content-area.fade-out { opacity: 0; }

/* =============================================
   HOURGLASS OVERLAY
   ============================================= */
.hourglass-overlay {
    display: none;
    position: absolute;
    inset: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 5;
    padding: 24px;
}

.hourglass-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

#gravityClockCanvas { display: block; margin: 0 auto; }

.hourglass-label {
    font-size: 0.85rem; font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase; letter-spacing: 1px;
}

.hourglass-countdown {
    font-family: 'Noto Serif SC', 'Georgia', serif;
    font-size: 2.8rem; font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 4px; line-height: 1;
}

.hourglass-hint {
    font-size: 0.8rem; color: var(--text-tertiary);
    text-align: center; max-width: 260px; line-height: 1.5;
}

/* =============================================
   BOOK SPREAD — 3D unfold interaction
   ============================================= */
.book-spread {
    perspective: 1200px;
    width: 180px;
    height: 270px;
    position: relative;
    margin: 0 auto 32px;
    cursor: pointer;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1),
                height 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
}

.book-spread.open {
    width: 400px;
}

.book-3d {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
}

/* Inner pages */
.book-pages {
    position: absolute;
    inset: 0;
    display: flex;
    border-radius: 4px;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.3s ease 0.1s;
}

.book-spread.open .book-pages {
    opacity: 1;
}

.book-page-left, .book-page-right {
    flex: 1;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    color: #FFFFFF;
    overflow: hidden;
}

.book-page-left {
    border-right: 1px solid rgba(0,0,0,0.1);
    box-shadow: inset -8px 0 12px rgba(0,0,0,0.08);
    align-items: center;
    text-align: center;
}

.book-page-right {
    box-shadow: inset 8px 0 12px rgba(0,0,0,0.08);
    position: relative;
    align-items: center;
    text-align: center;
    padding-top: 40px;
}

/* Page content styles */
.book-page-left .tag {
    display: inline-block;
    font-size: 0.6rem;
    font-weight: 600;
    color: rgba(255,255,255,0.9);
    background: rgba(255,255,255,0.15);
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    margin-bottom: 8px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.book-page-left .book-title {
    font-family: 'Noto Serif SC', 'Georgia', serif;
    font-size: 1.1rem;
    font-weight: 600;
    color: #FFFFFF;
    margin-bottom: 4px;
    line-height: 1.3;
}

.book-page-left .book-author {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.8);
    margin-bottom: 8px;
}

.book-page-left .book-desc {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.7);
    line-height: 1.5;
}

/* Quote decoration */
.book-page-right .quote-decoration {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255,255,255,0.25);
}

.book-page-right .quote-decoration svg {
    width: 32px;
    height: 32px;
}

.book-page-right .quote-text {
    font-family: 'Caveat', cursive;
    font-size: 1.2rem;
    font-weight: 500;
    line-height: 1.4;
    margin-bottom: 12px;
    color: #FFFFFF;
}

.book-page-right .quote-source {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.8);
    font-style: italic;
}

/* Book cover (the flipping part) */
.book-cover {
    position: absolute;
    width: 180px;
    height: 100%;
    left: 0;
    top: 0;
    transform-origin: left center;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 2;
    border-radius: 4px;
    overflow: hidden;
    backface-visibility: hidden;
    background: var(--bg-secondary);
    box-shadow:
        6px 6px 10px rgba(92, 79, 61, 0.06),
        18px 24px 32px rgba(92, 79, 61, 0.08),
        36px 48px 64px rgba(92, 79, 61, 0.06);
}

.book-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: opacity 0.3s ease;
}

/* Loading skeleton */
.book-cover.loading { background: var(--bg-secondary); }
.book-cover.loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent 0%, rgba(139,125,107,0.15) 50%, transparent 100%);
    animation: shimmer 1.5s infinite;
}
.book-cover.loading img { opacity: 0; }

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

[data-theme="dark"] .book-cover {
    box-shadow:
        6px 6px 10px rgba(0,0,0,0.12),
        18px 24px 32px rgba(0,0,0,0.15),
        36px 48px 64px rgba(0,0,0,0.1);
}

/* When closed: cover fills full width (centered) */
.book-spread:not(.open) .book-cover {
    width: 100%;
}

/* Desktop hover on closed cover */
@media (min-width: 769px) {
    .book-spread:not(.open):hover .book-cover {
        transform: rotateY(-12deg);
        box-shadow:
            10px 6px 14px rgba(92, 79, 61, 0.08),
            24px 24px 36px rgba(92, 79, 61, 0.1),
            42px 48px 68px rgba(92, 79, 61, 0.07);
    }
}

/* Open state — cover flips */
.book-spread.open .book-cover {
    width: 50%;
    transform: rotateY(-160deg);
    box-shadow: none;
}

/* =============================================
   BOOK META BELOW (shown when closed)
   ============================================= */
.book-meta-below {
    text-align: center;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: fadeIn 0.5s ease 0.15s both;
}

.book-spread.open ~ .book-meta-below {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.book-meta-below .tag {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-bg);
    padding: 5px 14px;
    border-radius: var(--radius-pill);
    margin-bottom: 10px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.book-meta-below .book-title {
    font-family: 'Noto Serif SC', 'Georgia', serif;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    line-height: 1.4;
}

.book-meta-below .book-author {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.book-meta-below .book-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* =============================================
   DESKTOP BOOK CAROUSEL
   ============================================= */
.book-carousel {
    display: none;
    width: 100%;
    overflow: visible;
    position: relative;
    margin-bottom: 32px;
}

.carousel-track {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 20px;
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 40px 0;
    will-change: transform;
}

.carousel-item {
    flex-shrink: 0;
    width: 180px;
    height: 270px;
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.5s ease, opacity 0.5s ease, box-shadow 0.5s ease;
    transform-origin: center center;
}

.carousel-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.carousel-item.active {
    transform: scale(1);
    opacity: 1;
    box-shadow:
        6px 6px 10px rgba(92, 79, 61, 0.06),
        18px 24px 32px rgba(92, 79, 61, 0.08),
        36px 48px 64px rgba(92, 79, 61, 0.06);
}

[data-theme="dark"] .carousel-item.active {
    box-shadow:
        6px 6px 10px rgba(0,0,0,0.12),
        18px 24px 32px rgba(0,0,0,0.15),
        36px 48px 64px rgba(0,0,0,0.1);
}

/* Desktop carousel — disabled for now, using book spread on all sizes */
/*
@media (min-width: 769px) {
    .book-carousel { display: block; }
}
*/

@media (min-width: 769px) {
    .book-spread {
        width: 240px;
        height: 360px;
    }
    .book-spread.open {
        width: 520px;
    }
    .book-meta-below {
        max-width: 420px;
    }
    .book-page-right .quote-text {
        font-size: 1.4rem;
    }
}

/* =============================================
   MOBILE
   ============================================= */
@media (max-width: 768px) {
    .book-spread {
        width: 160px;
        height: 240px;
    }

    .book-spread.open {
        width: min(400px, calc(100vw - 48px));
    }

    .book-spread:not(.open) .book-cover {
        width: 100%;
    }

    .book-spread.open .book-cover {
        width: 50%;
    }

    .book-page-left .book-title { font-size: 0.95rem; }
    .book-page-left .book-desc { font-size: 0.65rem; }
    .book-page-right .quote-text { font-size: 1rem; }

    .book-meta-below .book-title { font-size: 1.2rem; }
    .book-meta-below .book-author { font-size: 0.82rem; }
    .book-meta-below .book-desc { font-size: 0.82rem; }

    .content-area { padding: 16px 16px 40px; }

    .audio-player { width: 160px; }

    .calendar-track { padding: 0 16px; }
    .cal-cell { min-width: 48px; height: 58px; }

    .hourglass-countdown { font-size: 2.2rem; }
}

/* =============================================
   ANIMATIONS
   ============================================= */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* =============================================
   WEEKLY PAGE STYLES (kept for weekly.html)
   ============================================= */
.weekly-body { overflow: auto !important; height: auto !important; min-height: 100vh; }

.weekly-container { padding: 24px 24px 120px; max-width: 480px; margin: 0 auto; }

.weekly-header { text-align: center; padding: 40px 0 32px; }
.weekly-header h1 { font-family: 'Noto Serif SC', 'Georgia', serif; font-size: 1.75rem; font-weight: 600; color: var(--text-primary); margin-bottom: 8px; }
.weekly-header p { color: var(--text-secondary); font-size: 0.95rem; }

.day-card {
    background: var(--surface); border-radius: var(--radius-card);
    padding: 20px; margin-bottom: 16px;
    display: grid; grid-template-columns: 50px 72px 1fr;
    gap: 16px; align-items: center;
    text-decoration: none; color: inherit;
    box-shadow: var(--shadow-card); transition: all 0.2s;
}
.day-card:hover { box-shadow: var(--shadow-card-hover); transform: translateY(-2px); }
.day-card.today { border: 2px solid var(--accent); }
.day-number { font-size: 1.5rem; font-weight: 700; color: var(--text-tertiary); text-align: center; }
.day-card.today .day-number { color: var(--accent); }
.day-cover { width: 72px; height: 100px; border-radius: 6px; overflow: hidden; box-shadow: 0 4px 12px rgba(92, 79, 61, 0.1); }
.day-cover img { width: 100%; height: 100%; object-fit: cover; }
.day-info h3 { font-family: 'Noto Serif SC', 'Georgia', serif; font-size: 1rem; font-weight: 600; color: var(--text-primary); margin-bottom: 4px; line-height: 1.4; }
.day-info .author { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 8px; }
.day-info .meta { display: flex; gap: 8px; font-size: 0.7rem; }
.day-info .meta span:first-child { color: var(--accent); background: var(--accent-bg); padding: 2px 10px; border-radius: 12px; font-weight: 600; }
.today-badge { background: var(--accent); color: var(--bg); padding: 2px 10px; border-radius: 12px; font-weight: 600; }

.weekly-theme-toggle { position: absolute; right: 24px; top: 24px; background: none; border: 1.5px solid var(--border); color: var(--text-secondary); width: 36px; height: 36px; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.3s; }
.weekly-theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.weekly-theme-toggle .icon-sun, .weekly-theme-toggle .icon-moon { width: 18px; height: 18px; }
.weekly-theme-toggle .icon-sun { display: none; }
.weekly-theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .weekly-theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .weekly-theme-toggle .icon-moon { display: none; }

@media (max-width: 480px) {
    .weekly-container { padding: 16px 16px 100px; }
    .day-card { grid-template-columns: 40px 60px 1fr; gap: 12px; padding: 16px; }
    .day-cover { width: 60px; height: 84px; }
}

/* =============================================
   AUDIO PLAYER PILL
   ============================================= */
.audio-player {
    display: flex;
    justify-content: center;
    margin: 20px auto 0;
    width: 180px;
}

.audio-btn {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    height: 44px;
    padding: 0 16px;
    border: none;
    border-radius: 22px;
    background: var(--surface);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    cursor: pointer;
    overflow: hidden;
    transition: box-shadow 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.audio-btn:hover {
    box-shadow: 0 6px 16px rgba(0,0,0,0.08);
}

.audio-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    color: var(--accent-dark);
    z-index: 2;
}

.audio-icon.pause { display: none; }
.audio-player.playing .audio-icon.play { display: none; }
.audio-player.playing .audio-icon.pause { display: block; }

.audio-progress {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 0%;
    background: var(--accent-light);
    opacity: 0.18;
    border-radius: 22px;
    transition: width 0.15s linear;
    pointer-events: none;
}

.audio-time {
    margin-left: auto;
    font-family: 'Geist', system-ui, sans-serif;
    font-size: 13px;
    font-weight: 500;
    color: var(--accent);
    z-index: 2;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.audio-player.loading .audio-icon.play {
    animation: audio-pulse 1s ease-in-out infinite;
}

@keyframes audio-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* Dark mode */
[data-theme="dark"] .audio-btn {
    background: var(--surface);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* Permanent archive: calendar and reader share the same quiet bookish surface. */
html, body { height: auto; min-height: 100%; overflow: auto; }
.app-container { min-height: 100svh; height: auto; }
.archive-header { display: flex; align-items: center; justify-content: space-between; padding: 26px 5vw; border-bottom: 1px solid var(--border); }
.wordmark { font-family: Georgia, serif; font-size: 28px; letter-spacing: -1px; text-decoration: none; color: var(--text-primary); }
.wordmark span { display: inline-block; margin-left: 18px; font-family: 'Geist', sans-serif; font-size: 12px; letter-spacing: 2px; text-transform: uppercase; color: var(--text-secondary); }
.archive-link { color: var(--text-primary); font-size: 14px; text-underline-offset: 5px; }
.archive-layout { display: grid; grid-template-columns: 310px minmax(0, 1fr); width: min(1120px, 100%); margin: 0 auto; flex: 1; padding: 44px 24px; gap: 64px; }
.archive-sidebar { padding-top: 14px; }
.archive-intro { font: 26px/1.3 Georgia, serif; margin-bottom: 10px; }
.archive-summary { font-size: 14px; color: var(--text-secondary); margin-bottom: 32px; }
.month-controls { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.month-controls select { min-width: 0; font: 500 16px 'Geist', sans-serif; color: var(--text-primary); background: transparent; border: 0; padding: 10px 4px; cursor: pointer; }
.month-controls option { color: var(--text-primary); background: var(--bg); }
.month-controls button, .entry-navigation button { width: 44px; height: 44px; border: 1px solid var(--border); border-radius: 50%; color: var(--text-primary); background: transparent; font: 24px Georgia, serif; cursor: pointer; flex-shrink: 0; }
button:disabled { cursor: default; opacity: .35; }
button:focus-visible, a:focus-visible, select:focus-visible, [role="button"]:focus-visible { outline: 2px solid var(--text-primary); outline-offset: 4px; }
.calendar-weekdays, .archive-calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); text-align: center; gap: 3px; }
.calendar-weekdays { font-size: 12px; margin-bottom: 8px; color: var(--text-secondary); }
.archive-day { position: relative; height: 42px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--text-primary); font: 14px 'Geist', sans-serif; cursor: pointer; }
.archive-day.has-entry::after { content: ''; position: absolute; bottom: 5px; left: calc(50% - 1.5px); width: 3px; height: 3px; border-radius: 50%; background: currentColor; }
.archive-day.has-entry:hover { background: var(--bg-secondary); }
.archive-day.selected, .archive-day.selected:hover { background: var(--text-primary); color: var(--bg); }
.calendar-key { font-size: 12px; color: var(--text-secondary); margin-top: 16px; }
.archive-note { border-top: 1px solid var(--border); padding-top: 24px; margin-top: 28px; font-size: 14px; line-height: 1.8; color: var(--text-secondary); }
.content-area { justify-content: flex-start; overflow: visible; padding: 0 0 32px; min-width: 0; }
.entry-navigation { display: flex; width: min(100%, 420px); justify-content: space-between; align-items: center; margin-bottom: 40px; gap: 12px; }
.entry-navigation time { font-size: 14px; font-variant-numeric: tabular-nums; }
.book-hint { font-size: 12px; color: var(--text-secondary); margin-top: 18px; }
.book-meta-below .book-desc { font-size: 16px; }
.book-spread.open ~ .book-meta-below { display: none; }
.book-spread.open { height: auto; min-height: 360px; cursor: pointer; }
.book-spread.open .book-3d { min-height: 360px; }
.book-spread.open .book-pages { position: relative; min-height: 360px; }
.book-page-left, .book-page-right { overflow: visible; }
.book-page-right .quote-text { font-size: 1.4rem; color: #30271f; }
.book-page-right .quote-source, .book-page-left .book-author { font-size: 14px; color: #30271f; }
.book-page-left .book-title { color: #30271f; }
[data-theme="dark"] .book-pages .quote-text, [data-theme="dark"] .book-pages .quote-source, [data-theme="dark"] .book-pages .book-title, [data-theme="dark"] .book-pages .book-author { color: #fff; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
@media (max-width: 800px) {
    .archive-header { padding: 18px 20px; }
    .wordmark { font-size: 25px; }
    .wordmark span { margin-left: 10px; font-size: 10px; }
    .archive-layout { grid-template-columns: 1fr; gap: 30px; padding: 24px 20px; }
    .archive-sidebar { width: min(100%, 360px); margin: auto; padding: 0; }
    .archive-intro { display: none; }
    .archive-summary { margin-bottom: 16px; text-align: center; }
    .month-controls { margin-bottom: 8px; }
    .archive-day { height: 38px; }
    .calendar-key { margin-top: 10px; }
    .archive-note { margin-top: 16px; padding-top: 14px; font-size: 12px; }
    .archive-note br { display: none; }
    .entry-navigation { margin-bottom: 26px; }
    .book-spread.open { width: min(520px, calc(100vw - 40px)); }
    .book-page-left, .book-page-right { padding: 24px 12px; }
    .book-page-right { padding-top: 45px; }
    .book-page-right .quote-text { font-size: 1.25rem; }
    .book-meta-below .book-title { font-size: 1.5rem; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* Book-first reader, with a rigid two-sided cover hinged at the spine. */
.browse-button { display: none; }
.archive-dialog { color: var(--text-primary); background: var(--bg); border: 1px solid var(--border); border-radius: 24px 24px 0 0; width: 100%; max-width: 480px; max-height: 90svh; margin: auto auto 0; padding: 20px 24px max(24px, env(safe-area-inset-bottom)); overflow-y: auto; box-shadow: 0 -12px 60px #0002; }
.archive-dialog::backdrop { background: #171b1866; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.dialog-heading h2 { font: 24px Georgia, serif; }
.dialog-heading button { width: 44px; height: 44px; font-size: 28px; color: inherit; background: transparent; border: 1px solid var(--border); border-radius: 50%; }
.archive-dialog > .archive-link { display: inline-block; margin-top: 20px; }
body:has(.archive-dialog[open]) { overflow: hidden; }
.book-spread, .book-spread.open { --page-width: 240px; width: calc(var(--page-width) * 2); height: 360px; min-height: 0; perspective: 1600px; margin: 0 auto 28px; transition: none; isolation: isolate; }
.book-3d, .book-spread.open .book-3d { height: 100%; min-height: 0; transform: translateX(-25%); transform-style: preserve-3d; transition: transform 800ms cubic-bezier(.2,.7,.2,1); }
.book-spread.open .book-3d { transform: translateX(0); }
.book-pages, .book-spread.open .book-pages { position: absolute; inset: 0 0 0 50%; min-height: 0; opacity: 1; display: block; overflow: visible; background: transparent; border-radius: 0 5px 5px 0; transition: none; transform: translateZ(-1px); box-shadow: 3px 2px 0 #ddd5c6, 5px 4px 0 #f1eadb, 10px 16px 28px #30271f20; }
.book-page-right { height: 100%; width: 100%; background: var(--paper-color, #D4C9A1); border-radius: 0 5px 5px 0; padding: 36px 20px 24px; box-shadow: inset 12px 0 20px -15px #30271f88; overflow-y: auto; justify-content: safe center; }
.book-cover, .book-spread:not(.open) .book-cover, .book-spread.open .book-cover { width: 50%; height: 100%; left: 50%; border-radius: 0; overflow: visible; background: transparent; transform-origin: left center; transform: rotateY(0deg); transform-style: preserve-3d; backface-visibility: visible; -webkit-backface-visibility: visible; box-shadow: none; transition: transform 800ms cubic-bezier(.2,.7,.2,1); }
.book-spread:not(.open):hover .book-cover { transform: rotateY(0deg); box-shadow: none; }
.book-spread.open .book-cover { transform: rotateY(-180deg); }
.cover-front, .cover-back { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; overflow: hidden; }
.cover-front { transform: translateZ(1px); border-radius: 2px 5px 5px 2px; background: #171717; box-shadow: 8px 16px 30px #30271f25; }
.cover-front::after { content: ''; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(90deg, #0003 0, #fff2 3%, transparent 7%); border: 1px solid #ffffff18; border-radius: inherit; }
.cover-back { transform: rotateY(180deg) translateZ(1px); border-radius: 5px 0 0 5px; background: var(--paper-color, #D4C9A1); box-shadow: inset -12px 0 20px -15px #30271f88; }
.cover-back .book-page-left { height: 100%; padding: 24px 20px; border: 0; box-shadow: none; }
.book-spread.open ~ .book-meta-below { display: flex; opacity: 1; pointer-events: auto; }
.book-meta-below { animation: none; }
.book-hint { order: 0; }
@media (hover: hover) and (prefers-reduced-motion: no-preference) {
    .book-spread:not(.open):hover .book-cover { transform: rotateY(-8deg); }
}
@media (max-width: 800px) {
    .archive-header { padding: 12px 20px; border-bottom: 0; }
    .wordmark { font-size: 24px; }
    .wordmark span { font-size: 9px; letter-spacing: 1.4px; margin-left: 8px; }
    .desktop-archive-link { display: none; }
    .browse-button { display: block; font: 14px 'Geist', sans-serif; color: var(--text-primary); background: var(--nav-bg); border: 1px solid var(--border); border-radius: 24px; padding: 10px 14px; min-height: 44px; }
    .archive-layout { display: block; padding: 8px 20px max(24px, env(safe-area-inset-bottom)); }
    .content-area { padding: 0; min-height: calc(100svh - 92px); }
    .entry-navigation { margin: 0 auto 30px; max-width: 340px; }
    .entry-navigation button { border-color: transparent; }
    .book-spread, .book-spread.open { --page-width: min(42vw, 200px); width: calc(var(--page-width) * 2); height: clamp(250px, 66vw, 300px); min-height: 0; margin-bottom: 28px; }
    .book-page-right { padding: 30px 14px 18px; }
    .book-page-right .quote-text { font-size: 1.2rem; line-height: 1.4; }
    .book-page-right .quote-source, .cover-back .book-author { font-size: 12px; line-height: 1.5; }
    .cover-back .book-page-left { padding: 20px 14px; }
    .cover-back .book-title { font-size: 1rem; }
    .book-meta-below { max-width: 340px; }
    .book-meta-below .book-title { font-size: 1.4rem; line-height: 1.3; }
    .book-meta-below .book-desc { font-size: 14px; line-height: 1.6; }
    .book-meta-below .tag { font-size: 10px; padding: 3px 10px; margin-bottom: 8px; }
    .book-meta-below .book-author { font-size: 14px; }
    .book-hint { margin-top: 14px; }
    .archive-dialog .archive-sidebar { width: 100%; }
    .archive-dialog .archive-day { height: 44px; }
    .archive-dialog .archive-note { display: none; }
}
@media (max-width: 360px) { .wordmark span { display: none; } }
@media (prefers-reduced-motion: reduce) { .book-3d, .book-cover { transition: none !important; } }
/* Keep long quotes readable within the paper; overflow remains scrollable. */
.book-page-right .quote-text { font-family: 'Caveat', Georgia, serif; flex-shrink: 0; }
.book-page-right .quote-source { flex-shrink: 0; }
@media (max-width: 800px) {
    .book-page-right { padding: 26px 12px 16px; scrollbar-width: thin; }
    .book-page-right .quote-text { font-size: 16px; line-height: 1.4; margin-bottom: 8px; }
    .book-page-right .quote-source { font-size: 11px; line-height: 1.4; }
    .book-spread.open .book-page-right::after { content: ''; display: block; min-height: 4px; }
}
@media (max-width: 800px) {
    .book-spread.long-quote .quote-text { font-size: 14px; line-height: 1.4; }
    .book-spread.long-quote .book-page-right { padding-top: 22px; padding-bottom: 12px; }
}

/* React Bits Pattern Waves: muted ink on Littlebook's paper palette. */
body::before { background: none; }
body::after { background: radial-gradient(ellipse at 65% 38%, #f4f1e8 0%, #e8ede9 65%, #dfe7e2 100%); opacity: 1; }
[data-theme="dark"] body::after { background: radial-gradient(ellipse at 65% 38%, #26251f 0%, #1a1815 75%); opacity: 1; }
#patternWaves { position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; }
body::after { z-index: -2; }
#patternWaves canvas { display: block; width: 100%; height: 100%; }
@media (max-width: 800px) { #patternWaves { opacity: .7; } }
#patternWaves { opacity: .45; }
@media (max-width: 800px) { #patternWaves { opacity: .4; } }

/* Native modal stays open until its exit motion completes, keeping focus contained. */
.archive-dialog[open] { animation: calendar-arrive 320ms cubic-bezier(.2,.8,.2,1) both; }
.archive-dialog[open]::backdrop { animation: calendar-backdrop-in 320ms ease both; }
.archive-dialog[open].is-closing { animation: calendar-leave 220ms cubic-bezier(.4,0,1,1) both; pointer-events: none; }
.archive-dialog[open].is-closing::backdrop { animation: calendar-backdrop-out 220ms ease both; }
@keyframes calendar-arrive { from { transform: translateY(48px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes calendar-leave { from { transform: translateY(0); opacity: 1; } to { transform: translateY(40px); opacity: 0; } }
@keyframes calendar-backdrop-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes calendar-backdrop-out { from { opacity: 1; } to { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
    .archive-dialog[open], .archive-dialog[open]::backdrop { animation: none !important; }
}

/* Consistent calendar geometry, including narrow phone widths. */
.archive-day, .archive-dialog .archive-day { width: 100%; max-width: 44px; height: auto; aspect-ratio: 1; justify-self: center; border-radius: 50%; }
#calendarHeading { outline: none; }
.dialog-heading button { border: 0; background: transparent; -webkit-tap-highlight-color: transparent; }
.dialog-heading button:focus:not(:focus-visible) { outline: none; }

/* Compact archive navigation; never allow intrinsic SVG sizing. */
.weekly-container .pill-nav { display: flex; justify-content: center; gap: 28px; margin-top: 28px; }
.weekly-container .nav-item { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; font-size: 14px; color: var(--text-secondary); text-decoration: none; }
.weekly-container .nav-item.active { color: var(--text-primary); }
.weekly-container .nav-icon { display: block; width: 20px; height: 20px; flex: 0 0 20px; }
.weekly-container { animation: archive-page-arrive 350ms cubic-bezier(.2,.8,.2,1) both; }
@keyframes archive-page-arrive { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .weekly-container { animation: none; } }

/* Preserve the pill player; only the progress fill has a flat leading edge. */
.audio-progress { border-radius: 0; }
