* {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
    -webkit-font-smoothing: antialiased;
}

html,
body {
    height: 100%;
    width: 100%;
    background-color: #141414;
    color: #D0D0D0;
    letter-spacing: 0.01em;
    overflow: hidden;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
}

textarea {
    width: 100%;
    padding: 12px 16px;
    background-color: #1C1C1E;
    border: 1px solid rgba(200, 200, 200, 0.08);
    border-radius: 14px;
    margin-bottom: 8px;
    font-size: 1rem;
    font-weight: 400;
    color: #D8D8D8;
    resize: none;
    overflow-y: hidden;
    height: auto;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

textarea:focus {
    outline: none;
    border-color: rgba(139, 116, 168, 0.35);
    background-color: #1E1E22;
}

button {
    background-color: transparent;
    border: 1px solid rgba(200, 200, 200, 0.2);
    color: #D0D0D0;
    padding: 8px 16px;
    font-size: 0.9rem;
    border-radius: 10px;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

button:hover {
    background-color: #222226;
    border-color: rgba(200, 200, 200, 0.3);
}

button:active {
    background-color: #1a1a1e;
}

button:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(139, 116, 168, 0.3);
}

#status-msg {
    padding-top: 5%;
}

.chat {
    width: 100%;
    padding: 24px 24px 0;
    display: flex;
    flex-direction: column;
}

#history {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-bottom: 12px;
}

.history-user-message {
    max-width: 72%;
    width: fit-content;
    margin-left: auto;
    padding: 10px 16px;
    background-color: #232328;
    border-radius: 18px 18px 6px 18px;
    font-size: 0.95rem;
    font-weight: 420;
    line-height: 1.55;
    color: #D0D0D0;
    word-wrap: break-word;
    overflow-wrap: break-word;
    animation: msgIn 200ms ease-out both;
}

.history-chat-response {
    max-width: 90%;
    width: fit-content;
    margin: 0;
    border-radius: 16px;
    background-color: #1A1A22;
    border: 1px solid rgba(139, 116, 168, 0.06);
    padding: 18px 22px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
    word-wrap: break-word;
    overflow-wrap: break-word;
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
    font-size: 1rem;
    font-weight: 420;
    line-height: 1.65;
    letter-spacing: 0.01em;
    color: #DCDCDC;
    animation: msgIn 200ms ease-out both;
}

.user-message {
    width: 100%;
    padding: 0;
}

.user-input {
    width: 100%;
    margin-top: auto;
    padding: 8px 0 10px;
    border-top: 1px solid rgba(200, 200, 200, 0.05);
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.user-input textarea {
    flex: 1;
    margin-bottom: 0;
}

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

#user-input-text:focus {
    outline: none;
}

#chat-view {
    display: none;
    position: relative;
    width: 100%;
    height: 100%;
    flex-direction: column;
    --canvas-size: 40%;
}

#chat-view.layout-top { flex-direction: column; }
#chat-view.layout-bottom { flex-direction: column-reverse; }
#chat-view.layout-left { flex-direction: row-reverse; }
#chat-view.layout-right { flex-direction: row; }

#toolbar {
    position: fixed;
    top: 10px;
    right: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 1001;
}

#canvas-toggle {
    display: none;
    width: 16px;
    height: 16px;
    cursor: pointer;
    color: #C8C8C8;
    opacity: 0.6;
    transition: opacity 0.2s;
}

#canvas-toggle:hover { opacity: 1; }
#canvas-toggle.active { opacity: 1; color: #8B74A8; }

#render-canvas {
    touch-action: none;
}

.toolbar-button {
    display: none;
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: 999px;
    align-items: center;
    justify-content: center;
    color: #B0B0B0;
    opacity: 0.72;
}

.toolbar-button svg {
    width: 16px;
    height: 16px;
}

.toolbar-button:hover {
    opacity: 1;
}

.toolbar-button.active {
    border-color: #7BA4B8;
    color: #7BA4B8;
    opacity: 1;
}

.toolbar-button.recording {
    border-color: #C48080;
    color: #C48080;
    opacity: 1;
    animation: pulse 1s ease-in-out infinite alternate;
}

.voice-indicator {
    flex-shrink: 0;
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    cursor: pointer;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    border-radius: 10px;
    transition: background-color 200ms ease;
    position: relative;
}

.voice-indicator:hover {
    background-color: rgba(200, 200, 200, 0.06);
}

.voice-indicator .mic-icon {
    width: 16px;
    height: 16px;
    color: #888;
    transition: opacity 200ms ease;
    opacity: 1;
}

.voice-indicator .spectrum-dots {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    position: absolute;
    inset: 0;
    opacity: 0;
    transition: opacity 200ms ease;
}

.voice-indicator.listening .mic-icon,
.voice-indicator.speaking .mic-icon,
.voice-indicator.processing .mic-icon,
.voice-indicator.responding .mic-icon {
    opacity: 0;
    pointer-events: none;
}

.voice-indicator.listening .spectrum-dots,
.voice-indicator.speaking .spectrum-dots,
.voice-indicator.processing .spectrum-dots,
.voice-indicator.responding .spectrum-dots {
    opacity: 1;
}

.voice-indicator.listening .spectrum-dot {
    background-color: #666;
}

.spectrum-dot {
    width: 3px;
    min-height: 3px;
    height: 3px;
    border-radius: 1.5px;
    background-color: #4a4a4a;
    transition: height 80ms ease-out, background-color 300ms ease;
}

.voice-indicator.listening .spectrum-dot {
    background-color: #7AB88A;
}

.voice-indicator.speaking .spectrum-dot {
    background-color: #7AB88A;
}

.voice-indicator.processing .spectrum-dot {
    background-color: #C8A855;
}

.voice-indicator.responding .spectrum-dot {
    background-color: #8B74A8;
}

#canvas-view {
    flex: 0 0 var(--canvas-size);
    background-color: #111114;
    border-bottom: 1px solid rgba(200, 200, 200, 0.06);
    position: relative;
    overflow: hidden;
    transition: flex-basis 2600ms cubic-bezier(0.22, 1, 0.36, 1);
}

.layout-bottom #canvas-view { border-bottom: none; border-top: 1px solid rgba(200, 200, 200, 0.06); }
.layout-left #canvas-view { border-bottom: none; border-right: 1px solid rgba(200, 200, 200, 0.06); }
.layout-right #canvas-view { border-bottom: none; border-left: 1px solid rgba(200, 200, 200, 0.06); }

.layout-left #canvas-view,
.layout-right #canvas-view { flex: 0 0 var(--canvas-size); }

#canvas-view.hidden { display: none; }

#render-canvas {
    width: 100%;
    height: 100%;
}

.chat {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
}

.chat::-webkit-scrollbar {
    width: 10px;
}

.chat::-webkit-scrollbar-track {
    background: #141414;
}

.chat::-webkit-scrollbar-thumb {
    background: rgba(200, 200, 200, 0.16);
    border: 2px solid #141414;
    border-radius: 999px;
}

.chat::-webkit-scrollbar-thumb:hover {
    background: rgba(200, 200, 200, 0.24);
}

.chat::before {
    content: "";
    position: sticky;
    top: 0;
    display: block;
    height: 28px;
    background: linear-gradient(to bottom, #141414, transparent);
    z-index: 999;
    pointer-events: none;
}

#settings-view {
    display: none;
    width: 100%;
    height: 100%;
    justify-content: center;
    align-items: center;
}

.settings-content {
    width: 60%;
    max-width: 480px;
    max-height: 80vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.settings-tabs {
    display: flex;
    gap: 2px;
    background: rgba(200, 200, 200, 0.06);
    border-radius: 10px;
    padding: 3px;
}

.settings-tab {
    flex: 1;
    min-height: 32px;
    padding: 6px 12px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #888;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 150ms ease, color 150ms ease;
}

.settings-tab:hover {
    color: #B0B0B0;
    background: rgba(200, 200, 200, 0.04);
}

.settings-tab.active {
    background: rgba(200, 200, 200, 0.1);
    color: #D8D8D8;
}

.settings-page {
    display: none;
    flex-direction: column;
    gap: 14px;
}

.settings-page.active {
    display: flex;
}

.settings-label {
    color: #C8C8C8;
    font-size: 0.85rem;
}

.settings-content input:not([type="range"]):not([type="checkbox"]),
.settings-content select {
    padding: 10px;
    background-color: #1C1C1E;
    border: 1px solid rgba(200, 200, 200, 0.15);
    color: #D0D0D0;
    border-radius: 10px;
    font-size: 0.95rem;
    width: 100%;
}

.settings-content input:not([type="range"]):not([type="checkbox"]):focus,
.settings-content select:focus {
    outline: none;
    border-color: rgba(139, 116, 168, 0.35);
}

.settings-content input[type="range"] {
    width: 100%;
    padding: 0;
    accent-color: #7BA4B8;
}

.settings-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #C8C8C8;
    font-size: 0.85rem;
    line-height: 1.4;
}

.settings-checkbox input {
    width: 16px;
    height: 16px;
    accent-color: #7BA4B8;
}

.settings-hint {
    color: #666;
    font-size: 0.78rem;
    margin-top: -8px;
    line-height: 1.4;
}

#voice-server-status.status-ok {
    color: #79C495;
}

#voice-server-status.status-error {
    color: #D96C6C;
}

.anim-preview-box {
    min-height: 60px;
    padding: 14px 16px;
    background: #1A1A22;
    border: 1px solid rgba(139, 116, 168, 0.06);
    border-radius: 12px;
    font-size: 0.95rem;
    line-height: 1.6;
    color: #DCDCDC;
    overflow: hidden;
}

#anim-preview-btn {
    align-self: flex-start;
    min-height: 32px;
    padding: 6px 14px;
    font-size: 0.82rem;
    border-color: rgba(139, 116, 168, 0.3);
}

#anim-preview-btn:hover {
    background: rgba(139, 116, 168, 0.1);
    border-color: rgba(139, 116, 168, 0.5);
}

.button-group {
    display: flex;
    justify-content: flex-end;
    padding-top: 4px;
    border-top: 1px solid rgba(200, 200, 200, 0.04);
}

#cancel-btn {
    background-color: rgba(200, 200, 200, 0.08);
    color: #C0C0C0;
    margin-right: 4px;
}

#cancel-btn:hover {
    background-color: rgba(200, 200, 200, 0.14);
    color: #D0D0D0;
}

#chat-view.intro-mode {
    display: flex !important;
    background-color: #000;
    z-index: 2000;
}

#chat-view.intro-mode #toolbar,
#chat-view.intro-mode .chat,
#chat-view.intro-mode #status-container {
    display: none !important;
}

#chat-view.intro-mode #canvas-view {
    flex: 1 !important;
    display: flex !important;
    height: 100vh !important;
}

#chat-view.intro-mode #render-canvas {
    width: 100vw !important;
    height: 100vh !important;
}

#initial-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    text-align: center;
}

#app-logo {
    width: 420px;
    max-width: 80%;
    height: auto;
    margin-bottom: 20px;
}

#settings-icon {
    display: none;
    cursor: pointer;
    width: 16px;
    height: 16px;
}

.history-system-message {
    width: 100%;
    padding: 6px 20px;
    color: #555;
    font-size: 0.78rem;
    text-align: center;
    font-style: italic;
    letter-spacing: 0.02em;
}

#stop-request-container {
    display: none;
    align-items: center;
    gap: 5px;
    position: fixed;
    bottom: 68px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.75rem;
}

#stop-request-btn {
    font-size: 0.75rem;
    background-color: rgba(28, 28, 30, 0.85);
}

#mic-feedback {
    display: none;
    position: fixed;
    left: 50%;
    bottom: 68px;
    transform: translateX(-50%);
    min-width: 120px;
    padding: 6px 12px;
    border-radius: 999px;
    background-color: rgba(20, 20, 20, 0.92);
    border: 1px solid rgba(200, 200, 200, 0.12);
    color: #C0C0C0;
    font-size: 0.78rem;
    text-align: center;
    z-index: 1002;
    backdrop-filter: blur(12px);
}

#mic-feedback.visible {
    display: block;
}

#mic-feedback.recording {
    border-color: rgba(196, 128, 128, 0.5);
    color: #D4AAAA;
}

#status-container {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 3px 14px;
    font-size: 0.65rem;
    color: #555;
    border-top: 1px solid rgba(200, 200, 200, 0.04);
    flex-shrink: 0;
}

.status-left, .status-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

.history-chat-response h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 14px 0 6px 0;
    color: #E0E0E0;
}

.history-chat-response p {
    margin: 4px 0;
    line-height: 1.6;
}

.history-chat-response ul {
    margin: 6px 0 6px 18px;
    padding: 0;
}

.history-chat-response li {
    margin: 3px 0;
    line-height: 1.6;
}

.history-chat-response strong {
    color: #E8E8E8;
    font-weight: 600;
}

.history-chat-response code {
    background: rgba(255, 255, 255, 0.06);
    padding: 2px 6px;
    border-radius: 5px;
    font-size: 0.88em;
}

.history-chat-response.reflect-summary {
    border-left: 2px solid #7BA4B8;
    color: #D6E3E8;
}

#live-transcript {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    max-width: 80%;
    text-align: center;
    font-size: 0.85rem;
    color: #888;
    font-style: italic;
    pointer-events: none;
    opacity: 0;
}

#live-transcript.visible {
    animation: fadeIn 0.4s ease forwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateX(-50%) translateY(4px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

#pipeline-state {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-left: 4px;
    transition: background-color 0.5s ease, box-shadow 0.5s ease;
}

.pipeline-idle {
    background-color: #4a4a4a;
}

.pipeline-listening {
    background-color: #7AB88A;
    box-shadow: 0 0 4px rgba(122, 184, 138, 0.5);
    animation: pulse-listen 2s ease-in-out infinite;
}

.pipeline-thinking {
    background-color: #C8A855;
    box-shadow: 0 0 4px rgba(200, 168, 85, 0.5);
    animation: pulse-think 1s ease-in-out infinite;
}

.pipeline-responding {
    background-color: #8B74A8;
    box-shadow: 0 0 4px rgba(139, 116, 168, 0.5);
    animation: pulse-respond 0.8s ease-in-out infinite;
}

@keyframes pulse-listen {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

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

@keyframes pulse-respond {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

/* Loading Animation Styles */
.dots-loading {
    display: flex;
    align-items: center;
    padding: 4px 0;
}

.dots-loading>div {
    width: 5px;
    height: 5px;
    background-color: rgba(139, 116, 168, 0.5);
    border-radius: 50%;
    margin: 0 3px;
    animation: bounce 0.6s infinite alternate;
}

.dots-loading>div:nth-child(2) {
    animation-delay: 0.2s;
}

.dots-loading>div:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes bounce {
    to {
        transform: translateY(-6px);
    }
}

@keyframes pulse {
    to {
        box-shadow: 0 0 0 4px rgba(196, 128, 128, 0.1);
    }
}

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

#spinner {
    border: 2px solid rgba(200, 200, 200, 0.3);
    border-radius: 50%;
    border-top: 2px solid #8B74A8;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Text streaming animations */
.anim-fade {
    display: inline;
    opacity: 0;
    animation: animFadeIn 400ms ease forwards;
}

.anim-ink-fill {
    display: inline-block;
    color: transparent;
    background-image: linear-gradient(90deg, #DCDCDC, #DCDCDC);
    background-repeat: no-repeat;
    background-size: 0% 100%;
    background-position: left center;
    -webkit-background-clip: text;
    background-clip: text;
    animation: animInkIn 550ms ease forwards;
}

.anim-sweep {
    display: inline-block;
    animation: animSweepIn 350ms ease forwards;
}

.anim-slide-up {
    display: inline-block;
    opacity: 0;
    transform: translateY(8px);
    animation: animSlideUp 400ms ease forwards;
}

.anim-unblur {
    display: inline;
    opacity: 0;
    filter: blur(6px);
    animation: animUnblur 450ms ease forwards;
}

.anim-breath {
    display: inline-block;
    animation: animBreathIn 700ms ease;
}

.anim-scramble {
    color: #C8A855;
}

.anim-ghost-pending {
    color: rgba(220, 220, 220, 0.18);
}

@keyframes animFadeIn {
    to { opacity: 1; }
}

@keyframes animInkIn {
    0% { opacity: 0.45; background-size: 0% 100%; }
    100% { opacity: 1; background-size: 100% 100%; }
}

@keyframes animSweepIn {
    0% { color: #fff; background: rgba(139, 116, 168, 0.18); transform: translateY(2px); }
    100% { color: #DCDCDC; background: transparent; transform: translateY(0); }
}

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

@keyframes animUnblur {
    to { opacity: 1; filter: blur(0); }
}

@keyframes animBreathIn {
    0% { opacity: 0.35; transform: scale(0.995); }
    55% { opacity: 1; transform: scale(1.004); }
    100% { opacity: 1; transform: scale(1); }
}
