/* ═══════════════════════════════════════════════════════════════════
   J.A.R.V.I.S. — Star Trek LCARS Interface
   Color palette: LCARS standard (amber, blue, purple, cream)
   ═══════════════════════════════════════════════════════════════════ */

:root {
    --lcars-bg: #0a0a12;
    --lcars-amber: #ff9900;
    --lcars-blue: #9999ff;
    --lcars-purple: #cc99cc;
    --lcars-red: #cc6666;
    --lcars-cream: #ffcc99;
    --lcars-teal: #99cccc;
    --lcars-orange: #ff7700;
    --lcars-dark-blue: #333366;
    --lcars-panel: #12121e;
    --lcars-text: #ffcc99;
    --lcars-dim: #555566;
    --orb-idle: #1a3a5c;
    --orb-active: #4a9eff;
    --orb-think: #ff9900;
    --orb-speak: #00cc66;
    --orb-error: #cc3333;
}

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

body {
    background: var(--lcars-bg);
    color: var(--lcars-text);
    font-family: 'Courier New', 'Consolas', monospace;
    height: 100vh;
    overflow: hidden;
    user-select: none;
}

/* ── LCARS Layout ─────────────────────────────────────────────── */
#lcars {
    display: flex;
    flex-direction: column;
    height: 100vh;
    gap: 3px;
    padding: 3px;
}

/* ── Top Bar ──────────────────────────────────────────────────── */
#topbar {
    display: flex;
    align-items: flex-end;
    height: 48px;
    gap: 3px;
    flex-shrink: 0;
}

.lcars-elbow {
    width: 80px;
    height: 100%;
    background: var(--lcars-amber);
    border-radius: 20px 0 0 0;
    position: relative;
}
.lcars-elbow::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 20px;
    height: 20px;
    background: var(--lcars-bg);
    border-radius: 0 0 0 4px;
}
.lcars-elbow.bottom {
    border-radius: 0 0 0 20px;
}
.lcars-elbow.bottom::after {
    border-radius: 0 4px 0 0;
    top: 0;
    bottom: auto;
}

.lcars-bar {
    height: 100%;
    display: flex;
    align-items: center;
    padding: 0 16px;
    font-size: 18px;
    font-weight: bold;
    letter-spacing: 3px;
    text-transform: uppercase;
}

.top-label {
    background: var(--lcars-dark-blue);
    color: var(--lcars-cream);
    flex: 1;
    border-radius: 0;
}

.bottom-label {
    background: var(--lcars-dark-blue);
    color: var(--lcars-teal);
    flex: 1;
    font-size: 13px;
    letter-spacing: 2px;
}

.lcars-segment {
    height: 100%;
    display: flex;
    align-items: center;
    padding: 0 14px;
    background: var(--lcars-amber);
    color: var(--lcars-bg);
    font-size: 14px;
    font-weight: bold;
    letter-spacing: 1px;
    min-width: 100px;
}

.lcars-endcap {
    width: 30px;
    height: 100%;
    background: var(--lcars-amber);
    border-radius: 0 10px 10px 0;
}
.lcars-endcap.bottom {
    border-radius: 10px 0 0 10px;
}

/* ── Bottom Bar ───────────────────────────────────────────────── */
#bottombar {
    display: flex;
    align-items: flex-start;
    height: 36px;
    gap: 3px;
    flex-shrink: 0;
}

/* ── Main Grid ────────────────────────────────────────────────── */
#main-grid {
    display: grid;
    grid-template-columns: 180px 1fr 300px;
    gap: 3px;
    flex: 1;
    min-height: 0;
}

/* ── Left Panel ───────────────────────────────────────────────── */
#left-panel {
    display: flex;
    flex-direction: column;
    gap: 3px;
    overflow-y: auto;
}

.lcars-block {
    background: var(--lcars-panel);
    border-left: 4px solid var(--lcars-amber);
    padding: 8px 10px;
    min-height: 48px;
}

.lcars-block:nth-child(2) { border-color: var(--lcars-blue); }
.lcars-block:nth-child(3) { border-color: var(--lcars-purple); }
.lcars-block:nth-child(4) { border-color: var(--lcars-teal); }
.lcars-block:nth-child(5) { border-color: var(--lcars-orange); }
.lcars-block:nth-child(7) { border-color: var(--lcars-blue); }
.lcars-block:nth-child(8) { border-color: var(--lcars-purple); }

.lcars-label {
    font-size: 9px;
    letter-spacing: 2px;
    color: var(--lcars-dim);
    margin-bottom: 3px;
    text-transform: uppercase;
}

.lcars-value {
    font-size: 12px;
    color: var(--lcars-cream);
    word-break: break-all;
}

.lcars-spacer { flex: 1; }

/* ── Voice Switcher Block ────────────────────────────────────── */
.voice-switcher-block {
    border-left: 4px solid var(--lcars-teal) !important;
    position: relative;
}

#voice-switcher {
    margin-top: 6px;
}

.voice-dropdown {
    width: 100%;
    background: var(--lcars-bg);
    border: 1px solid var(--lcars-dim);
    color: var(--lcars-cream);
    font-family: inherit;
    font-size: 11px;
    letter-spacing: 1px;
    text-transform: uppercase;
    padding: 8px 6px;
    cursor: pointer;
    transition: all 0.2s;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M0 0l6 8 6-8z' fill='%238899aa'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}

.voice-dropdown:hover {
    border-color: var(--lcars-teal);
    color: var(--lcars-teal);
}

.voice-dropdown:focus {
    outline: none;
    border-color: var(--lcars-teal);
    box-shadow: 0 0 6px var(--lcars-teal-glow);
}

.voice-dropdown option {
    background: #1a1a2e;
    color: var(--lcars-cream);
    padding: 6px;
    font-size: 12px;
    letter-spacing: 0.5px;
    text-transform: none;
}

/* ── Center: Orb Stage ────────────────────────────────────────── */
#center {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    background: radial-gradient(ellipse at center, #0d1525 0%, #0a0a12 70%);
    border-radius: 4px;
}

#orb-stage {
    position: relative;
    width: 280px;
    height: 280px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Holographic rings */
#orb-ring-1, #orb-ring-2, #orb-ring-3 {
    position: absolute;
    border-radius: 50%;
    border: 1px solid;
    opacity: 0.3;
}

#orb-ring-1 {
    width: 240px; height: 240px;
    border-color: var(--orb-active);
    animation: ring-rotate 20s linear infinite;
}
#orb-ring-2 {
    width: 210px; height: 210px;
    border-color: var(--lcars-amber);
    animation: ring-rotate 15s linear infinite reverse;
    border-style: dashed;
}
#orb-ring-3 {
    width: 180px; height: 180px;
    border-color: var(--lcars-purple);
    animation: ring-rotate 25s linear infinite;
    border-style: dotted;
}

@keyframes ring-rotate {
    from { transform: rotate(0deg) rotateX(60deg); }
    to { transform: rotate(360deg) rotateX(60deg); }
}

/* The core orb */
#orb-core {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    position: relative;
    z-index: 2;
    cursor: pointer;
    transition: all 0.4s ease;
}

#orb-core.state-idle {
    background: radial-gradient(circle at 35% 35%, #2a4a6c, #0d1b2a);
    box-shadow: 0 0 40px rgba(30, 90, 160, 0.3), 0 0 80px rgba(30, 90, 160, 0.1);
    animation: idle-breathe 4s ease-in-out infinite;
}

#orb-core.state-listening {
    background: radial-gradient(circle at 35% 35%, #4a9eff, #1a3a5c);
    box-shadow: 0 0 60px rgba(74, 158, 255, 0.6), 0 0 120px rgba(74, 158, 255, 0.2);
    animation: pulse-listen 1.2s ease-in-out infinite;
}

#orb-core.state-thinking {
    background: radial-gradient(circle at 35% 35%, #ffcc00, #996600);
    box-shadow: 0 0 60px rgba(255, 204, 0, 0.5), 0 0 120px rgba(255, 153, 0, 0.15);
    animation: pulse-think 0.6s ease-in-out infinite;
}

#orb-core.state-speaking {
    background: radial-gradient(circle at 35% 35%, #00cc66, #006633);
    box-shadow: 0 0 60px rgba(0, 204, 102, 0.6), 0 0 120px rgba(0, 204, 102, 0.2);
    animation: pulse-speak 0.4s ease-in-out infinite;
}

#orb-core.state-error {
    background: radial-gradient(circle at 35% 35%, #cc3333, #660000);
    box-shadow: 0 0 60px rgba(204, 51, 51, 0.6);
    animation: pulse-error 1s ease-in-out infinite;
}

@keyframes idle-breathe {
    0%, 100% { transform: scale(1); opacity: 0.9; }
    50% { transform: scale(1.02); opacity: 1; }
}
@keyframes pulse-listen {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.06); }
}
@keyframes pulse-think {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}
@keyframes pulse-speak {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
}
@keyframes pulse-error {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Orb glow */
#orb-glow {
    position: absolute;
    width: 160px;
    height: 160px;
    border-radius: 50%;
    z-index: 1;
    background: radial-gradient(circle, rgba(74, 158, 255, 0.08) 0%, transparent 70%);
    animation: glow-pulse 3s ease-in-out infinite;
}

@keyframes glow-pulse {
    0%, 100% { transform: scale(1); opacity: 0.5; }
    50% { transform: scale(1.3); opacity: 0.8; }
}

/* Frequency visualizer */
#freq-bars {
    position: absolute;
    bottom: 20px;
    display: flex;
    gap: 3px;
    align-items: flex-end;
    height: 40px;
    z-index: 3;
    opacity: 0;
    transition: opacity 0.3s;
}
#freq-bars.active { opacity: 1; }

#freq-bars span {
    width: 4px;
    background: var(--orb-speak);
    border-radius: 2px 2px 0 0;
    height: 4px;
    transition: height 0.1s;
}

/* ── Mic Button (Push-to-Talk) ──────────────────────────────── */
#mic-btn {
    margin-top: 24px;
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--lcars-panel);
    border: 2px solid var(--lcars-amber);
    color: var(--lcars-cream);
    padding: 12px 28px;
    font-family: inherit;
    font-size: 13px;
    letter-spacing: 2px;
    cursor: pointer;
    text-transform: uppercase;
    transition: all 0.3s;
    position: relative;
    min-height: 48px;
}

#mic-btn:hover {
    background: var(--lcars-amber);
    color: var(--lcars-bg);
}

#mic-btn.recording {
    background: var(--orb-error);
    border-color: var(--orb-error);
    color: #fff;
    animation: mic-rec-pulse 1s ease-in-out infinite;
}

@keyframes mic-rec-pulse {
    0%, 100% { box-shadow: 0 0 10px rgba(204, 51, 51, 0.3); }
    50% { box-shadow: 0 0 30px rgba(204, 51, 51, 0.7); }
}

/* Recording indicator (red pulsing dot) */
#rec-indicator {
    display: none;
    width: 12px;
    height: 12px;
    background: #ff3333;
    border-radius: 50%;
    flex-shrink: 0;
}

#mic-btn.recording #rec-indicator {
    display: block;
    animation: rec-dot-pulse 0.8s ease-in-out infinite;
}

@keyframes rec-dot-pulse {
    0%, 100% { opacity: 1; transform: scale(1); box-shadow: 0 0 6px #ff3333; }
    50% { opacity: 0.4; transform: scale(0.8); box-shadow: 0 0 14px #ff3333; }
}

/* ── Text Input ───────────────────────────────────────────────── */
#text-input-row {
    display: flex;
    margin-top: 12px;
    width: 80%;
    max-width: 400px;
}

#text-input {
    flex: 1;
    background: var(--lcars-panel);
    border: 1px solid var(--lcars-dim);
    border-right: none;
    color: var(--lcars-cream);
    padding: 10px 14px;
    font-family: inherit;
    font-size: 13px;
    outline: none;
    letter-spacing: 1px;
}
#text-input:focus {
    border-color: var(--lcars-amber);
}
#text-input::placeholder {
    color: var(--lcars-dim);
}

#send-btn {
    background: var(--lcars-amber);
    border: 1px solid var(--lcars-amber);
    color: var(--lcars-bg);
    padding: 10px 16px;
    font-size: 16px;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.2s;
}
#send-btn:hover {
    background: var(--lcars-orange);
}

/* ── Status Line ──────────────────────────────────────────────── */
#status-line {
    margin-top: 16px;
    font-size: 12px;
    color: var(--lcars-dim);
    letter-spacing: 1px;
    min-height: 18px;
    text-align: center;
}

/* ── Right Panel: Transcript ──────────────────────────────────── */
#right-panel {
    display: flex;
    flex-direction: column;
    background: var(--lcars-panel);
    overflow: hidden;
}

.lcars-header-strip {
    background: var(--lcars-dark-blue);
    padding: 6px 12px;
    border-bottom: 3px solid var(--lcars-purple);
}
.lcars-header-strip .lcars-label {
    font-size: 11px;
    color: var(--lcars-purple);
}

#transcript {
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#transcript::-webkit-scrollbar {
    width: 6px;
}
#transcript::-webkit-scrollbar-track {
    background: var(--lcars-bg);
}
#transcript::-webkit-scrollbar-thumb {
    background: var(--lcars-dim);
    border-radius: 3px;
}

.transcript-entry {
    padding: 6px 10px;
    border-left: 3px solid var(--lcars-dim);
    font-size: 12px;
    line-height: 1.5;
    animation: fade-in 0.3s ease;
}
.transcript-entry.user {
    border-color: var(--lcars-blue);
    color: var(--lcars-teal);
}
.transcript-entry.jarvis {
    border-color: var(--lcars-amber);
    color: var(--lcars-cream);
}
.transcript-entry .time {
    font-size: 9px;
    color: var(--lcars-dim);
    display: block;
    margin-bottom: 2px;
}

@keyframes fade-in {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Scrollbar for left panel ─────────────────────────────────── */
#left-panel::-webkit-scrollbar { width: 4px; }
#left-panel::-webkit-scrollbar-track { background: transparent; }
#left-panel::-webkit-scrollbar-thumb { background: var(--lcars-dim); }

/* ── SpeechRecognition Warning Banner ─────────────────────────── */
.speech-warn {
    position: fixed;
    top: 52px;
    left: 50%;
    transform: translateX(-50%);
    background: #332200;
    border: 1px solid var(--lcars-orange);
    color: var(--lcars-orange);
    padding: 8px 20px;
    font-size: 12px;
    letter-spacing: 1px;
    z-index: 100;
    border-radius: 0 0 6px 6px;
    animation: warn-slide-down 0.4s ease;
    max-width: 90vw;
    text-align: center;
}
.speech-warn.hidden { display: none; }

@keyframes warn-slide-down {
    from { opacity: 0; transform: translateX(-50%) translateY(-100%); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Toast Notifications ──────────────────────────────────────── */
#toast-container {
    position: fixed;
    bottom: 44px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 200;
    pointer-events: none;
}

.toast {
    background: var(--lcars-dark-blue);
    border-left: 4px solid var(--lcars-teal);
    color: var(--lcars-cream);
    padding: 10px 18px;
    font-size: 12px;
    letter-spacing: 1px;
    font-family: inherit;
    border-radius: 0 4px 4px 0;
    animation: toast-in 0.3s ease, toast-out 0.3s ease 2.7s forwards;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    max-width: 300px;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}
@keyframes toast-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

.toast-trade {
    background: #0a3d1a;
    border-left: 4px solid #00ff88;
    color: #00ff88;
    font-size: 13px;
    font-weight: bold;
    animation: toast-in 0.3s ease, toast-out 0.3s ease 7.5s forwards;
    max-width: 360px;
    box-shadow: 0 4px 20px rgba(0,255,136,0.3);
}

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 900px) {
    #main-grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
    }
    #left-panel {
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
    }
    #left-panel .lcars-block {
        min-width: 120px;
        flex-shrink: 0;
    }
    #left-panel .lcars-spacer { display: none; }
    #right-panel { max-height: 200px; }
    #orb-ring-1, #orb-ring-2, #orb-ring-3 {
        width: 180px; height: 180px;
    }
    #orb-core { width: 90px; height: 90px; }
    /* Voice dropdown mobile */
    .voice-dropdown {
        padding: 10px 28px 10px 8px;
        font-size: 12px;
    }
}
