/**
 * Prakrit Library Reader - Minimalist Styles
 * Mobile-first, Devanagari-optimized
 */

/* =====================
   Base & Typography
   ===================== */

.reader-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 1rem;
    padding-bottom: 4rem;
}

/* Adishila font for Devanagari */
@font-face {
    font-family: 'Adishila';
    src: url('../../css/fonts/Adishila.woff2') format('woff2');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

/* =====================
   Header
   ===================== */

.reader-header {
    text-align: center;
    padding: 1.5rem 0;
    border-bottom: 1px solid #e5e5e5;
    margin-bottom: 1rem;
}

.reader-header h1 {
    font-family: 'Adishila', 'Noto Sans Devanagari', serif;
    font-size: 1.75rem;
    color: #1a1a1a;
    margin: 0 0 0.25rem 0;
}

.reader-header .subtitle {
    font-size: 0.9rem;
    color: #666;
    margin: 0;
}

/* =====================
   Controls
   ===================== */

.reader-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    justify-content: center;
    padding: 0.75rem;
    background: #f8f8f8;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.script-toggle {
    display: flex;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid #ddd;
}

.script-toggle button {
    padding: 0.5rem 1rem;
    border: none;
    background: white;
    cursor: pointer;
    font-size: 0.875rem;
    transition: background 0.2s, color 0.2s;
}

.script-toggle button:first-child {
    border-right: 1px solid #ddd;
}

.script-toggle button.active {
    background: #2563eb;
    color: white;
}

.script-toggle button:hover:not(.active) {
    background: #f0f0f0;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.control-group label {
    font-size: 0.875rem;
    color: #666;
}

.control-group select {
    padding: 0.4rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: white;
    font-size: 0.875rem;
}

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

#toc-toggle {
    padding: 0.5rem 1rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: white;
    cursor: pointer;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#chapter-list {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    max-height: 300px;
    overflow-y: auto;
    min-width: 200px;
    z-index: 100;
}

#chapter-list.show {
    display: block;
}

#chapter-list a {
    display: block;
    padding: 0.75rem 1rem;
    color: #333;
    text-decoration: none;
    border-bottom: 1px solid #eee;
    font-size: 0.875rem;
}

#chapter-list a:last-child {
    border-bottom: none;
}

#chapter-list a:hover {
    background: #f5f5f5;
}

#chapter-list a.active {
    background: #e8f0fe;
    color: #2563eb;
}

/* =====================
   Chapter Navigation
   ===================== */

.chapter-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 0;
    gap: 1rem;
}

#chapter-title {
    font-size: 1rem;
    font-weight: 500;
    color: #333;
    text-align: center;
    flex: 1;
    margin: 0;
}

.nav-btn {
    padding: 0.5rem 1rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: white;
    cursor: pointer;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    transition: background 0.2s;
    white-space: nowrap;
}

.nav-btn:hover:not(:disabled) {
    background: #f5f5f5;
}

.nav-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* =====================
   Content Area
   ===================== */

#reader-content {
    font-family: 'Adishila', 'Noto Sans Devanagari', Georgia, serif;
    line-height: 2;
    color: #1a1a1a;
}

/* Font size classes */
#reader-content.font-small { font-size: 1rem; line-height: 1.8; }
#reader-content.font-medium { font-size: 1.25rem; line-height: 2; }
#reader-content.font-large { font-size: 1.5rem; line-height: 2.2; }
#reader-content.font-xlarge { font-size: 1.75rem; line-height: 2.4; }

/* =====================
   Verses
   ===================== */

.verse {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1rem 0;
    border-bottom: 1px solid #f0f0f0;
}

.verse-text {
    flex: 1;
}

.verse-line {
    display: block;
    margin-bottom: 0.25em;
}

.verse-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
    margin-top: 0.25rem;
}

.verse-num {
    font-size: 0.75rem;
    color: #888;
    background: #f5f5f5;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.share-btn {
    padding: 0.25rem 0.4rem;
    border: none;
    background: transparent;
    color: #aaa;
    cursor: pointer;
    font-size: 0.7rem;
    border-radius: 4px;
    transition: color 0.2s, background 0.2s;
}

.share-btn:hover {
    color: #2563eb;
    background: #e8f0fe;
}

.share-btn.copied {
    color: #16a34a;
}

/* Highlighted verse (from URL link) */
.verse.highlighted {
    background: #fef3c7;
    border-radius: 8px;
    animation: highlight-fade 2s ease-out;
}

@keyframes highlight-fade {
    0% { background: #fef3c7; }
    100% { background: transparent; }
}

/* =====================
   Prose
   ===================== */

.prose {
    padding: 1rem 0;
    border-bottom: 1px solid #f0f0f0;
}

.sentence {
    margin-right: 0.25em;
}

/* =====================
   Words & Dictionary
   ===================== */

.word {
    cursor: pointer;
    border-radius: 2px;
    transition: background 0.15s, color 0.15s;
}

.word:hover {
    background: #fff3cd;
}

.word.selected {
    background: #2563eb;
    color: white;
}

/* Word popup */
.word-popup {
    position: absolute;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    padding: 1rem;
    z-index: 1000;
    min-width: 180px;
    max-width: 280px;
}

.popup-word {
    font-family: 'Adishila', 'Noto Sans Devanagari', serif;
    font-size: 1.25rem;
    color: #333;
    margin-bottom: 0.75rem;
    word-break: break-word;
}

.popup-search {
    display: block;
    text-align: center;
    padding: 0.6rem 1rem;
    background: #2563eb;
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.875rem;
    transition: background 0.2s;
}

.popup-search:hover {
    background: #1d4ed8;
}

.popup-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 1.25rem;
    color: #999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.popup-close:hover {
    color: #333;
}

/* =====================
   Loading & Error States
   ===================== */

.loading {
    text-align: center;
    padding: 3rem 1rem;
    color: #666;
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #e5e5e5;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1rem;
}

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

.error-message {
    text-align: center;
    padding: 2rem 1rem;
    color: #dc2626;
}

.error-message button {
    margin-top: 1rem;
    padding: 0.5rem 1.5rem;
    background: #2563eb;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

/* =====================
   Mobile Responsive
   ===================== */

/* Tablet */
@media (max-width: 768px) {
    .reader-container {
        padding: 0.75rem;
    }

    .reader-header {
        padding: 1rem 0;
    }

    .reader-header h1 {
        font-size: 1.5rem;
    }

    .reader-header .subtitle {
        font-size: 0.85rem;
    }

    .reader-controls {
        padding: 0.5rem;
        gap: 0.5rem;
    }

    .script-toggle button {
        padding: 0.4rem 0.75rem;
        font-size: 0.8rem;
    }

    .control-group select {
        padding: 0.35rem 0.5rem;
        font-size: 0.8rem;
    }

    #toc-toggle {
        padding: 0.4rem 0.75rem;
        font-size: 0.8rem;
    }

    /* Hide "Chapters" text on tablet, show icon only */
    .toc-label {
        display: none;
    }
}

/* Mobile */
@media (max-width: 600px) {
    .reader-container {
        padding: 0.5rem;
        padding-bottom: 3rem;
    }

    .reader-header {
        padding: 0.75rem 0;
        margin-bottom: 0.5rem;
    }

    .reader-header h1 {
        font-size: 1.35rem;
    }

    .reader-header .subtitle {
        font-size: 0.8rem;
    }

    .reader-controls {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.4rem;
        padding: 0.5rem;
        margin-bottom: 0.5rem;
    }

    .script-toggle {
        order: 1;
    }

    .script-toggle button {
        padding: 0.35rem 0.6rem;
        font-size: 0.75rem;
    }

    .control-group {
        order: 2;
    }

    .control-group label {
        font-size: 0.75rem;
    }

    .control-group select {
        padding: 0.3rem 0.4rem;
        font-size: 0.75rem;
    }

    .chapter-dropdown {
        order: 3;
    }

    #toc-toggle {
        padding: 0.35rem 0.6rem;
        font-size: 0.75rem;
    }

    .chapter-nav {
        flex-direction: row;
        gap: 0.5rem;
        padding: 0.5rem 0;
        align-items: center;
    }

    #chapter-title {
        font-size: 0.85rem;
        flex: 1;
        text-align: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .nav-btn {
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
    }

    .nav-btn span.btn-text {
        display: none;
    }

    /* Content area */
    #reader-content {
        line-height: 1.8;
    }

    #reader-content.font-small { font-size: 0.95rem; line-height: 1.7; }
    #reader-content.font-medium { font-size: 1.05rem; line-height: 1.8; }
    #reader-content.font-large { font-size: 1.15rem; line-height: 1.9; }
    #reader-content.font-xlarge { font-size: 1.25rem; line-height: 2; }

    /* Verses */
    .verse {
        flex-direction: column-reverse;
        gap: 0.4rem;
        padding: 0.75rem 0;
    }

    .verse-text {
        width: 100%;
    }

    .verse-line {
        margin-bottom: 0.15em;
    }

    .verse-actions {
        align-self: flex-end;
        gap: 0.4rem;
    }

    .verse-num {
        font-size: 0.7rem;
        padding: 0.2rem 0.4rem;
    }

    .share-btn {
        font-size: 0.65rem;
        padding: 0.2rem 0.35rem;
    }

    /* Prose */
    .prose {
        padding: 0.75rem 0;
    }

    /* Word popup */
    .word-popup {
        position: fixed;
        left: 10px !important;
        right: 10px !important;
        bottom: 10px !important;
        top: auto !important;
        max-width: none;
        border-radius: 12px;
    }

    /* Chapter list dropdown */
    #chapter-list {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        max-height: 60vh;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
    }

    #chapter-list a {
        padding: 1rem;
        font-size: 0.9rem;
    }
}

/* Very small screens */
@media (max-width: 380px) {
    .reader-header h1 {
        font-size: 1.2rem;
    }

    .script-toggle button {
        padding: 0.3rem 0.5rem;
        font-size: 0.7rem;
    }

    #reader-content.font-small { font-size: 0.9rem; }
    #reader-content.font-medium { font-size: 1rem; }
    #reader-content.font-large { font-size: 1.1rem; }
    #reader-content.font-xlarge { font-size: 1.2rem; }
}

/* =====================
   Print Styles
   ===================== */

@media print {
    .reader-controls,
    .chapter-nav,
    .word-popup,
    .popup-close {
        display: none !important;
    }

    .verse, .prose {
        page-break-inside: avoid;
    }

    .word {
        cursor: default;
    }

    .word:hover, .word.selected {
        background: none;
        color: inherit;
    }
}
