/* ==========================================================================
   Design System & Variables
   ========================================================================== */
:root {
    --bg: #0B1118;
    --card: #141D27;
    --primary: #0FAE96;
    --primary-hover: #0c8a77;
    --accent: #FFD166;
    --text: #FFFFFF;
    --text-sec: #9AA5B1;
    --danger: #FF5A5F;
    --success: #0FAE96;
    
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-arabic: 'Amiri', serif;
    
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-full: 9999px;
    
    --shadow-soft: 0 4px 24px rgba(0, 0, 0, 0.2);
    --glass-border: 1px solid rgba(255, 255, 255, 0.05);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    line-height: 1.5;
    overflow-x: hidden;
}

a { text-decoration: none; color: inherit; }
ul { list-style: none; }

.text-primary { color: var(--primary); }
.text-accent { color: var(--accent); }
.text-secondary { color: var(--text-sec); }
.text-center { text-align: center; }
.mt-4 { margin-top: 1rem; }
.mt-2 { margin-top: 0.5rem; }
.mb-4 { margin-bottom: 1rem; }
.hidden { display: none !important; }

/* Global Loading Screen */
.full-screen-center {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: var(--bg);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Global Recording Popup */
.recording-popup {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--danger);
    color: white;
    padding: 10px 20px;
    border-radius: 30px;
    z-index: 10001;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    gap: 15px;
    font-size: 0.9rem;
    font-weight: 500;
}
.stop-btn {
    background: white;
    color: var(--danger);
    border: none;
    padding: 5px 15px;
    border-radius: 15px;
    font-weight: bold;
    cursor: pointer;
}

/* Light Mode Overrides */
body.light-mode {
    --bg: #F8FAFC;
    --card: #FFFFFF;
    --text: #0F172A;
    --text-sec: #64748B;
    --glass-border: 1px solid rgba(0, 0, 0, 0.05);
    --shadow-soft: 0 4px 24px rgba(0, 0, 0, 0.06);
}
body.light-mode .glass-card { background: var(--card); }
body.light-mode .bottom-nav,
body.light-mode .app-header { background: rgba(248, 250, 252, 0.9); }
body.light-mode .search-container input { background: #F1F5F9; color: var(--text); }
body.light-mode .toggle { background: #CBD5E1; }
body.light-mode .toggle::after { transform: translateX(0); }
body.light-mode .auth-input { border: 1px solid rgba(0, 0, 0, 0.1); background: #F1F5F9; color: #0F172A; }
body.light-mode .full-screen-center { background: #F8FAFC; }

/* Authentication Views */
body.on-auth .view:not(#auth-view) { display: none !important; }
body.on-auth #auth-view {
    display: flex !important;
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: var(--bg); z-index: 9999;
    justify-content: center; align-items: center;
}
#auth-view { display: none; flex-direction: column; justify-content: center; align-items: center; min-height: 80vh; padding: 1.5rem; }
#auth-view.active { display: flex !important; }
body.on-auth .bottom-nav, body.on-auth .app-header { display: none !important; }

.auth-card { width: 100%; max-width: 380px; padding: 2.5rem 1.75rem; text-align: center; border-radius: 20px; }
.auth-input {
    width: 100%; padding: 0.85rem 1rem; margin-bottom: 1rem; border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.15); background: rgba(255, 255, 255, 0.05);
    color: var(--text); font-size: 0.95rem; outline: none; box-sizing: border-box;
}
.auth-btn-primary {
    width: 100%; padding: 0.85rem; border-radius: 10px; border: none; background: var(--primary);
    color: #000; font-weight: 600; font-size: 0.95rem; cursor: pointer; margin-bottom: 0.75rem;
}
.auth-btn-secondary {
    width: 100%; padding: 0.85rem; border-radius: 10px; border: 1px solid var(--text-sec);
    background: transparent; color: var(--text); font-weight: 500; font-size: 0.95rem; cursor: pointer;
}

/* Layout Shell */
.app-container {
    max-width: 480px; margin: 0 auto; height: 100vh; display: flex; flex-direction: column;
    background-color: var(--bg); position: relative; box-shadow: var(--shadow-soft);
}
.app-header {
    display: flex; align-items: center; justify-content: space-between; padding: 1.5rem;
    background: rgba(11, 17, 24, 0.8); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    z-index: 100; position: sticky; top: 0;
}
.logo { display: flex; align-items: center; gap: 0.75rem; font-weight: 700; font-size: 1.25rem; letter-spacing: -0.5px; }
.icon-btn {
    background: none; border: none; color: var(--text); cursor: pointer; display: flex;
    align-items: center; justify-content: center; padding: 0.5rem; border-radius: 50%; transition: background 0.2s ease;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.1); }
.app-main { flex: 1; overflow-y: auto; position: relative; }

/* Bottom Navigation - UPDATED WITH SAFE AREA FIX */
.bottom-nav {
    display: flex; justify-content: space-around; 
    /* The calc() specifically pushes the bar up past the mobile browser UI */
    padding: 0.75rem 1rem calc(1.5rem + env(safe-area-inset-bottom, 20px)) 1rem;
    background: rgba(20, 29, 39, 0.9); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-top: var(--glass-border);
}
.nav-item {
    display: flex; flex-direction: column; align-items: center; gap: 0.25rem;
    color: var(--text-sec); font-size: 0.75rem; font-weight: 500; transition: color 0.3s ease;
}
.nav-item svg { transition: transform 0.3s ease, stroke 0.3s ease; }
.nav-item.active { color: var(--primary); }
.nav-item.active svg { transform: translateY(-2px); stroke: var(--primary); }

/* UI Components */
.glass-card { background: var(--card); border-radius: var(--radius-md); padding: 1.25rem; border: var(--glass-border); box-shadow: var(--shadow-soft); }
.border-accent { border-left: 4px solid var(--accent); }
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
    padding: 0.875rem 1.5rem; border-radius: var(--radius-full); font-size: 1rem;
    font-weight: 600; cursor: pointer; border: none; transition: all 0.2s ease; font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(15, 174, 150, 0.3); }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }
.btn-outline { background: transparent; color: var(--text); border: 1px solid var(--text-sec); }
.btn-outline:hover { background: rgba(255, 255, 255, 0.05); }
.btn-large { width: 100%; padding: 1.125rem; font-size: 1.125rem; }
.btn-block { width: 100%; }
.btn-text { background: none; border: none; color: var(--primary); font-weight: 600; cursor: pointer; font-family: inherit; }

/* Views & Routing Animations */
.view { display: none; padding: 1.5rem; animation: fadeSlideUp 0.4s ease forwards; opacity: 0; }
.view.active { display: block; }
@keyframes fadeSlideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* Screen: Home */
.hero-section { margin-bottom: 2rem; }
.hero-title { font-size: 2rem; line-height: 1.2; margin-bottom: 0.5rem; font-weight: 700; }
.hero-subtitle { color: var(--text-sec); font-size: 1rem; }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; margin-bottom: 2rem; }
.stat-card { display: flex; flex-direction: column; align-items: center; padding: 1rem 0.5rem; text-align: center; }
.stat-icon { font-size: 1.25rem; margin-bottom: 0.25rem; }
.stat-value { font-size: 1.25rem; font-weight: 700; }
.stat-label { font-size: 0.75rem; color: var(--text-sec); }
.action-section { margin-bottom: 2rem; }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.section-header h2 { font-size: 1.25rem; font-weight: 600; }
.recent-card { display: flex; justify-content: space-between; align-items: center; cursor: pointer; transition: transform 0.2s ease, background 0.2s ease; }
.recent-card:hover { transform: translateY(-2px); background: rgba(20, 29, 39, 0.8); }
.recent-info { display: flex; align-items: center; gap: 1rem; }
.surah-number { display: flex; align-items: center; justify-content: center; width: 40px; height: 40px; background: rgba(15, 174, 150, 0.1); color: var(--primary); border-radius: var(--radius-sm); font-weight: 600; }
.recent-info h3 { font-size: 1rem; font-weight: 600; }
.recent-info p { font-size: 0.75rem; color: var(--text-sec); }
.recent-score { font-weight: 700; font-size: 1.125rem; }
.disclaimer-card { margin-top: 2rem; display: flex; gap: 1rem; background: rgba(255, 90, 95, 0.1); border: 1px solid rgba(255, 90, 95, 0.2); }
.disclaimer-icon { font-size: 1.25rem; }
.disclaimer-card p { font-size: 0.875rem; color: rgba(255,255,255,0.8); }

/* Screen: Surah Selection */
.search-container { position: relative; margin-bottom: 1.5rem; }
.search-icon { position: absolute; left: 1rem; top: 50%; transform: translateY(-50%); color: var(--text-sec); }
.search-container input { width: 100%; padding: 1rem 1rem 1rem 3rem; background: var(--card); border: var(--glass-border); border-radius: var(--radius-full); color: var(--text); font-size: 1rem; outline: none; font-family: inherit; transition: border-color 0.3s ease; }
.search-container input:focus { border-color: var(--primary); }
.surah-list { display: flex; flex-direction: column; gap: 0.75rem; }
.surah-item { display: flex; justify-content: space-between; align-items: center; cursor: pointer; }
.surah-item:hover { background: rgba(20, 29, 39, 0.7); }
.surah-item-ar { font-family: var(--font-arabic); font-size: 1.25rem; color: var(--accent); }

/* Screen: Record */
.record-header { text-align: center; margin-bottom: 3rem; }
.mic-container { position: relative; width: 160px; height: 160px; margin: 0 auto 3rem auto; display: flex; align-items: center; justify-content: center; }
.mic-button { width: 80px; height: 80px; background: var(--primary); border-radius: 50%; border: none; color: white; display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 10; box-shadow: 0 8px 24px rgba(15, 174, 150, 0.4); transition: transform 0.2s ease; }
.mic-button:hover { transform: scale(1.05); }
.mic-button.active { background: var(--danger); box-shadow: 0 8px 24px rgba(255, 90, 95, 0.4); }
.mic-waves { position: absolute; width: 100%; height: 100%; top: 0; left: 0; display: none; }
.mic-waves.active { display: block; }
.wave { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 80px; height: 80px; border-radius: 50%; background: rgba(255, 90, 95, 0.3); animation: ripple 2s infinite ease-in-out; }
.wave:nth-child(2) { animation-delay: 0.6s; }
.wave:nth-child(3) { animation-delay: 1.2s; }
@keyframes ripple { 0% { transform: translate(-50%, -50%) scale(1); opacity: 1; } 100% { transform: translate(-50%, -50%) scale(2.5); opacity: 0; } }
.timer { font-size: 3rem; font-weight: 300; text-align: center; font-variant-numeric: tabular-nums; margin-bottom: 0.5rem; }
.recording-status { text-align: center; font-weight: 500; margin-bottom: 3rem; animation: pulseText 1.5s infinite; }
.recording-status.stopped { color: var(--text-sec); animation: none; }
@keyframes pulseText { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.record-controls { display: flex; gap: 1rem; }
.record-controls .btn { flex: 1; }

/* Screen: Analysis Loading */
.analysis-container { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 70vh; text-align: center; }
.loader-circular { width: 64px; height: 64px; border: 4px solid rgba(15, 174, 150, 0.2); border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; margin-bottom: 2rem; }
@keyframes spin { to { transform: rotate(360deg); } }
.analysis-steps { margin-top: 3rem; text-align: left; width: 100%; }
.step { padding: 1rem; color: var(--text-sec); position: relative; padding-left: 2rem; opacity: 0.5; transition: opacity 0.3s ease, color 0.3s ease; }
.step::before { content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%); width: 8px; height: 8px; border-radius: 50%; background: var(--text-sec); }
.step.active { color: var(--text); opacity: 1; }
.step.active::before { background: var(--primary); box-shadow: 0 0 10px var(--primary); }
.step.done::before { background: var(--primary); }

/* Screen: Results */
.result-header { margin-bottom: 2rem; }
.overall-score-container { display: flex; flex-direction: column; align-items: center; margin-bottom: 1.5rem; padding: 2rem; }
.circular-chart { display: block; margin: 0 auto; max-width: 120px; max-height: 120px; margin-bottom: 1rem; }
.circle-bg { fill: none; stroke: rgba(255,255,255,0.05); stroke-width: 2.5; }
.circle-value { fill: none; stroke-width: 2.5; stroke-linecap: round; animation: progress 1s ease-out forwards; }
.primary .circle-value { stroke: var(--primary); }
.circular-chart .percentage { fill: #fff; font-family: var(--font-sans); font-size: 0.5em; text-anchor: middle; font-weight: 700; }
@keyframes progress { 0% { stroke-dasharray: 0 100; } }
.metrics-grid { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1.5rem; }
.metric-card { display: flex; align-items: center; gap: 1rem; padding: 1rem; }
.metric-title { width: 100px; font-size: 0.875rem; font-weight: 500; }
.metric-bar-bg { flex: 1; height: 6px; background: rgba(255,255,255,0.1); border-radius: var(--radius-full); overflow: hidden; }
.metric-bar-fill { height: 100%; border-radius: var(--radius-full); transition: width 1s ease-out; }
.bg-primary { background: var(--primary); }
.bg-accent { background: var(--accent); }
.metric-val { font-weight: 700; width: 40px; text-align: right; }
.feedback-list { display: flex; flex-direction: column; gap: 0.75rem; margin-top: 1rem; }
.feedback-item { background: rgba(20, 29, 39, 0.5); padding: 1rem; border-radius: var(--radius-sm); border-left: 3px solid transparent; }
.feedback-item.perfect { border-left-color: var(--success); }
.feedback-item.warning { border-left-color: var(--accent); }
.feedback-item.error { border-left-color: var(--danger); }
.feedback-header { display: flex; justify-content: space-between; margin-bottom: 0.25rem; font-size: 0.875rem; color: var(--text-sec); }
.feedback-text { font-size: 0.95rem; }
.feedback-ar { font-family: var(--font-arabic); font-size: 1.2rem; color: var(--accent); }
.action-tip { background: rgba(15, 174, 150, 0.1); padding: 10px 12px; border-radius: 8px; margin-top: 12px; font-size: 0.85rem; border-left: 3px solid var(--primary); color: var(--text); }

/* Screen: Progress & History */
.bar-chart { display: flex; align-items: flex-end; justify-content: space-between; height: 150px; margin-top: 1.5rem; padding-bottom: 0.5rem; border-bottom: 1px solid rgba(255,255,255,0.1); }
.bar { width: 12%; background: var(--primary); border-radius: 4px 4px 0 0; transition: height 1s ease; opacity: 0.7; }
.bar.today { background: var(--accent); opacity: 1; }
.chart-labels { display: flex; justify-content: space-between; margin-top: 0.5rem; font-size: 0.75rem; color: var(--text-sec); }
.history-list { display: flex; flex-direction: column; gap: 0.75rem; }
.history-item { display: flex; justify-content: space-between; align-items: center; cursor: pointer; transition: transform 0.2s ease; }
.history-item:hover { transform: scale(1.02); }
.history-item-date { font-size: 0.75rem; color: var(--text-sec); margin-top: 0.25rem; }

/* Screen: Settings */
.settings-group { padding: 0.5rem 1.25rem; }
.setting-item { display: flex; justify-content: space-between; align-items: center; padding: 1rem 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
.setting-item:last-child { border-bottom: none; }
.setting-item h4 { font-weight: 500; font-size: 1rem; }
.toggle { width: 44px; height: 24px; background: rgba(255,255,255,0.2); border-radius: var(--radius-full); position: relative; cursor: pointer; transition: background 0.3s ease; }
.toggle::after { content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; background: white; border-radius: 50%; transition: transform 0.3s ease; }
.toggle.active { background: var(--primary); }
.toggle.active::after { transform: translateX(20px); }