/* ===================================================
   DALIL — Premium Islamic AI Interface
   Dark Gold Palette · Glassmorphism · Fluid Animations
   =================================================== */

:root {
    --gold:          #C9A84C;
    --gold-light:    #E4C76B;
    --gold-glow:     rgba(201, 168, 76, 0.35);
    --gold-dim:      rgba(201, 168, 76, 0.08);
    --bg:            #080810;
    --bg-card:       rgba(14, 14, 22, 0.75);
    --surface:       rgba(255, 255, 255, 0.03);
    --surface-hover: rgba(255, 255, 255, 0.06);
    --border:        rgba(201, 168, 76, 0.12);
    --border-light:  rgba(255, 255, 255, 0.05);
    --text:          #F0EDE6;
    --text-muted:    #8A8A9A;
    --text-dim:      #4A4A5A;
    --danger:        #E05555;
    --danger-glow:   rgba(224, 85, 85, 0.3);
    --radius-lg:     20px;
    --radius-xl:     28px;
}

/* ── Reset & Base ─────────────────────────────── */
*, *::before, *::after {
    margin: 0; padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
    /* Prevent bounce on iOS outside scroll areas */
    overscroll-behavior: none;
}

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

/* ── Ambient Background ───────────────────────── */
.bg-grid {
    position: fixed;
    inset: 0;
    background-image:
        linear-gradient(rgba(201,168,76,0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(201,168,76,0.03) 1px, transparent 1px);
    background-size: 48px 48px;
    pointer-events: none;
    z-index: 0;
}

.bg-glow-1, .bg-glow-2 {
    position: fixed;
    border-radius: 50%;
    filter: blur(120px);
    pointer-events: none;
    z-index: 0;
}
.bg-glow-1 {
    width: 500px; height: 500px;
    background: radial-gradient(circle, rgba(201,168,76,0.08) 0%, transparent 70%);
    top: -150px; left: -100px;
}
.bg-glow-2 {
    width: 400px; height: 400px;
    background: radial-gradient(circle, rgba(100,80,200,0.06) 0%, transparent 70%);
    bottom: -100px; right: -50px;
}

/* ── App Container ────────────────────────────── */
.app-container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 640px;
    /* 100dvh = dynamic viewport height, properly accounts for mobile browser chrome */
    height: 100dvh;
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 28px 24px 20px;
    /* iOS + Android safe area insets (notch / gesture nav bar) */
    /* viewport-fit=cover must be set in <meta> for these to work */
    padding-top: max(28px, env(safe-area-inset-top));
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    padding-left: max(24px, env(safe-area-inset-left));
    padding-right: max(24px, env(safe-area-inset-right));
}

/* ── Header ───────────────────────────────────── */
header {
    text-align: center;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
    position: relative;
}

.logo-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 10px;
}

.logo-icon {
    width: 44px; height: 44px;
    background: linear-gradient(135deg, rgba(201,168,76,0.15), rgba(201,168,76,0.04));
    border: 1px solid var(--border);
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    color: var(--gold);
    box-shadow: 0 0 20px var(--gold-glow);
    flex-shrink: 0;
}

.logo-text {
    font-family: 'Cinzel', serif;
    font-size: 2.2rem;
    font-weight: 600;
    letter-spacing: 3px;
    background: linear-gradient(135deg, #FFFFFF 0%, var(--gold-light) 60%, var(--gold) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline-row {
    margin-bottom: 10px;
}

.tag-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--gold);
    background: var(--gold-dim);
    border: 1px solid rgba(201,168,76,0.2);
    border-radius: 20px;
    padding: 3px 14px;
}

.header-desc {
    font-size: 0.82rem;
    color: var(--text-muted);
    letter-spacing: 0.3px;
    line-height: 1.5;
}

/* ── Interaction Area ─────────────────────────── */
.interaction-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    padding: 28px 0 20px;
}

.mic-outer-ring {
    position: relative;
    width: 128px; height: 128px;
    display: flex; align-items: center; justify-content: center;
}

.mic-ring-2 {
    position: absolute;
    inset: -12px;
    border-radius: 50%;
    border: 1px solid rgba(201,168,76,0.08);
    pointer-events: none;
}

.mic-container {
    position: relative;
    width: 100px; height: 100px;
    display: flex; align-items: center; justify-content: center;
}

.wave-canvas {
    position: absolute;
    inset: -20px;
    width: calc(100% + 40px);
    height: calc(100% + 40px);
    border-radius: 50%;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.mic-btn {
    position: relative; z-index: 2;
    width: 80px; height: 80px;
    border-radius: 50%;
    border: 1px solid rgba(201,168,76,0.3);
    background: linear-gradient(145deg, rgba(201,168,76,0.12), rgba(201,168,76,0.03));
    color: var(--gold);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow:
        0 0 0 0 var(--gold-glow),
        0 8px 32px rgba(0,0,0,0.5),
        inset 0 1px 0 rgba(255,255,255,0.05);
    backdrop-filter: blur(12px);
}

.mic-icon {
    width: 30px; height: 30px;
    transition: transform 0.3s ease;
}

.mic-btn:hover:not(:disabled) {
    transform: scale(1.06) translateY(-2px);
    border-color: rgba(201,168,76,0.6);
    box-shadow:
        0 0 40px var(--gold-glow),
        0 12px 40px rgba(0,0,0,0.5),
        inset 0 1px 0 rgba(255,255,255,0.08);
    background: linear-gradient(145deg, rgba(201,168,76,0.2), rgba(201,168,76,0.06));
}

.mic-btn:active:not(:disabled) {
    transform: scale(0.97);
}

.mic-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    filter: grayscale(0.8);
}

/* Recording state */
.mic-btn.recording {
    border-color: rgba(224,85,85,0.6);
    background: linear-gradient(145deg, rgba(224,85,85,0.15), rgba(224,85,85,0.04));
    color: var(--danger);
    animation: rec-pulse 2s ease-in-out infinite;
    box-shadow:
        0 0 0 0 var(--danger-glow),
        0 8px 32px rgba(0,0,0,0.5);
}

.mic-btn.recording + .wave-canvas {
    opacity: 1;
}

/* Processing state */
.mic-btn.processing {
    border-color: rgba(201,168,76,0.5);
    background: linear-gradient(145deg, rgba(201,168,76,0.18), rgba(201,168,76,0.05));
    animation: proc-glow 1.8s ease-in-out infinite alternate;
    box-shadow: 0 0 30px var(--gold-glow), 0 8px 32px rgba(0,0,0,0.5);
}

.wave-canvas.visible { opacity: 1; }

@keyframes rec-pulse {
    0%, 100% { box-shadow: 0 0 0 0 var(--danger-glow), 0 8px 32px rgba(0,0,0,0.5); }
    50%       { box-shadow: 0 0 0 12px rgba(224,85,85,0), 0 8px 32px rgba(0,0,0,0.5); }
}

@keyframes proc-glow {
    from { box-shadow: 0 0 20px var(--gold-glow), 0 8px 32px rgba(0,0,0,0.5); }
    to   { box-shadow: 0 0 50px var(--gold-glow), 0 8px 32px rgba(0,0,0,0.5); }
}

/* ── Status Text ──────────────────────────────── */
.status-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    text-align: center;
}

.action-text {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text);
    min-height: 26px;
    transition: color 0.3s ease;
}

.action-sub {
    font-size: 0.73rem;
    color: var(--text-dim);
    letter-spacing: 0.2px;
}

/* ── Stop Button ──────────────────────────────── */
.stop-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 22px;
    border-radius: 30px;
    border: 1px solid rgba(224,85,85,0.35);
    background: rgba(224,85,85,0.08);
    color: var(--danger);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: all 0.2s ease;
    letter-spacing: 0.2px;
}

.stop-btn:hover {
    background: rgba(224,85,85,0.16);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(224,85,85,0.2);
}

/* ── Chat Log ─────────────────────────────────── */
.conversation-log {
    flex: 1;
    min-height: 0; /* Critical: allows flex child to shrink below content size */
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xl);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* iOS momentum scrolling */
    box-shadow:
        0 0 0 1px rgba(201,168,76,0.04),
        0 10px 60px rgba(0,0,0,0.6),
        inset 0 1px 0 rgba(255,255,255,0.03);
    backdrop-filter: blur(24px);
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: rgba(201,168,76,0.15) transparent;
    margin-top: 2px;
}

.conversation-log::-webkit-scrollbar { width: 5px; }
.conversation-log::-webkit-scrollbar-thumb {
    background: rgba(201,168,76,0.15);
    border-radius: 10px;
}

/* Placeholder */
.chat-placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    text-align: center;
    color: var(--text-dim);
    padding: 20px;
}

.placeholder-icon {
    font-size: 2.6rem;
    opacity: 0.25;
    margin-bottom: 4px;
}

.chat-placeholder p {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.chat-placeholder span {
    font-size: 0.72rem;
    color: var(--text-dim);
    line-height: 1.7;
}

/* Chat Bubbles */
.log-entry {
    display: flex;
    flex-direction: column;
    gap: 5px;
    animation: fadeUp 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    opacity: 0;
    transform: translateY(12px);
    max-width: 88%;
}

.log-entry.assistant {
    align-self: flex-start;
}

.log-entry.user {
    align-self: flex-end;
    align-items: flex-end;
}

.log-entry .label {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 1.8px;
    text-transform: uppercase;
    color: var(--gold);
    padding: 0 4px;
    opacity: 0.7;
}

.log-entry.user .label {
    color: var(--text-muted);
}

.log-entry .text {
    font-size: 0.97rem;
    line-height: 1.65;
    color: var(--text);
    padding: 14px 18px;
    border-radius: 4px 18px 18px 18px;
    background: var(--surface);
    border: 1px solid var(--border-light);
    box-shadow: 0 2px 12px rgba(0,0,0,0.25);
    white-space: pre-wrap;
}

.log-entry.user .text {
    border-radius: 18px 4px 18px 18px;
    background: linear-gradient(135deg, rgba(201,168,76,0.08), rgba(201,168,76,0.03));
    border-color: rgba(201,168,76,0.12);
}

@keyframes fadeUp {
    to { opacity: 1; transform: translateY(0); }
}

/* ── Bottom Status Bar ─────────────────────── */
.bottom-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 12px;
    padding-bottom: env(safe-area-inset-bottom);
    border-top: 1px solid var(--border-light);
    /* Sticky so it's always visible at the bottom, even if layout slightly overflows */
    flex-shrink: 0;
}

.status-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--text-dim);
    transition: background 0.4s ease, box-shadow 0.4s ease;
}

.status-dot.ready {
    background: #4ADE80;
    box-shadow: 0 0 8px rgba(74,222,128,0.6);
}

.status-dot.error {
    background: var(--danger);
    box-shadow: 0 0 8px var(--danger-glow);
}

.status-label {
    font-size: 0.75rem;
    color: var(--text-dim);
    letter-spacing: 0.2px;
    flex: 1;
}

/* ── Settings Button ──────────────────────────── */
.settings-btn {
    background: none;
    border: 1px solid rgba(212,175,55,0.2);
    border-radius: 6px;
    color: var(--text-dim);
    cursor: pointer;
    padding: 4px 6px;
    display: flex;
    align-items: center;
    transition: color 0.2s, border-color 0.2s, background 0.2s;
    margin-left: auto;
}
.settings-btn:hover {
    color: var(--gold);
    border-color: rgba(212,175,55,0.5);
    background: rgba(212,175,55,0.05);
}

/* ── URL Modal ────────────────────────────────── */
.url-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(6px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.url-modal-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px 28px 24px;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 24px 64px rgba(0,0,0,0.6);
}

.url-modal-card h3 {
    font-family: 'Cinzel', serif;
    color: var(--gold);
    font-size: 1.1rem;
    margin: 0 0 8px;
}

.url-modal-card p {
    color: var(--text-dim);
    font-size: 0.85rem;
    margin: 0 0 18px;
    line-height: 1.5;
}

#url-input {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: 'Inter', monospace;
    font-size: 0.82rem;
    padding: 10px 12px;
    outline: none;
    box-sizing: border-box;
    transition: border-color 0.2s;
}
#url-input:focus {
    border-color: var(--gold);
}

.url-modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 18px;
    justify-content: flex-end;
}

.url-btn-secondary {
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 8px 16px;
    transition: border-color 0.2s, color 0.2s;
}
.url-btn-secondary:hover { border-color: var(--gold); color: var(--gold); }

.url-btn-primary {
    background: linear-gradient(135deg, var(--gold), #b8860b);
    border: none;
    border-radius: 8px;
    color: #1a1408;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 8px 20px;
    transition: opacity 0.2s;
}
.url-btn-primary:hover { opacity: 0.85; }

/* ── Utility ──────────────────────────────────── */
.hidden {
    display: none !important;
}

/* ══════════════════════════════════════════════
   MOBILE RESPONSIVE  (≤ 600px)
   ══════════════════════════════════════════════ */
@media (max-width: 600px) {

    .app-container {
        padding: 16px 16px 12px;
        padding-top: max(16px, env(safe-area-inset-top));
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    /* Compact header */
    header {
        padding-bottom: 14px;
        margin-bottom: 2px;
    }

    .logo-icon {
        width: 34px; height: 34px;
    }

    .logo-text {
        font-size: 1.6rem;
        letter-spacing: 2px;
    }

    .tagline-row {
        margin-bottom: 6px;
    }

    .header-desc {
        font-size: 0.72rem;
    }

    /* Compact mic area */
    .interaction-area {
        gap: 12px;
        padding: 14px 0 12px;
    }

    .mic-outer-ring {
        width: 100px; height: 100px;
    }

    .mic-container {
        width: 80px; height: 80px;
    }

    .mic-btn {
        width: 66px; height: 66px;
    }

    .mic-icon {
        width: 24px; height: 24px;
    }

    .action-text {
        font-size: 0.9rem;
    }

    .action-sub {
        font-size: 0.67rem;
    }

    /* Chat bubbles — full width on mobile */
    .log-entry {
        max-width: 95%;
    }

    .log-entry .text {
        font-size: 0.9rem;
        padding: 11px 14px;
    }

    /* Chat log — reduced padding */
    .conversation-log {
        padding: 14px;
        gap: 14px;
        border-radius: 18px;
    }

    /* Bottom bar — tighter */
    .bottom-bar {
        padding-top: 8px;
    }

    .status-label {
        font-size: 0.68rem;
    }

    /* URL modal — full screen on small phones */
    .url-modal-card {
        padding: 20px 18px 18px;
    }

    .url-modal-card h3 {
        font-size: 1rem;
    }
}

/* Very small phones (≤ 380px — iPhone SE etc.) */
@media (max-width: 380px) {

    .logo-text {
        font-size: 1.35rem;
    }

    .header-desc {
        display: none; /* Hide trilingual subtitle on tiny screens */
    }

    .interaction-area {
        padding: 10px 0 8px;
        gap: 10px;
    }

    .mic-btn {
        width: 58px; height: 58px;
    }

    .conversation-log {
        padding: 12px;
    }
}
