/*
 * 天玄剧情框容纳修复。
 *
 * 只改 GameEventDialogPanel 内部排版；外层面板、遮罩和选项按钮仍使用原版位置。
 * 当前原版复刻把 82px 宽的竖排地点、619px 正文和右侧头像绝对定位在同一块
 * 底板上。天玄文本更长，窄桌面中正文会伸进头像热区，因此在天玄世界里给三者
 * 划出明确边界，并让正文自己滚动。
 */

html.tx-edition #dialogue-box {
    --tx-dialogue-edge: 3.5rem;
    --tx-dialogue-portrait-reserve: 11rem;
    box-sizing: border-box;
    overflow: hidden;
}

html.tx-edition #dialogue-box .dlg-main {
    position: static;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
}

/* 地点/说话者改为面板内的横向眉题，不再占掉一整条正文列。 */
html.tx-edition #speaker-name {
    left: var(--tx-dialogue-edge);
    right: var(--tx-dialogue-portrait-reserve);
    top: 2.15rem;
    width: auto;
    height: 2.8rem;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    overflow: hidden;
    color: #d7b77a;
    font: 500 1.45rem/1.4 "STKaiti", "KaiTi", serif;
    letter-spacing: .14em;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-break: keep-all;
    overflow-wrap: normal;
}

/* 右侧头像有自己的栏位；正文右缘不会再钻到头像下面。 */
html.tx-edition #dialogue-head-wrap {
    left: auto;
    right: 3rem;
    top: 1.7rem;
}

html.tx-edition #dialogue-text {
    left: var(--tx-dialogue-edge);
    right: var(--tx-dialogue-portrait-reserve);
    top: 6rem;
    bottom: 3.2rem;
    width: auto;
    height: auto;
    box-sizing: border-box;
    padding: .2rem .55rem .8rem 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    color: #f1ecde;
    font: 400 1.32rem/1.82 "Source Han Sans SC", "Microsoft YaHei", sans-serif;
    text-align: left;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: normal;
    touch-action: pan-y;
}

html.tx-edition #dialogue-box.no-head #speaker-name,
html.tx-edition #dialogue-box.no-head #dialogue-text {
    right: var(--tx-dialogue-edge);
}

/* 面板本身就是继续热区；此提示不新增按钮，也不改变原有点击事件。 */
html.tx-edition #dialogue-box::after {
    content: "点击继续";
    position: absolute;
    right: var(--tx-dialogue-edge);
    bottom: 1.15rem;
    z-index: 3;
    color: rgba(218, 190, 137, .82);
    font: 400 .86rem/1.4 "Source Han Sans SC", "Microsoft YaHei", sans-serif;
    letter-spacing: .12em;
    pointer-events: none;
}

html.tx-edition #dialogue-box.choice-state::after {
    content: "";
}

html.tx-edition #dialogue-text::-webkit-scrollbar {
    width: .5rem;
}

html.tx-edition #dialogue-text::-webkit-scrollbar-track {
    background: rgba(9, 24, 31, .28);
}

html.tx-edition #dialogue-text::-webkit-scrollbar-thumb {
    border: .1rem solid transparent;
    border-radius: 999px;
    background: rgba(204, 176, 116, .62);
    background-clip: padding-box;
}

/* 满幅剧情插画沿用原来的底部对白条，只统一正文的安全边界。 */
html.tx-edition.tx-story-open #dialogue-box {
    top: auto;
    bottom: 6rem;
    height: 20rem;
    transform: translateX(-50%);
}

html.tx-edition.tx-story-open #speaker-name {
    left: 3rem;
    right: 3rem;
    top: 1.45rem;
    height: 2.7rem;
}

html.tx-edition.tx-story-open #dialogue-text {
    left: 3rem;
    right: 3rem;
    top: 5rem;
    bottom: 3rem;
}

html.tx-edition.tx-story-open #dialogue-box::after {
    right: 3rem;
}

/* 手机把面板内部变成两行流式网格：眉题固定，正文独立滚动。 */
@media (max-width: 960px) {
    html.tx-edition.tx-mobile #dialogue-box {
        left: 1rem;
        right: 1rem;
        top: max(5.5rem, calc(env(safe-area-inset-top) + 4.5rem));
        bottom: auto;
        width: auto;
        height: min(44dvh, 25rem);
        min-height: clamp(9rem, 32dvh, 13rem);
        max-height: 44dvh;
        padding: 0;
        transform: none;
        overflow: hidden;
    }

    html.tx-edition.tx-mobile #dialogue-box .dlg-main {
        display: grid;
        grid-template-rows: auto minmax(0, 1fr);
        gap: .55rem;
        padding: 1rem 1.1rem 2.65rem;
        box-sizing: border-box;
    }

    html.tx-edition.tx-mobile #speaker-name,
    html.tx-edition.tx-mobile #dialogue-box.no-head #speaker-name {
        position: static;
        inset: auto;
        width: auto;
        height: auto;
        min-width: 0;
        min-height: 1.65rem;
        margin: 0;
        color: #d7b77a;
        font-size: 1.08rem;
        line-height: 1.45;
        letter-spacing: .1em;
    }

    html.tx-edition.tx-mobile #dialogue-text,
    html.tx-edition.tx-mobile #dialogue-box.no-head #dialogue-text {
        position: static;
        inset: auto;
        width: auto;
        height: auto;
        min-width: 0;
        min-height: 0;
        padding: 0 .35rem .35rem 0;
        font-size: 1rem;
        line-height: 1.75;
        overflow-y: auto;
    }

    html.tx-edition.tx-mobile #dialogue-head-wrap,
    html.tx-edition.tx-mobile #dialogue-player-wrap {
        display: none !important;
    }

    html.tx-edition.tx-mobile #dialogue-box::after {
        content: "轻触继续";
        right: 1.15rem;
        bottom: .85rem;
        font-size: .75rem;
    }

    html.tx-edition.tx-mobile #dialogue-box.choice-state::after {
        content: "";
    }

    html.tx-edition.tx-mobile.tx-story-open #dialogue-box {
        top: auto;
        bottom: calc(5.25rem + env(safe-area-inset-bottom));
        height: min(38dvh, 20rem);
        min-height: 9rem;
        max-height: 38dvh;
    }
}

/* 触屏横屏高度很短，给下方三列选项留出完整点击区。 */
@media (max-width: 960px) and (max-height: 600px) {
    html.tx-edition.tx-mobile #dialogue-box {
        /* 横屏 HUD 仍占据顶部约 4.8rem；对白从它下方开始。 */
        top: max(4.75rem, calc(env(safe-area-inset-top) + 4.5rem));
        height: 35dvh;
        min-height: 7.5rem;
        max-height: 35dvh;
    }

    html.tx-edition.tx-mobile #dialogue-box .dlg-main {
        gap: .25rem;
        padding: .65rem .9rem 2.1rem;
    }

    html.tx-edition.tx-mobile #speaker-name,
    html.tx-edition.tx-mobile #dialogue-box.no-head #speaker-name {
        min-height: 1.35rem;
        font-size: .9rem;
    }

    html.tx-edition.tx-mobile #dialogue-text,
    html.tx-edition.tx-mobile #dialogue-box.no-head #dialogue-text {
        font-size: .86rem;
        line-height: 1.6;
    }

    html.tx-edition.tx-mobile #dialogue-box::after {
        right: .9rem;
        bottom: .55rem;
        font-size: .68rem;
    }

    /* 六选一会在底部排成两行；选择状态再收短一点，避免两层热区相压。 */
    html.tx-edition.tx-mobile #dialogue-box.choice-state {
        height: 30dvh;
        min-height: 6.5rem;
        max-height: 30dvh;
    }

    html.tx-edition.tx-mobile.tx-story-open #dialogue-box {
        top: auto;
        bottom: calc(4.5rem + env(safe-area-inset-bottom));
        height: 38dvh;
        min-height: 8rem;
        max-height: 38dvh;
    }
}

@media (prefers-reduced-motion: reduce) {
    html.tx-edition #dialogue-box,
    html.tx-edition .avatar-pop {
        animation: none !important;
    }
}
