:root {
    --bg-color: #050505;
    --surface-color: #0f0f11;
    --border-color: #333;

    --primary-hue: 0;
    --primary-color: hsl(var(--primary-hue), 100%, 50%);
    /* Red by default */
    --accent-color: #ffffff;
    --text-muted: #888;

    --font-mono: 'JetBrains Mono', monospace;
    --font-display: 'Space Grotesk', sans-serif;

    --ease-elastic: cubic-bezier(0.68, -0.6, 0.32, 1.6);
}

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

body {
    background-color: var(--bg-color);
    color: var(--accent-color);
    font-family: var(--font-display);
    height: 100vh;
    height: 100dvh;
    /* Mobile viewport fix */
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* --- Layout --- */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    z-index: 1;
}

/* Prevent auto-zoom on iOS inputs */
input,
textarea,
select {
    font-size: 16px !important;
}

/* --- Header --- */
.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
}

.logo {
    font-family: var(--font-mono);
    font-weight: 700;
    letter-spacing: -1px;
}

.logo .highlight {
    color: var(--primary-color);
}

.logo .version {
    font-size: 0.7em;
    color: var(--text-muted);
    font-weight: 400;
    margin-left: 0.5rem;
}

.metrics {
    display: flex;
    gap: 2rem;
    align-items: center;
}

.metric {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 120px;
}

.metric .label {
    font-size: 0.6rem;
    font-family: var(--font-mono);
    color: var(--text-muted);
    text-transform: uppercase;
}

.bar-container {
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    background: var(--primary-color);
    transition: width 0.5s ease;
    box-shadow: 0 0 10px var(--primary-color);
}

#patience-meter {
    background: #4ade80;
    /* Green initially */
    box-shadow: 0 0 10px #4ade80;
}

/* --- Main Stage (Avatar) --- */
.stage {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    min-height: 0;
    /* Flexbox scrolling fix */
}

.avatar-container {
    width: 300px;
    height: 300px;
    position: relative;
    /* border: 1px solid rgba(255,0,0,0.1); Debug */
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.3s ease;
}

/* Face Structure */
.face-structure {
    width: 200px;
    height: 150px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    position: relative;
    z-index: 2;
}

/* Eyes */
.eye {
    width: 60px;
    height: 60px;
    border: 2px solid var(--accent-color);
    border-radius: 50%;
    /* Circle by default */
    position: absolute;
    top: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.5);
    overflow: hidden;
    transition: all 0.3s var(--ease-elastic);
}

.eye.left {
    left: 0;
}

.eye.right {
    right: 0;
}

.pupil {
    width: 15px;
    height: 15px;
    background: var(--accent-color);
    border-radius: 50%;
    box-shadow: 0 0 15px var(--primary-color);
    transition: transform 0.1s;
}

.eyelid {
    position: absolute;
    top: -100%;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-color);
    border-bottom: 2px solid var(--accent-color);
    transition: top 0.1s;
}

/* Mouth */
.mouth-container {
    position: absolute;
    bottom: 0;
    width: 40px;
    height: 10px;
    /* border: 1px solid blue; Debug */
    display: flex;
    justify-content: center;
    align-items: center;
}

.mouth {
    width: 100%;
    height: 2px;
    background: var(--accent-color);
    transition: all 0.1s;
    border-radius: 2px;
}

/* Aura */
.aura {
    position: absolute;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, var(--primary-color) 0%, transparent 70%);
    opacity: 0.05;
    z-index: 1;
    filter: blur(40px);
    animation: pulse 4s infinite ease-in-out;
}

/* Subtitles */
.subtitles-container {
    margin-top: 2rem;
    height: 60px;
    text-align: center;
    font-family: var(--font-mono);
    color: var(--primary-color);
    font-size: 1.1rem;
    max-width: 600px;
    text-shadow: 0 0 10px rgba(0, 0, 0, 0.8);
    opacity: 0.9;
}


/* --- Interaction Layer --- */
.interaction-layer {
    background: linear-gradient(to top, var(--bg-color) 20%, transparent);
    padding: 1rem 2rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
}

.chat-history {
    height: 150px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding-right: 1rem;
    mask-image: linear-gradient(to bottom, transparent, black 20%);
    -webkit-mask-image: linear-gradient(to bottom, transparent, black 20%);
}

.message {
    padding: 0.8rem 1rem;
    border-radius: 8px;
    font-size: 0.95rem;
    line-height: 1.5;
    animation: slideIn 0.3s ease-out;
    max-width: 80%;
}

.message.ai {
    background: rgba(255, 255, 255, 0.05);
    border-left: 2px solid var(--primary-color);
    align-self: flex-start;
}

.message.user {
    background: rgba(255, 255, 255, 0.1);
    align-self: flex-end;
    text-align: right;
    color: #ccc;
}

.message.system {
    align-self: center;
    font-style: italic;
    font-size: 0.8rem;
    color: var(--text-muted);
    border: none;
    background: transparent;
}

.mic-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    margin-right: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    opacity: 1;
    /* Override opacity from generic icon-btn */
}

.mic-btn svg {
    width: 20px;
    height: 20px;
}

.mic-btn.listening {
    background: var(--primary-color);
    animation: pulseMic 1.5s infinite;
}

@keyframes pulseMic {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 0, 0, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(255, 0, 0, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(255, 0, 0, 0);
    }
}

/* Input Area */
.input-area {
    display: flex;
    gap: 1rem;
    background: var(--surface-color);
    padding: 0.5rem;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    align-items: flex-end;
}

textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: white;
    font-family: var(--font-display);
    font-size: 1rem;
    padding: 0.8rem;
    resize: none;
    outline: none;
    max-height: 100px;
}

.send-btn {
    background: var(--primary-color);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.send-btn:hover {
    transform: scale(1.05);
}

.icon-btn {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 1.2rem;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.icon-btn:hover {
    opacity: 1;
}

/* --- Modal --- */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    padding: 2rem;
    border-radius: 16px;
    width: 100%;
    max-width: 500px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.modal-content h2 {
    margin-bottom: 1rem;
}

.modal-content p {
    margin-bottom: 1.5rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.9rem;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.8rem;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    color: white;
    border-radius: 6px;
    font-family: var(--font-mono);
}

.form-group small {
    display: block;
    margin-top: 0.4rem;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

.btn-primary {
    background: white;
    color: black;
    border: none;
    padding: 0.8rem 1.5rem;
    border-radius: 6px;
    font-weight: 700;
    cursor: pointer;
}

.btn-text {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
}

/* --- Animations --- */
@keyframes pulse {

    0%,
    100% {
        opacity: 0.05;
        transform: scale(1);
    }

    50% {
        opacity: 0.15;
        transform: scale(1.1);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Avatar States */
/* Angry */
.avatar-container[data-mood="angry"] .eye {
    border-top: 10px solid var(--primary-color);
    /* Furrowed brow */
    border-radius: 40% 40% 50% 50%;
    height: 50px;
}

.avatar-container[data-mood="angry"] .pupil {
    background: var(--primary-color);
    width: 10px;
    height: 10px;
}

/* Suspicious */
.avatar-container[data-mood="suspicious"] .eye {
    height: 30px;
    border-radius: 10px;
}

/* Speaking */
.avatar-container[data-speaking="true"] .mouth {
    height: 15px;
    /* Opens */
    border-radius: 50%;
}