@import url('https://fonts.googleapis.com/css2?family=Almarai:wght@300;400;700;800&display=swap');

/* ── Variables ── */
:root {
    --grad-primary:     linear-gradient(90deg, #7b61ff, #3ec5ff);
    --grad-secondary:   linear-gradient(90deg, #4cd964, #28a745);
    --grad-warm:        linear-gradient(90deg, #ff9800, #ff5722);
    --grad-bg:          radial-gradient(circle at 10% 10%, #fff9e6 0%, #ffe6f2 25%, #e6f7ff 60%, #f0f8ff 100%);

    --purple:           #7b61ff;
    --purple-deep:      #4f33d6;
    --purple-light:     #f3f1ff;
    --cyan:             #3ec5ff;
    --green:            #28a745;
    --green-light:      #f0fff4;
    --orange:           #ff9800;
    --orange-light:     #fff8e8;
    --red:              #ff5252;
    --red-light:        #fff3f3;
    --yellow:           #ffd600;

    --text-dark:        #221f32;
    --text-mid:         #4d4d5e;
    --text-light:       #888;

    --border:           #e6e4f2;
    --border-dashed:    rgba(255, 182, 56, 0.55);

    --card-bg:          rgba(255, 255, 255, 0.95);
    --grad-card-bg:     linear-gradient(135deg, rgba(255,255,255,0.92) 0%, rgba(253,250,255,0.88) 100%);
    --shadow-card:      0 1px 2px rgba(40,28,90,0.04), 0 20px 50px -12px rgba(76, 49, 178, 0.18);
    --shadow-header:    0 6px 20px rgba(60, 30, 120, 0.15);
    --shadow-btn:       0 10px 24px rgba(65, 53, 118, 0.18);
    --shadow-modal:     0 32px 80px rgba(30, 20, 80, 0.22);

    --radius-card:      26px;
    --radius-btn:       30px;
    --radius-pill:      999px;
    --radius-inner:     18px;
    
    --bg-primary:       #f5f5f5;
    --border-color:     rgba(0, 0, 0, 0.1);
    --text-on-dark:     #ffffff;
    --text-on-light:    #1a1a2e;
}

/* ── DARK MODE ── */
html[data-theme="dark"] {
    --grad-bg:          radial-gradient(circle at 10% 10%, #2a1d55 0%, #1a0d3a 25%, #0d1f3a 60%, #0a0f2e 100%);
    
    --text-dark:        #f3f0ff;
    --text-mid:         #c8c3e0;
    --text-light:       #9690b8;

    --border:           rgba(255,255,255,0.10);
    --border-dashed:    rgba(123, 97, 255, 0.30);

    --card-bg:          rgba(30, 27, 55, 0.82);
    --grad-card-bg:     linear-gradient(135deg, rgba(30,27,55,0.82) 0%, rgba(38,32,70,0.78) 100%);
    --shadow-card:      0 1px 2px rgba(0,0,0,0.4), 0 24px 60px -16px rgba(0,0,0,0.55);
    --shadow-header:    0 8px 24px rgba(0, 0, 0, 0.5);
    --shadow-btn:       0 4px 10px rgba(123, 97, 255, 0.25), 0 12px 28px -6px rgba(123, 97, 255, 0.32);
    --shadow-modal:     0 32px 80px rgba(0, 0, 0, 0.65);

    --purple-light:     rgba(243, 241, 255, 0.12);
    --green-light:      rgba(47, 168, 106, 0.12);
    --orange-light:     rgba(255, 152, 0, 0.12);
    --red-light:        rgba(255, 82, 82, 0.12);
    
    --bg-primary:       #0d0d1a;
    --border-color:     rgba(255, 255, 255, 0.08);
    --text-on-dark:     #ffffff;
    --text-on-light:    #1a1a2e;
}

html[data-theme="dark"] .card { border-color: rgba(255,255,255,0.08); }

@media (prefers-color-scheme: dark) {
    html:not([data-theme]) {
        color-scheme: dark;
    }
}


/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
a       { text-decoration: none; color: inherit; }
button  { cursor: pointer; font-family: inherit; border: none; }
img     { display: block; max-width: 100%; }

/* ── Base ── */
html, body {
    min-height: 100%;
    font-family: "Almarai", "Segoe UI", sans-serif;
    background: var(--grad-bg);
    background-attachment: fixed;
    color: var(--text-dark);
    direction: rtl;
    text-align: right;
    transition: background 0.3s ease, color 0.3s ease;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── Scrollbar ── */
::-webkit-scrollbar               { width: 10px; }
::-webkit-scrollbar-track         { background: var(--text-light); }
::-webkit-scrollbar-thumb         { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover   { background: var(--purple-deep); }

.header {
    background: var(--grad-primary);
    color: white;
    padding: 22px 18px;
    text-align: center;
    box-shadow: var(--shadow-header);
    position: relative;
    overflow: hidden;
    border-radius: var(--radius-card);
    max-width: 98%;
    margin: 15px auto 0;
    align-self: center;
}
.header::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
      radial-gradient(circle at 20% 30%, rgba(255,255,255,0.18), transparent 40%),
      radial-gradient(circle at 80% 70%, rgba(255,255,255,0.10), transparent 40%);
    pointer-events: none;
}
.header::after {
    content: '';
    position: absolute;
    top: 0; left: -30%;
    width: 20%; height: 90%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.18), transparent);
    transform: skewX(-20deg);
    animation: shine 4s ease-in-out infinite;
    pointer-events: none;
}
@keyframes shine {
    0%, 100% { left: -30%; }
    50%      { left: 110%; }
}

.header-title {
    font-size: 45px;
    font-weight: 900;
    position: relative;
    z-index: 1;
    letter-spacing: -0.1px;
}
.header-subtitle {
    font-size: 20px;
    margin-top: 8px;
    font-weight: 800;
    position: relative;
    z-index: 1;
    text-align: center;
}

/* Brand */
.header-brand {
    display: flex;
    align-items: center;
    gap: 11px;
    position: relative;
    z-index: 1;
    flex-shrink: 0;
    text-decoration: none;
    color: white;
}
.brand-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.22);
    border: 1px solid rgba(255, 255, 255, 0.30);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 19px;
    backdrop-filter: blur(6px);
    flex-shrink: 0;
}
.brand-text   { display: flex; flex-direction: column; gap: 1px; }
.brand-name   { font-size: 19px; font-weight: 800; line-height: 1; letter-spacing: -0.3px; }
.brand-tag    { font-size: 10.5px; font-weight: 400; opacity: 0.75; letter-spacing: 0.2px; }


.header-nav {
    gap: 10px;
    position: absolute;
    z-index: 1;
    left: 70px;              
    top: 50%;
    transform: translateY(-50%);
    align-items: center;
    justify-content: center;
    display: flex;           
}

.header-nav a {
    color: rgba(255,255,255,0.85);
    font-size: 14px;
    font-weight: 700;
    padding: 8px 16px;
    border-radius: var(--radius-pill);
    transition: background 0.2s;
    display: inline-flex;
    gap: 5px;
}
.header-nav a:hover       { background: rgba(255,255,255,0.15); color: white; }
.header-nav a.active      { background: rgba(255,255,255,0.22); color: white; }


/* زر الوضع الليلي */
.theme-toggle {
    position: absolute;
    top: 50%;
    left: 18px;
    transform: translateY(-50%);
    width: 40px; height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.18);
    color: white;
    font-size: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
    padding: 0;
    backdrop-filter: blur(6px);
    transition: background 0.2s, transform 0.2s;
    z-index: 2;
}
.theme-toggle:hover { background: rgba(255,255,255,0.30); transform: translateY(-50%) scale(1.08); }


.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

.card {
    background: var(--grad-card-bg);
    backdrop-filter: blur(18px) saturate(160%);
    -webkit-backdrop-filter: blur(18px) saturate(160%);
    border: 1px solid var(--border-color);
    border-radius: 26px;
    box-shadow: var(--shadow-card);
    padding: 24px;
    margin-bottom: 24px;
    position: relative;
    overflow: hidden;
    animation: card-rise 0.65s cubic-bezier(0.34,1.56,0.64,1) both;
}

.card::before {
    content: '';
    position: absolute;
    top: -80px; left: -80px;
    width: 220px; height: 220px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(123, 97, 255, 0.12), transparent 70%);
    pointer-events: none;
}
.card::after {
    content: '';
    position: absolute;
    bottom: -60px; right: -60px;
    width: 180px; height: 180px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(62, 197, 255, 0.12), transparent 70%);
    pointer-events: none;
}

@keyframes card-rise {
    from { opacity: 0; transform: translateY(28px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.video-wrapper {
    position: relative;
    width: 100%;
    height: 450px;
    overflow: hidden;
    border-radius: 22px;
    background: #000;
    margin-bottom: 22px;
}

.video-frame {
    width: 100%;
    height: 100%;
    border: none;
}

.video-wrapper:fullscreen,
.video-wrapper:-webkit-full-screen,
.video-wrapper:-moz-full-screen,
.video-wrapper:-ms-fullscreen {
    width: 100%;
    height: 100%;
}

.video-wrapper:fullscreen .video-frame,
.video-wrapper:-webkit-full-screen .video-frame,
.video-wrapper:-moz-full-screen .video-frame,
.video-wrapper:-ms-fullscreen .video-frame {
    height: 100%;
}

.video-overlay {
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
}

.video-overlay-blocker {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: auto;
    background: transparent;
}

.video-timer {
    position: absolute;
    right: 18px;
    bottom: 18px;
    z-index: 3;
    background: rgba(0, 0, 0, 0.65);
    color: white;
    padding: 8px 12px;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.02em;
    pointer-events: none;
}

.fullscreen-corner-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 4;
    background: rgba(0, 0, 0, 0.75);
    color: white;
    border: none;
    border-radius: 999px;
    padding: 10px 14px;
    font-size: 14px;
    cursor: pointer;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}

.fullscreen-corner-btn:hover {
    background: rgba(0, 0, 0, 0.9);
}

.story-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    margin-bottom: 18px;
}

.badge {
    background: #ff9800;
    color: var(--card-bg);
    border-radius: 999px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
}

.story-title {
    font-size: 26px;
    margin-right: 5px;
    margin-top: 10px;
    font-weight: 800;
    color: var(--text-dark);
}

.story-description {
    line-height: 1.8;
    color: var(--text-mid);
    font-size: 16px;
    margin-bottom: 20px;
    margin-top: 10px;
    margin-right: 5px;
}

.question-box,
.result-box,
.final-results {
    border-radius: 20px;
    padding: 18px 20px;
    margin-top: 18px;
    background: var(--purple-light);
    border: 2px dashed var(--border-dashed);
}

.question-box {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-dark);
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 22px;
    justify-content: center;
    align-items: center;
}

button {
    cursor: pointer;
    border: none;
    border-radius: 30px;
    padding: 14px 26px;
    font-size: 16px;
    font-weight: 700;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    box-shadow: 0 10px 24px rgba(65, 53, 118, 0.1);
}

button:hover {
    transform: translateY(-2px);
}

.primary-btn {
    background: linear-gradient(90deg, #7b61ff, #3ec5ff);
    color: white;
}

.secondary-btn {
    background: linear-gradient(90deg, #4cd964, #28a745);
    color: white;
}

.alt-btn {
    background: white;
    color: var(--text-mid);
    border: 1px solid var(--border);
}

.hidden {
    display: none !important;
}

.recording-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--orange-light);
    border: 1px solid #ff7043;
    color: #bf360c;
    border-radius: 18px;
    padding: 16px 18px;
    font-size: 17px;
    margin-top: 18px;
}

.suggestions-wrapper {
    display: grid;
    gap: 16px;
}

.suggestions-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.suggestions-header h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 800;
    color: var(--text-dark);
}

.suggestions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
}

.story-card {
    background: var(--grad-card-bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 16px;
    cursor: pointer;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
    min-height: 135px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.story-card:hover {
    box-shadow: 0 14px 26px rgba(61, 56, 121, 0.12);
    transform: translateY(-2px);
}

.story-card.active {
    border-color: #684ee7;
    background: var(--grad-card-bg);
}

.story-card-title {
    font-size: 16px;
    font-weight: 800;
    margin-bottom: 8px;
    color: var(--text-dark);
}

.story-card-meta {
    font-size: 13px;
    color: var(--text-light);
    line-height: 1.6;
}

@media (max-width: 900px) {
    .video-frame {
        height: 320px;
    }
}

@media (max-width: 620px) {
    .controls {
        flex-direction: column;
    }

    .story-meta {
        flex-direction: column;
        align-items: flex-start;
    }
}

.q-card {
    overflow: hidden;
}

.q-errors {
    overflow-x: auto;
    overflow-y: hidden;
}

.err-chip {
    white-space: nowrap;
}