/* ═══════════════════════════════════════════════════════════════════════════
   JARVIS Interface — Stylesheet
   Dark HUD theme inspired by Iron Man's AI assistant
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── CSS Variables ────────────────────────────────────────────────────────── */
:root {
    --bg-primary: #060a13;
    --bg-secondary: #0b1121;
    --bg-card: rgba(10, 20, 40, 0.7);
    --bg-glass: rgba(0, 180, 255, 0.03);

    --accent: #00c8ff;
    --accent-dim: rgba(0, 200, 255, 0.15);
    --accent-glow: rgba(0, 200, 255, 0.4);
    --accent-bright: #40e0ff;
    --accent-warm: #00a5d4;

    --text-primary: #e0f0ff;
    --text-secondary: #7a9ab5;
    --text-dim: #3d5a73;

    --user-bubble: rgba(0, 200, 255, 0.08);
    --user-border: rgba(0, 200, 255, 0.25);
    --jarvis-bubble: rgba(20, 30, 50, 0.6);
    --jarvis-border: rgba(0, 200, 255, 0.1);

    --danger: #ff4060;
    --success: #00ff88;
    --warning: #ffb020;

    --font-display: 'Orbitron', sans-serif;
    --font-body: 'Rajdhani', sans-serif;
    --font-mono: 'Share Tech Mono', monospace;

    --radius: 12px;
    --radius-sm: 8px;
}

/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* ── Background Effects ───────────────────────────────────────────────────── */
.bg-grid {
    position: fixed;
    inset: 0;
    background-image:
        linear-gradient(rgba(0, 200, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 200, 255, 0.03) 1px, transparent 1px);
    background-size: 60px 60px;
    z-index: 0;
    pointer-events: none;
}

.bg-particles {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.particle {
    position: absolute;
    width: 2px;
    height: 2px;
    background: var(--accent);
    border-radius: 50%;
    opacity: 0;
    animation: particleFloat 8s infinite ease-in-out;
}

@keyframes particleFloat {
    0% {
        opacity: 0;
        transform: translateY(100vh) scale(0);
    }

    20% {
        opacity: 0.6;
    }

    80% {
        opacity: 0.3;
    }

    100% {
        opacity: 0;
        transform: translateY(-20vh) scale(1);
    }
}

/* ── HUD Header ──────────────────────────────────────────────────────────── */
.hud-header {
    position: relative;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 28px;
    background: linear-gradient(180deg, rgba(0, 15, 30, 0.95) 0%, transparent 100%);
    border-bottom: 1px solid rgba(0, 200, 255, 0.08);
}

.hud-left,
.hud-right {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 160px;
}

.hud-right {
    justify-content: flex-end;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 8px var(--success), 0 0 20px rgba(0, 255, 136, 0.3);
    animation: dotPulse 2s infinite ease-in-out;
}

@keyframes dotPulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.6;
        transform: scale(0.8);
    }
}

.hud-label {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-secondary);
    letter-spacing: 1.5px;
    text-transform: uppercase;
}

.hud-center {
    text-align: center;
}

.jarvis-title {
    font-family: var(--font-display);
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 8px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-bright) 50%, var(--accent) 100%);
    background-size: 200% auto;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: shimmer 4s linear infinite;
    text-shadow: none;
}

@keyframes shimmer {
    0% {
        background-position: 0% center;
    }

    100% {
        background-position: 200% center;
    }
}

.jarvis-subtitle {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    color: var(--text-dim);
    letter-spacing: 3px;
    margin-top: 2px;
    text-transform: uppercase;
}

.memory-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    padding: 4px 10px;
    border: 1px solid rgba(0, 200, 255, 0.1);
    border-radius: 20px;
    background: rgba(0, 200, 255, 0.03);
}

/* ── Main Container ──────────────────────────────────────────────────────── */
.main-container {
    position: relative;
    z-index: 5;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 28px 10px;
    overflow: hidden;
    min-height: 0;
}

/* ── Arc Reactor ─────────────────────────────────────────────────────────── */
.arc-reactor-container {
    position: relative;
    width: 140px;
    height: 140px;
    margin-bottom: 20px;
    flex-shrink: 0;
    transition: all 0.5s ease;
}

.arc-reactor-container.active {
    filter: brightness(1.4);
}

.arc-reactor-container.speaking {
    filter: brightness(1.6) hue-rotate(10deg);
}

.reactor-ring {
    position: absolute;
    border-radius: 50%;
    border: 1px solid;
    animation-timing-function: linear;
    animation-iteration-count: infinite;
}

.ring-outer {
    inset: 0;
    border-color: rgba(0, 200, 255, 0.15);
    animation: spinCW 20s linear infinite;
    border-top-color: var(--accent);
    border-right-color: transparent;
}

.ring-middle {
    inset: 15px;
    border-color: rgba(0, 200, 255, 0.1);
    animation: spinCCW 12s linear infinite;
    border-bottom-color: var(--accent-warm);
    border-left-color: transparent;
}

.ring-inner {
    inset: 30px;
    border-color: rgba(0, 200, 255, 0.2);
    animation: spinCW 8s linear infinite;
    border-top-color: var(--accent-bright);
}

@keyframes spinCW {
    to {
        transform: rotate(360deg);
    }
}

@keyframes spinCCW {
    to {
        transform: rotate(-360deg);
    }
}

.reactor-core {
    position: absolute;
    inset: 40px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(0, 200, 255, 0.2) 0%, transparent 70%);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.core-glow {
    position: absolute;
    inset: -10px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(0, 200, 255, 0.15) 0%, transparent 60%);
    animation: coreBreath 3s ease-in-out infinite;
}

@keyframes coreBreath {

    0%,
    100% {
        transform: scale(1);
        opacity: 0.5;
    }

    50% {
        transform: scale(1.3);
        opacity: 1;
    }
}

.wave-svg {
    position: relative;
    z-index: 2;
    width: 50px;
    height: 20px;
}

.reactor-status {
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--font-mono);
    font-size: 0.6rem;
    letter-spacing: 2px;
    color: var(--text-dim);
    white-space: nowrap;
    transition: color 0.3s;
}

.arc-reactor-container.active .reactor-status {
    color: var(--accent);
}

/* ── Chat Container ──────────────────────────────────────────────────────── */
.chat-container {
    flex: 1;
    width: 100%;
    max-width: 800px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 10px 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

/* Scrollbar */
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 200, 255, 0.15);
    border-radius: 4px;
}

/* ── Chat Messages ───────────────────────────────────────────────────────── */
.message {
    display: flex;
    gap: 12px;
    animation: messageIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    opacity: 0;
    transform: translateY(16px);
    max-width: 85%;
}

@keyframes messageIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message.jarvis {
    align-self: flex-start;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-family: var(--font-display);
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 1px;
}

.message.jarvis .message-avatar {
    background: var(--accent-dim);
    border: 1px solid rgba(0, 200, 255, 0.3);
    color: var(--accent);
}

.message.user .message-avatar {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
}

.message-content {
    padding: 12px 18px;
    border-radius: var(--radius);
    font-size: 0.95rem;
    line-height: 1.6;
    font-weight: 400;
    letter-spacing: 0.2px;
}

.message.user .message-content {
    background: var(--user-bubble);
    border: 1px solid var(--user-border);
    border-top-right-radius: 4px;
}

.message.jarvis .message-content {
    background: var(--jarvis-bubble);
    border: 1px solid var(--jarvis-border);
    border-top-left-radius: 4px;
}

.message-content strong {
    color: var(--accent);
    font-weight: 600;
}

.message-content code {
    font-family: var(--font-mono);
    background: rgba(0, 200, 255, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85em;
    color: var(--accent-bright);
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 8px 4px;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    opacity: 0.4;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.4;
    }

    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* ── Input Bar ───────────────────────────────────────────────────────────── */
.input-bar {
    position: relative;
    z-index: 10;
    padding: 16px 28px 20px;
    background: linear-gradient(0deg, rgba(0, 10, 20, 0.98) 0%, transparent 100%);
}

.input-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 800px;
    margin: 0 auto;
    background: rgba(10, 20, 40, 0.8);
    border: 1px solid rgba(0, 200, 255, 0.1);
    border-radius: 50px;
    padding: 6px 8px 6px 6px;
    backdrop-filter: blur(20px);
    transition: border-color 0.3s, box-shadow 0.3s;
}

.input-wrapper:focus-within {
    border-color: rgba(0, 200, 255, 0.3);
    box-shadow: 0 0 30px rgba(0, 200, 255, 0.05);
}

.message-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 400;
    padding: 10px 12px;
    outline: none;
}

.message-input::placeholder {
    color: var(--text-dim);
    font-weight: 300;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.mic-btn,
.send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
    position: relative;
    overflow: visible;
}

.mic-btn {
    background: rgba(0, 200, 255, 0.08);
    color: var(--accent);
    border: 1px solid rgba(0, 200, 255, 0.2);
}

.mic-btn:hover {
    background: rgba(0, 200, 255, 0.15);
    transform: scale(1.05);
}

.mic-btn.listening {
    background: rgba(255, 50, 80, 0.15);
    border-color: var(--danger);
    color: var(--danger);
    animation: micPulse 1.5s ease-in-out infinite;
}

@keyframes micPulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(255, 50, 80, 0.3);
    }

    50% {
        box-shadow: 0 0 0 12px rgba(255, 50, 80, 0);
    }
}

.mic-pulse {
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 2px solid var(--danger);
    opacity: 0;
    pointer-events: none;
}

.mic-btn.listening .mic-pulse {
    animation: pulseRing 1.5s ease-out infinite;
}

@keyframes pulseRing {
    0% {
        transform: scale(0.8);
        opacity: 0.6;
    }

    100% {
        transform: scale(1.6);
        opacity: 0;
    }
}

.mode-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid rgba(0, 200, 255, 0.2);
    background: rgba(0, 200, 255, 0.05);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.mode-btn:hover {
    background: rgba(0, 200, 255, 0.1);
    color: var(--accent);
}

.mode-btn.active {
    background: rgba(0, 200, 255, 0.15);
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 0 15px rgba(0, 200, 255, 0.2);
}

.mode-btn svg {
    width: 20px;
    height: 20px;
}

.send-btn {
    background: linear-gradient(135deg, var(--accent), var(--accent-warm));
    color: var(--bg-primary);
}

.send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 20px rgba(0, 200, 255, 0.3);
}

.send-btn svg {
    width: 18px;
    height: 18px;
}

/* ── Input Status ────────────────────────────────────────────────────────── */
.input-status {
    text-align: center;
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--text-dim);
    letter-spacing: 1.5px;
    margin-top: 8px;
    min-height: 16px;
    text-transform: uppercase;
    transition: color 0.3s;
}

.input-status.active {
    color: var(--accent);
}

.input-status.error {
    color: var(--danger);
}

/* ── Welcome Message Special Style ───────────────────────────────────────── */
.message.welcome .message-content {
    background: linear-gradient(135deg, rgba(0, 200, 255, 0.06) 0%, rgba(10, 20, 40, 0.6) 100%);
    border-color: rgba(0, 200, 255, 0.2);
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
/* ── Responsive Mobile Design v2 (Premium) ────────────────────────────── */
@media (max-width: 768px) {
    body {
        height: 100dvh;
        /* Dynamic viewport height */
        /* min-height: -webkit-fill-available; */
    }

    /* 1. Header: Focused on Name */
    .hud-header {
        flex-direction: column;
        justify-content: center;
        align-items: center;
        height: auto;
        padding: 50px 0 10px;
        /* Increased top padding significantly */
        background: transparent;
        border-bottom: none;
    }

    .hud-left,
    .hud-right {
        display: none;
        /* Hide stats for clean look */
    }

    .jarvis-title {
        font-size: 1.8rem;
        /* Large and center */
        text-align: center;
        margin-bottom: 2px;
        text-shadow: 0 0 15px rgba(0, 200, 255, 0.5);
    }

    .jarvis-subtitle {
        display: block;
        /* Show subtitle */
        font-size: 0.55rem;
        letter-spacing: 5px;
        opacity: 0.8;
        text-align: center;
        margin-bottom: 25px;
        /* More space below subtitle */
        margin-top: 5px;
    }

    .hud-center {
        width: 100%;
        text-align: center;
    }

    /* 2. Main Container: Compact */
    .main-container {
        padding: 0 16px;
        display: flex;
        flex-direction: column;
        margin-top: 20px;
        /* Push content down further */
    }

    /* 3. Reactor: Integrated at Top */
    .arc-reactor-container {
        width: 100px;
        height: 100px;
        margin: 0 auto 5px;
        /* Center it */
        flex-shrink: 0;
    }

    /* 4. Chat Area */
    .chat-container {
        /* Fade in top of chat for smooth look */
        mask-image: linear-gradient(to bottom, transparent, black 15px);
        -webkit-mask-image: linear-gradient(to bottom, transparent, black 15px);
    }

    .chat-messages {
        padding-bottom: 20px;
        /* Space above input */
    }

    .message {
        max-width: 90%;
        margin-bottom: 8px;
    }

    .message-content {
        padding: 12px 16px;
        font-size: 0.95rem;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    }

    /* 5. Input Bar: Floating Effect */
    .input-bar {
        position: relative;
        /* Normal flow but sticky-ish feel */
        padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
        background: linear-gradient(to top, rgba(6, 10, 19, 1) 30%, transparent);
        border-top: none;
        z-index: 20;
    }

    .input-wrapper {
        background: rgba(16, 26, 48, 0.85);
        /* Slightly lighter glass */
        backdrop-filter: blur(25px);
        border: 1px solid rgba(0, 200, 255, 0.15);
        box-shadow: 0 4px 25px rgba(0, 0, 0, 0.5);
        border-radius: 50px;
        /* Pill shape */
        padding: 6px;
    }

    .message-input {
        font-size: 16px;
        /* Prevents iOS auto-zoom */
        padding: 10px 12px;
    }

    /* Touch-friendly buttons */
    .mic-btn,
    .send-btn,
    .mode-btn {
        width: 44px;
        /* Larger touch target */
        height: 44px;
    }

    /* Hide scrollbar in chat for cleaner look but keep functionality */
    .chat-messages::-webkit-scrollbar {
        width: 4px;
    }
}

/* ── Utility ─────────────────────────────────────────────────────────────── */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}