/* Black's Law Dictionary - iA Writer/Monocle Inspired Design */

:root {
    --bg: #F5F0E6;
    --bg2: #EDE7DA;
    --fg: #2C1810;
    --fg2: #6B5B4A;
    --accent: #8B1A1A;
    --border: #D4C9B0;
    --sidebar-bg: #FAF7F0;
    --hover: #EDE7DA;
    --pill-bg: #E8E0D0;
    --overlay: rgba(0,0,0,0.3);
    --shadow: rgba(0,0,0,0.15);
    --font-size: 17px;
}

.dark {
    --bg: #1a1814;
    --bg2: #232019;
    --fg: #D4C9B0;
    --fg2: #9A8E78;
    --accent: #C4785A;
    --border: #3A352C;
    --sidebar-bg: #1E1B16;
    --hover: #2E2A22;
    --pill-bg: #2E2A22;
    --overlay: rgba(0,0,0,0.5);
    --shadow: rgba(0,0,0,0.3);
}

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

html {
    font-size: var(--font-size);
}

body {
    font-family: 'EB Garamond', Georgia, 'Times New Roman', serif;
    background: var(--bg);
    color: var(--fg);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Layout */
.content-wrapper {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
    height: 100vh;
}

/* Letter Rail */
.letter-rail {
    width: 48px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 8px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.letter-btn {
    width: 36px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-size: 14px;
    font-weight: 600;
    color: var(--fg2);
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.15s ease;
}

.letter-btn:hover {
    background: var(--hover);
    color: var(--fg);
}

.letter-btn.active {
    background: var(--accent);
    color: #fff;
}

/* Mobile Sidebar */
.sidebar {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    z-index: 20;
    overflow-y: auto;
    padding: 16px 0;
    box-shadow: 4px 0 20px var(--shadow);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
}

.sidebar.open {
    transform: translateX(0);
}

.sidebar-header {
    padding: 0 20px 16px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}

.sidebar-title {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-size: 18px;
    font-weight: 600;
    color: var(--fg);
}

.sidebar-letters {
    display: flex;
    flex-direction: column;
}

.sidebar-letter {
    display: flex;
    justify-content: space-between;
    width: 100%;
    padding: 8px 20px;
    border: none;
    cursor: pointer;
    font-size: 15px;
    font-family: 'EB Garamond', Georgia, serif;
    background: transparent;
    color: var(--fg);
    transition: background 0.15s ease;
}

.sidebar-letter:hover {
    background: var(--hover);
}

.sidebar-letter.active {
    background: var(--hover);
    color: var(--accent);
    font-weight: 600;
}

.sidebar-letter .count {
    color: var(--fg2);
    font-size: 13px;
}

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--overlay);
    z-index: 15;
    display: none;
}

.overlay.show {
    display: block;
}

/* Main Content */
main {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px 80px;
    display: flex;
    justify-content: center;
}

.reading-col {
    max-width: 680px;
    width: 100%;
}

/* Header */
.site-header {
    margin-bottom: 32px;
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
}

.menu-btn {
    display: none;
    background: transparent;
    border: none;
    color: var(--fg);
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
}

.menu-btn:hover {
    background: var(--hover);
}

.book-title {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-size: 22px;
    font-weight: 700;
    color: var(--fg);
    letter-spacing: 0.02em;
    flex: 1;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

.font-btn, .theme-btn {
    background: transparent;
    border: none;
    color: var(--fg2);
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 4px;
    font-family: inherit;
    font-size: 14px;
    transition: all 0.15s ease;
}

.font-btn:hover, .theme-btn:hover {
    background: var(--hover);
    color: var(--fg);
}

.theme-btn {
    font-size: 18px;
    padding: 6px 8px;
}

.theme-btn .sun {
    display: none;
}

.dark .theme-btn .moon {
    display: none;
}

.dark .theme-btn .sun {
    display: inline;
}

/* Search */
.search-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
}

#search-box {
    flex: 1;
    padding: 10px 16px;
    font-family: 'EB Garamond', Georgia, serif;
    font-size: 16px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--fg);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#search-box:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(139, 26, 26, 0.1);
}

.dark #search-box:focus {
    box-shadow: 0 0 0 3px rgba(196, 120, 90, 0.15);
}

#search-box::placeholder {
    color: var(--fg2);
}

#resultCount {
    color: var(--fg2);
    font-size: 13px;
    white-space: nowrap;
}

/* Letter Headings */
.letter-group {
    margin-bottom: 24px;
}

.letter-heading {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-size: 32px;
    font-weight: 700;
    color: var(--accent);
    border-bottom: 2px solid var(--border);
    padding-bottom: 4px;
    margin: 32px 0 16px;
    letter-spacing: 0.06em;
    scroll-margin-top: 24px;
}

.letter-heading:first-child {
    margin-top: 0;
}

/* Entries */
.entry {
    margin-bottom: 14px;
    font-size: var(--font-size);
    line-height: 1.85;
    text-align: justify;
    scroll-margin-top: 24px;
}

.term {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 0.01em;
    cursor: pointer;
}

.term:hover {
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--fg2);
}

.empty-state p {
    font-size: 18px;
}

/* Sentinel for lazy loading */
.sentinel {
    height: 100px;
    margin-top: 20px;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .letter-rail {
        width: 100%;
        height: 40px;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        gap: 0;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 4px 8px;
    }

    .letter-btn {
        width: 32px;
        height: 32px;
        flex-shrink: 0;
    }

    .content-wrapper {
        flex-direction: column;
    }

    .book-title {
        display: none;
    }

    .menu-btn {
        display: block;
    }

    #search-box {
        max-width: 100%;
    }

    main {
        padding: 16px 16px 60px;
    }

    .reading-col {
        max-width: 100%;
    }

    .letter-heading {
        font-size: 28px;
    }
}

@media (min-width: 769px) {
    #menuBtn {
        display: none;
    }

    .sidebar {
        display: none;
    }

    .overlay {
        display: none !important;
    }
}

/* Print styles */
@media print {
    .letter-rail,
    .sidebar,
    .overlay,
    .site-header {
        display: none !important;
    }

    main {
        padding: 0;
    }

    .entry {
        break-inside: avoid;
    }
}
/* Loading States */
.loading-state {
    text-align: center;
    padding: 80px 20px;
    color: var(--fg2);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-inline {
    text-align: center;
    padding: 40px;
    color: var(--fg2);
    font-style: italic;
}

.error {
    text-align: center;
    padding: 40px;
    color: #c53030;
}

.dark .error {
    color: #fc8181;
}

/* Welcome State */
.welcome-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--fg2);
}

.welcome-state p {
    font-size: 18px;
    margin-bottom: 12px;
}

.welcome-state .welcome-hint {
    font-size: 14px;
    color: var(--fg2);
    opacity: 0.8;
}

.welcome-state.hidden {
    display: none;
}

