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

:root {
    --bg-dark: #0d0a1a;
    --bg-card: #1a1230;
    --bg-input: #241a3d;
    --accent-gold: #c9a84c;
    --accent-gold-dim: #8a6f30;
    --text-primary: #e8e0d0;
    --text-secondary: #9a8fb0;
    --text-muted: #5a5070;
    --user-bubble: #2a1f45;
    --assistant-bubble: #161030;
    --border-subtle: #2a2040;
    --shadow: rgba(0, 0, 0, 0.4);
}

html, body {
    height: 100%;
    background: var(--bg-dark);
    color: var(--text-primary);
    font-family: Georgia, "Times New Roman", serif;
    font-size: 16px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-width: 640px;
    margin: 0 auto;
}

/* Intro Screen */
.intro {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 24px;
    text-align: center;
}

.intro-content {
    max-width: 420px;
}

.intro-symbol {
    font-size: 3rem;
    color: var(--accent-gold);
    margin-bottom: 8px;
    animation: pulse 3s ease-in-out infinite;
}

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

.intro-title {
    font-size: 1.8rem;
    font-weight: normal;
    color: var(--accent-gold);
    letter-spacing: 0.08em;
    margin-bottom: 4px;
}

.intro-subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-style: italic;
    margin-bottom: 28px;
}

.intro-text {
    text-align: left;
    margin-bottom: 28px;
}

.intro-text p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.7;
    margin-bottom: 12px;
}

.intro-highlight {
    color: var(--accent-gold) !important;
    text-align: center !important;
    font-style: italic;
    font-size: 0.95rem !important;
    margin-top: 16px;
}

.intro-button {
    display: inline-block;
    background: transparent;
    color: var(--accent-gold);
    border: 1px solid var(--accent-gold-dim);
    padding: 12px 40px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 1rem;
    letter-spacing: 0.1em;
    cursor: pointer;
    transition: background 0.3s, border-color 0.3s;
    margin-bottom: 16px;
}

.intro-button:hover {
    background: rgba(201, 168, 76, 0.1);
    border-color: var(--accent-gold);
}

.intro-note {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.changelog-link {
    display: inline-block;
    color: var(--text-muted);
    font-size: 0.7rem;
    text-decoration: none;
    margin-top: 24px;
    transition: color 0.2s;
}

.changelog-link:hover {
    color: var(--text-secondary);
}

/* Chat Screen */
.chat-screen {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-card);
    flex-shrink: 0;
}

.header h1 {
    font-size: 1.1rem;
    font-weight: normal;
    color: var(--accent-gold);
    letter-spacing: 0.05em;
}

.questions-indicator {
    display: flex;
    gap: 6px;
}

.orb {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: background 0.5s ease, box-shadow 0.5s ease;
}

.orb.active {
    background: var(--accent-gold);
    box-shadow: 0 0 6px var(--accent-gold-dim);
}

/* Chat area */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    scroll-behavior: smooth;
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.95rem;
    line-height: 1.5;
    animation: fadeIn 0.3s ease;
    white-space: pre-wrap;
}

.message.assistant {
    align-self: flex-start;
    background: var(--assistant-bubble);
    border-left: 2px solid var(--accent-gold-dim);
    color: var(--text-primary);
}

.message.user {
    align-self: flex-end;
    background: var(--user-bubble);
    color: var(--text-primary);
}

.message.system-msg {
    align-self: center;
    background: none;
    color: var(--text-secondary);
    font-style: italic;
    font-size: 0.85rem;
    text-align: center;
    max-width: 90%;
}

.message.oracle {
    align-self: center;
    background: rgba(201, 168, 76, 0.08);
    border: 1px solid rgba(201, 168, 76, 0.2);
    border-radius: 10px;
    color: var(--text-secondary);
    font-size: 0.82rem;
    line-height: 1.7;
    max-width: 90%;
    padding: 10px 16px;
    text-align: left;
}

.message.assistant.streaming {
    border-left-color: var(--accent-gold);
}

.message.assistant.streaming::after {
    content: "\25AE";
    color: var(--accent-gold);
    animation: blink 0.8s step-end infinite;
    margin-left: 1px;
}

@keyframes blink {
    50% { opacity: 0; }
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
    align-self: flex-start;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-gold-dim);
    animation: typingDot 1.2s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-3px); }
}

/* Djinn waiting animation */
.djinn-waiting {
    align-self: center;
    text-align: center;
    padding: 20px;
    animation: fadeIn 0.5s ease;
}

.djinn-lamp {
    font-size: 2.4rem;
    display: inline-block;
    animation: lampFloat 2.5s ease-in-out infinite;
    filter: drop-shadow(0 0 8px rgba(201, 168, 76, 0.4));
}

.djinn-smoke {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-bottom: 8px;
    height: 40px;
}

.djinn-smoke span {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-gold);
    opacity: 0;
    animation: smokeRise 2s ease-out infinite;
}

.djinn-smoke span:nth-child(1) { animation-delay: 0s; }
.djinn-smoke span:nth-child(2) { animation-delay: 0.4s; }
.djinn-smoke span:nth-child(3) { animation-delay: 0.8s; }
.djinn-smoke span:nth-child(4) { animation-delay: 0.3s; }
.djinn-smoke span:nth-child(5) { animation-delay: 0.7s; }

.djinn-text {
    color: var(--accent-gold-dim);
    font-size: 0.82rem;
    font-style: italic;
    margin-top: 6px;
    animation: textPulse 2s ease-in-out infinite;
}

.djinn-queue {
    color: var(--text-secondary);
    font-size: 0.75rem;
    margin-top: 8px;
    min-height: 1.2em;
}

@keyframes lampFloat {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    25% { transform: translateY(-4px) rotate(-2deg); }
    75% { transform: translateY(-2px) rotate(2deg); }
}

@keyframes smokeRise {
    0% {
        opacity: 0;
        transform: translateY(0) scale(0.5);
    }
    30% {
        opacity: 0.6;
        transform: translateY(-10px) scale(1);
    }
    60% {
        opacity: 0.3;
        transform: translateY(-25px) scale(1.4);
    }
    100% {
        opacity: 0;
        transform: translateY(-40px) scale(0.3);
    }
}

@keyframes textPulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

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

/* Input area */
.input-area {
    padding: 12px 16px;
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-card);
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-input);
    border-radius: 12px;
    padding: 8px 12px;
}

textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    line-height: 1.5;
    resize: none;
    outline: none;
    max-height: 120px;
    overflow-y: auto;
}

textarea::placeholder {
    color: var(--text-muted);
}

#sendButton {
    background: none;
    border: none;
    color: var(--accent-gold);
    cursor: pointer;
    padding: 4px;
    flex-shrink: 0;
    transition: opacity 0.2s;
}

#sendButton:disabled {
    color: var(--text-muted);
    cursor: not-allowed;
}

#sendButton:hover:not(:disabled) {
    opacity: 0.8;
}

/* Input disabled state */
.input-area.disabled textarea,
.input-area.disabled #sendButton {
    pointer-events: none;
    opacity: 0.4;
}

/* Error overlay */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.overlay-content {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 24px;
    max-width: 320px;
    text-align: center;
}

.overlay-content p {
    margin-bottom: 16px;
    color: var(--text-primary);
}

.overlay-content button {
    background: var(--accent-gold-dim);
    color: var(--text-primary);
    border: none;
    padding: 8px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
}

/* Scrollbar */
.chat-container::-webkit-scrollbar {
    width: 4px;
}

.chat-container::-webkit-scrollbar-track {
    background: transparent;
}

.chat-container::-webkit-scrollbar-thumb {
    background: var(--border-subtle);
    border-radius: 2px;
}

/* Safe area for notched phones */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .input-area {
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
}
