/* ============================================================
   Qoorah — Immersive Quran Reader
   styles.css
   ============================================================ */

/* ── Google Fonts ──────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Amiri:ital,wght@0,400;0,700;1,400&family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,400&family=DM+Mono:wght@400;500&display=swap');

/* ── Design Tokens ─────────────────────────────────────────── */

.dark-theme {
    --bg:            #080d14;
    --surface:       #0f1623;
    --surface-2:     #162030;
    --border:        #1e2d42;
    --text:          #e8edf5;
    --text-muted:    #6b7fa0;
    --accent:        #10b981;
    --accent-dark:   #059669;
    --accent-glow:   rgba(16, 185, 129, 0.18);
    --topbar-bg:     rgba(8, 13, 20, 0.75);
    --shadow-color:  rgba(0, 0, 0, 0.5);
    --blob-1:        #10b981;
    --blob-2:        #3b82f6;
}

.light-theme {
    --bg:            #f0f4f8;
    --surface:       #ffffff;
    --surface-2:     #f8fafc;
    --border:        #dde3ec;
    --text:          #0f1a2e;
    --text-muted:    #7a8caa;
    --accent:        #059669;
    --accent-dark:   #047857;
    --accent-glow:   rgba(5, 150, 105, 0.14);
    --topbar-bg:     rgba(240, 244, 248, 0.82);
    --shadow-color:  rgba(15, 26, 46, 0.12);
    --blob-1:        #10b981;
    --blob-2:        #6366f1;
}

/* ── Reset & Base ──────────────────────────────────────────── */

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

html {
    height: 100%;
    scroll-behavior: smooth;
}

body {
    min-height: 100%;
    background-color: var(--bg);
    color: var(--text);
    font-family: 'DM Sans', system-ui, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    transition: background-color 0.35s ease, color 0.35s ease;
    overflow-x: hidden;
}

/* ── Topbar ────────────────────────────────────────────────── */

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 28px;
    background: var(--topbar-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    gap: 16px;
}

.logo {
    font-weight: 600;
    font-size: 1.05rem;
    color: var(--accent);
    letter-spacing: -0.3px;
    white-space: nowrap;
}

.topbar-title {
    font-size: 1.1rem;
    font-weight: 500;
    font-family: 'Amiri', serif;
    text-align: center;
    flex: 1;
    color: var(--text);
    /* Prevent title from overflowing on small screens */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
}

.clock {
    font-family: 'DM Mono', monospace;
    font-size: 0.88rem;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 7px;
    border-radius: 50%;
    transition: color 0.2s, background-color 0.2s;
    line-height: 0;
}

.icon-btn:hover {
    color: var(--accent);
    background: var(--accent-glow);
}

/* ── Views ─────────────────────────────────────────────────── */

.view {
    display: none;
}

.view.active {
    display: block;
}

/* ── Home View — Surah Grid ────────────────────────────────── */

#home-view {
    padding: 32px 24px 80px;
}

.surah-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 14px;
    max-width: 1160px;
    margin: 0 auto;
}

.surah-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 18px 20px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    transition:
        transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1),
        box-shadow 0.25s ease,
        border-color 0.25s ease;
    outline: none; /* We style focus manually */
}

.surah-card:hover,
.surah-card:focus-visible {
    transform: translateY(-3px);
    border-color: var(--accent);
    box-shadow: 0 8px 24px var(--accent-glow), 0 2px 8px var(--shadow-color);
}

.surah-card:active {
    transform: translateY(0);
}

.card-left-group {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0; /* Allow text truncation */
}

.surah-number {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--accent);
}

.surah-name-en {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.surah-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.surah-name-ar {
    font-family: 'Amiri', serif;
    font-size: 1.55rem;
    color: var(--accent);
    line-height: 1;
    flex-shrink: 0;
}

.error-message {
    grid-column: 1 / -1;
    text-align: center;
    padding: 48px;
    color: var(--text-muted);
    font-size: 1rem;
}

/* ── Reading View ──────────────────────────────────────────── */

#reading-view {
    display: none; /* Overridden below when .active */
    flex-direction: column;
    align-items: center;
    justify-content: flex-start; /* Allow content to start from top when tall */
    height: 100vh;
    width: 100vw;
    overflow-x: hidden;
    overflow-y: auto;  /* Scroll instead of clipping on long ayat */
    position: relative;
}

#reading-view.active {
    display: flex;
}

/* Ambient animated background */
.ambient-bg {
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(110px);
    opacity: 0.28;
    animation: blob-float 24s infinite alternate ease-in-out;
}

.dark-theme .blob { opacity: 0.32; }

.blob-1 {
    width: 500px;
    height: 500px;
    top: -15%;
    left: 5%;
    background: var(--blob-1);
}

.blob-2 {
    width: 550px;
    height: 550px;
    bottom: -15%;
    right: 5%;
    background: var(--blob-2);
    animation-delay: -8s;
}

@keyframes blob-float {
    0%   { transform: translate(0, 0) scale(1); }
    33%  { transform: translate(60px, 80px) scale(1.08); }
    66%  { transform: translate(-40px, 40px) scale(0.95); }
    100% { transform: translate(30px, -50px) scale(1.04); }
}

/* Ayat content area */
.reading-container {
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: 800px;
    /* Top padding keeps content clear of the ambient blobs visually;
       bottom padding keeps it clear of the floating controls bar. */
    padding: 40px 32px 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Grow to fill the viewport when content is short (keeps centered feel),
       but also shrinks naturally when content is taller than the screen. */
    min-height: 100vh;
    box-sizing: border-box;
}

/* ── Ayat Card — Animation State Machine ───────────────────── */

.ayat-card {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 20px;
    transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.25, 1, 0.5, 1);
}

/* Default: invisible, shifted down */
.ayat-card {
    opacity: 0;
    transform: translateY(28px);
}

/* Entering: invisible, shifted up (prepares for fade-in from below) */
.ayat-card.state-entering {
    opacity: 0;
    transform: translateY(28px);
}

/* Leaving: fade out upward */
.ayat-card.state-leaving {
    opacity: 0;
    transform: translateY(-20px);
}

/* Visible: fully shown */
.ayat-card.state-visible {
    opacity: 1;
    transform: translateY(0);
}

/* Loading skeleton pulse */
.ayat-card.state-loading .arabic-text,
.ayat-card.state-loading .latin-text,
.ayat-card.state-loading .translation-text {
    background: var(--surface-2);
    border-radius: 8px;
    color: transparent;
    animation: skeleton-pulse 1.4s ease-in-out infinite;
    min-height: 1em;
    min-width: 60%;
    user-select: none;
}

.ayat-card.state-loading .arabic-text {
    min-height: 3.5rem;
    width: 80%;
}

@keyframes skeleton-pulse {
    0%, 100% { opacity: 0.4; }
    50%       { opacity: 0.8; }
}

/* ── Typography — Ayat Content ─────────────────────────────── */

.arabic-text {
    font-family: 'Amiri', serif;
    font-size: clamp(1.6rem, 4vw, 2.8rem); /* Tighter ceiling prevents overflow on long ayat */
    line-height: 2;
    direction: rtl;
    color: var(--text);
    width: 100%;
}

.latin-text {
    font-size: clamp(0.95rem, 2vw, 1.15rem);
    color: var(--accent);
    font-style: italic;
    font-weight: 500;
    line-height: 1.5;
    width: 100%;
}

.translation-text {
    font-size: clamp(1rem, 2.2vw, 1.2rem);
    color: var(--text-muted);
    line-height: 1.75;
    font-weight: 400;
    width: 100%;
}

/* ── Controls Bar ──────────────────────────────────────────── */

.controls-bar {
    position: absolute;
    bottom: 36px;
    left: 50%;
    transform: translateX(-50%) translateY(16px);
    z-index: 10;

    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;

    background: var(--topbar-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 100px;
    box-shadow: 0 16px 40px var(--shadow-color);

    /* Hidden by default */
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    transition:
        opacity 0.35s cubic-bezier(0.25, 1, 0.5, 1),
        transform 0.35s cubic-bezier(0.25, 1, 0.5, 1),
        visibility 0s linear 0.35s;
}

.controls-bar.interactive-visible {
    opacity: 1;
    pointer-events: auto;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
    transition:
        opacity 0.35s cubic-bezier(0.25, 1, 0.5, 1),
        transform 0.35s cubic-bezier(0.25, 1, 0.5, 1),
        visibility 0s linear 0s;
}

.control-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background-color 0.2s, transform 0.15s;
    line-height: 0;
    flex-shrink: 0;
}

.control-btn:hover {
    color: var(--accent);
    background: var(--accent-glow);
}

.control-btn:active {
    transform: scale(0.9);
}

.play-btn {
    background: var(--accent);
    color: #fff !important;
    width: 50px;
    height: 50px;
    box-shadow: 0 4px 16px var(--accent-glow);
    transition: background-color 0.2s, transform 0.15s, box-shadow 0.2s;
}

.play-btn:hover {
    background: var(--accent-dark);
    color: #fff !important;
    box-shadow: 0 6px 20px var(--accent-glow);
    transform: scale(1.06);
}

/* Autoplay button — active (on) state */
.control-btn.autoplay-active {
    color: var(--accent);
    background: var(--accent-glow);
}

.control-btn.autoplay-active:hover {
    color: var(--accent);
    background: var(--accent-glow);
}

.divider {
    width: 1px;
    height: 20px;
    background: var(--border);
    margin: 0 2px;
    flex-shrink: 0;
}

/* Ayat selector dropdown */
.ayat-selector-container {
    display: flex;
    align-items: center;
}

.ayat-select-dropdown {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    padding: 5px 30px 5px 12px;
    border-radius: 20px;
    font-size: 0.82rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    min-width: 100px;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2310B981' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 9px center;
    background-size: 12px;
}

.ayat-select-dropdown:hover,
.ayat-select-dropdown:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.ayat-select-dropdown option {
    background: var(--surface);
    color: var(--text);
}

/* ── Back Button ───────────────────────────────────────────── */

.back-btn {
    position: absolute;
    top: 24px;
    left: 24px;
    z-index: 10;

    display: flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    background: var(--topbar-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text-muted);
    font-size: 0.88rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;

    /* Hidden by default */
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    transform: translateY(-10px);
    transition:
        opacity 0.35s cubic-bezier(0.25, 1, 0.5, 1),
        transform 0.35s cubic-bezier(0.25, 1, 0.5, 1),
        color 0.2s,
        border-color 0.2s,
        visibility 0s linear 0.35s;
}

.back-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
}

.back-btn.interactive-visible {
    opacity: 1;
    pointer-events: auto;
    visibility: visible;
    transform: translateY(0);
    transition:
        opacity 0.35s cubic-bezier(0.25, 1, 0.5, 1),
        transform 0.35s cubic-bezier(0.25, 1, 0.5, 1),
        color 0.2s,
        border-color 0.2s,
        visibility 0s linear 0s;
}

/* ── Confirmation Modal ────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.modal-overlay.active {
    display: flex;
    opacity: 1;
}

.modal-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 36px;
    max-width: 380px;
    width: 90%;
    text-align: center;
    box-shadow: 0 24px 60px var(--shadow-color);
    transform: scale(0.92) translateY(10px);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.active .modal-box {
    transform: scale(1) translateY(0);
}

.modal-box h3 {
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 10px;
}

.modal-box p {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 28px;
    line-height: 1.55;
}

.modal-actions {
    display: flex;
    gap: 10px;
}

.modal-btn {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.15s;
}

.modal-btn:hover  { opacity: 0.88; }
.modal-btn:active { transform: scale(0.97); }

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

.btn-secondary {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
}

/* ── Responsive ────────────────────────────────────────────── */

@media (max-width: 640px) {
    .topbar {
        padding: 12px 16px;
    }

    .clock {
        display: none; /* Too cramped on small phones */
    }

    #home-view {
        padding: 20px 12px 80px;
    }

    .surah-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .reading-container {
        padding: 0 20px 110px;
    }

    .controls-bar {
        width: calc(100% - 40px);
        bottom: 24px;
        justify-content: space-around;
    }

    .back-btn {
        top: 16px;
        left: 16px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .blob { animation: none; }
    .ayat-card { transition: none; }
    .surah-card { transition: none; }
}