/* ── Virtual Buddha — Stylesheet ── */

:root {
    --bg:          #0d0a07;
    --bg-panel:    #13100c;
    --bg-bubble-u: #1e1a14;
    --bg-bubble-b: #17140f;
    --gold:        #c8943a;
    --gold-light:  #e0b96a;
    --gold-dim:    #7a5a20;
    --cream:       #f0e6cc;
    --cream-dim:   #9a8d75;
    --border:      #2e2516;
    --radius:      14px;
    --font-body:   'EB Garamond', Georgia, serif;
    --font-ui:     'Raleway', sans-serif;
}

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

html {
    height: 100%;
    height: -webkit-fill-available;
}

body {
    min-height: 100%;
    min-height: -webkit-fill-available;
    background: var(--bg);
    color: var(--cream);
    font-family: var(--font-body);
    font-size: 18px;
    line-height: 1.7;
    /* Prevent overscroll bounce revealing white background on iOS */
    overscroll-behavior: none;
}

/* ── Starfield background ── */
.stars {
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse at 20% 30%, rgba(200,148,58,0.04) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 70%, rgba(200,148,58,0.03) 0%, transparent 60%);
    pointer-events: none;
    z-index: 0;
}

/* ── Layout ── */
.app-container {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    /* dvh = dynamic viewport height — accounts for mobile browser chrome */
    height: 100vh;
    height: 100dvh;
    max-width: 780px;
    margin: 0 auto;
}

/* ── Header ── */
.header {
    text-align: center;
    padding: 20px 20px 14px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(13,10,7,0.98) 0%, rgba(13,10,7,0.80) 100%);
    flex-shrink: 0;
    /* Safe area for notches/islands at the top */
    padding-top: max(20px, env(safe-area-inset-top));
}

.dharma-wheel {
    font-size: 36px;
    color: var(--gold);
    display: block;
    margin-bottom: 6px;
    animation: slow-spin 60s linear infinite;
    filter: drop-shadow(0 0 8px rgba(200,148,58,0.5));
    /* Prevent layout shift during animation on mobile */
    will-change: transform;
}

@keyframes slow-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

.header h1 {
    font-family: var(--font-body);
    font-size: 1.7rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    color: var(--gold-light);
    text-shadow: 0 0 20px rgba(200,148,58,0.35);
}

.subtitle {
    font-family: var(--font-ui);
    font-size: 0.75rem;
    font-weight: 300;
    letter-spacing: 0.15em;
    color: var(--cream-dim);
    margin-top: 4px;
    text-transform: uppercase;
}

/* ── Chat window ── */
.chat-window {
    flex: 1;
    overflow-y: auto;
    /* Momentum scrolling on iOS */
    -webkit-overflow-scrolling: touch;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.chat-window::-webkit-scrollbar { width: 4px; }
.chat-window::-webkit-scrollbar-track { background: transparent; }
.chat-window::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Messages ── */
.message {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    max-width: 100%;
    animation: fade-in 0.3s ease;
}

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

.buddha-message { flex-direction: row; }
.user-message   { flex-direction: row-reverse; }

.avatar {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--bg-panel);
    border: 1px solid var(--gold-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    color: var(--gold);
    filter: drop-shadow(0 0 4px rgba(200,148,58,0.3));
}

.bubble {
    max-width: calc(100% - 48px);
    padding: 13px 16px;
    border-radius: var(--radius);
    font-size: 1rem;
    line-height: 1.75;
    /* Prevent very long words from overflowing on mobile */
    overflow-wrap: break-word;
    word-break: break-word;
}

.buddha-message .bubble {
    background: var(--bg-bubble-b);
    border: 1px solid var(--border);
    border-left: 3px solid var(--gold-dim);
    color: var(--cream);
}

.user-message .bubble {
    background: var(--bg-bubble-u);
    border: 1px solid var(--border);
    color: var(--cream-dim);
    font-style: italic;
}

.bubble p { margin-bottom: 0.6em; }
.bubble p:last-child { margin-bottom: 0; }

/* ── Thinking indicator ── */
.thinking-bubble {
    font-family: var(--font-ui);
    font-style: italic;
    font-size: 0.9rem;
    color: var(--cream-dim);
    letter-spacing: 0.03em;
    min-width: 160px;
}

.thinking-phrase {
    transition: opacity 0.4s ease;
}

/* Streaming cursor */
.cursor {
    display: inline-block;
    color: var(--gold);
    animation: blink 0.8s step-end infinite;
    font-size: 0.7em;
    vertical-align: middle;
}

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

/* ── Input area ── */
.input-area {
    flex-shrink: 0;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: rgba(13,10,7,0.97);
    /* Safe area inset for iPhone home indicator */
    padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.input-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

textarea {
    flex: 1;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--cream);
    font-family: var(--font-body);
    /* 16px minimum to prevent iOS auto-zoom on focus */
    font-size: max(16px, 1rem);
    line-height: 1.5;
    padding: 11px 14px;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
    min-height: 46px;
    max-height: 120px;
    /* Prevent iOS adding inner shadow */
    -webkit-appearance: none;
    appearance: none;
}

textarea:focus {
    border-color: var(--gold-dim);
    box-shadow: 0 0 0 2px rgba(200,148,58,0.1);
}

textarea::placeholder {
    color: var(--cream-dim);
    font-style: italic;
}

textarea:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Shared styles for both icon buttons */
button#sendBtn,
button#micBtn {
    flex-shrink: 0;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 1px solid var(--gold-dim);
    background: transparent;
    color: var(--gold);
    cursor: pointer;
    transition: background 0.2s, box-shadow 0.2s, border-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

button#sendBtn svg,
button#micBtn svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
}

button#sendBtn:hover:not(:disabled),
button#sendBtn:active:not(:disabled),
button#micBtn:hover:not(:disabled),
button#micBtn:active:not(:disabled) {
    background: rgba(200,148,58,0.15);
    box-shadow: 0 0 12px rgba(200,148,58,0.2);
}

button#sendBtn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* Mic listening state — pulsing red ring */
button#micBtn.listening {
    border-color: #c0392b;
    color: #e74c3c;
    animation: mic-pulse 1.2s ease-in-out infinite;
}

@keyframes mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.4); }
    50%       { box-shadow: 0 0 0 6px rgba(231, 76, 60, 0); }
}

.disclaimer {
    font-family: var(--font-ui);
    font-size: 0.65rem;
    color: var(--cream-dim);
    text-align: center;
    margin-top: 8px;
    opacity: 0.6;
    letter-spacing: 0.02em;
    line-height: 1.4;
}

/* ── Mobile — small screens ── */
@media (max-width: 480px) {
    body { font-size: 16px; }

    .header {
        padding-top: max(14px, env(safe-area-inset-top));
        padding-bottom: 10px;
    }

    .dharma-wheel { font-size: 26px; margin-bottom: 4px; }
    .header h1    { font-size: 1.25rem; }
    .subtitle     { display: none; }  /* reclaim vertical space */

    .chat-window  { padding: 14px 10px; gap: 14px; }

    /* On very small screens, hide avatar and let bubble fill width */
    .avatar { display: none; }
    .bubble { max-width: 100%; padding: 11px 13px; font-size: 0.95rem; }

    .input-area { padding: 10px 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }

    textarea { padding: 10px 12px; }

    button#sendBtn,
    button#micBtn { width: 42px; height: 42px; }
    button#sendBtn svg,
    button#micBtn svg { width: 16px; height: 16px; }

    .disclaimer { font-size: 0.6rem; margin-top: 6px; }
}

/* ── Landscape on a narrow phone ── */
@media (max-height: 500px) and (max-width: 900px) {
    .header {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 10px;
        padding: 8px 16px;
        text-align: left;
    }
    .dharma-wheel { font-size: 22px; margin-bottom: 0; display: inline-block; }
    .header h1    { font-size: 1.1rem; }
    .subtitle     { display: none; }
}
