/* EV - Jarvis dashboard. Full-screen amber reactor on pure black. */

:root {
    --bg:        #000000;
    --gold:      #ffab2e;
    --gold-hot:  #ffd77a;
    --gold-dim:  rgba(255, 171, 46, 0.42);
    --gold-line: rgba(255, 171, 46, 0.18);
    --gold-wash: rgba(255, 171, 46, 0.07);
    --text:      #f3e4cd;
    --text-dim:  rgba(243, 228, 205, 0.52);
    --danger:    #ff5b47;
    --veil:      rgba(0, 0, 0, 0.62);
    --mono: "SF Mono", "JetBrains Mono", "Cascadia Mono", Consolas, monospace;
    --sans: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

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

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}

.screen { display: none; position: relative; height: 100%; }
.screen.active { display: flex; }

/* ---------------- the reactor, full viewport ---------------- */
/* Fixed to the whole screen and centred, on black. Every panel floats above
   it, so the reactor is the ground the interface sits on. */
#reactor-wrap,
.reactor-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    transition: opacity 0.6s ease;
}

#reactor-canvas,
.reactor-bg {
    display: block;
    width: 100%;
    height: 100%;
}

/* While a conversation is on screen the reactor recedes so text stays legible. */
#reactor-wrap.compact { opacity: 0.45; }

/* Slightly held back on the login screen so the access card reads cleanly. */
.reactor-bg { opacity: 0.72; }

#reactor-caption {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(96px + env(safe-area-inset-bottom));
    z-index: 1;
    text-align: center;
    font-family: var(--mono);
    font-size: 9.5px;
    letter-spacing: 0.3em;
    color: var(--gold-dim);
    text-transform: uppercase;
    pointer-events: none;
    transition: opacity 0.4s;
}

/* ---------------- login ---------------- */
#login-screen { align-items: center; justify-content: center; }

.login-card {
    position: relative;
    z-index: 2;
    width: min(90vw, 340px);
    padding: 38px 30px 30px;
    text-align: center;
    background: rgba(0, 0, 0, 0.66);
    border: 1px solid var(--gold-line);
    border-radius: 4px;
    backdrop-filter: blur(14px);
    box-shadow: 0 0 60px rgba(255, 140, 20, 0.14), inset 0 0 40px rgba(255, 140, 20, 0.05);
}

.login-mark {
    font-family: var(--mono);
    font-size: 42px;
    letter-spacing: 0.32em;
    color: var(--gold-hot);
    text-shadow: 0 0 26px rgba(255, 171, 46, 0.75);
}

.login-sub {
    margin: 8px 0 26px;
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.22em;
    color: var(--text-dim);
    text-transform: uppercase;
}

input, textarea {
    width: 100%;
    padding: 13px 14px;
    background: rgba(255, 171, 46, 0.05);
    border: 1px solid var(--gold-line);
    border-radius: 3px;
    color: var(--text);
    font-family: var(--mono);
    font-size: 13px;
    letter-spacing: 0.1em;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus, textarea:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 1px var(--gold-dim), 0 0 22px rgba(255, 171, 46, 0.18);
}

.btn-primary {
    margin-top: 14px;
    width: 100%;
    padding: 12px;
    background: linear-gradient(180deg, rgba(255, 171, 46, 0.22), rgba(255, 171, 46, 0.10));
    border: 1px solid var(--gold-dim);
    border-radius: 3px;
    color: var(--gold-hot);
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.22em;
    cursor: pointer;
    transition: background 0.2s, box-shadow 0.2s;
}

.btn-primary:hover {
    background: linear-gradient(180deg, rgba(255, 171, 46, 0.34), rgba(255, 171, 46, 0.16));
    box-shadow: 0 0 26px rgba(255, 171, 46, 0.28);
}

.login-error {
    margin-top: 14px;
    color: var(--danger);
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.08em;
}

/* ---------------- dashboard shell ---------------- */
#dashboard-screen { display: none; }
#dashboard-screen.active { display: flex; }

#sidebar {
    position: relative;
    z-index: 12;
    width: 232px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: rgba(0, 0, 0, 0.72);
    border-right: 1px solid var(--gold-line);
    backdrop-filter: blur(10px);
}

.side-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 14px 12px;
    border-bottom: 1px solid var(--gold-line);
}

.side-title {
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.22em;
    color: var(--text-dim);
}

#new-session-btn {
    width: 24px;
    height: 24px;
    background: transparent;
    border: 1px solid var(--gold-line);
    border-radius: 3px;
    color: var(--gold);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
}

#new-session-btn:hover { background: var(--gold-wash); border-color: var(--gold-dim); }

#session-list { flex: 1; overflow-y: auto; padding: 8px; }

.session-item {
    position: relative;
    padding: 9px 26px 9px 10px;
    margin-bottom: 4px;
    border: 1px solid transparent;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-dim);
    line-height: 1.35;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.session-item:hover { background: var(--gold-wash); color: var(--text); }

.session-item.active {
    background: var(--gold-wash);
    border-color: var(--gold-dim);
    color: var(--gold-hot);
}

.session-item .kill {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 14px;
    opacity: 0;
    padding: 0 4px;
}

.session-item:hover .kill { opacity: 1; }
.session-item .kill:hover { color: var(--danger); }

.session-item .tag {
    display: inline-block;
    margin-right: 6px;
    padding: 1px 4px;
    border-radius: 2px;
    font-family: var(--mono);
    font-size: 8px;
    letter-spacing: 0.1em;
    vertical-align: 1px;
    background: rgba(255, 171, 46, 0.14);
    color: var(--gold);
}

.side-voice {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid var(--gold-line);
}

.side-voice label {
    font-family: var(--mono);
    font-size: 9px;
    letter-spacing: 0.18em;
    color: var(--text-dim);
}

.side-voice select {
    flex: 1;
    min-width: 0;
    padding: 5px 6px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid var(--gold-line);
    border-radius: 3px;
    color: var(--gold);
    font-family: var(--mono);
    font-size: 10px;
    outline: none;
    cursor: pointer;
}

.side-voice select:focus { border-color: var(--gold); }
.side-voice select option { background: #0b0806; color: var(--text); }

.side-foot {
    padding: 10px 14px 14px;
    border-top: 1px solid var(--gold-line);
    display: flex;
    justify-content: space-between;
    gap: 6px;
}

.stat { font-family: var(--mono); font-size: 9px; letter-spacing: 0.12em; text-align: center; }
.stat span { display: block; color: var(--text-dim); }
.stat b { color: var(--gold); font-weight: 500; }

/* ---------------- stage ---------------- */
#stage {
    position: relative;
    z-index: 10;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: transparent;
}

#topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 16px;
    border-bottom: 1px solid var(--gold-line);
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.85), rgba(0, 0, 0, 0.5));
    backdrop-filter: blur(10px);
    transition: opacity 0.4s, transform 0.4s;
}

.spacer { flex: 1; }

.brand {
    font-family: var(--mono);
    font-size: 15px;
    letter-spacing: 0.3em;
    color: var(--gold-hot);
    text-shadow: 0 0 16px rgba(255, 171, 46, 0.6);
}

#menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--gold);
    font-size: 17px;
    cursor: pointer;
}

#status-readout {
    display: flex;
    align-items: center;
    gap: 7px;
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.18em;
    color: var(--text-dim);
}

.dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--gold);
    box-shadow: 0 0 10px var(--gold);
    animation: breathe 3s ease-in-out infinite;
}

@keyframes breathe { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }

body[data-state="thinking"] .dot { animation-duration: 0.55s; }
body[data-state="listening"] .dot { background: #4fd6ff; box-shadow: 0 0 10px #4fd6ff; animation-duration: 1s; }
body[data-state="speaking"] .dot { animation-duration: 0.9s; }

#mode-toggle { display: flex; border: 1px solid var(--gold-line); border-radius: 3px; overflow: hidden; }

#mode-toggle button {
    padding: 5px 11px;
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-family: var(--mono);
    font-size: 9px;
    letter-spacing: 0.16em;
    cursor: pointer;
}

#mode-toggle button.active { background: rgba(255, 171, 46, 0.18); color: var(--gold-hot); }

.icon-btn {
    background: transparent;
    border: 1px solid var(--gold-line);
    border-radius: 3px;
    color: var(--gold);
    font-size: 14px;
    padding: 5px 9px;
    cursor: pointer;
    transition: background 0.2s;
}

.icon-btn:hover { background: var(--gold-wash); }
.icon-btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.icon-btn.on { background: rgba(255, 91, 71, 0.18); border-color: var(--danger); color: var(--danger); }
.icon-btn.off { opacity: 0.4; }

/* ---------------- messages ---------------- */
#messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 22px 22px 8px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
    transition: opacity 0.4s;
}

.msg { max-width: 760px; width: 100%; margin: 0 auto; animation: rise 0.35s ease both; }

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

.msg .who {
    font-family: var(--mono);
    font-size: 9px;
    letter-spacing: 0.2em;
    color: var(--text-dim);
    margin-bottom: 5px;
}

.msg.ev .who { color: var(--gold); }

/* Panels are veiled so text stays readable with the reactor burning behind. */
.msg .body {
    padding: 11px 14px;
    border-radius: 3px;
    font-size: 14.5px;
    line-height: 1.62;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    background: var(--veil);
    backdrop-filter: blur(6px);
}

.msg.user .body { border-left: 2px solid rgba(255, 255, 255, 0.22); }

.msg.ev .body {
    background: linear-gradient(90deg, rgba(60, 32, 0, 0.72), rgba(0, 0, 0, 0.66));
    border-left: 2px solid var(--gold);
}

.msg.err .body {
    background: rgba(48, 10, 6, 0.78);
    border-left: 2px solid var(--danger);
    color: #ffb5aa;
    font-family: var(--mono);
    font-size: 12.5px;
}

/* ---------------- composer ---------------- */
#composer {
    display: flex;
    align-items: flex-end;
    gap: 9px;
    padding: 12px 22px 16px;
    border-top: 1px solid var(--gold-line);
    background: linear-gradient(0deg, rgba(0, 0, 0, 0.9), rgba(0, 0, 0, 0.55));
    backdrop-filter: blur(10px);
    transition: opacity 0.4s, transform 0.4s;
}

#message-input {
    flex: 1;
    resize: none;
    max-height: 130px;
    font-family: var(--sans);
    letter-spacing: 0;
    font-size: 14px;
    background: rgba(0, 0, 0, 0.5);
}

#send-btn { width: auto; margin-top: 0; padding: 12px 20px; }
#mic-btn { padding: 10px 12px; font-size: 15px; }

/* ---------------- ambient mode: reactor alone on black ---------------- */
body.ambient #topbar { opacity: 0; transform: translateY(-100%); pointer-events: none; }
body.ambient #composer { opacity: 0; transform: translateY(100%); pointer-events: none; }
body.ambient #messages-container { opacity: 0; pointer-events: none; }
body.ambient #sidebar { display: none; }
body.ambient #reactor-wrap.compact { opacity: 1; }
body.ambient #reactor-caption { bottom: 40px; }

#ambient-exit {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: none;
    border: none;
    background: transparent;
    cursor: pointer;
}

body.ambient #ambient-exit { display: block; }

#ambient-hint {
    position: fixed;
    left: 0;
    right: 0;
    top: 28px;
    z-index: 41;
    text-align: center;
    font-family: var(--mono);
    font-size: 9px;
    letter-spacing: 0.28em;
    text-transform: uppercase;
    color: var(--text-dim);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s;
}

body.ambient #ambient-hint { animation: hint 4s ease forwards; }

@keyframes hint { 0% { opacity: 0; } 15% { opacity: 1; } 70% { opacity: 1; } 100% { opacity: 0; } }

/* ---------------- responsive ---------------- */
#scrim { display: none; }

@media (max-width: 820px) {
    #menu-btn { display: block; }

    #sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 30;
        transform: translateX(-100%);
        transition: transform 0.28s ease;
    }

    #sidebar.open { transform: none; }

    #scrim {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 20;
        background: rgba(0, 0, 0, 0.6);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.28s;
    }

    #scrim.on { opacity: 1; pointer-events: auto; }
    #messages-container { padding: 16px 14px 6px; }
    #composer { padding: 10px 14px calc(12px + env(safe-area-inset-bottom)); }
    .brand { font-size: 13px; }
    #status-readout { display: none; }
}

@media (max-width: 380px) {
    #mode-toggle button { padding: 5px 7px; }
    #send-btn { padding: 12px 13px; }
}

@media (prefers-reduced-motion: reduce) {
    #reactor-wrap, #topbar, #composer, #messages-container { transition: none; }
    .msg { animation: none; }
}

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 171, 46, 0.22); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 171, 46, 0.4); }

/* ---------------- sphere reactor (3D) ---------------- */
.sphere-canvas {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(80vw, 80vh);
    height: min(80vw, 80vh);
    max-width: 600px;
    max-height: 600px;
}

#reactor-wrap {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    transition: opacity 0.6s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

#reactor-wrap.compact { opacity: 0.35; }
