:root {
    --bg-base: #fcfaf7;
    --bg-gradient: linear-gradient(180deg, #fdfbf7 0%, #f1f2f6 100%);
    --text-main: #2d3436;
    --text-muted: #57606f;
    --card-bg: #ffffff;
    --card-border: rgba(0, 0, 0, 0.02);
    --card-shadow: rgba(0, 0, 0, 0.03);
    --accent-primary: #e67e22;
    --accent-secondary: #3498db;
    --nav-bg: rgba(255, 255, 255, 0.4);
    --nav-border: rgba(0, 0, 0, 0.05);
    --hover-highlight: rgba(230, 126, 34, 0.1);
    --progress-bg: rgba(0, 0, 0, 0.05);
    --danger: #e74c3c;
    --font-scale: 1;
}

[data-theme="dark"] {
    --bg-base: #0f172a;
    --bg-gradient: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --card-bg: #1e293b;
    --card-border: rgba(255, 255, 255, 0.05);
    --card-shadow: rgba(0, 0, 0, 0.4);
    --accent-primary: #fbbf24;
    --accent-secondary: #22d3ee;
    --nav-bg: rgba(15, 23, 42, 0.5);
    --nav-border: rgba(255, 255, 255, 0.1);
    --hover-highlight: rgba(251, 191, 36, 0.15);
    --progress-bg: rgba(255, 255, 255, 0.1);
    --danger: #ef4444;
}

@font-face {
    font-family: 'UthmanicHafs';
    src: url('https://verses.quran.foundation/fonts/quran/hafs/uthmanic_hafs/UthmanicHafs1Ver18.woff2') format('woff2'),
        url('https://verses.quran.foundation/fonts/quran/hafs/uthmanic_hafs/UthmanicHafs1Ver18.ttf') format('truetype');
    font-display: swap;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body,
html {
    width: 100%;
    height: 100dvh;
    font-family: 'Georgia', serif;
    background-color: var(--bg-base);
    color: var(--text-main);
    overflow: hidden;
    transition: background-color 0.3s ease;
}

.hidden {
    display: none !important;
}

.invisible {
    visibility: hidden !important;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.fade-in {
    animation: fadeIn 0.4s ease-out forwards;
}

/* --- Landing Page --- */
#home-view {
    height: 100dvh;
    width: 100vw;
    overflow-y: auto;
    padding: 2rem 1.5rem 1rem 1.5rem;
    background: var(--bg-gradient);
    position: relative;
}

.home-header {
    display: grid;
    grid-template-columns: 45px 1fr 45px;
    align-items: center;
    margin-top: 1rem;
    margin-bottom: 3rem;
    width: 100%;
    max-width: 600px;
    margin-inline: auto;
}

.header-title {
    grid-column: 2;
    text-align: center;
    margin: 0;
    color: var(--accent-primary);
    letter-spacing: 4px;
    text-transform: uppercase;
    font-size: 1.8rem;
    font-weight: 300;
}

.header-actions {
    grid-column: 3;
    display: flex;
    justify-content: flex-end;
}

.icon-btn,
.pill-btn,
.header-icon-btn,
.nav-icon-btn {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

.icon-btn {
    background: var(--card-bg);
    color: var(--text-main);
    border: 1px solid var(--nav-border);
    border-radius: 50%;
    width: 45px;
    height: 45px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 10px var(--card-shadow);
    transition: all 0.2s ease;
}

.icon-btn:hover {
    border-color: var(--accent-secondary);
    transform: scale(1.05);
}

.icon-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.icon-btn.active {
    color: var(--accent-primary);
    border-color: var(--accent-primary);
}

.icon-btn.active svg {
    fill: currentColor;
}

#surah-list {
    list-style: none;
    max-width: 600px;
    margin: 0 auto;
    padding-bottom: 3rem;
}

.surah-item {
    padding: 1.2rem 1.5rem;
    margin-bottom: 0.8rem;
    background: var(--card-bg);
    border-radius: 15px;
    box-shadow: 0 4px 15px var(--card-shadow);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-muted);
    border: 1px solid var(--card-border);
    transition: 0.2s;
}

.surah-item-info {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.surah-name {
    font-size: 1.15rem;
    font-weight: bold;
    color: var(--text-main);
}

.surah-translation {
    font-size: 0.85rem;
    font-family: sans-serif;
    opacity: 0.8;
}

.surah-item:hover {
    background-color: var(--hover-highlight);
    transform: scale(1.02);
}

.surah-item:hover .surah-name {
    color: var(--accent-primary);
}

/* --- Settings View --- */
#settings-view {
    height: 100dvh;
    width: 100vw;
    overflow-y: auto;
    padding: 2rem 1.5rem;
    background: var(--bg-gradient);
}

.settings-container {
    max-width: 600px;
    margin: 0 auto;
    padding-bottom: 4rem;
}

.settings-header {
    display: flex;
    align-items: center;
    margin-bottom: 3rem;
    gap: 1.5rem;
}

.settings-header h2 {
    color: var(--accent-primary);
    font-weight: 300;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.settings-back-btn {
    background: transparent;
    border: none;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: sans-serif;
    font-weight: bold;
}

.settings-back-btn svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.setting-group {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 15px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 15px var(--card-shadow);
}

.setting-group label {
    display: block;
    margin-bottom: 1rem;
    font-weight: bold;
    color: var(--text-main);
    font-family: sans-serif;
    letter-spacing: 1px;
    text-transform: uppercase;
    font-size: 0.85rem;
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.setting-text {
    font-size: 0.95rem;
    font-family: sans-serif;
    color: var(--text-main);
}

.top-control {
    background: var(--bg-base);
    color: var(--text-main);
    border: 1px solid var(--nav-border);
    padding: 0.8rem 1.2rem;
    border-radius: 10px;
    cursor: pointer;
    font-family: sans-serif;
    font-size: 0.9rem;
    font-weight: bold;
    width: 100%;
    outline: none;
    transition: all 0.2s ease;
}

.top-control:hover {
    border-color: var(--accent-secondary);
}

.top-control:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.bookmarks-list {
    list-style: none;
    margin-top: 1rem;
}

.bookmark-item {
    background: var(--bg-base);
    padding: 1rem;
    border-radius: 10px;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid var(--card-border);
    cursor: pointer;
    transition: all 0.2s;
}

.bookmark-item:hover {
    border-color: var(--accent-secondary);
}

.bookmark-info {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.bookmark-title {
    font-weight: bold;
    font-family: sans-serif;
    font-size: 0.9rem;
}

.bookmark-snippet {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.bookmark-delete {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 5px;
}

.bookmark-delete:hover {
    background: rgba(231, 76, 60, 0.1);
}

.bookmark-delete svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* --- Header Assembly --- */
.header-assembly {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 100;
    background: var(--nav-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--nav-border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem 1.5rem;
    height: 60px;
}

.persistent-title {
    font-size: 0.9rem;
    color: var(--accent-primary);
    letter-spacing: 2px;
    text-transform: uppercase;
    font-weight: 700;
    transition: all 0.3s;
    cursor: pointer;
    user-select: none;
}

.persistent-title:hover {
    opacity: 0.7;
}

.persistent-title.arabic-mode {
    font-family: 'Amiri', serif;
    font-size: 1.2rem;
    font-weight: bold;
    letter-spacing: 0;
}

.persistent-verse {
    font-size: 0.8rem;
    color: var(--accent-secondary);
    font-family: sans-serif;
    letter-spacing: 1px;
    font-weight: bold;
}

.tabs-bar {
    display: flex;
    height: 45px;
    width: 100%;
}

.tab-btn {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: sans-serif;
    font-size: 0.85rem;
    font-weight: bold;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.tab-btn.active {
    color: var(--accent-primary);
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 20%;
    width: 60%;
    height: 3px;
    background: var(--accent-primary);
    border-radius: 3px 3px 0 0;
}

.header-icon-btn {
    flex: 0 0 55px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    border-left: 1px solid var(--nav-border);
    transition: all 0.2s ease;
}

.header-icon-btn:hover {
    color: var(--accent-secondary);
    background: var(--hover-highlight);
}

.header-icon-btn.active {
    color: var(--accent-primary);
}

.header-icon-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* --- Bottom Bar Assembly --- */
.bottom-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: var(--nav-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid var(--nav-border);
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.progress-hit-area {
    position: absolute;
    top: -10px;
    left: 0;
    width: 100%;
    height: 20px;
    cursor: pointer;
    z-index: 101;
    display: flex;
    align-items: center;
}

.progress-container {
    width: 100%;
    height: 4px;
    background: var(--progress-bg);
    pointer-events: none;
}

#progress-bar {
    height: 100%;
    width: 0%;
    background: var(--accent-secondary);
    box-shadow: 0 0 10px var(--accent-secondary);
    transition: width 0.1s linear;
}

.nav-buttons {
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0.5rem 1.5rem;
    padding-bottom: calc(0.8rem + env(safe-area-inset-bottom, 0px));
    max-width: 500px;
    margin: 0 auto;
    width: 100%;
}

.nav-icon-btn {
    background: transparent;
    color: var(--text-muted);
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 25px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s ease;
}

.nav-icon-btn:hover {
    background: var(--hover-highlight);
    color: var(--accent-secondary);
}

.nav-icon-btn svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

#home-btn {
    color: var(--accent-primary);
}

#home-btn:hover {
    background: rgba(230, 126, 34, 0.1);
}

/* --- Zen Mode Classes --- */
.zen-hidden-top {
    transform: translateY(-100%);
}

.zen-hidden-bottom {
    transform: translateY(100%);
}

/* --- Scrubber & Banners --- */
.scrubber-tooltip {
    position: absolute;
    bottom: 25px;
    left: 0;
    transform: translateX(-50%);
    background: var(--text-main);
    color: var(--bg-base);
    padding: 4px 10px;
    border-radius: 12px;
    font-family: sans-serif;
    font-size: 0.75rem;
    font-weight: bold;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    white-space: nowrap;
    z-index: 110;
}

.scrubber-tooltip.visible {
    opacity: 1;
}

.continue-banner {
    position: absolute;
    top: 115px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: var(--text-main);
    color: var(--bg-base);
    border: 1px solid var(--accent-secondary);
    padding: 10px 20px;
    border-radius: 25px;
    font-family: sans-serif;
    font-size: 0.85rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 6px 20px var(--card-shadow);
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 90;
    display: flex;
    align-items: center;
    gap: 8px;
}

.continue-banner.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    pointer-events: auto;
}

.continue-banner:hover {
    transform: translateX(-50%) translateY(-2px) scale(1.02);
}

.continue-banner svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

/* --- Nested Carousel System --- */
#surah-view {
    position: relative;
    height: 100dvh;
    width: 100vw;
}

.tab-carousel {
    width: 100vw;
    height: 100dvh;
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    touch-action: pan-x pan-y;
}

.tab-carousel::-webkit-scrollbar {
    display: none;
}

.vertical-feed {
    flex: 0 0 100vw;
    width: 100vw;
    height: 100dvh;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-snap-type: y mandatory;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    scrollbar-width: none;
}

.vertical-feed::-webkit-scrollbar {
    display: none;
}

.verse-screen {
    width: 100vw;
    height: 100dvh;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 9rem 2rem 8rem 2rem;
    text-align: center;
    position: relative;
}

.verse-actions {
    position: absolute;
    bottom: calc(85px + env(safe-area-inset-bottom, 0px));
    right: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: flex-end;
    z-index: 10;
    transition: opacity 0.3s ease;
}

.vertical-feed.is-scrolling .verse-actions {
    opacity: 0.3;
    pointer-events: none;
}

.bookmark-btn:not(.active) svg {
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.play-pill {
    display: flex;
    align-items: center;
    background: var(--card-bg);
    border: 1px solid var(--nav-border);
    border-radius: 25px;
    box-shadow: 0 4px 10px var(--card-shadow);
    overflow: hidden;
}

.pill-btn {
    background: transparent;
    border: none;
    color: var(--text-main);
    width: 45px;
    height: 45px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.pill-btn:hover {
    background: var(--hover-highlight);
    color: var(--accent-secondary);
}

.pill-btn.active {
    color: var(--accent-primary);
}

.pill-btn.playing {
    color: var(--accent-secondary);
}

.pill-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.pill-divider {
    width: 1px;
    height: 24px;
    background: var(--nav-border);
}

.verse-text {
    font-size: calc(2rem * var(--font-scale, 1));
    line-height: 1.6;
    max-width: 800px;
    text-wrap: balance;
    color: var(--text-main);
}

.verse-text.long-verse {
    font-size: calc(1.4rem * var(--font-scale, 1));
}

.verse-text.extra-long-verse {
    font-size: calc(1.1rem * var(--font-scale, 1));
}

.verse-text-arabic {
    direction: rtl;
    text-align: center;
    max-width: 900px;
}

[data-arabic-font="uthmanic"] .verse-text-arabic {
    font-family: 'UthmanicHafs', serif;
    font-size: calc(2.8rem * var(--font-scale, 1));
    line-height: 1.8;
}

[data-arabic-font="default"] .verse-text-arabic {
    font-family: 'Amiri', 'Scheherazade New', sans-serif;
    font-size: calc(2.3rem * var(--font-scale, 1));
    line-height: 1.6;
}

[data-arabic-font="uthmanic"] .verse-text-arabic.long-verse {
    font-size: calc(1.8rem * var(--font-scale, 1));
}

[data-arabic-font="default"] .verse-text-arabic.long-verse {
    font-size: calc(1.6rem * var(--font-scale, 1));
}

.swipe-hint {
    position: fixed;
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    background: var(--card-bg);
    color: var(--text-muted);
    border: 1px solid var(--nav-border);
    padding: 8px 16px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: sans-serif;
    font-size: 0.85rem;
    font-weight: bold;
    z-index: 90;
    pointer-events: none;
    box-shadow: 0 4px 15px var(--card-shadow);
    animation: bounceUp 1.5s infinite;
    transition: opacity 0.3s ease;
}

.swipe-hint.fade-out {
    opacity: 0;
}

.swipe-hint svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

@keyframes bounceUp {

    0%,
    100% {
        transform: translateX(-50%) translateY(0);
    }

    50% {
        transform: translateX(-50%) translateY(-8px);
    }
}

#toast-container {
    position: fixed;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--text-main);
    color: var(--bg-base);
    padding: 0.8rem 1.5rem;
    border-radius: 30px;
    font-family: sans-serif;
    font-size: 0.85rem;
    font-weight: bold;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    white-space: nowrap;
}

#toast-container.show {
    opacity: 0.95;
    transform: translateX(-50%) translateY(0);
}

@media (max-width: 600px) {
    .verse-text {
        font-size: calc(1.5rem * var(--font-scale, 1));
    }

    .verse-text.long-verse {
        font-size: calc(1.2rem * var(--font-scale, 1));
    }

    .verse-text.extra-long-verse {
        font-size: calc(1.05rem * var(--font-scale, 1));
    }

    [data-arabic-font="uthmanic"] .verse-text-arabic {
        font-size: calc(2.2rem * var(--font-scale, 1));
    }

    [data-arabic-font="default"] .verse-text-arabic {
        font-size: calc(1.8rem * var(--font-scale, 1));
    }

    .verse-actions {
        right: 1rem;
    }

    .icon-btn,
    .pill-btn,
    .nav-icon-btn {
        width: 40px;
        height: 40px;
    }
}