/**
 * Speech Bubble Block Styles
 *
 * 吹き出しブロックのスタイル（エディター・フロントエンド共通）
 *
 * @package Mitachi_Yuru
 * @since 1.1.0
 */

/* ============================================================
   CSS Variables - 吹き出しブロック専用変数
   ============================================================ */

.wp-block-mitachi-speech-bubble {
    --speech-bubble-color: var(--c-theme, #E0C895);
    --speech-bubble-bg: var(--c-bg-card, #FFFFFF);
    --speech-bubble-text: var(--c-text-main, #595048);
    --speech-bubble-radius: var(--radius-m, 16px);
    --speech-bubble-filled-text: var(--speech-bubble-text);
}

/* ============================================================
   Base Styles - 基本レイアウト
   ============================================================ */

.wp-block-mitachi-speech-bubble {
    display: flex;
    gap: 24px;
    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;
    object-fit: cover;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Outrank Gutenberg's generic img radius without blocking mobile sizing. */
.wp-block-mitachi-speech-bubble .speech-bubble__avatar {
    border-radius: 50%;
}

/* アバター枠線あり */
.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;
}

/* ============================================================
   Cocoon-style speech pointer: two CSS triangles on the body itself.
   The outer color and the inset background triangle cover the body's
   side border without any SVG or independent patch/mask.
   ============================================================ */

.wp-block-mitachi-speech-bubble {
    --speech-bubble-pointer-width: 12px;
    --speech-bubble-pointer-half: 8px;
    --speech-bubble-pointer-stroke: 2px;
}

.wp-block-mitachi-speech-bubble.is-direction-left { flex-direction: row; }
.wp-block-mitachi-speech-bubble.is-direction-right { flex-direction: row-reverse; }
.wp-block-mitachi-speech-bubble.is-type-bubble { gap: 42px; }

.wp-block-mitachi-speech-bubble.has-full-width .speech-bubble__content {
    flex: 1 1 auto;
    width: 100%;
}
.wp-block-mitachi-speech-bubble.has-auto-width .speech-bubble__content {
    flex: 0 1 auto;
    width: fit-content;
    max-width: 100%;
}

/* The pointer stays within the straight side, even in a one-line bubble. */
.wp-block-mitachi-speech-bubble.is-type-normal:is(.is-style-rounded, .is-style-rounded-filled, .is-style-shadow) .speech-bubble__content {
    min-height: calc(2 * var(--speech-bubble-radius) + 2 * var(--speech-bubble-pointer-half) + 4px);
}

/* The existing empty div is retained for thought bubbles only. */
.wp-block-mitachi-speech-bubble .speech-bubble__tail { display: none; }

/* Keep the base selector weaker than the left/right edge declarations.
   'border: 0' explicitly clears transparent-side browser defaults. */
.wp-block-mitachi-speech-bubble.is-type-normal .speech-bubble__content::before,
.wp-block-mitachi-speech-bubble.is-type-normal .speech-bubble__content::after {
    content: "";
    display: block;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border: 0 solid transparent;
    border-top-width: var(--speech-bubble-pointer-half);
    border-bottom-width: var(--speech-bubble-pointer-half);
    pointer-events: none;
}

.wp-block-mitachi-speech-bubble.is-type-normal.is-direction-left .speech-bubble__content::before {
    left: calc(-1 * var(--speech-bubble-pointer-width));
    border-right-width: var(--speech-bubble-pointer-width);
    border-right-color: var(--speech-bubble-color);
}
.wp-block-mitachi-speech-bubble.is-type-normal.is-direction-left .speech-bubble__content::after {
    left: calc(-1 * var(--speech-bubble-pointer-width) + var(--speech-bubble-pointer-stroke) + 1px);
    border-right-width: var(--speech-bubble-pointer-width);
    border-right-color: var(--speech-bubble-bg);
}
.wp-block-mitachi-speech-bubble.is-type-normal.is-direction-right .speech-bubble__content::before {
    right: calc(-1 * var(--speech-bubble-pointer-width));
    border-left-width: var(--speech-bubble-pointer-width);
    border-left-color: var(--speech-bubble-color);
}
.wp-block-mitachi-speech-bubble.is-type-normal.is-direction-right .speech-bubble__content::after {
    right: calc(-1 * var(--speech-bubble-pointer-width) + var(--speech-bubble-pointer-stroke) + 1px);
    border-left-width: var(--speech-bubble-pointer-width);
    border-left-color: var(--speech-bubble-bg);
}

/* Filled/outlined bodies use the same tip geometry. */
.wp-block-mitachi-speech-bubble:is(.is-style-square, .is-style-rounded) .speech-bubble__content {
    background-color: var(--speech-bubble-bg);
    border: var(--speech-bubble-pointer-stroke) solid var(--speech-bubble-color);
}
.wp-block-mitachi-speech-bubble:is(.is-style-square, .is-style-square-filled) .speech-bubble__content {
    border-radius: 4px;
}
.wp-block-mitachi-speech-bubble:is(.is-style-rounded, .is-style-rounded-filled) .speech-bubble__content {
    border-radius: var(--speech-bubble-radius);
}
.wp-block-mitachi-speech-bubble:is(.is-style-square-filled, .is-style-rounded-filled) .speech-bubble__content {
    --speech-bubble-pointer-stroke: 0px;
    background-color: var(--speech-bubble-color);
    border: 0;
}
.wp-block-mitachi-speech-bubble:is(.is-style-square-filled, .is-style-rounded-filled) .speech-bubble__text {
    color: var(--speech-bubble-filled-text);
}
.wp-block-mitachi-speech-bubble.is-type-normal:is(.is-style-square-filled, .is-style-rounded-filled) .speech-bubble__content::after {
    display: none;
}

/* No solid normal tip on dashed styles; retain thinking dots. */
.wp-block-mitachi-speech-bubble:is(.is-style-dashed, .is-style-dashed-filled) .speech-bubble__content {
    border: 2px dashed var(--speech-bubble-color);
    border-radius: var(--speech-bubble-radius);
}
.wp-block-mitachi-speech-bubble.is-style-dashed .speech-bubble__content {
    background-color: var(--speech-bubble-bg);
}
.wp-block-mitachi-speech-bubble.is-style-dashed-filled {
    /* The same opaque surface behind the body and both thinking dots. */
    --speech-bubble-dashed-fill: color-mix(in srgb, var(--speech-bubble-color) 15%, var(--speech-bubble-bg));
}
.wp-block-mitachi-speech-bubble.is-style-dashed-filled .speech-bubble__content {
    background-color: var(--speech-bubble-dashed-fill);
}
.wp-block-mitachi-speech-bubble.is-type-normal:is(.is-style-dashed, .is-style-dashed-filled) .speech-bubble__content::before,
.wp-block-mitachi-speech-bubble.is-type-normal:is(.is-style-dashed, .is-style-dashed-filled) .speech-bubble__content::after {
    display: none;
}

/* The content filter shadows both the normal pointer and its descendant thought dots. */
.wp-block-mitachi-speech-bubble.is-style-shadow .speech-bubble__content {
    --speech-bubble-pointer-stroke: 0px;
    background-color: var(--speech-bubble-bg);
    border: 0;
    border-radius: var(--speech-bubble-radius);
    filter: drop-shadow(0 4px 10px rgba(0, 0, 0, .16));
}
.wp-block-mitachi-speech-bubble.is-type-normal.is-style-shadow.is-direction-left .speech-bubble__content::before {
    border-right-color: var(--speech-bubble-bg);
}
.wp-block-mitachi-speech-bubble.is-type-normal.is-style-shadow.is-direction-right .speech-bubble__content::before {
    border-left-color: var(--speech-bubble-bg);
}
.wp-block-mitachi-speech-bubble.is-type-normal.is-style-shadow .speech-bubble__content::after {
    display: none;
}

/* Thought bubble circles use their own geometry, never the normal triangles. */
.wp-block-mitachi-speech-bubble.is-type-bubble .speech-bubble__tail {
    display: block;
    position: absolute;
    top: calc(50% - 11px);
    width: 0;
    height: 0;
    background: transparent;
    transform: none;
    pointer-events: 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: "";
    display: block;
    position: absolute;
    border-radius: 50%;
    background-color: var(--speech-bubble-color);
}
.wp-block-mitachi-speech-bubble.is-type-bubble .speech-bubble__tail::before {
    width: 14px;
    height: 14px;
}
.wp-block-mitachi-speech-bubble.is-type-bubble .speech-bubble__tail::after {
    width: 9px;
    height: 9px;
}
.wp-block-mitachi-speech-bubble.is-type-bubble.is-direction-left .speech-bubble__tail {
    left: -15px;
}
.wp-block-mitachi-speech-bubble.is-type-bubble.is-direction-left .speech-bubble__tail::before {
    left: -2px;
    top: 0;
}
.wp-block-mitachi-speech-bubble.is-type-bubble.is-direction-left .speech-bubble__tail::after {
    left: -17px;
    top: 13px;
}
.wp-block-mitachi-speech-bubble.is-type-bubble.is-direction-right .speech-bubble__tail {
    right: -15px;
}
.wp-block-mitachi-speech-bubble.is-type-bubble.is-direction-right .speech-bubble__tail::before {
    right: -2px;
    top: 0;
}
.wp-block-mitachi-speech-bubble.is-type-bubble.is-direction-right .speech-bubble__tail::after {
    right: -17px;
    top: 13px;
}
.wp-block-mitachi-speech-bubble.is-type-bubble:is(.is-style-square, .is-style-rounded, .is-style-dashed, .is-style-dashed-filled) .speech-bubble__tail::before,
.wp-block-mitachi-speech-bubble.is-type-bubble:is(.is-style-square, .is-style-rounded, .is-style-dashed, .is-style-dashed-filled) .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-dashed-filled .speech-bubble__tail::before,
.wp-block-mitachi-speech-bubble.is-type-bubble.is-style-dashed-filled .speech-bubble__tail::after {
    background-color: var(--speech-bubble-dashed-fill);
}
.wp-block-mitachi-speech-bubble.is-type-bubble:is(.is-style-square-filled, .is-style-rounded-filled) .speech-bubble__tail::before,
.wp-block-mitachi-speech-bubble.is-type-bubble:is(.is-style-square-filled, .is-style-rounded-filled) .speech-bubble__tail::after {
    background-color: 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);
}

/* ============================================================
   Responsive - レスポンシブ対応
   ============================================================ */

@media (max-width: 768px) {
    .wp-block-mitachi-speech-bubble {
        gap: 22px;
    }

    .wp-block-mitachi-speech-bubble.is-type-bubble {
        gap: 38px;
    }

    .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;
    }
}

/* Force body and speech pointer to use the same system outline palette. */
@media (forced-colors: active) {
    .wp-block-mitachi-speech-bubble .speech-bubble__content {
        --speech-bubble-pointer-stroke: 2px !important;
        background-color: Canvas !important;
        border: 2px solid CanvasText !important;
        filter: none !important;
    }
    .wp-block-mitachi-speech-bubble .speech-bubble__text { color: CanvasText !important; }
    .wp-block-mitachi-speech-bubble.is-type-normal.is-direction-left .speech-bubble__content::before {
        border-right-color: CanvasText !important;
    }
    .wp-block-mitachi-speech-bubble.is-type-normal.is-direction-right .speech-bubble__content::before {
        border-left-color: CanvasText !important;
    }
    .wp-block-mitachi-speech-bubble.is-type-normal:not(.is-style-dashed):not(.is-style-dashed-filled) .speech-bubble__content::after {
        display: block !important;
    }
    .wp-block-mitachi-speech-bubble.is-type-normal.is-direction-left .speech-bubble__content::after {
        border-right-color: Canvas !important;
    }
    .wp-block-mitachi-speech-bubble.is-type-normal.is-direction-right .speech-bubble__content::after {
        border-left-color: Canvas !important;
    }
    .wp-block-mitachi-speech-bubble.is-type-bubble .speech-bubble__tail {
        forced-color-adjust: 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 {
        background-color: Canvas !important;
        border: 2px solid CanvasText !important;
    }
    .wp-block-mitachi-speech-bubble .speech-bubble__avatar {
        border: 2px solid CanvasText !important;
    }
}

/* All speech bubble presentation, including variations and responsive
   behavior, is shared by Gutenberg and the published page. Editing controls
   belong in speech-bubble-block-editor.js, not duplicated color/size CSS. */

/* ============================================================
   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,
    .wp-block-mitachi-speech-bubble.is-type-normal .speech-bubble__content::before,
    .wp-block-mitachi-speech-bubble.is-type-normal .speech-bubble__content::after {
        display: none !important;
    }

    .wp-block-mitachi-speech-bubble .speech-bubble__content {
        filter: none !important;
    }

    .wp-block-mitachi-speech-bubble .speech-bubble__text {
        color: #333 !important;
    }
}