/* ===================================================
   ずんだもんと会話 — Zundamon Chat
   =================================================== */

:root {
    --zc-bg: #0a0e14;
    --zc-surface: #141b24;
    --zc-surface-hover: #1c2633;
    --zc-accent: #5ce08e;
    --zc-accent-dim: rgba(92, 224, 142, 0.15);
    --zc-accent-glow: rgba(92, 224, 142, 0.3);
    --zc-user-bubble: #1e3a5f;
    --zc-zunda-bubble: #1a2e1a;
    --zc-text: #e4e8ec;
    --zc-text-dim: #7a8a9e;
    --zc-danger: #ff6b6b;
    --zc-radius: 16px;
}

/* ── Layout ── */
.zc-page {
    min-height: calc(100vh - 56px);
    background: var(--zc-bg);
    display: flex;
    flex-direction: column;
    font-family: 'M PLUS Rounded 1c', 'Noto Sans JP', sans-serif;
    color: var(--zc-text);
}

.zc-header {
    padding: 20px 24px 12px;
    text-align: center;
    position: relative;
    z-index: 2;
}

.zc-btn-clear {
    position: absolute;
    top: 14px;
    right: 14px;
    background: transparent;
    border: 1px solid var(--zc-accent-dim);
    color: var(--zc-text-dim);
    padding: 5px 10px;
    border-radius: 14px;
    font-size: 0.72rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    font-family: inherit;
    transition: all 0.2s;
}

.zc-btn-clear:hover {
    color: var(--zc-danger);
    border-color: var(--zc-danger);
    background: rgba(255, 107, 107, 0.08);
}

.zc-btn-clear svg {
    flex-shrink: 0;
}

.zc-header h1 {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--zc-accent);
    margin: 0;
}

.zc-header .zc-subtitle {
    font-size: 0.75rem;
    color: var(--zc-text-dim);
    margin-top: 2px;
}

/* ── Status indicators ── */
.zc-status-bar {
    display: flex;
    justify-content: center;
    gap: 16px;
    padding: 8px 0 12px;
    font-size: 0.72rem;
    color: var(--zc-text-dim);
}

.zc-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 5px;
    vertical-align: middle;
}

.zc-status-dot.ok { background: var(--zc-accent); box-shadow: 0 0 6px var(--zc-accent-glow); }
.zc-status-dot.ng { background: var(--zc-danger); }
.zc-status-dot.loading { background: #f0ad4e; animation: zc-pulse 1.2s infinite; }

@keyframes zc-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ── Chat area ── */
.zc-chat-area {
    flex: 0 1 auto;
    max-height: 500px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 0 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-top: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--zc-surface-hover) transparent;
}

.zc-chat-area > * {
    flex-shrink: 0;
}

/* コンテンツが少ないときは最下部に寄せるためのスペーサー */
.zc-chat-area::before {
    content: '';
    margin-top: auto;
}

/* ── Message bubbles ── */
.zc-msg {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    max-width: 85%;
    animation: zc-fade-in 0.35s ease-out;
}

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

.zc-msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.zc-msg.zundamon {
    align-self: flex-start;
}

.zc-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    background: var(--zc-surface);
    border: 2px solid var(--zc-accent-dim);
}

.zc-msg.user .zc-avatar {
    border-color: rgba(94, 158, 214, 0.3);
}

.zc-bubble {
    padding: 12px 16px;
    border-radius: var(--zc-radius);
    line-height: 1.6;
    font-size: 0.9rem;
    word-break: break-word;
    position: relative;
}

.zc-msg.user .zc-bubble {
    background: var(--zc-user-bubble);
    border-bottom-right-radius: 4px;
}

.zc-msg.zundamon .zc-bubble {
    background: var(--zc-zunda-bubble);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--zc-accent-dim);
}

.zc-bubble-audio {
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.7rem;
    color: var(--zc-text-dim);
    cursor: pointer;
    transition: color 0.2s;
}

.zc-bubble-audio:hover {
    color: var(--zc-accent);
}

.zc-bubble-audio svg {
    width: 14px;
    height: 14px;
}

/* ── Typing indicator ── */
.zc-typing {
    display: flex;
    gap: 5px;
    padding: 10px 16px;
}

.zc-typing span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--zc-accent);
    opacity: 0.4;
    animation: zc-typing-bounce 1.4s infinite ease-in-out;
}

.zc-typing span:nth-child(2) { animation-delay: 0.15s; }
.zc-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes zc-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ── Input area ── */
.zc-input-area {
    padding: 12px 16px 20px;
    background: var(--zc-surface);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.zc-input-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.zc-text-input {
    flex: 1;
    background: var(--zc-bg);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 24px;
    padding: 10px 18px;
    color: var(--zc-text);
    font-size: 0.88rem;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}

.zc-text-input:focus {
    border-color: var(--zc-accent-dim);
}

.zc-text-input::placeholder {
    color: var(--zc-text-dim);
}

/* ── Buttons ── */
.zc-btn {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

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

.zc-btn-send {
    background: var(--zc-accent);
    color: var(--zc-bg);
}

.zc-btn-send:hover {
    background: #4cd47e;
    transform: scale(1.05);
}

.zc-btn-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.zc-btn-mic {
    background: transparent;
    border: 2px solid var(--zc-accent);
    color: var(--zc-accent);
    position: relative;
}

.zc-btn-mic:hover {
    background: var(--zc-accent-dim);
}

.zc-btn-mic.recording {
    background: var(--zc-danger);
    border-color: var(--zc-danger);
    color: #fff;
    animation: zc-mic-pulse 1.5s infinite;
}

@keyframes zc-mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.4); }
    50% { box-shadow: 0 0 0 10px rgba(255, 107, 107, 0); }
}

/* ── Waveform visualizer ── */
.zc-waveform {
    height: 32px;
    display: none;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 0 8px;
}

.zc-waveform.active {
    display: flex;
}

.zc-waveform-bar {
    width: 3px;
    height: 4px;
    background: var(--zc-accent);
    border-radius: 2px;
    transition: height 0.08s ease;
}

/* ── 音声認識準備中 ── */
.zc-model-loader {
    text-align: center;
    padding: 12px;
    font-size: 0.8rem;
    color: var(--zc-text-dim);
}

/* ── Welcome message ── */
.zc-welcome {
    text-align: center;
    padding: 40px 20px;
    color: var(--zc-text-dim);
}

.zc-welcome-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    filter: drop-shadow(0 0 12px var(--zc-accent-glow));
}

.zc-welcome-icon-img {
    width: min(95vw, 800px);
    height: min(95vw, 800px);
    object-fit: cover;
    border-radius: 50%;
    border: 3px solid var(--zc-accent-dim);
}

.zc-welcome h2 {
    font-size: 1rem;
    color: var(--zc-text);
    margin-bottom: 6px;
}

.zc-welcome p {
    font-size: 0.8rem;
    line-height: 1.7;
}

/* ── 認識中テキスト ── */
.zc-interim-bubble {
    opacity: 0.5;
    font-style: italic;
    border: 1px dashed rgba(255, 255, 255, 0.15) !important;
    background: transparent !important;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .zc-msg {
        max-width: 92%;
    }

    .zc-avatar {
        width: 34px;
        height: 34px;
        font-size: 1.1rem;
    }

    /* スマホ: ビューポートにぴったり収める（アプリ共通ヘッダー56px分を差し引く） */
    .zc-page {
        height: calc(100dvh - 56px);
        min-height: calc(100dvh - 56px);
        max-height: calc(100dvh - 56px);
        overflow: hidden;
    }

    .zc-header { padding: 10px 16px 6px; }
    .zc-status-bar { padding: 4px 0 6px; }
    .zc-model-loader { padding: 6px; }

    /* アバター画像: 残りスペースをすべて使う */
    .zc-page > .text-center {
        flex: 1 1 0;
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 0;
        overflow: hidden;
    }

    .zc-welcome-icon-img {
        width: auto;
        height: 100%;
        max-width: 100%;
        max-height: 100%;
        object-fit: contain;
        border: none;
    }

    /* チャットエリアはコンパクトに */
    .zc-chat-area {
        max-height: 35dvh;
        margin-top: 0;
    }
}
