/**
 * Speech Bubble Block Styles
 *
 * 吹き出しブロックのスタイル（エディター・フロントエンド共通）
 *
 * @package Mitachi_Yuru
 * @since 1.1.0
 */

/* ============================================================
   CSS Variables - 吹き出しブロック専用変数
   ============================================================ */

:root {
    --speech-bubble-color-default: #E0C895;
    --speech-bubble-bg-default: #FFFFFF;
    --speech-bubble-text-default: #595048;
    --speech-bubble-radius-default: 16px;
}

.wp-block-mitachi-speech-bubble {
    --speech-bubble-color: var(--c-theme, var(--speech-bubble-color-default, #E0C895));
    --speech-bubble-bg: var(--c-bg-card, var(--speech-bubble-bg-default, #FFFFFF));
    --speech-bubble-text: var(--c-text-main, var(--speech-bubble-text-default, #595048));
    --speech-bubble-radius: var(--radius-m, var(--speech-bubble-radius-default, 16px));
}

/* ============================================================
   Base Styles - 基本レイアウト
   ============================================================ */

.wp-block-mitachi-speech-bubble {
    display: flex;
    gap: 16px;
    margin-bottom: 1.5rem;
    font-family: var(--f-base, 'Zen Maru Gothic', sans-serif);
}

/* アバター部分 */
.speech-bubble__avatar-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.speech-bubble__avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* アバター枠線あり */
.wp-block-mitachi-speech-bubble.has-avatar-border .speech-bubble__avatar {
    border: 3px solid var(--speech-bubble-color);
}

/* アバター枠線なし */
.wp-block-mitachi-speech-bubble:not(.has-avatar-border) .speech-bubble__avatar {
    border: none;
}

.speech-bubble__avatar--placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--speech-bubble-color);
    color: #fff;
}

.speech-bubble__avatar--placeholder svg {
    width: 32px;
    height: 32px;
}

.speech-bubble__name {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--speech-bubble-text);
    text-align: center;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 吹き出し本体 */
.speech-bubble__content {
    position: relative;
    flex: 1;
    min-width: 0;
}

.speech-bubble__text {
    padding: 16px 20px;
    color: var(--speech-bubble-text);
    line-height: 1.8;
    font-size: 1rem;
}

.speech-bubble__text p {
    margin-bottom: 0.8em;
}

.speech-bubble__text p:last-child {
    margin-bottom: 0;
}

/* ============================================================
   吹き出しの尻尾 - 回転した四角形で枠線と完全に繋げる
   ============================================================ */

.speech-bubble__tail {
    position: absolute;
    width: 16px;
    height: 16px;
    background-color: var(--speech-bubble-bg);
    transform: rotate(45deg);
    /* デフォルトでは枠線なし */
}

/* ============================================================
   Direction - 向き
   ============================================================ */

/* 左向き（アバターが左） */
.wp-block-mitachi-speech-bubble.is-direction-left {
    flex-direction: row;
}

.wp-block-mitachi-speech-bubble.is-direction-left .speech-bubble__tail {
    left: -8px;
    top: 22px;
}

/* 右向き（アバターが右） */
.wp-block-mitachi-speech-bubble.is-direction-right {
    flex-direction: row-reverse;
}

.wp-block-mitachi-speech-bubble.is-direction-right .speech-bubble__tail {
    right: -8px;
    top: 22px;
}

/* ============================================================
   Width - 幅設定
   ============================================================ */

.wp-block-mitachi-speech-bubble.has-full-width .speech-bubble__content {
    width: 100%;
}

.wp-block-mitachi-speech-bubble.has-auto-width .speech-bubble__content {
    width: fit-content;
    max-width: 100%;
}

/* ============================================================
   Style Variations - スタイルバリエーション
   ============================================================ */

/* --- 四角（枠線） --- */
.wp-block-mitachi-speech-bubble.is-style-square .speech-bubble__content {
    background-color: var(--speech-bubble-bg);
    border: 2px solid var(--speech-bubble-color);
    border-radius: 4px;
}

.wp-block-mitachi-speech-bubble.is-style-square .speech-bubble__tail {
    background-color: var(--speech-bubble-bg);
}

.wp-block-mitachi-speech-bubble.is-style-square.is-direction-left .speech-bubble__tail {
    border-bottom: 2px solid var(--speech-bubble-color);
    border-left: 2px solid var(--speech-bubble-color);
}

.wp-block-mitachi-speech-bubble.is-style-square.is-direction-right .speech-bubble__tail {
    border-top: 2px solid var(--speech-bubble-color);
    border-right: 2px solid var(--speech-bubble-color);
}

/* --- 四角塗りつぶし --- */
.wp-block-mitachi-speech-bubble.is-style-square-filled .speech-bubble__content {
    background-color: var(--speech-bubble-color);
    border-radius: 4px;
}

.wp-block-mitachi-speech-bubble.is-style-square-filled .speech-bubble__text {
    color: #fff;
}

.wp-block-mitachi-speech-bubble.is-style-square-filled .speech-bubble__tail {
    background-color: var(--speech-bubble-color);
}

/* --- 角丸（枠線） --- */
.wp-block-mitachi-speech-bubble.is-style-rounded .speech-bubble__content {
    background-color: var(--speech-bubble-bg);
    border: 2px solid var(--speech-bubble-color);
    border-radius: var(--speech-bubble-radius);
}

.wp-block-mitachi-speech-bubble.is-style-rounded .speech-bubble__tail {
    background-color: var(--speech-bubble-bg);
}

.wp-block-mitachi-speech-bubble.is-style-rounded.is-direction-left .speech-bubble__tail {
    border-bottom: 2px solid var(--speech-bubble-color);
    border-left: 2px solid var(--speech-bubble-color);
}

.wp-block-mitachi-speech-bubble.is-style-rounded.is-direction-right .speech-bubble__tail {
    border-top: 2px solid var(--speech-bubble-color);
    border-right: 2px solid var(--speech-bubble-color);
}

/* --- 角丸塗りつぶし --- */
.wp-block-mitachi-speech-bubble.is-style-rounded-filled .speech-bubble__content {
    background-color: var(--speech-bubble-color);
    border-radius: var(--speech-bubble-radius);
}

.wp-block-mitachi-speech-bubble.is-style-rounded-filled .speech-bubble__text {
    color: #fff;
}

.wp-block-mitachi-speech-bubble.is-style-rounded-filled .speech-bubble__tail {
    background-color: var(--speech-bubble-color);
}

/* --- 破線（枠線） --- */
.wp-block-mitachi-speech-bubble.is-style-dashed .speech-bubble__content {
    background-color: var(--speech-bubble-bg);
    border: 2px dashed var(--speech-bubble-color);
    border-radius: var(--speech-bubble-radius);
}

.wp-block-mitachi-speech-bubble.is-style-dashed .speech-bubble__tail {
    display: none;
}

/* --- 破線塗りつぶし --- */
.wp-block-mitachi-speech-bubble.is-style-dashed-filled .speech-bubble__content {
    background-color: color-mix(in srgb, var(--speech-bubble-color) 15%, transparent);
    border: 2px dashed var(--speech-bubble-color);
    border-radius: var(--speech-bubble-radius);
}

.wp-block-mitachi-speech-bubble.is-style-dashed-filled .speech-bubble__tail {
    display: none;
}

/* --- シャドウ --- */
.wp-block-mitachi-speech-bubble.is-style-shadow .speech-bubble__content {
    background-color: var(--speech-bubble-bg);
    border-radius: var(--speech-bubble-radius);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.wp-block-mitachi-speech-bubble.is-style-shadow .speech-bubble__tail {
    background-color: var(--speech-bubble-bg);
    box-shadow: -2px 2px 4px rgba(0, 0, 0, 0.05);
}

/* ============================================================
   Bubble Type - バブル（思考吹き出し）タイプ
   尻尾を小さな丸に変更
   ============================================================ */

.wp-block-mitachi-speech-bubble.is-type-bubble .speech-bubble__tail {
    width: auto;
    height: auto;
    background: transparent;
    transform: none;
    border: none;
    box-shadow: none;
}

.wp-block-mitachi-speech-bubble.is-type-bubble .speech-bubble__tail::before,
.wp-block-mitachi-speech-bubble.is-type-bubble .speech-bubble__tail::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    background-color: var(--speech-bubble-color);
}

.wp-block-mitachi-speech-bubble.is-type-bubble .speech-bubble__tail::before {
    width: 12px;
    height: 12px;
}

.wp-block-mitachi-speech-bubble.is-type-bubble .speech-bubble__tail::after {
    width: 8px;
    height: 8px;
}

/* バブル左向き */
.wp-block-mitachi-speech-bubble.is-type-bubble.is-direction-left .speech-bubble__tail {
    left: -20px;
    top: 24px;
}

.wp-block-mitachi-speech-bubble.is-type-bubble.is-direction-left .speech-bubble__tail::before {
    left: 8px;
    top: 0;
}

.wp-block-mitachi-speech-bubble.is-type-bubble.is-direction-left .speech-bubble__tail::after {
    left: 0;
    top: 10px;
}

/* バブル右向き */
.wp-block-mitachi-speech-bubble.is-type-bubble.is-direction-right .speech-bubble__tail {
    right: -20px;
    top: 24px;
}

.wp-block-mitachi-speech-bubble.is-type-bubble.is-direction-right .speech-bubble__tail::before {
    right: 8px;
    top: 0;
}

.wp-block-mitachi-speech-bubble.is-type-bubble.is-direction-right .speech-bubble__tail::after {
    right: 0;
    top: 10px;
}

/* バブル + 枠線スタイル */
.wp-block-mitachi-speech-bubble.is-type-bubble.is-style-square .speech-bubble__tail::before,
.wp-block-mitachi-speech-bubble.is-type-bubble.is-style-square .speech-bubble__tail::after,
.wp-block-mitachi-speech-bubble.is-type-bubble.is-style-rounded .speech-bubble__tail::before,
.wp-block-mitachi-speech-bubble.is-type-bubble.is-style-rounded .speech-bubble__tail::after,
.wp-block-mitachi-speech-bubble.is-type-bubble.is-style-dashed .speech-bubble__tail::before,
.wp-block-mitachi-speech-bubble.is-type-bubble.is-style-dashed .speech-bubble__tail::after {
    background-color: var(--speech-bubble-bg);
    border: 2px solid var(--speech-bubble-color);
}

/* バブル + シャドウスタイル */
.wp-block-mitachi-speech-bubble.is-type-bubble.is-style-shadow .speech-bubble__tail::before,
.wp-block-mitachi-speech-bubble.is-type-bubble.is-style-shadow .speech-bubble__tail::after {
    background-color: var(--speech-bubble-bg);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

/* ============================================================
   Responsive - レスポンシブ対応
   ============================================================ */

@media (max-width: 768px) {
    .wp-block-mitachi-speech-bubble {
        gap: 12px;
    }

    .speech-bubble__avatar {
        width: 48px;
        height: 48px;
    }

    .speech-bubble__avatar--placeholder svg {
        width: 24px;
        height: 24px;
    }

    .speech-bubble__name {
        font-size: 0.7rem;
        max-width: 60px;
    }

    .speech-bubble__text {
        padding: 12px 16px;
        font-size: 0.95rem;
    }
}

/* ============================================================
   Accessibility - アクセシビリティ
   ============================================================ */

@media (prefers-reduced-motion: reduce) {

    .wp-block-mitachi-speech-bubble,
    .wp-block-mitachi-speech-bubble * {
        transition: none !important;
        animation: none !important;
    }
}

@media (prefers-contrast: high) {
    .wp-block-mitachi-speech-bubble .speech-bubble__content {
        border: 2px solid currentColor !important;
    }

    .wp-block-mitachi-speech-bubble .speech-bubble__avatar {
        border: 2px solid currentColor !important;
    }
}

/* ============================================================
   Editor Specific Styles - エディター専用スタイル
   ============================================================ */

.editor-styles-wrapper .wp-block-mitachi-speech-bubble {
    --speech-bubble-color: #E0C895;
    --speech-bubble-bg: #FFFFFF;
    --speech-bubble-text: #595048;
    --speech-bubble-radius: 16px;
    margin-bottom: 1.5rem;
}

.editor-styles-wrapper .speech-bubble__avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    object-fit: cover;
}

.editor-styles-wrapper .wp-block-mitachi-speech-bubble.has-avatar-border .speech-bubble__avatar {
    border: 3px solid var(--speech-bubble-color, #E0C895);
}

.editor-styles-wrapper .speech-bubble__avatar--placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--speech-bubble-color, #E0C895);
    color: #fff;
}

.editor-styles-wrapper .speech-bubble__name {
    font-size: 0.75rem;
    font-weight: 600;
    color: #595048;
}

.editor-styles-wrapper .speech-bubble__text {
    padding: 16px 20px;
    color: #595048;
    line-height: 1.8;
}

/* エディター用スタイルバリエーション */
.editor-styles-wrapper .wp-block-mitachi-speech-bubble.is-style-square .speech-bubble__content {
    border: 2px solid var(--speech-bubble-color, #E0C895) !important;
    border-radius: 4px !important;
    background: var(--speech-bubble-bg, #FFFFFF) !important;
}

.editor-styles-wrapper .wp-block-mitachi-speech-bubble.is-style-square-filled .speech-bubble__content {
    background-color: var(--speech-bubble-color, #E0C895) !important;
    border-radius: 4px !important;
}

.editor-styles-wrapper .wp-block-mitachi-speech-bubble.is-style-square-filled .speech-bubble__text {
    color: #fff !important;
}

.editor-styles-wrapper .wp-block-mitachi-speech-bubble.is-style-rounded .speech-bubble__content {
    border: 2px solid var(--speech-bubble-color, #E0C895) !important;
    border-radius: 16px !important;
    background: var(--speech-bubble-bg, #FFFFFF) !important;
}

.editor-styles-wrapper .wp-block-mitachi-speech-bubble.is-style-rounded-filled .speech-bubble__content {
    background-color: var(--speech-bubble-color, #E0C895) !important;
    border-radius: 16px !important;
}

.editor-styles-wrapper .wp-block-mitachi-speech-bubble.is-style-rounded-filled .speech-bubble__text {
    color: #fff !important;
}

.editor-styles-wrapper .wp-block-mitachi-speech-bubble.is-style-dashed .speech-bubble__content {
    border: 2px dashed var(--speech-bubble-color, #E0C895) !important;
    border-radius: 16px !important;
    background: var(--speech-bubble-bg, #FFFFFF) !important;
}

.editor-styles-wrapper .wp-block-mitachi-speech-bubble.is-style-dashed-filled .speech-bubble__content {
    border: 2px dashed var(--speech-bubble-color, #E0C895) !important;
    border-radius: 16px !important;
    background-color: rgba(224, 200, 149, 0.15) !important;
}

.editor-styles-wrapper .wp-block-mitachi-speech-bubble.is-style-shadow .speech-bubble__content {
    background-color: #FFFFFF !important;
    border-radius: 16px !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1) !important;
}

/* ============================================================
   Print Styles - 印刷用スタイル
   ============================================================ */

@media print {
    .wp-block-mitachi-speech-bubble {
        page-break-inside: avoid;
    }

    .speech-bubble__content {
        border: 1px solid #333 !important;
        background: #fff !important;
    }

    .speech-bubble__tail {
        display: none !important;
    }
}