/* --- Premium Sattvic Design Tokens --- */
:root {
    --bg-canvas: #faf6eb;       /* Smooth Sandalwood canvas background */
    --bg-sidebar: #f7f0df;      /* Deepening chandan warmth for sidebar */
    --bg-card: #fffdfa;         /* Pristine warm parchment card background */
    --text-main: #3c230b;       /* Earthy dark roasted clay */
    --text-brand: #b35600;      /* Rich Saffron / Kumkum highlight */
    --text-muted: #734820;
    --border: #e6dac1;          /* Soft traditional paper crease border */
    --border-focus: #b35600;
    --brand-light: rgba(179, 86, 0, 0.08);
    --overlay: rgba(26, 17, 10, 0.85);
    --shadow: 0 4px 20px rgba(61, 35, 11, 0.05);
}

/* --- Sattvic Dark Mode ("Ratri Sadhana") Tokens --- */
[data-theme="dark"] {
    --bg-canvas: #120e0a;       /* Deep Temple Night Backdrop */
    --bg-sidebar: #19120c;      /* Dark Sandalwood Sidebar */
    --bg-card: #201811;         /* Terracotta Night Card */
    --text-main: #e8d8c3;       /* Warm Ivory Text */
    --text-brand: #f59e0b;      /* Radiant Saffron Glow */
    --text-muted: #a68e79;
    --border: #3d2d1e;          /* Dark Clay Border */
    --border-focus: #f59e0b;
    --brand-light: rgba(245, 158, 11, 0.12);
    --overlay: rgba(10, 7, 5, 0.90);
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Noto Sans', 'Noto Sans Kannada', 'Noto Sans Telugu', 'Noto Sans Tamil', sans-serif;
    background-color: var(--bg-canvas);
    color: var(--text-main);
    font-size: 1rem;
    line-height: 1.8;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* --- Dynamic Onboarding Wizard --- */
.onboarding-gate {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--overlay);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(12px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    padding: 1rem;
    overflow-y: auto;
}

.onboarding-gate.active {
    opacity: 1;
    pointer-events: auto;
}

.wizard-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 100%;
    max-width: 550px;
    padding: 2rem;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
    max-height: 88vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.wizard-card::-webkit-scrollbar {
    width: 5px;
}

.wizard-card::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.wizard-step {
    display: none;
}

.wizard-step.active {
    display: block;
}

.wizard-title {
    font-size: 1.45rem;
    color: var(--text-brand);
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.wizard-desc {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 2rem;
    line-height: 1.5;
}

.selection-grid {
    display: grid;
    grid-template-columns: repeat(1, 1fr);
    gap: 0.5rem;
    max-height: 240px;
    overflow-y: auto;
    padding-right: 0.5rem;
    margin-bottom: 1.5rem;
}

.selection-grid::-webkit-scrollbar {
    width: 6px;
}

.selection-grid::-webkit-scrollbar-track {
    background: var(--bg-canvas);
    border-radius: 4px;
}

.selection-grid::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.select-btn {
    background: var(--bg-canvas);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 0.9rem 1.2rem;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    text-align: left;
    transition: all 0.2s ease;
}

.select-btn:hover {
    border-color: var(--text-brand);
    background-color: var(--brand-light);
}

.select-btn.selected {
    background-color: var(--text-brand);
    color: #ffffff;
    border-color: var(--text-brand);
}

.wizard-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.action-btn {
    background-color: var(--text-brand);
    color: #ffffff;
    border: none;
    padding: 0.7rem 1.5rem;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
}

.action-btn.secondary {
    background: transparent;
    color: var(--text-brand);
    border: 1px solid var(--border-focus);
}

.action-btn.secondary:hover {
    background: var(--brand-light);
}

/* --- App Shell Structure --- */
.app-shell {
    display: flex;
    min-height: 100vh;
    position: relative;
    background-color: var(--bg-canvas);
}

/* --- Clean Nav Sidebar --- */
#sidebar {
    width: 320px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    padding: 2rem 1.5rem;
    overflow-y: auto;
    transition: transform 0.3s ease, margin-left 0.3s ease;
    z-index: 100;
}

#sidebar.collapsed {
    margin-left: -320px;
}

.sidebar-category {
    font-size: 0.95rem;
    color: var(--text-brand);
    font-weight: 700;
    margin: 1.75rem 0 0.75rem;
    letter-spacing: 0.01em;
    line-height: 1.4;
}

.stotra-list-wrapper {
    list-style: none;
}

.nav-item {
    display: block;
    padding: 0.45rem 0.25rem;
    color: var(--text-main);
    text-decoration: none;
    font-size: 1.05rem;
    font-weight: 500;
    cursor: pointer;
    line-height: 1.6;
    transition: color 0.15s ease;
}

.nav-item:hover {
    color: var(--text-brand);
}

.nav-item.active {
    color: var(--text-brand);
    font-weight: 700;
}

/* --- Main Content Sheet --- */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-canvas);
    min-width: 0;
}

header {
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 1.25rem 2.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
}

.brand-header {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.hamburger-icon {
    display: block;
    font-size: 1.4rem;
    color: var(--text-brand);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.hamburger-icon:hover {
    background-color: var(--brand-light);
}

.header-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-brand);
}

/* --- TRADITIONAL HIGH-DENSITY BOOK LAYOUT --- */
#canvas {
    max-width: 800px;
    width: 100%;
    margin: 1.5rem auto;
    padding: 2rem 3rem;
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.stotra-title-block {
    text-align: center;
    margin-bottom: 2rem;
    border-bottom: 1px dashed var(--border);
    padding-bottom: 1rem;
}

.stotra-title-block h2 {
    font-size: 2rem;
    color: var(--text-brand);
    font-weight: 700;
}

#contentView {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.section-block {
    background-color: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    padding: 0.25rem 0 !important;
    box-shadow: none !important;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.6rem !important;
}

.section-block[id*="mutt_"] {
    margin-top: 1rem;
    padding: 1rem !important;
    background-color: var(--brand-light) !important;
    border: 1px dashed var(--text-brand) !important;
    border-radius: 8px !important;
}

.instruction {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    font-weight: 700;
    border-left: 2px solid var(--text-brand);
    padding-left: 0.4rem;
    line-height: 1;
}

.mantra-box {
    font-size: 1.25rem;
    font-weight: 500;
    color: var(--text-main);
    line-height: 1.8;
    padding-left: 0.4rem;
}

.mantra-box p {
    margin-bottom: 0.25rem;
}

.mantra-box p:last-child {
    margin-bottom: 0;
}

/* --- High-Contrast Traditional Sattvic Prayoga Framework --- */

.shastra-heading,
.prayoga-card h3,
.prayoga-card h4 {
    color: var(--text-brand) !important;
    font-weight: 700;
    font-size: 1.25rem;
    margin-top: 0;
    margin-bottom: 0.75rem;
    border-bottom: 1px dashed var(--border);
    padding-bottom: 0.5rem;
}

.prayoga-card,
.verse-study-card {
    background: var(--bg-card) !important;
    border: 1px solid var(--border) !important;
    border-radius: 10px !important;
    padding: 1.5rem !important;
    margin-bottom: 1.25rem !important;
    box-shadow: var(--shadow) !important;
}

.verse-meaning {
    background: var(--bg-canvas) !important;
    color: var(--text-main) !important;
    border: 1px solid var(--border) !important;
}

.verse-script-main {
    color: var(--text-main) !important;
}

/* High-Density Grid Matrix (Sattvic Warmth) */
.prayoga-matrix-table {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid var(--border) !important;
    margin-top: 1rem;
    background: var(--bg-card);
}

.prayoga-matrix-table th {
    background: var(--bg-sidebar) !important;
    color: var(--text-main) !important;
    font-weight: 700 !important;
    font-size: 0.9rem;
    border: 1px solid var(--border) !important;
    padding: 0.75rem 1rem !important;
}

.prayoga-matrix-table td {
    border: 1px solid var(--border) !important;
    padding: 0.75rem 1rem !important;
    vertical-align: middle;
    color: var(--text-main) !important;
}

.prayoga-matrix-table tbody tr:nth-child(even) {
    background: var(--brand-light);
}

/* --- Deity Tag Cards Grid Styling --- */
.deity-card {
    cursor: pointer;
    text-align: center;
    background: var(--bg-card) !important;
    border: 1px solid var(--border) !important;
    border-radius: 12px;
    padding: 1rem 0.5rem;
    box-shadow: var(--shadow);
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.deity-card:hover {
    transform: translateY(-3px);
    border-color: var(--text-brand) !important;
    box-shadow: 0 6px 16px rgba(179, 86, 0, 0.12);
}

.deity-card-img-wrapper {
    width: 76px;
    height: 76px;
    margin: 0 auto 0.6rem auto;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid var(--text-brand);
    background-color: var(--bg-sidebar);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.deity-card-img-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
}

.deity-card-title {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-main);
    line-height: 1.3;
}

/* --- Deep Nested Sidebar Layout System --- */
.sidebar-chapter-group-title {
    font-family: 'Noto Sans Kannada', 'Noto Sans Telugu', 'Noto Sans', sans-serif !important;
    font-weight: 700 !important;
    font-size: 1.05rem !important;
    color: var(--text-brand) !important;
    padding: 0.6rem 0.75rem !important;
    margin-top: 0.8rem !important;
    line-height: 1.4 !important;
}

.sidebar-nested-list {
    list-style: none;
    padding-left: 1.25rem;
    margin: 0;
    border-left: 1px solid var(--border);
    margin-left: 1rem;
}

.sidebar-nested-item {
    font-size: 0.85rem !important;
    padding: 0.4rem 0.75rem !important;
}

.nav-item {
    font-family: 'Noto Sans Kannada', 'Noto Sans Telugu', 'Noto Sans', sans-serif !important;
    font-size: 0.95rem !important;
    font-weight: 500 !important;
}

/* --- Responsive Layout Adjustments --- */
@media (max-width: 900px) {
    #sidebar {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        margin-left: 0 !important;
        transform: translateX(-100%);
    }

    #sidebar.active {
        transform: translateX(0);
    }

    #canvas {
        padding: 1.25rem 1.5rem;
        margin: 0.75rem auto;
    }
}

/* --- Global Reader Font Scaling & Line Preservation --- */
:root {
    --user-font-scale: 1;
}

.continuous-reading-stream,
.verse-script-main {
    white-space: pre-line !important;
    word-break: break-word;
}

.mantra-box,
.continuous-reading-stream {
    font-size: calc(1.25rem * var(--user-font-scale)) !important;
    line-height: 1.8em !important;
}

.verse-script-main {
    font-size: calc(1.3rem * var(--user-font-scale)) !important;
    line-height: 1.8em !important;
    margin-bottom: 0.5em !important;
}

.verse-meaning {
    font-size: calc(0.9rem * var(--user-font-scale)) !important;
    line-height: 1.6em !important;
    margin-top: 0.5em !important;
}

.verse-study-card {
    padding-bottom: 1em !important;
    margin-bottom: 1.25em !important;
}

/* Header Controls Styling */
.header-controls {
    display: flex;
    gap: 0.35rem;
    align-items: center;
}

.header-brand-logo {
    height: 38px;
    width: 38px;
    object-fit: cover;
    border-radius: 50%;
    border: 1.5px solid var(--text-brand);
    cursor: pointer;
    background: var(--bg-sidebar);
    flex-shrink: 0;
}

.profile-icon {
    display: none;
}

/* --- DUAL-ROW MOBILE HEADER ARCHITECTURE (< 600px) --- */
@media (max-width: 600px) {
    header {
        flex-direction: column !important;
        align-items: stretch !important;
        padding: 0.65rem 0.85rem !important;
        gap: 0.5rem !important;
    }

    /* Row 1: Dedicated 100% to Identity & App Title */
    .brand-header {
        width: 100% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: flex-start !important;
        gap: 0.6rem !important;
    }

    .header-brand-logo {
        height: 32px !important;
        width: 32px !important;
    }

    .header-title {
        font-size: 1.15rem !important;
        line-height: 1.3 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        flex: 1 !important;
        min-width: 0 !important;
    }

    /* Row 2: Spacious Touch-Friendly Utility Bar */
    .header-controls {
        width: 100% !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding-top: 0.45rem !important;
        border-top: 1px dashed var(--border) !important;
        gap: 0.4rem !important;
    }

    .header-controls .action-btn {
        flex: 1 !important;
        padding: 0.4rem 0.5rem !important;
        font-size: 0.85rem !important;
        text-align: center !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 6px !important;
    }

    .profile-text {
        display: none !important;
    }

    .profile-icon {
        display: inline !important;
    }

    .wizard-card {
        padding: 1.25rem !important;
        max-height: 85vh !important;
        border-radius: 12px !important;
    }

    .wizard-title {
        font-size: 1.2rem !important;
    }

    .wizard-desc {
        margin-bottom: 1rem !important;
    }

    /* Tighten Reading Sheet Whitespace */
    #canvas {
        padding: 0.85rem 0.75rem !important;
        margin: 0.5rem auto !important;
        border-radius: 8px !important;
        border-left: none !important;
        border-right: none !important;
    }

    .prayoga-card,
    .verse-study-card {
        padding: 0.85rem 0.75rem !important;
        margin-bottom: 0.75rem !important;
        border-radius: 8px !important;
    }

    .stotra-title-block {
        margin-bottom: 1rem !important;
        padding-bottom: 0.5rem !important;
    }

    .stotra-title-block h2 {
        font-size: 1.3rem !important;
    }

    .shastra-heading {
        font-size: 1.05rem !important;
        margin-bottom: 0.5rem !important;
        padding-bottom: 0.35rem !important;
    }

    .prayoga-matrix-table th,
    .prayoga-matrix-table td {
        padding: 0.5rem 0.6rem !important;
        font-size: 0.85rem !important;
    }
}

/* --- Collapsible Accordion Sidebar System --- */
.sidebar-chapter-group-title {
    cursor: pointer !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    user-select: none;
    transition: color 0.15s ease;
    border-radius: 6px;
}

.sidebar-chapter-group-title:hover {
    color: var(--text-brand) !important;
    background-color: var(--brand-light);
}

.group-toggle-icon {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: normal;
    transition: transform 0.2s ease;
}

.sidebar-nested-list {
    transition: all 0.2s ease-in-out;
}

/* --- Modernized Search Bar Component --- */
.search-container {
    margin-bottom: 1.25rem;
    width: 100%;
}

.search-input {
    width: 100%;
    padding: 0.65rem 1rem 0.65rem 2.4rem;
    border-radius: 20px;
    border: 1px solid var(--border);
    background-color: var(--bg-card);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23b35600' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'%3E%3C/circle%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'%3E%3C/line%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 0.8rem center;
    background-size: 0.95rem;
    color: var(--text-main);
    font-size: 0.9rem;
    outline: none;
    box-shadow: var(--shadow);
    transition: all 0.2s ease;
}

.search-input:focus {
    border-color: var(--text-brand);
    box-shadow: 0 0 0 3px var(--brand-light);
}

.search-input::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}