/* ============================================
   Theron AI — Main Stylesheet
   Dark theme, Jarvis-inspired aesthetic
   ============================================ */

:root {
    --bg-primary: #05080f;
    --bg-secondary: #0a0f1a;
    --bg-panel: rgba(10, 15, 26, 0.92);
    --accent-blue: #00d4ff;
    --accent-blue-dim: #0066aa;
    --accent-amber: #ffaa00;
    --accent-green: #00ff88;
    --accent-red: #ff3355;
    --text-primary: #e0e6f0;
    --text-secondary: #8899aa;
    --text-dim: #556677;
    --border-glow: rgba(0, 212, 255, 0.15);
    --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --orb-size: 200px;
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-sans);
    -webkit-font-smoothing: antialiased;
}

/* Background */
.theron-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    background:
        radial-gradient(ellipse at 50% 30%, rgba(0, 100, 180, 0.08) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 80%, rgba(0, 180, 220, 0.04) 0%, transparent 50%),
        var(--bg-primary);
}

.particles {
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(circle at 20% 30%, rgba(0, 212, 255, 0.03) 0%, transparent 2px),
        radial-gradient(circle at 70% 60%, rgba(0, 212, 255, 0.03) 0%, transparent 2px),
        radial-gradient(circle at 40% 80%, rgba(0, 212, 255, 0.02) 0%, transparent 2px);
    background-size: 300px 300px;
    animation: particleDrift 20s linear infinite;
}

@keyframes particleDrift {
    0% { transform: translateY(0); }
    100% { transform: translateY(-40px); }
}

.grid-overlay {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(0, 212, 255, 0.02) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 212, 255, 0.02) 1px, transparent 1px);
    background-size: 60px 60px;
    mask-image: radial-gradient(ellipse at center, black 20%, transparent 70%);
    -webkit-mask-image: radial-gradient(ellipse at center, black 20%, transparent 70%);
}

/* Main App */
.theron-app {
    position: fixed;
    inset: 0;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.theron-main {
    position: relative;
    width: 100%;
    max-width: 900px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 20px;
    z-index: 2;
}

/* Header */
.theron-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-panel);
    border: 1px solid var(--border-glow);
    border-radius: 12px;
    backdrop-filter: blur(12px);
    margin-bottom: 20px;
    flex-shrink: 0;
}

.theron-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-blue-dim));
    border-radius: 8px;
    font-weight: 700;
    font-size: 14px;
    color: white;
    box-shadow: 0 0 12px rgba(0, 212, 255, 0.3);
}

.brand-name {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 3px;
    color: var(--text-primary);
}

.theron-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-dim);
    transition: background var(--transition-fast);
}

.status-dot.online { background: var(--accent-green); box-shadow: 0 0 8px var(--accent-green); }
.status-dot.listening { background: var(--accent-amber); box-shadow: 0 0 8px var(--accent-amber); }
.status-dot.processing { background: var(--accent-blue); box-shadow: 0 0 8px var(--accent-blue); }
.status-dot.speaking { background: var(--accent-blue); box-shadow: 0 0 12px var(--accent-blue); }
.status-dot.error { background: var(--accent-red); box-shadow: 0 0 8px var(--accent-red); }

.theron-controls {
    display: flex;
    gap: 6px;
}

.ctrl-btn {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border-glow);
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.ctrl-btn:hover {
    border-color: var(--accent-blue);
    color: var(--accent-blue);
    background: rgba(0, 212, 255, 0.05);
}

/* Orb */
.theron-orb-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 30px;
    min-height: 0;
}

.theron-orb {
    position: relative;
    width: var(--orb-size);
    height: var(--orb-size);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform var(--transition-normal);
}

.theron-orb:hover {
    transform: scale(1.03);
}

.orb-core {
    position: absolute;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: radial-gradient(circle at 40% 40%, var(--accent-blue), var(--accent-blue-dim));
    box-shadow:
        0 0 40px rgba(0, 212, 255, 0.4),
        0 0 80px rgba(0, 212, 255, 0.15),
        inset 0 0 20px rgba(255, 255, 255, 0.1);
    transition: all var(--transition-normal);
}

.orb-ring {
    position: absolute;
    border-radius: 50%;
    border: 1px solid rgba(0, 212, 255, 0.15);
    transition: all var(--transition-normal);
}

.orb-ring-1 { width: 100px; height: 100px; }
.orb-ring-2 { width: 140px; height: 140px; border-style: dashed; }
.orb-ring-3 { width: 180px; height: 180px; border-color: rgba(0, 212, 255, 0.08); }

/* Orb States */
.theron-orb.state-idle .orb-core {
    animation: breathe 4s ease-in-out infinite;
}

.theron-orb.state-idle .orb-ring-1 {
    animation: pulseRing 4s ease-in-out infinite;
}

.theron-orb.state-idle .orb-ring-2 {
    animation: pulseRing 4s ease-in-out infinite 0.5s;
}

.theron-orb.state-listening .orb-core {
    background: radial-gradient(circle at 40% 40%, var(--accent-amber), #cc7700);
    box-shadow:
        0 0 50px rgba(255, 170, 0, 0.5),
        0 0 100px rgba(255, 170, 0, 0.2);
    animation: pulseFast 1s ease-in-out infinite;
}

.theron-orb.state-listening .orb-ring {
    border-color: rgba(255, 170, 0, 0.25);
}

.theron-orb.state-listening .orb-ring-1 {
    animation: expandRing 1.5s ease-out infinite;
}

.theron-orb.state-processing .orb-core {
    background: radial-gradient(circle at 40% 40%, var(--accent-blue), var(--accent-blue-dim));
    animation: spinCore 1s linear infinite;
}

.theron-orb.state-processing .orb-ring-2 {
    animation: spinRing 2s linear infinite;
}

.theron-orb.state-speaking .orb-core {
    background: radial-gradient(circle at 40% 40%, #66e5ff, var(--accent-blue));
    box-shadow:
        0 0 60px rgba(0, 212, 255, 0.6),
        0 0 120px rgba(0, 212, 255, 0.25);
}

/* Waveform (visible when speaking) */
.orb-waveform {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 4px;
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.theron-orb.state-speaking .orb-waveform {
    opacity: 1;
}

.wave-bar {
    width: 3px;
    height: 16px;
    background: var(--accent-blue);
    border-radius: 2px;
    animation: waveBar 0.5s ease-in-out infinite alternate;
}

.wave-bar:nth-child(1) { animation-delay: 0s; }
.wave-bar:nth-child(2) { animation-delay: 0.1s; }
.wave-bar:nth-child(3) { animation-delay: 0.2s; }
.wave-bar:nth-child(4) { animation-delay: 0.3s; }
.wave-bar:nth-child(5) { animation-delay: 0.4s; }

/* Orb Label */
.orb-label {
    font-size: 14px;
    color: var(--text-dim);
    letter-spacing: 2px;
    text-transform: uppercase;
    transition: all var(--transition-normal);
}

.theron-orb.state-listening ~ .orb-label {
    color: var(--accent-amber);
}

.theron-orb.state-processing ~ .orb-label {
    color: var(--accent-blue);
}

.theron-orb.state-speaking ~ .orb-label {
    color: var(--accent-blue);
}

/* Transcript */
.theron-transcript {
    flex-shrink: 0;
    height: 240px;
    background: var(--bg-panel);
    border: 1px solid var(--border-glow);
    border-radius: 12px;
    backdrop-filter: blur(12px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all var(--transition-normal);
}

.theron-transcript.hidden {
    height: 0;
    opacity: 0;
    margin: 0;
    border: none;
    padding: 0;
}

.transcript-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: thin;
    scrollbar-color: var(--accent-blue-dim) transparent;
}

.transcript-messages::-webkit-scrollbar {
    width: 4px;
}

.transcript-messages::-webkit-scrollbar-thumb {
    background: var(--accent-blue-dim);
    border-radius: 2px;
}

.msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    animation: msgIn 0.3s ease;
}

@keyframes msgIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.msg-user {
    align-self: flex-end;
    background: rgba(0, 212, 255, 0.08);
    border: 1px solid rgba(0, 212, 255, 0.15);
    color: var(--text-primary);
}

.msg-assistant {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
}

.msg-time {
    font-size: 10px;
    color: var(--text-dim);
    margin-top: 4px;
    text-align: right;
}

.msg-assistant .msg-time {
    text-align: left;
}

.transcript-input-area {
    display: flex;
    gap: 8px;
    padding: 10px 16px;
    border-top: 1px solid var(--border-glow);
}

.transcript-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-glow);
    border-radius: 8px;
    padding: 10px 14px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: all var(--transition-fast);
}

.transcript-input:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 2px rgba(0, 212, 255, 0.1);
}

.transcript-input::placeholder {
    color: var(--text-dim);
}

.attach-btn {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border-glow);
    border-radius: 8px;
    background: transparent;
    color: var(--text-dim);
    font-size: 16px;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
}

.attach-btn:hover {
    border-color: var(--accent-blue);
    color: var(--accent-blue);
    background: rgba(0, 212, 255, 0.05);
}

.send-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-blue-dim));
    color: white;
    font-size: 14px;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-btn:hover {
    box-shadow: 0 0 16px rgba(0, 212, 255, 0.4);
    transform: scale(1.05);
}

/* Minimized Widget */
.theron-minimized {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 100;
    cursor: pointer;
}

.mini-orb {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--bg-panel);
    border: 1px solid var(--border-glow);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(12px);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    transition: all var(--transition-normal);
}

.mini-orb:hover {
    transform: scale(1.1);
    border-color: var(--accent-blue);
}

.mini-core {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: radial-gradient(circle at 40% 40%, var(--accent-blue), var(--accent-blue-dim));
    box-shadow: 0 0 16px rgba(0, 212, 255, 0.4);
    animation: breathe 3s ease-in-out infinite;
}

/* Panels */
.theron-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 420px;
    background: var(--bg-panel);
    border: 1px solid var(--border-glow);
    border-radius: 16px;
    backdrop-filter: blur(20px);
    z-index: 50;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: panelIn 0.3s ease;
}

@keyframes panelIn {
    from { opacity: 0; transform: translate(-50%, -50%) scale(0.95); }
    to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-glow);
}

.panel-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.panel-close {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all var(--transition-fast);
}

.panel-close:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.panel-body {
    padding: 16px 20px;
    max-height: 60vh;
    overflow-y: auto;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.setting-row:last-child {
    border-bottom: none;
}

.setting-row label {
    font-size: 14px;
    color: var(--text-secondary);
}

.setting-row select,
.setting-row input[type="range"] {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-glow);
    border-radius: 6px;
    padding: 6px 10px;
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
}

.toggle {
    position: relative;
    width: 44px;
    height: 24px;
    cursor: pointer;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 24px;
    transition: all var(--transition-fast);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    top: 3px;
    background: var(--text-dim);
    border-radius: 50%;
    transition: all var(--transition-fast);
}

.toggle input:checked + .toggle-slider {
    background: rgba(0, 212, 255, 0.2);
}

.toggle input:checked + .toggle-slider::before {
    transform: translateX(20px);
    background: var(--accent-blue);
    box-shadow: 0 0 8px rgba(0, 212, 255, 0.4);
}

.panel-btn {
    width: 100%;
    padding: 10px;
    background: rgba(255, 50, 80, 0.08);
    border: 1px solid rgba(255, 50, 80, 0.2);
    border-radius: 8px;
    color: var(--accent-red);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.panel-btn:hover {
    background: rgba(255, 50, 80, 0.15);
}

/* Help Grid */
.help-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-bottom: 16px;
}

.help-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.help-item code,
.help-item kbd {
    background: rgba(0, 212, 255, 0.08);
    border: 1px solid rgba(0, 212, 255, 0.15);
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 12px;
    font-family: var(--font-mono);
    color: var(--accent-blue);
    white-space: nowrap;
}

.help-item span {
    font-size: 13px;
    color: var(--text-secondary);
}

.help-section h4 {
    font-size: 13px;
    color: var(--text-primary);
    margin-bottom: 8px;
    font-weight: 600;
}

.help-section p {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    line-height: 1.5;
}

.help-section strong {
    color: var(--accent-blue);
}

/* Toasts */
.theron-toasts {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--bg-panel);
    border: 1px solid var(--border-glow);
    border-radius: 10px;
    padding: 12px 16px;
    font-size: 13px;
    color: var(--text-primary);
    backdrop-filter: blur(12px);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    animation: toastIn 0.3s ease;
    max-width: 300px;
    word-wrap: break-word;
}

.toast.toast-error {
    border-color: rgba(255, 50, 80, 0.3);
    background: rgba(255, 50, 80, 0.05);
}

.toast.toast-success {
    border-color: rgba(0, 255, 136, 0.3);
    background: rgba(0, 255, 136, 0.05);
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(20px); }
}

/* Animations */
@keyframes breathe {
    0%, 100% { transform: scale(1); opacity: 0.8; }
    50% { transform: scale(1.08); opacity: 1; }
}

@keyframes pulseFast {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

@keyframes pulseRing {
    0%, 100% { transform: scale(1); opacity: 0.3; }
    50% { transform: scale(1.1); opacity: 0.6; }
}

@keyframes expandRing {
    0% { transform: scale(1); opacity: 0.4; }
    100% { transform: scale(1.5); opacity: 0; }
}

@keyframes spinCore {
    0% { transform: rotate(0deg) scale(1); }
    50% { transform: rotate(180deg) scale(1.1); }
    100% { transform: rotate(360deg) scale(1); }
}

@keyframes spinRing {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes waveBar {
    0% { transform: scaleY(0.4); }
    100% { transform: scaleY(1.2); }
}

/* Mobile */
@media (max-width: 640px) {
    :root {
        --orb-size: 160px;
    }

    .theron-main {
        padding: 12px;
    }

    .theron-header {
        padding: 10px 12px;
    }

    .brand-name {
        display: none;
    }

    .theron-transcript {
        height: 200px;
    }

    .theron-orb-container {
        gap: 20px;
    }

    .msg {
        max-width: 92%;
        font-size: 13px;
    }

    .theron-minimized {
        bottom: 16px;
        right: 16px;
    }

    .mini-orb {
        width: 48px;
        height: 48px;
    }

    .theron-panel {
        width: 95%;
    }
}

/* Mobile overlay enhancements */
@media (max-width: 640px) {
    .theron-app {
        position: fixed;
        inset: 0;
    }

    .theron-main {
        height: 100dvh; /* dynamic viewport height for mobile keyboards */
        padding: 8px;
    }

    .theron-header {
        position: sticky;
        top: 0;
        z-index: 10;
    }

    .theron-orb-container {
        flex: 1;
        min-height: 0;
    }

    .theron-transcript {
        position: relative;
        height: 180px;
    }

    .theron-transcript::before {
        content: '';
        position: absolute;
        top: -20px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background: rgba(255,255,255,0.1);
        border-radius: 2px;
    }

    .transcript-input {
        font-size: 16px; /* prevents iOS zoom on focus */
    }

    .send-btn {
        width: 44px;
        height: 44px;
    }

    .ctrl-btn {
        width: 36px;
        height: 36px;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
