/* ═══════════════════════════════════════════════════════════════
   وضحى — Premium 3D AI Trainer Interface
   Deep Navy + Cyan/Purple Glow Theme
   ═══════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;800;900&family=Tajawal:wght@400;500;700;900&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-deep: #040714;
    --bg-navy: #0a1128;
    --bg-card: rgba(15, 25, 60, 0.6);
    --bg-card-hover: rgba(20, 35, 80, 0.7);
    --border: rgba(100, 160, 255, 0.08);
    --border-active: rgba(80, 180, 255, 0.25);
    --cyan: #00d4ff;
    --cyan-light: #60efff;
    --blue: #4d8dff;
    --purple: #a855f7;
    --purple-light: #c084fc;
    --magenta: #e040fb;
    --green: #34d399;
    --red: #f43f5e;
    --gold: #fbbf24;
    --text: #e8edf5;
    --text-dim: #6b7fa3;
    --glow-cyan: rgba(0, 212, 255, 0.3);
    --glow-blue: rgba(77, 141, 255, 0.25);
    --glow-purple: rgba(168, 85, 247, 0.2);
    --font: 'Cairo', 'Tajawal', sans-serif;
}

html,
body {
    height: 100%;
    font-family: var(--font);
    background: var(--bg-deep);
    color: var(--text);
    overflow: hidden;
    user-select: none;
    -webkit-font-smoothing: antialiased;
}

/* ═══ Ambient Background ═══ */
.scene-bg {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background:
        radial-gradient(ellipse 100% 80% at 50% -20%, rgba(0, 100, 200, 0.08) 0%, transparent 70%),
        radial-gradient(ellipse 60% 50% at 15% 85%, rgba(100, 50, 200, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse 50% 40% at 85% 70%, rgba(0, 180, 255, 0.04) 0%, transparent 50%);
}

.scene-bg::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 50% 50%, transparent 30%, var(--bg-deep) 100%);
}

/* Grid floor */
.grid-floor {
    position: fixed;
    bottom: -25%;
    left: -15%;
    right: -15%;
    height: 55%;
    background:
        linear-gradient(90deg, rgba(0, 180, 255, 0.03) 1px, transparent 1px),
        linear-gradient(0deg, rgba(0, 180, 255, 0.03) 1px, transparent 1px);
    background-size: 50px 50px;
    transform: perspective(500px) rotateX(65deg);
    transform-origin: center top;
    animation: gridScroll 25s linear infinite;
    mask-image: linear-gradient(to top, rgba(0, 0, 0, 0.4) 0%, transparent 90%);
    -webkit-mask-image: linear-gradient(to top, rgba(0, 0, 0, 0.4) 0%, transparent 90%);
}

@keyframes gridScroll {
    0% {
        background-position: 0 0;
    }

    100% {
        background-position: 0 50px;
    }
}

/* Floating particles */
.particles {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 0;
}

.particle {
    position: absolute;
    border-radius: 50%;
    opacity: 0;
    animation: floatUp var(--dur, 10s) var(--delay, 0s) infinite ease-in-out;
}

@keyframes floatUp {
    0% {
        opacity: 0;
        transform: translateY(100vh) scale(0.2);
    }

    15% {
        opacity: var(--op, 0.5);
    }

    85% {
        opacity: var(--op, 0.5);
    }

    100% {
        opacity: 0;
        transform: translateY(-15vh) scale(0.05);
    }
}

/* ═══ App Layout ═══ */
.app {
    position: relative;
    z-index: 1;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 20px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 180, 255, 0.15) transparent;
}

/* ═══ Header ═══ */
.header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 20px;
    margin-bottom: 6px;
}

.header-avatar {
    width: 62px;
    height: 62px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--cyan), var(--purple));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    box-shadow: 0 0 30px var(--glow-cyan), 0 4px 20px rgba(0, 0, 0, 0.4);
    position: relative;
    animation: avatarGlow 4s ease-in-out infinite;
}

.header-avatar::after {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 1.5px solid rgba(0, 212, 255, 0.25);
    animation: ringBreath 3s ease-in-out infinite;
}

@keyframes avatarGlow {

    0%,
    100% {
        box-shadow: 0 0 30px var(--glow-cyan), 0 4px 20px rgba(0, 0, 0, 0.4);
    }

    50% {
        box-shadow: 0 0 50px var(--glow-cyan), 0 4px 30px rgba(0, 0, 0, 0.3);
    }
}

@keyframes ringBreath {

    0%,
    100% {
        opacity: 0.25;
        transform: scale(1);
    }

    50% {
        opacity: 0.5;
        transform: scale(1.04);
    }
}

.header-info h1 {
    font-size: 1.4rem;
    font-weight: 900;
    background: linear-gradient(135deg, var(--cyan-light), var(--cyan), var(--blue));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1.3;
}

.header-info p {
    font-size: 0.72rem;
    color: var(--text-dim);
    margin-top: 1px;
    letter-spacing: 0.3px;
}

/* ═══ Status Pill ═══ */
.status-pill {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 99px;
    font-size: 0.78rem;
    color: var(--text-dim);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    margin-bottom: 10px;
}

.status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--text-dim);
    transition: all 0.4s ease;
}

.status-dot.ok {
    background: var(--green);
    box-shadow: 0 0 12px var(--green);
}

.status-dot.listen {
    background: var(--green);
    box-shadow: 0 0 12px var(--green);
    animation: pulse 1.2s infinite;
}

.status-dot.think {
    background: var(--gold);
    box-shadow: 0 0 12px var(--gold);
    animation: pulse 0.7s infinite;
}

.status-dot.speak {
    background: var(--cyan);
    box-shadow: 0 0 14px var(--cyan);
    animation: pulse 0.5s infinite;
}

.status-dot.err {
    background: var(--red);
    box-shadow: 0 0 12px var(--red);
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.35;
        transform: scale(0.85);
    }
}

/* ═══ 3D Sphere Container ═══ */
.orb-container {
    position: relative;
    width: 280px;
    height: 280px;
    margin: 10px 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Three.js canvas will be placed inside here */
#sphereCanvas {
    display: none !important;
}

/* 3D Avatar Container */
#avatar3d-box {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    overflow: hidden;
}

#avatar3d-box canvas {
    border-radius: 50%;
}

/* Outer glow ring */
.orb-container::before {
    content: '';
    position: absolute;
    inset: -12px;
    border-radius: 50%;
    border: 1.5px solid rgba(0, 180, 255, 0.12);
    animation: ringRotate 20s linear infinite;
}

.orb-container::after {
    content: '';
    position: absolute;
    inset: -28px;
    border-radius: 50%;
    border: 1px solid rgba(100, 50, 200, 0.07);
    animation: ringRotate 30s linear infinite reverse;
}

@keyframes ringRotate {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Background glow behind avatar */
.sphere-glow {
    position: absolute;
    width: 200%;
    height: 200%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: radial-gradient(circle,
            rgba(0, 180, 255, 0.06) 0%,
            rgba(100, 50, 200, 0.04) 30%,
            transparent 60%);
    pointer-events: none;
    transition: all 0.5s ease;
}

.sphere-glow.speaking {
    background: radial-gradient(circle,
            rgba(0, 212, 255, 0.12) 0%,
            rgba(168, 85, 247, 0.08) 30%,
            transparent 55%);
}

/* Hide old orb elements */
.orb,
.orb-ring,
.orb-ring-1,
.orb-ring-2,
.orb-ring-3,
.orb-wave,
.orb-wave-bar {
    display: none !important;
}

/* ═══ Waveform Canvas ═══ */
#waveCanvas {
    width: 280px;
    height: 40px;
    opacity: 0.7;
    margin-bottom: 6px;
}

/* ═══ Mic Button ═══ */
.mic-btn-wrapper {
    position: relative;
    margin: 6px 0;
}

.mic-btn-glow {
    position: absolute;
    inset: -10px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--glow-cyan) 0%, transparent 65%);
    opacity: 0;
    transition: opacity 0.4s ease;
}

.mic-btn-wrapper:hover .mic-btn-glow {
    opacity: 0.4;
}

.mic-btn-wrapper.on .mic-btn-glow {
    opacity: 1;
    animation: micPulse 2s ease-in-out infinite;
}

@keyframes micPulse {

    0%,
    100% {
        opacity: 0.4;
        transform: scale(1);
    }

    50% {
        opacity: 1;
        transform: scale(1.12);
    }
}

#micBtn {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: linear-gradient(135deg, var(--cyan), var(--blue));
    box-shadow:
        0 0 30px var(--glow-cyan),
        0 6px 24px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.15);
    font-size: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    color: #fff;
    position: relative;
    z-index: 2;
}

#micBtn:hover {
    transform: scale(1.08);
}

#micBtn:active {
    transform: scale(0.92);
}

#micBtn.on {
    background: linear-gradient(135deg, var(--red), #e11d48);
    box-shadow: 0 0 35px rgba(244, 63, 94, 0.4), 0 6px 24px rgba(0, 0, 0, 0.5);
}

#micBtn:disabled {
    opacity: 0.25;
    cursor: not-allowed;
    transform: none;
}

/* ═══ Subtitle ═══ */
.subtitle-area {
    display: none !important;
}

.subtitle-text {
    font-size: 0.88rem;
    color: rgba(232, 237, 245, 0.7);
    line-height: 1.6;
    padding: 10px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    backdrop-filter: blur(16px);
    display: none;
    direction: rtl;
}

.subtitle-text.visible {
    display: block;
    animation: fadeSlideIn 0.35s ease;
}

@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ═══ Action Buttons ═══ */
.actions-row {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 18px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-dim);
    font-family: var(--font);
    font-size: 0.76rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(12px);
}

.action-btn:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-active);
    color: var(--cyan);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 180, 255, 0.08);
}

.action-btn.active {
    border-color: var(--cyan);
    background: rgba(0, 212, 255, 0.08);
    color: var(--cyan);
    box-shadow: 0 0 20px rgba(0, 212, 255, 0.1);
}

.action-btn svg {
    width: 15px;
    height: 15px;
}

/* ═══ Screen Preview ═══ */
.screen-preview {
    position: fixed;
    bottom: 16px;
    left: 16px;
    width: 300px;
    border-radius: 14px;
    overflow: hidden;
    border: 1.5px solid rgba(0, 180, 255, 0.2);
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6), 0 0 30px rgba(0, 180, 255, 0.05);
    display: none;
    z-index: 100;
    background: var(--bg-navy);
}

.screen-preview.visible {
    display: block;
    animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.97);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.screen-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 12px;
    background: rgba(0, 180, 255, 0.06);
    border-bottom: 1px solid rgba(0, 180, 255, 0.12);
}

.screen-preview-header span {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--cyan);
    display: flex;
    align-items: center;
    gap: 6px;
}

.screen-preview-header button {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    border: none;
    background: rgba(244, 63, 94, 0.15);
    color: var(--red);
    cursor: pointer;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.screen-preview-header button:hover {
    background: rgba(244, 63, 94, 0.3);
}

.screen-preview video {
    width: 100%;
    height: auto;
    display: block;
}

.screen-analyze-btn {
    width: 100%;
    padding: 9px;
    border: none;
    background: linear-gradient(135deg, var(--cyan), var(--blue));
    color: #fff;
    font-family: var(--font);
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: filter 0.2s;
}

.screen-analyze-btn:hover {
    filter: brightness(1.15);
}

/* ═══ Features Cards ═══ */
.features {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
    max-width: 460px;
    width: 100%;
    margin-top: 12px;
}

.feature-card {
    padding: 11px 8px;
    border-radius: 11px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    text-align: center;
    backdrop-filter: blur(12px);
    transition: all 0.3s ease;
}

.feature-card:hover {
    border-color: var(--border-active);
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0, 180, 255, 0.06);
}

.feature-icon {
    font-size: 1.2rem;
    margin-bottom: 3px;
}

.feature-title {
    font-size: 0.66rem;
    font-weight: 700;
    color: var(--cyan);
}

.feature-desc {
    font-size: 0.58rem;
    color: var(--text-dim);
    margin-top: 1px;
}

/* ═══ Toast ═══ */
.toast {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%) translateY(16px);
    background: rgba(10, 17, 40, 0.92);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 22px;
    font-size: 0.8rem;
    color: var(--text);
    opacity: 0;
    transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 200;
    pointer-events: none;
    backdrop-filter: blur(16px);
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.err {
    border-color: rgba(244, 63, 94, 0.35);
}

.toast.ok {
    border-color: rgba(52, 211, 153, 0.3);
}

/* ═══ Chart Deco ═══ */
.chart-deco {
    position: fixed;
    bottom: 28px;
    right: 18px;
    display: flex;
    gap: 3px;
    align-items: flex-end;
    opacity: 0.1;
    pointer-events: none;
}

.candle {
    width: 5px;
    border-radius: 2px;
    position: relative;
}

.candle::before,
.candle::after {
    content: '';
    position: absolute;
    width: 1px;
    left: 50%;
    transform: translateX(-50%);
}

.candle.bull {
    background: var(--green);
}

.candle.bear {
    background: var(--red);
}

.candle.bull::before {
    top: -4px;
    height: 4px;
    background: var(--green);
}

.candle.bull::after {
    bottom: -3px;
    height: 3px;
    background: var(--green);
}

.candle.bear::before {
    top: -3px;
    height: 3px;
    background: var(--red);
}

.candle.bear::after {
    bottom: -4px;
    height: 4px;
    background: var(--red);
}

/* ═══ Scrollbar ═══ */
::-webkit-scrollbar {
    width: 3px;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 180, 255, 0.15);
    border-radius: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

/* ═══ Responsive ═══ */
@media (max-width: 640px) {
    .header-avatar {
        width: 50px;
        height: 50px;
        font-size: 24px;
    }

    .header-info h1 {
        font-size: 1.15rem;
    }

    .orb-container {
        width: 220px;
        height: 220px;
    }

    .features {
        gap: 5px;
    }

    .feature-card {
        padding: 9px 5px;
    }

    #micBtn {
        width: 68px;
        height: 68px;
        font-size: 28px;
    }

    .screen-preview {
        width: 220px;
        bottom: 8px;
        left: 8px;
    }

    #waveCanvas {
        width: 220px;
        height: 35px;
    }
}