#dialogueContainer {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: none;
    overflow: hidden;
    background: var(--ink);
}

#dialogueBackground {
    position: absolute;
    inset: -2px;
    z-index: 0;
    background-color: #0a1116;
    background-position: center;
    background-size: cover;
    image-rendering: pixelated;
    transition: background-image 120ms steps(2);
}

.scene-shade {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    background:
        linear-gradient(0deg, rgba(4, 8, 11, 0.98) 0%, rgba(4, 8, 11, 0.64) 26%, transparent 58%),
        linear-gradient(90deg, rgba(4, 8, 11, 0.42), transparent 28%, transparent 72%, rgba(4, 8, 11, 0.42));
}

.scene-shade::after {
    content: "";
    position: absolute;
    inset: 0;
    opacity: 0.12;
    background-image:
        linear-gradient(rgba(82, 255, 184, 0.16) 1px, transparent 1px),
        linear-gradient(90deg, rgba(82, 255, 184, 0.16) 1px, transparent 1px);
    background-size: 72px 72px;
    mask-image: linear-gradient(0deg, #000, transparent 72%);
}

.story-hud {
    position: absolute;
    z-index: 6;
    top: 0;
    right: 0;
    left: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 64px;
    padding: 10px clamp(18px, 3.5vw, 54px);
    border-bottom: 1px solid rgba(82, 255, 184, 0.2);
    background: linear-gradient(90deg, rgba(4, 9, 12, 0.9), rgba(4, 9, 12, 0.36));
}

.story-brand {
    display: flex;
    align-items: center;
    gap: 11px;
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 0.6rem;
    letter-spacing: 0.14em;
}

.story-brand img {
    width: 38px;
    height: 38px;
    object-fit: cover;
    image-rendering: pixelated;
}

.story-location {
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--paper);
    font-size: 0.72rem;
    letter-spacing: 0.1em;
}

#sceneMode {
    color: var(--cyan);
    font-family: var(--font-mono);
    font-size: 0.62rem;
}

.story-location b {
    color: var(--dim);
    font-weight: 400;
}

.dialogue-screen[data-scene-type="investigation"] #choicesContainer {
    border-color: rgba(66, 217, 255, 0.58);
}

.dialogue-screen[data-scene-type="ending"] #dialogueBox {
    border-color: rgba(243, 191, 91, 0.54);
}

.character-area {
    position: absolute;
    z-index: 2;
    bottom: clamp(190px, 24vh, 252px);
    width: min(44vw, 700px);
    height: calc(100% - clamp(190px, 24vh, 252px) - 44px);
    display: flex;
    align-items: flex-end;
    pointer-events: none;
}

.character-left {
    left: 2vw;
    justify-content: flex-start;
}

.character-right {
    right: 2vw;
    justify-content: flex-end;
}

.character-sprite {
    position: relative;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    width: 100%;
    height: 100%;
    transform-origin: center bottom;
    transition: opacity 120ms steps(2), filter 120ms steps(2), transform 120ms steps(2);
}

.character-portrait {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center bottom;
    image-rendering: pixelated;
}

.character-left .character-portrait {
    filter: drop-shadow(-16px 12px 0 rgba(2, 5, 7, 0.36));
}

.character-right .character-portrait {
    filter: drop-shadow(16px 12px 0 rgba(2, 5, 7, 0.36));
}

.character-sprite.speaking {
    z-index: 2;
    opacity: 1;
    filter: brightness(1.05) saturate(1.04);
    transform: translateY(0) scale(1.02);
}

.character-sprite.dimmed {
    z-index: 1;
    opacity: 0.54;
    filter: brightness(0.52) saturate(0.55);
    transform: translateY(4px) scale(0.98);
}

.sprite-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    width: min(68%, 320px);
    min-height: 58%;
    margin-bottom: 16px;
    border: 1px solid var(--line);
    background: rgba(5, 12, 15, 0.75);
    clip-path: var(--step-cut);
}

.sprite-icon {
    color: var(--mint);
    font-family: var(--font-mono);
    font-size: 3rem;
}

.sprite-name {
    margin: 12px 0 20px;
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 0.62rem;
    letter-spacing: 0.12em;
}

#dialogueBox {
    position: absolute;
    z-index: 7;
    right: clamp(18px, 4vw, 68px);
    bottom: clamp(18px, 3vh, 34px);
    left: clamp(18px, 4vw, 68px);
    min-height: clamp(158px, 20vh, 205px);
    padding: clamp(22px, 2.4vw, 34px) clamp(24px, 3vw, 42px) 18px;
    border: 1px solid rgba(82, 255, 184, 0.45);
    border-left: 4px solid var(--mint);
    background: rgba(5, 11, 15, 0.95);
    box-shadow: 12px 12px 0 rgba(1, 5, 7, 0.44);
    cursor: pointer;
    clip-path: var(--step-cut);
}

#dialogueBox::before {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    width: 18%;
    height: 3px;
    background: var(--cyan);
}

.dialogue-file {
    position: absolute;
    top: 10px;
    right: 18px;
    color: #4f6760;
    font-family: var(--font-mono);
    font-size: 0.52rem;
    letter-spacing: 0.13em;
}

#speakerName {
    min-height: 22px;
    margin-bottom: 9px;
    color: var(--mint);
    font-size: 0.95rem;
    font-weight: 750;
    letter-spacing: 0.1em;
}

#speakerName:empty::before {
    content: "NARRATION / 旁白";
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 0.62rem;
    font-weight: 400;
    letter-spacing: 0.13em;
}

#dialogueText {
    max-width: 1120px;
    min-height: 52px;
    color: #d5dfda;
    font-size: clamp(0.9rem, 1.2vw, 1.08rem);
    line-height: 1.82;
    letter-spacing: 0.035em;
}

.dialogue-controls {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

#nextButton,
#autoPlayBtn {
    min-height: 34px;
    padding: 0 13px;
    border: 1px solid var(--line);
    background: #0c171a;
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 0.58rem;
    letter-spacing: 0.08em;
    cursor: pointer;
}

#nextButton {
    min-width: 132px;
    border-color: var(--mint);
    background: rgba(27, 69, 55, 0.62);
    color: var(--paper);
}

#nextButton span {
    margin-left: 12px;
    color: var(--mint);
}

#nextButton:hover,
#autoPlayBtn:hover {
    border-color: var(--cyan);
    color: var(--paper);
}

#choicesContainer {
    position: absolute;
    z-index: 9;
    right: clamp(18px, 7vw, 110px);
    bottom: clamp(22px, 5vh, 54px);
    left: clamp(18px, 7vw, 110px);
    display: none;
    padding: 16px;
    border: 1px solid rgba(82, 255, 184, 0.36);
    background: rgba(5, 11, 15, 0.97);
    clip-path: var(--step-cut);
}

#dialogueContainer.has-choices #dialogueBox {
    visibility: hidden;
}

.choice-button {
    position: relative;
    display: grid;
    grid-template-columns: 40px 1fr;
    align-items: center;
    width: 100%;
    min-height: 52px;
    margin-top: 7px;
    padding: 8px 14px;
    border: 1px solid var(--line);
    background: #0a1417;
    color: var(--paper);
    text-align: left;
    cursor: pointer;
}

.choice-button:first-child {
    margin-top: 0;
}

.choice-button:hover {
    border-color: var(--mint);
    background: #10251f;
    transform: translateX(4px);
}

.choice-number {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border: 1px solid var(--mint);
    color: var(--mint);
    font-family: var(--font-mono);
    font-size: 0.62rem;
}

.choice-text {
    color: #d4dfda;
    font-size: 0.84rem;
    line-height: 1.55;
}

.choice-risk {
    grid-column: 2;
    margin-top: 2px;
    color: var(--amber);
    font-family: var(--font-mono);
    font-size: 0.56rem;
    line-height: 1.45;
    letter-spacing: 0.08em;
}

.choice-button.is-risk-companion {
    border-color: rgba(255, 190, 80, 0.5);
}

.choice-button.is-risk-fatal {
    border-color: rgba(255, 72, 72, 0.62);
    background: rgba(34, 9, 12, 0.92);
}

.choice-button.is-risk-fatal .choice-number {
    border-color: var(--red);
    color: var(--red);
}

.choice-button.is-risk-fatal .choice-risk {
    color: #ff7777;
}

.choice-button.is-risk-fatal:hover {
    border-color: #ff7777;
    background: rgba(56, 12, 17, 0.96);
}

@media (max-width: 760px) {
    .story-hud {
        min-height: 54px;
        padding: 8px 14px;
    }

    .story-brand span {
        display: none;
    }

    .story-brand img {
        width: 34px;
        height: 34px;
    }

    .story-location {
        font-size: 0.62rem;
    }

    .character-area {
        bottom: 232px;
        width: 58vw;
        height: calc(100% - 256px);
    }

    .character-left { left: -8vw; }
    .character-right { right: -8vw; }

    #dialogueBox {
        right: 12px;
        bottom: 12px;
        left: 12px;
        min-height: 205px;
        padding: 28px 18px 14px;
    }

    #dialogueText {
        min-height: 86px;
        font-size: 0.88rem;
        line-height: 1.72;
    }

    .dialogue-controls {
        margin-top: 8px;
    }

    #choicesContainer {
        right: 12px;
        bottom: 12px;
        left: 12px;
        padding: 10px;
    }

    .choice-button {
        min-height: 48px;
    }
}
