/* ===================================
   Variables - Academic Dark Mode
   =================================== */
:root {
    /* Dark grey backgrounds (not pure black) */
    --bg-main: #1a1a1a;
    --bg-sidebar: #1f1f1f;
    --bg-highlight: #262626;
    --bg-hover: #2a2a2a;
    
    /* Text colors - following style guide */
    --text-primary: #e8e8e8;
    --text-secondary: #b0b0b0;
    --text-muted: #808080;
    --text-faint: #606060;
    
    /* Accent */
    --accent: #9a9a9a;
    
    /* Borders */
    --border: #2a2a2a;
    --border-light: #333333;
    
    /* Typography - Style Guide Fonts */
    --font-serif: 'EB Garamond', Georgia, serif;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

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

body {
    font-family: var(--font-sans);
    background: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===================================
   App Container
   =================================== */
#app {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===================================
   Header
   =================================== */
.header {
    background: var(--bg-main);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
}

.header-top {
    height: 80px;
    padding-top: 0.5rem;
    padding-bottom: 0.4rem;
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 0 0 auto;
    min-width: 60px;
}

.header-left {
    justify-content: flex-start;
}

.header-right {
    justify-content: flex-end;
}

.header-center {
    flex: 1;
    text-align: center;
}

.header-title {
    font-family: var(--font-serif);
    font-size: 1.5rem;
    font-weight: 400;
    color: var(--text-primary);
    margin-bottom: 0.15rem;
    letter-spacing: 0.02em;
}

.header-subtitle {
    font-family: var(--font-sans);
    font-size: 0.875rem;
    color: var(--text-muted);
    letter-spacing: 0.03em;
}

.header-icon {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 4px;
    transition: background 150ms ease, color 150ms ease;
}

.header-icon:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Reader Toolbar */
.header-toolbar {
    height: 40px;
    justify-content: center;
    gap: 2rem;
    border-top: 1px solid var(--border);
    display: none;
}

.header-toolbar.visible {
    display: flex;
}

.toolbar-nav {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.toolbar-tools {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.toolbar-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 4px;
    transition: background 150ms ease, color 150ms ease;
}

.toolbar-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.toolbar-btn:disabled {
    opacity: 0.3;
    cursor: default;
}

.toolbar-btn:disabled:hover {
    background: transparent;
    color: var(--text-muted);
}

.toolbar-btn.active {
    color: var(--text-primary);
}

/* Chapter Dropdown */
.chapter-dropdown-wrapper {
    position: relative;
}

.chapter-dropdown {
    appearance: none;
    -webkit-appearance: none;
    background: var(--bg-highlight);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.3rem 2rem 0.3rem 0.75rem;
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    color: var(--text-secondary);
    cursor: pointer;
    min-width: 200px;
    transition: border-color 150ms ease, color 150ms ease;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23808080' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
}

.chapter-dropdown:hover {
    border-color: var(--border-light);
    color: var(--text-primary);
}

.chapter-dropdown:focus {
    outline: none;
    border-color: var(--border-light);
}

.chapter-dropdown option {
    background: var(--bg-sidebar);
    color: var(--text-secondary);
}

/* Copy feedback toast */
.copy-toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(1rem);
    background: var(--bg-highlight);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    padding: 0.6rem 1.25rem;
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    color: var(--text-primary);
    opacity: 0;
    pointer-events: none;
    transition: opacity 200ms ease, transform 200ms ease;
    z-index: 2000;
}

.copy-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ===================================
   Main Two-Column Content
   =================================== */
.main-content {
    flex: 1;
    overflow: hidden;
}

/* Views */
.view {
    display: none;
    height: 100%;
}

.view.active {
    display: flex;
}

/* ===================================
   Home View
   =================================== */
#home-view {
    overflow-y: auto;
    flex-direction: column;
}

/* Hero */
.hero {
    position: relative;
    min-height: 85vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.hero-bg {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.hero-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        to bottom,
        rgba(26, 26, 26, 0.5) 0%,
        rgba(26, 26, 26, 0.7) 50%,
        rgba(26, 26, 26, 0.95) 100%
    );
}

.hero-content {
    position: relative;
    z-index: 1;
    text-align: center;
    max-width: 640px;
    padding: 2rem;
}

.hero-label {
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    color: var(--text-muted);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    margin-bottom: 1rem;
}

.hero-title {
    font-family: var(--font-serif);
    font-size: 4.5rem;
    font-weight: 400;
    color: var(--text-primary);
    line-height: 1.1;
    margin-bottom: 1.5rem;
    letter-spacing: 0.02em;
}

.hero-description {
    font-family: var(--font-serif);
    font-size: 1.2rem;
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 2.5rem;
}

.hero-cta {
    display: inline-block;
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    text-decoration: none;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 0.85rem 2.5rem;
    border: 1px solid var(--border-light);
    border-radius: 4px;
    transition: background 200ms ease, border-color 200ms ease;
}

.hero-cta:hover {
    background: var(--bg-hover);
    border-color: var(--text-muted);
}

/* Shared Section Styles */
.home-section {
    padding: 3rem 2rem;
}

.section-inner {
    max-width: 1100px;
    margin: 0 auto;
}

.section-heading {
    text-align: center;
    margin-bottom: 3rem;
}

.section-title {
    font-family: var(--font-serif);
    font-size: 2.25rem;
    font-weight: 400;
    color: var(--text-primary);
    margin-bottom: 0.6rem;
}

.section-subtitle {
    font-family: var(--font-sans);
    font-size: 1rem;
    color: var(--text-muted);
}

/* Featured Verse */
.featured-verse-section {
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    background: var(--bg-sidebar);
}

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

.featured-verse-pali {
    font-family: var(--font-serif);
    font-size: 1.5rem;
    font-style: italic;
    color: var(--text-secondary);
    line-height: 1.8;
    margin-bottom: 1rem;
}

.featured-verse-english {
    font-family: var(--font-serif);
    font-size: 1.25rem;
    color: var(--text-primary);
    line-height: 1.7;
    margin-bottom: 1.25rem;
}

.featured-verse-source {
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    color: var(--text-muted);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

/* Home Search */
.home-search-wrapper {
    max-width: 480px;
    margin: 0 auto 2rem;
}

.home-search-input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: var(--font-sans);
    font-size: 1rem;
    color: var(--text-primary);
    transition: border-color 150ms ease;
}

.home-search-input:focus {
    outline: none;
    border-color: var(--border-light);
}

.home-search-input::placeholder {
    color: var(--text-faint);
}

/* Text Cards (improved) */
.text-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
}

.text-card {
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    overflow: hidden;
    transition: background 200ms ease, border-color 200ms ease, transform 200ms ease;
}

.text-card:hover {
    background: var(--bg-hover);
    transform: translateY(-2px);
}

.text-card-body {
    padding: 2rem;
}

.text-card-title {
    font-family: var(--font-serif);
    font-size: 1.75rem;
    font-weight: 400;
    color: var(--text-primary);
    margin-bottom: 0.3rem;
}

.text-card-subtitle {
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    letter-spacing: 0.03em;
}

.text-card-description {
    font-family: var(--font-serif);
    font-size: 1.05rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 1.25rem;
}

.text-card-meta {
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    color: var(--text-muted);
}

/* About Section */
.about-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3rem;
    align-items: center;
}

.about-image img {
    width: 100%;
    height: auto;
    border-radius: 8px;
    display: block;
}

.about-content .section-title {
    text-align: left;
    margin-bottom: 1.25rem;
}

.about-content .about-text {
    font-family: var(--font-serif);
    font-size: 1.05rem;
    color: var(--text-secondary);
    line-height: 1.75;
    margin-bottom: 1rem;
}

.about-stats {
    display: flex;
    gap: 2.5rem;
    margin-top: 1.75rem;
    padding-top: 1.75rem;
    border-top: 1px solid var(--border);
}

.stat {
    display: flex;
    flex-direction: column;
}

.stat-number {
    font-family: var(--font-serif);
    font-size: 1.75rem;
    font-weight: 400;
    color: var(--text-primary);
}

.stat-label {
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    text-transform: uppercase;
    margin-top: 0.2rem;
}

/* Features */
.features-section {
    background: var(--bg-sidebar);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2rem;
}

.feature-card {
    padding: 2rem 1.5rem;
    text-align: center;
}

.feature-icon {
    color: var(--text-muted);
    margin-bottom: 1.25rem;
}

.feature-title {
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.6rem;
}

.feature-text {
    font-family: var(--font-sans);
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* Footer */
.home-footer {
    padding: 2.5rem 2rem;
    border-top: 1px solid var(--border);
    text-align: center;
}

.footer-text {
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    color: var(--text-faint);
    letter-spacing: 0.03em;
}

/* ===================================
   Reader Layout
   =================================== */
.reader-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ===================================
   Left: Primary Reading Panel (70-75%)
   =================================== */
.reading-panel {
    flex: 0 0 72%;
    background: var(--bg-main);
    overflow-y: auto;
    padding: 3rem 4rem;
}

.reading-content {
    max-width: 800px;
    margin: 0 auto;
}

/* Scripture Header */
.scripture-header {
    margin-bottom: 2.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.text-title {
    font-family: var(--font-serif);
    font-size: 1.875rem; /* 30px - Page Title */
    font-weight: 400;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    line-height: 1.3;
}

.text-subtitle {
    font-family: var(--font-sans);
    font-size: 1.125rem; /* 18px - CHAPTER style */
    color: var(--text-secondary);
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 0.05em; /* Tracking 50 */
}

/* Scripture Text */
.scripture-text {
    margin-bottom: 3rem;
}

.text-passage {
    margin-bottom: 2.5rem;
    padding: 1.5rem 2rem;
}

.text-passage.highlighted {
    background: var(--bg-highlight);
    border-radius: 6px;
    border-left: 3px solid var(--border-light);
}

.verse-line {
    margin-bottom: 0.5rem;
    line-height: 2;
}

.reference-marker {
    font-family: var(--font-sans);
    font-size: 0.8125rem; /* 13px - Small Text */
    font-weight: 400;
    color: var(--text-muted);
    margin-right: 0.75rem;
    vertical-align: super;
}

.pali-text {
    font-family: var(--font-serif);
    font-size: 1.375rem; /* 22px - enlarged from 18px */
    color: var(--text-primary);
    font-weight: 400;
    line-height: 2;
}

.pali-word {
    display: inline-block;
    cursor: pointer;
    padding: 0.1rem 0.15rem;
    margin: 0.05rem;
    border-radius: 3px;
    transition: background 150ms ease, color 150ms ease;
    font-family: var(--font-serif);
    font-size: 1.375rem; /* 22px - match .pali-text */
    color: var(--text-primary);
    line-height: 2;
}

.pali-word:hover {
    background: #3a3a3a;
    color: var(--text-primary);
}

/* Word Tooltip */
.word-tooltip {
    position: fixed;
    padding: 0.85rem 1rem;
    background: var(--bg-highlight);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    max-width: 320px;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 150ms ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.word-tooltip.visible {
    opacity: 1;
}

.word-tooltip.pinned {
    opacity: 1;
    pointer-events: auto;
    user-select: text;
    -webkit-user-select: text;
}

.tooltip-close {
    position: absolute;
    top: 0.3rem;
    right: 0.4rem;
    width: 22px;
    height: 22px;
    display: none;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.125rem;
    line-height: 1;
    cursor: pointer;
    border-radius: 3px;
    transition: background 150ms ease, color 150ms ease;
}

.tooltip-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.word-tooltip.pinned .tooltip-close {
    display: flex;
}

.pali-word.word-active {
    background: #3a3a3a;
    color: var(--text-primary);
}

.tooltip-word {
    font-family: var(--font-serif);
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.4rem;
}

.tooltip-definition {
    font-family: var(--font-sans);
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--text-secondary);
}

.verse-translation {
    margin-top: 0.5rem;
    padding-left: 1.5rem;
    font-family: var(--font-serif);
    font-size: 1.25rem; /* 20px - enlarged from 18px */
    color: var(--text-secondary);
    line-height: 1.9;
    font-weight: 400;
    margin-bottom: 0.25rem;
}

/* Passage Navigation */
.passage-navigation {
    display: flex;
    justify-content: space-between;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
}

.nav-btn-simple {
    padding: 0.6rem 1.25rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: var(--font-sans);
    font-size: 1rem; /* 16px - System text */
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 150ms ease, color 150ms ease, border-color 150ms ease;
}

.nav-btn-simple:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-light);
}

/* ===================================
   Right: Sidebar (25-30%)
   =================================== */
.sidebar {
    flex: 0 0 28%;
    background: var(--bg-sidebar);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    padding: 2rem 1.5rem;
}

.sidebar-section {
    margin-bottom: 0;
}

.sidebar-header {
    font-family: var(--font-sans);
    font-size: 1rem; /* 16px - SECTION TITLE */
    font-weight: 400;
    color: var(--text-muted);
    margin-bottom: 0.85rem;
    letter-spacing: 0.1em; /* Tracking 100 */
    text-transform: uppercase;
}

.sidebar-content {
    margin-bottom: 0;
}

.sidebar-text {
    font-family: var(--font-sans);
    font-size: 1rem; /* 16px - System text */
    color: var(--text-secondary);
    line-height: 1.7;
}

.sidebar-divider {
    height: 1px;
    background: var(--border);
    margin: 1.5rem 0;
}

.sidebar-list {
    list-style: none;
}

.sidebar-list-item {
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.25rem;
    font-family: var(--font-sans);
    font-size: 1rem; /* 16px - System text */
    color: var(--text-secondary);
    border-radius: 4px;
    cursor: pointer;
    transition: background 150ms ease, color 150ms ease;
}

.sidebar-list-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-list-item.active {
    background: var(--bg-highlight);
    color: var(--text-primary);
}

/* Search Input */
.search-input-sidebar {
    width: 100%;
    padding: 0.6rem 0.85rem;
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: var(--font-sans);
    font-size: 1rem; /* 16px - System text */
    color: var(--text-primary);
}

.search-input-sidebar:focus {
    outline: none;
    border-color: var(--border-light);
}

.search-input-sidebar::placeholder {
    color: var(--text-faint);
}

/* Study Notes */
.notes-verse-label {
    font-family: var(--font-sans);
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
    letter-spacing: 0;
    text-transform: none;
    margin-left: 0.5rem;
}

.study-notes-textarea {
    width: 100%;
    min-height: 120px;
    padding: 0.6rem 0.75rem;
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: var(--font-sans);
    font-size: 0.875rem;
    color: var(--text-primary);
    line-height: 1.6;
    resize: vertical;
}

.study-notes-textarea:focus {
    outline: none;
    border-color: var(--border-light);
}

.study-notes-textarea::placeholder {
    color: var(--text-faint);
}

.study-notes-textarea:disabled {
    opacity: 0.4;
    cursor: default;
}

/* Note indicator on verse */
.text-passage.has-note .reference-marker::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #C4956A;
    margin-left: 0.4rem;
    vertical-align: middle;
}

/* ===================================
   Scrollbar
   =================================== */
.reading-panel::-webkit-scrollbar,
.sidebar::-webkit-scrollbar {
    width: 6px;
}

.reading-panel::-webkit-scrollbar-track,
.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.reading-panel::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.reading-panel::-webkit-scrollbar-thumb:hover,
.sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}

/* ===================================
   Responsive
   =================================== */
@media (max-width: 1024px) {
    .reading-panel {
        flex: 0 0 65%;
        padding: 2rem 2.5rem;
    }
    
    .sidebar {
        flex: 0 0 35%;
        padding: 1.5rem 1.25rem;
    }

    .about-layout {
        grid-template-columns: 1fr;
        gap: 2rem;
    }

    .about-image {
        order: -1;
    }

    .about-content .section-title {
        text-align: center;
    }

    .about-stats {
        justify-content: center;
    }
}

@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
    }
    
    .reading-panel {
        flex: 1;
        padding: 2rem 1.5rem;
    }
    
    .sidebar {
        flex: none;
        max-height: 40vh;
        border-left: none;
        border-top: 1px solid var(--border);
    }
    
    .header-left,
    .header-right {
        min-width: auto;
    }
    
    .header-title {
        font-size: 0.85rem;
    }
    
    .header-subtitle {
        display: none;
    }

    .hero-title {
        font-size: 3rem;
    }

    .hero {
        min-height: 70vh;
    }

    .features-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

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