/* =========================================================
 * 天翔える（あまがえる）チャットウィジェット
 * トップページ右下の固定キャラクター + 吹き出し + チャットパネル
 * カラーは学苑祭テーマ（ベージュ／金）に合わせる
 * ========================================================= */

:root {
    --amg-primary: #b88a3e;
    --amg-primary-dark: #8a6429;
    --amg-bg: #fffaf0;
    --amg-bg-soft: #faf2dd;
    --amg-text: #3a2a12;
    --amg-text-soft: #7a5a2a;
    --amg-border: #e7d6a8;
    --amg-shadow: 0 10px 30px rgba(70, 45, 10, 0.18);
    --amg-z: 10000;
}

/* ===== 起動ボタン（右下のキャラクター） ===== */
.amg-launcher {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: var(--amg-z);
    display: flex;
    align-items: flex-end;
    gap: 8px;
    pointer-events: none; /* 子要素のみ反応させる */
}

.amg-launcher__bubble {
    pointer-events: auto;
    background: #fff;
    color: var(--amg-text);
    border: 1.5px solid var(--amg-border);
    border-radius: 16px 16px 4px 16px;
    padding: 8px 12px;
    font-size: 13px;
    line-height: 1.4;
    font-family: 'Noto Sans JP', system-ui, sans-serif;
    box-shadow: 0 4px 14px rgba(70, 45, 10, 0.15);
    max-width: 200px;
    margin-bottom: 12px;
    position: relative;
    animation: amgBubbleIn 0.5s ease-out;
    cursor: pointer;
}

.amg-launcher__bubble::after {
    content: '';
    position: absolute;
    right: 14px;
    bottom: -7px;
    width: 0;
    height: 0;
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    border-top: 7px solid #fff;
    filter: drop-shadow(0 1px 0 var(--amg-border));
}

.amg-launcher__bubble-close {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    border: 1.5px solid var(--amg-border);
    color: var(--amg-text-soft);
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.amg-launcher__bubble-close:hover {
    background: var(--amg-bg-soft);
}

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

.amg-launcher__btn {
    pointer-events: auto;
    width: 86px;
    height: 86px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ffe9a8 0%, #f6cf6c 60%, #d39a3e 100%);
    border: 3px solid #fff;
    box-shadow: var(--amg-shadow);
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    animation: amgFloat 3.6s ease-in-out infinite;
}
.amg-launcher__btn:hover {
    transform: translateY(-3px) scale(1.04);
    box-shadow: 0 14px 36px rgba(70, 45, 10, 0.25);
}
.amg-launcher__btn:focus-visible {
    outline: 3px solid #2563eb;
    outline-offset: 3px;
}
.amg-launcher__btn img {
    width: 92%;
    height: 92%;
    object-fit: contain;
    display: block;
    user-select: none;
    -webkit-user-drag: none;
}

@keyframes amgFloat {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-6px); }
}

/* 開いている状態では起動ボタンを隠す */
.amg-launcher.is-open .amg-launcher__btn,
.amg-launcher.is-open .amg-launcher__bubble {
    display: none;
}

/* ===== チャットパネル ===== */
.amg-panel {
    position: fixed;
    right: 18px;
    bottom: 18px;
    width: 360px;
    max-width: calc(100vw - 24px);
    height: calc(100dvh - 96px);
    max-height: calc(100dvh - 96px);
    background: var(--amg-bg);
    border-radius: 18px;
    box-shadow: var(--amg-shadow);
    border: 1px solid var(--amg-border);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: calc(var(--amg-z) + 1);
    font-family: 'Noto Sans JP', system-ui, sans-serif;
    color: var(--amg-text);
    animation: amgPanelIn 0.28s cubic-bezier(.2,.8,.2,1);
}
.amg-panel.is-open {
    display: flex;
}

@keyframes amgPanelIn {
    from { opacity: 0; transform: translateY(16px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ヘッダー */
.amg-panel__header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: linear-gradient(135deg, #ffe9a8 0%, #f6cf6c 100%);
    border-bottom: 1px solid var(--amg-border);
    flex-shrink: 0;
}
.amg-panel__avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(70, 45, 10, 0.15);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.amg-panel__avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}
.amg-panel__title-wrap {
    flex: 1;
    min-width: 0;
}
.amg-panel__title {
    font-family: 'Zen Old Mincho', serif;
    font-weight: 700;
    font-size: 15px;
    color: var(--amg-text);
    margin: 0;
    line-height: 1.2;
}
.amg-panel__subtitle {
    font-size: 11px;
    color: var(--amg-text-soft);
    margin: 2px 0 0;
    display: flex;
    align-items: center;
    gap: 5px;
}
.amg-panel__status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.25);
    display: inline-block;
}
.amg-panel__close {
    background: rgba(255, 255, 255, 0.55);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--amg-primary-dark);
    transition: background 0.15s ease;
    padding: 0;
    flex-shrink: 0;
}
.amg-panel__close:hover { background: #fff; }
.amg-panel__close:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

/* メッセージリスト */
.amg-panel__messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 14px 12px;
    background:
        radial-gradient(circle at 10% 10%, rgba(255, 233, 168, 0.6) 0%, transparent 35%),
        radial-gradient(circle at 90% 80%, rgba(255, 233, 168, 0.5) 0%, transparent 40%),
        var(--amg-bg);
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.amg-panel__messages::-webkit-scrollbar { width: 6px; }
.amg-panel__messages::-webkit-scrollbar-thumb {
    background: var(--amg-border);
    border-radius: 3px;
}

.amg-msg {
    display: flex;
    gap: 8px;
    max-width: 100%;
    animation: amgMsgIn 0.25s ease-out;
}
@keyframes amgMsgIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.amg-msg--bot {
    justify-content: flex-start;
}
.amg-msg--user {
    justify-content: flex-end;
}

.amg-msg__avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #fff;
    border: 1.5px solid var(--amg-border);
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.amg-msg__avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}
.amg-msg--user .amg-msg__avatar { display: none; }

.amg-msg__bubble {
    max-width: calc(100% - 44px);
    padding: 9px 13px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
    white-space: pre-wrap;
}
.amg-msg--bot .amg-msg__bubble {
    background: #fff;
    color: var(--amg-text);
    border: 1px solid var(--amg-border);
    border-top-left-radius: 4px;
    box-shadow: 0 2px 6px rgba(70, 45, 10, 0.06);
}
.amg-msg--user .amg-msg__bubble {
    background: linear-gradient(135deg, var(--amg-primary) 0%, var(--amg-primary-dark) 100%);
    color: #fff;
    border-top-right-radius: 4px;
    box-shadow: 0 2px 6px rgba(70, 45, 10, 0.18);
}

/* リンク化したURL */
.amg-msg__bubble a {
    color: inherit;
    text-decoration: underline;
    word-break: break-all;
}
.amg-msg--bot .amg-msg__bubble a { color: var(--amg-primary-dark); }

/* タイピングインジケーター */
.amg-typing {
    display: inline-flex;
    gap: 4px;
    padding: 4px 0;
}
.amg-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--amg-text-soft);
    opacity: 0.5;
    animation: amgTyping 1.2s infinite ease-in-out;
}
.amg-typing span:nth-child(2) { animation-delay: 0.15s; }
.amg-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes amgTyping {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40%           { transform: translateY(-4px); opacity: 1; }
}

/* クイック候補ボタン */
.amg-panel__quick {
    padding: 0 12px 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex-shrink: 0;
    background: var(--amg-bg);
    border-top: 1px solid var(--amg-border);
    padding-top: 8px;
}
.amg-quick-btn {
    background: #fff;
    border: 1px solid var(--amg-border);
    color: var(--amg-primary-dark);
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
    white-space: nowrap;
}
.amg-quick-btn:hover {
    background: var(--amg-bg-soft);
    border-color: var(--amg-primary);
}
.amg-quick-btn:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

/* 入力フォーム */
.amg-panel__form {
    display: flex;
    gap: 8px;
    padding: 10px 12px 12px;
    background: var(--amg-bg);
    border-top: 1px solid var(--amg-border);
    flex-shrink: 0;
    align-items: flex-end;
}
.amg-panel__input {
    flex: 1;
    border: 1.5px solid var(--amg-border);
    background: #fff;
    border-radius: 12px;
    padding: 9px 12px;
    font-size: 14px;
    font-family: inherit;
    color: var(--amg-text);
    resize: none;
    min-height: 40px;
    max-height: 110px;
    line-height: 1.4;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.amg-panel__input:focus {
    border-color: var(--amg-primary);
    box-shadow: 0 0 0 3px rgba(184, 138, 62, 0.18);
}
.amg-panel__input::placeholder {
    color: #b89a6c;
}
.amg-panel__send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--amg-primary) 0%, var(--amg-primary-dark) 100%);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s ease, opacity 0.15s ease;
}
.amg-panel__send:hover:not(:disabled) { transform: scale(1.08); }
.amg-panel__send:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}
.amg-panel__send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.amg-panel__send svg {
    width: 18px;
    height: 18px;
    transform: translateX(1px);
}

/* フッターラベル */
.amg-panel__footer-note {
    font-size: 10px;
    color: var(--amg-text-soft);
    text-align: center;
    padding: 0 12px 8px;
    background: var(--amg-bg);
    flex-shrink: 0;
}

/* ===== レスポンシブ ===== */
@media (max-width: 480px) {
    .amg-launcher {
        right: 12px;
        bottom: 12px;
    }
    .amg-launcher__btn {
        width: 72px;
        height: 72px;
    }
    .amg-launcher__bubble {
        font-size: 12px;
        max-width: 170px;
        padding: 7px 10px;
    }
    .amg-panel {
        right: 8px;
        left: 8px;
        bottom: 8px;
        width: auto;
        max-width: none;
        height: calc(100dvh - 16px);
        max-height: calc(100dvh - 16px);
        border-radius: 16px;
    }
}

@media (max-width: 360px) {
    .amg-launcher__btn { width: 64px; height: 64px; }
}

/* 動きを抑える設定の人向け */
@media (prefers-reduced-motion: reduce) {
    .amg-launcher__btn,
    .amg-launcher__bubble,
    .amg-panel,
    .amg-msg,
    .amg-typing span {
        animation: none !important;
    }
    .amg-launcher__btn:hover { transform: none; }
}

/* ハイコントラスト */
@media (prefers-contrast: more) {
    .amg-panel,
    .amg-launcher__bubble,
    .amg-msg--bot .amg-msg__bubble {
        border-color: #5a3d10;
    }
}
