.story-puzzle-game {
    position: fixed;
    inset: 0 auto auto 50%;
    transform: translateX(-50%);
    width: var(--title-container-width);
    height: var(--app-height);
    container-type: size;
    z-index: var(--layer-game);
    display: flex;
    flex-direction: column;
    color: #fff1d2;
    background:
        linear-gradient(#173d3560, #173d35b0),
        url('../../images/theme/library.webp?v=6bc816130648') center / cover;
    overflow: hidden;
}
.story-puzzle-game[data-kind='forge'] {
    background-image:
        linear-gradient(#173d3560, #173d35b0), url('../../images/theme/guild-courtyard.webp?v=6093abb89d1f');
}
.story-puzzle-game[data-kind='proverb'] {
    background:
        linear-gradient(#17352812, #0e241b40),
        url('../../images/theme/proverb-study.webp?v=2dea5cca6f3d') center / cover;
}
.story-puzzle-game[data-kind='proverb'] .gameplay-header {
    background: linear-gradient(#142e26c9, #142e265c);
}
.story-puzzle-game[data-kind='proverb'] #puzzle-progress {
    align-self: flex-start;
    padding: 6px 10px;
    border: 1px solid #d8bf8580;
    border-radius: 8px;
    background: #173d2dcc;
    color: #fff3cf;
}
.story-puzzle-game[data-kind='proverb'] .puzzle-word-pair {
    margin: 0;
}
.story-puzzle-game[data-kind='proverb'] #puzzle-prompt {
    min-height: 140px;
    padding: 24px 16px;
    color: #342d21;
    font-size: clamp(22px, 5.6cqw, 36px);
    line-height: 1.6;
    word-break: keep-all;
    text-shadow: none;
}
.story-puzzle-game[data-kind='proverb'] #puzzle-feedback:not(:empty) {
    padding: 12px;
    background: #142e26e8;
    border: 1px solid #d8bf8580;
    border-radius: 8px;
    color: var(--ui-answer-blue);
}
.story-puzzle-game[data-kind='proverb'] .puzzle-choices button {
    min-height: 76px;
    font-size: clamp(17px, 4.6cqw, 26px);
    line-height: 1.3;
    word-break: keep-all;
}
.puzzle-board {
    flex: 1;
    min-height: 0;
    padding: clamp(8px, 2cqw, 20px);
    display: flex;
    flex-direction: column;
    gap: clamp(8px, 1.8cqh, 16px);
    overflow: auto;
    overscroll-behavior: contain;
}
.puzzle-content {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: clamp(8px, 1.8cqh, 16px);
    overflow: auto;
    overscroll-behavior: contain;
}
.puzzle-content > * {
    flex-shrink: 0;
}
.puzzle-controls:empty,
.puzzle-content p:empty {
    display: none;
}
.puzzle-board p {
    margin: 0;
}
#puzzle-progress {
    font-size: clamp(12px, 3cqw, 18px);
    font-weight: 800;
}
#puzzle-prompt {
    min-height: 90px;
    padding: 20px 18px;
    display: grid;
    place-items: center;
    color: #263b32;
    border: 10px solid transparent;
    border-image: url('../../images/theme/parts/quest-paper.webp?v=4508631406be') 18% fill / 10px / 0 stretch;
    font-size: clamp(18px, 5cqw, 30px);
    font-weight: 800;
    line-height: 1.45;
    text-align: center;
    overflow-wrap: anywhere;
}
#puzzle-prompt[data-result='wrong'] {
    color: #8b2828;
}
#puzzle-current {
    font-size: clamp(28px, 8cqw, 50px);
    font-weight: 900;
    text-align: center;
}
[data-kind='forge'] .puzzle-word-pair:has(#puzzle-current:not(:empty)) {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    align-items: center;
}
[data-kind='forge'] #puzzle-prompt:has(.forge-word) {
    min-height: 0;
    padding: 12px 8px;
}
.forge-word {
    display: block;
    font-size: clamp(18px, 5cqw, 28px);
    font-weight: 900;
    line-height: 1.2;
}
.forge-meaning {
    display: block;
    margin-top: 3px;
    font-size: clamp(12px, 3.3cqw, 16px);
    font-weight: 600;
    line-height: 1.35;
    overflow-wrap: anywhere;
}
[data-kind='forge'] .puzzle-choices button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
#puzzle-guide,
#puzzle-trail,
#puzzle-feedback {
    font-size: clamp(13px, 3.4cqw, 19px);
    line-height: 1.5;
    text-align: center;
    overflow-wrap: anywhere;
}
#puzzle-trail {
    min-height: 1.5em;
    color: #f7d68c;
}
#puzzle-feedback {
    min-height: 3em;
}
.puzzle-choices {
    flex-shrink: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}
[data-kind='forge'] .puzzle-choices {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}
.puzzle-choices button,
.puzzle-controls button {
    min-height: 48px;
    padding: 12px 8px;
    color: #fff1d2;
    font: inherit;
    font-weight: 800;
}
.puzzle-controls {
    display: flex;
    justify-content: center;
    flex-shrink: 0;
}
.puzzle-controls button {
    width: 100%;
}
@container (max-height: 500px) {
    .puzzle-board,
    .puzzle-content {
        gap: 5px;
    }
    #puzzle-prompt {
        min-height: 60px;
        padding: 12px;
        font-size: 17px;
    }
    #puzzle-current {
        font-size: 22px;
    }
    [data-kind='forge'] .puzzle-content {
        gap: 3px;
    }
    [data-kind='forge'] #puzzle-guide,
    [data-kind='forge'] #puzzle-trail {
        font-size: 12px;
        line-height: 1.3;
    }
    [data-kind='forge'] #puzzle-prompt {
        min-height: 0;
        padding: 4px;
        border-width: 6px;
        border-image-width: 6px;
    }
    [data-kind='forge'] #puzzle-prompt:has(.forge-word) {
        padding: 4px;
    }
    [data-kind='forge'] .forge-word {
        font-size: 17px;
        line-height: 1.1;
    }
    [data-kind='forge'] .forge-meaning {
        font-size: 11px;
        line-height: 1.2;
    }
    [data-kind='forge'] .puzzle-choices button {
        border-width: 8px !important;
        border-image-width: 8px !important;
        padding: 2px 4px !important;
    }
    #puzzle-trail {
        min-height: 0;
    }
    #puzzle-feedback {
        min-height: 0;
    }
    .puzzle-choices button,
    .puzzle-controls button {
        min-height: 34px;
        padding: 7px 4px;
        font-size: 13px;
    }
    .story-puzzle-game[data-kind='proverb'] #puzzle-prompt {
        min-height: 88px;
        padding: 10px;
        font-size: 19px;
        line-height: 1.4;
    }
    .story-puzzle-game[data-kind='proverb'] .puzzle-choices button {
        min-height: 48px;
        font-size: 15px;
    }
}

/* 사자성어도 주입된 문제 유형으로 전용 장면을 선택한다. */
#battle-mode-game[data-question-kind='idiom'] {
    background:
        linear-gradient(#142b3815, #0b202d40),
        url('../../images/theme/idiom-study.webp?v=faf357c0ff76') center / cover;
}
#battle-mode-game[data-question-kind='idiom']::before,
#battle-mode-game[data-question-kind='idiom'] .battle-arena::after,
#battle-mode-game[data-question-kind='idiom'] #equipment-display,
#battle-mode-game[data-question-kind='idiom'] #skill-display,
#battle-mode-game[data-question-kind='idiom'] .gameplay-heading p {
    display: none !important;
}
:root[data-layout] #battle-mode-game[data-question-kind='idiom'] .battle-arena {
    flex: 0 0 94px;
    min-height: 94px;
    max-height: 94px;
    padding: 0;
    background: transparent;
    border: 0;
}
:root[data-layout] #battle-mode-game[data-question-kind='idiom'] .battle-hud {
    top: 8px;
    gap: 6px;
}
#battle-mode-game[data-question-kind='idiom'] .gameplay-header {
    background: linear-gradient(#102733cc, #10273366);
}
#battle-mode-game[data-question-kind='idiom'] .char-wrapper::before {
    display: none;
}
#battle-mode-game[data-question-kind='idiom'] #monster-img {
    opacity: 1;
    object-fit: contain;
}
:root[data-layout] #battle-mode-game[data-question-kind='idiom'] .quiz-area {
    flex: 1;
    min-height: 0;
    margin: 0;
    padding: 8px 12px max(12px, env(safe-area-inset-bottom));
    border-radius: 0;
    background: transparent;
    gap: 12px;
    overflow: auto;
}
#battle-mode-game[data-question-kind='idiom'] .question-box {
    min-height: 140px;
    display: grid;
    place-items: center;
    margin-block: auto;
    padding: 20px 14px;
}
#battle-mode-game[data-question-kind='idiom'] .q-text {
    color: #342d21;
    font-size: clamp(22px, 5.6cqw, 36px);
    line-height: 1.5;
    word-break: keep-all;
    text-shadow: none;
}
#battle-mode-game[data-question-kind='idiom'] .options-grid {
    grid-auto-rows: minmax(76px, auto);
    gap: 8px;
    margin-top: 0;
    padding-bottom: 0;
}
#battle-mode-game[data-question-kind='idiom'] .option-btn {
    font-size: clamp(18px, 5cqw, 28px);
    line-height: 1.3;
    word-break: keep-all;
}
@container battle-game (max-height: 500px) {
    :root[data-layout] #battle-mode-game[data-question-kind='idiom'] .battle-arena {
        flex-basis: 80px;
        min-height: 80px;
        max-height: 80px;
    }
    :root[data-layout] #battle-mode-game[data-question-kind='idiom'] .quiz-area {
        gap: 6px;
        padding: 4px 8px 8px;
    }
    #battle-mode-game[data-question-kind='idiom'] .question-box {
        min-height: 70px;
        padding: 8px;
    }
    #battle-mode-game[data-question-kind='idiom'] .q-text {
        font-size: 17px;
        line-height: 1.35;
    }
    #battle-mode-game[data-question-kind='idiom'] .options-grid {
        grid-auto-rows: minmax(48px, auto);
        gap: 5px;
    }
    #battle-mode-game[data-question-kind='idiom'] .option-btn {
        font-size: 16px;
        padding: 3px 6px !important;
    }
}

.story-puzzle-game[data-kind='proverb'] .puzzle-board {
    overflow: hidden;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
}
.story-puzzle-game[data-kind='proverb'] .puzzle-choices {
    align-self: end;
    width: 100%;
}
.story-puzzle-game[data-kind='proverb'] #puzzle-feedback {
    white-space: pre-line;
    color: var(--ui-answer-blue);
}
/* Only visible actions take space; question/review choices sit at the board bottom. */
.story-puzzle-game[data-kind='proverb'] .puzzle-controls {
    min-height: 54px;
}
.story-puzzle-game[data-kind='proverb'] .puzzle-controls button {
    height: 54px;
    min-height: 54px;
    padding: 4px 8px;
}
.story-puzzle-game[data-kind='proverb'] .puzzle-controls:not(:has(button:not([hidden]))) {
    display: none;
}
.puzzle-combat-scene {
    display: none;
}
[data-kind='proverb'][data-phase='question'] .puzzle-combat-scene,
[data-kind='proverb'][data-phase='review'] .puzzle-combat-scene {
    display: block;
    position: absolute;
    inset: -8px 0 auto;
    height: max(var(--objective-scene-size), var(--objective-scene-min));
    isolation: isolate;
    pointer-events: none;
}
.puzzle-combatant {
    position: absolute;
    bottom: 20px;
    left: 5%;
    width: clamp(88px, 21cqh, 180px);
    height: clamp(88px, 21cqh, 180px);
    filter: drop-shadow(0 6px 3px #123b3d55);
}
.puzzle-combatant.puzzle-monster {
    right: 5%;
    left: auto;
}
.puzzle-monster img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}
#puzzle-progress {
    z-index: 2;
}
@media (max-height: 500px) {
    [data-kind='proverb'] .puzzle-combat-scene {
        top: -4px;
    }
    .puzzle-combatant {
        width: 64px;
        height: 64px;
        bottom: 8px;
    }
}
