/* One illustrated choice component for English, idioms and story puzzles. */
:root {
    --choice-height: 76px;
    --choice-font-size: clamp(18px, 5cqw, 28px);
    --choice-gap: 8px;
    --action-height: 54px;
    --action-font-size: clamp(14px, calc(var(--title-container-width, 100vw) * 0.04), 19px);
    --ui-choice-default: var(--ui-action);
    --ui-choice-wrong: var(--ui-danger);
}

/* textContent preserves data safely; explicit newlines remain visible in prompts. */
.q-text,
.boss-hint {
    white-space: pre-line;
}

/* The same action always has the same tone, type and touch target across menus. */
:is(.mode-actions, .story-actions, .app-confirm-actions, #detail-actions) button,
.story-popup-body > .image-action-button,
.story-market-actions > .image-action-button,
.puzzle-controls > button,
#hangman-next-btn,
.modal-footer > .modal-btn-main,
#result-modal .result-btn,
#revenge-start-btn {
    min-height: var(--action-height);
    font-family: inherit;
    font-size: var(--action-font-size);
    font-weight: 800;
    line-height: 1.3;
}
.story-popup-body > .image-action-button {
    width: 100%;
}
.story-popup-body > label,
#story-confirm-copy,
#story-mystery-status,
#story-treasure-status {
    color: var(--ui-text-label);
    line-height: 1.5;
}
.story-popup-body > label {
    display: block;
    font-weight: 800;
}
#practice-mode-game .practice-chip[aria-pressed='true'],
#practice-mode-game #practice-memorized-btn[aria-pressed='true'] {
    --ui-control-art: var(--ui-confirm-execute);
}

:root[data-layout]
    :is(#battle-mode-game, #story-puzzle-game)
    :is(.options-grid, .puzzle-choices).answer-choices {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: minmax(var(--choice-height), auto);
    gap: var(--choice-gap);
    width: 100%;
    min-width: 0;
    flex: 0 0 auto;
    padding: 0;
    margin: auto 0 0;
}
:root[data-layout]
    :is(#battle-mode-game, #story-puzzle-game)
    :is(.option-btn, .image-action-button).answer-choice {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
    max-width: none;
    min-width: 0;
    min-height: var(--choice-height);
    margin: 0;
    padding: 2px 8px !important;
    border: 10px solid transparent !important;
    border-image: var(--answer-art, var(--ui-choice-default)) 48 fill / 10px / 0 stretch !important;
    border-radius: 0;
    background: transparent !important;
    box-shadow: none !important;
    color: var(--ui-text-on-art) !important;
    font-family: inherit;
    font-size: var(--choice-font-size);
    font-weight: 800;
    line-height: 1.3;
    text-align: center;
    text-shadow: 0 1px 1px var(--ui-text-shadow);
    overflow-wrap: anywhere;
    word-break: keep-all;
}
.answer-choice:is(.option-btn-correct, .option-btn-picked-correct, [data-result='correct']) {
    --answer-art: var(--ui-confirm-execute);
}
.answer-choice:is(.option-btn-picked-wrong, [data-result='wrong']) {
    --answer-art: var(--ui-choice-wrong);
}
#puzzle-choices .answer-choice:disabled {
    opacity: 1;
    filter: none;
}
.answer-choice:disabled {
    transform: none !important;
    outline: none !important;
}
:is(#battle-mode-game, #hangman-game, #story-puzzle-game, #shell-game) button:disabled {
    outline: none !important;
}
.answer-choice .forge-word {
    font-size: inherit;
    line-height: inherit;
}
.answer-choice .forge-meaning {
    margin-top: 0;
    font-size: clamp(11px, 3cqw, 14px);
    line-height: 1.1;
}
:root[data-layout] #story-puzzle-game[data-kind='forge'] .answer-choice {
    gap: 0;
}

/* Match the horizontal gutters, so the same grid produces the same button width. */
:root[data-layout]
    #practice-mode-game
    .practice-memorization-container
    :is(.practice-chip, .practice-memorized-btn, .practice-speak-btn, .practice-nav-btn) {
    height: 60px;
    min-height: 60px;
    padding-block: 8px !important;
    border-width: 8px !important;
    border-image-width: 8px !important;
}
.settings-install-help {
    margin: 8px 0 14px;
    color: var(--menu-ink);
    font-size: 13px;
    line-height: 1.5;
}
:root[data-layout] #battle-mode-game .quiz-area,
:root[data-layout] #battle-mode-game[data-question-kind='idiom'] .quiz-area {
    padding-inline: 12px;
}
#story-puzzle-game .puzzle-board {
    padding-inline: 12px;
}
#story-puzzle-game[data-kind='forge'] .answer-choices {
    max-height: 42cqh;
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* Compact question cards leave the scene visible between the prompt and choices. */
#battle-mode-game[data-question-kind='idiom'] .question-box {
    min-height: 68px;
    margin-block: 0;
    padding: 8px;
}
#battle-mode-game[data-question-kind='idiom'] .q-text,
#story-puzzle-game[data-kind='proverb'] #puzzle-prompt {
    font-size: clamp(18px, 4.6cqw, 28px);
    line-height: 1.5;
}
#story-puzzle-game[data-kind='proverb'] #puzzle-prompt {
    min-height: 84px;
    padding: 8px;
    border-width: 12px;
    border-image-width: 12px;
}
#story-puzzle-game .puzzle-blank {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
    min-height: 1.9em;
    margin-inline: 0.15em;
    padding: 0 0.2em;
    border: 1px solid #8c805e;
    border-radius: 4px;
    background: #fff8e3;
    font-size: 0.9em;
    line-height: 1.4;
    color: transparent;
}
#story-puzzle-game .puzzle-blank.puzzle-answer {
    color: var(--ui-answer-ink);
}

/* English, idioms and proverbs use the same scene height above the question. */
:is(#battle-mode-game, #story-puzzle-game) {
    --objective-scene-size: 35cqh;
    --objective-scene-min: 252px;
}
#story-puzzle-game[data-kind='proverb'] .puzzle-board {
    padding-top: 8px;
}
#story-puzzle-game[data-kind='proverb'] .puzzle-content {
    position: relative;
    padding-top: max(var(--objective-scene-size), var(--objective-scene-min));
}
#story-puzzle-game[data-kind='proverb'] #puzzle-progress {
    position: absolute;
    top: 0;
    left: 0;
}
:root[data-layout] #battle-mode-game:not([data-answer-entry='letters']) .battle-arena {
    flex: 0 0 var(--objective-scene-size);
    min-height: var(--objective-scene-min);
    max-height: none;
    padding: 8px 12px 20px;
}
:root[data-layout] #battle-mode-game:not([data-answer-entry='letters']) .quiz-area {
    margin: 0;
    padding-top: 8px;
}
:root[data-layout] #battle-mode-game:not([data-answer-entry='letters']) .question-box {
    min-height: 68px;
    margin-block: 0;
    padding: 8px;
}
#story-puzzle-game #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='forge'] .gameplay-header {
    background: linear-gradient(#142e26c9, #142e265c);
}

/* Hidden meanings and the next action retain their exact space for the whole round. */
#hangman-game .hangman-word {
    width: 100%;
    height: 2.6em;
    min-height: 2.6em;
    line-height: 1.3;
    overflow: auto;
}
#hangman-game .hangman-meaning {
    height: 3.8em;
    display: grid;
    place-items: safe center;
    overflow: auto;
}
#hangman-game .hangman-meaning[hidden] {
    display: grid !important;
    visibility: hidden;
}
#hangman-game #hangman-next-btn[hidden] {
    display: block !important;
    visibility: hidden;
}
#hangman-game[data-finished='true'] .english-keyboard {
    display: grid;
}
#hangman-status {
    height: 2.6em;
    min-height: 2.6em;
    overflow: auto;
}
.setting-vibration-icon {
    font-size: 30px;
    text-align: center;
    color: #36644e;
}
#setting-modal .settings-vibration-length {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 96px;
    align-items: center;
    gap: 8px;
    padding-block: 6px;
}
.setting-option-label {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-width: 0;
    margin: 0;
    text-align: left;
    word-break: keep-all;
}
.settings-select-control {
    position: relative;
    min-width: 0;
    color: var(--menu-ink);
}
.settings-select-control::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 14px;
    width: 7px;
    height: 7px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: translateY(-65%) rotate(45deg);
    pointer-events: none;
}
#setting-vibration-duration {
    appearance: none;
    width: 100%;
    min-width: 0;
    min-height: 44px;
    margin: 0;
    color: var(--menu-ink);
    background: transparent;
    border: 6px solid transparent;
    border-image: var(--ui-field) 18% fill / 6px / 0 stretch;
    border-radius: 0;
    padding: 4px 22px 4px 10px;
    cursor: pointer;
}
.settings-select-control:has(select:disabled) {
    opacity: 0.55;
}
#setting-vibration-duration:disabled {
    cursor: default;
}

@media (max-height: 850px) {
    :is(#battle-mode-game, #story-puzzle-game) {
        --objective-scene-size: 26cqh;
        --objective-scene-min: clamp(110px, 26cqh, 200px);
    }
}
@media (max-height: 550px) {
    :is(#battle-mode-game, #story-puzzle-game) {
        --objective-scene-size: 21cqh;
        --objective-scene-min: clamp(90px, 21cqh, 110px);
    }
}

/* The title, full-width context strip and scrolling body have identical geometry. */
:is(#shop-modal, #inventory-modal, #statistics-modal) .card.rpg-modal {
    height: calc(var(--app-height, 100dvh) - 84px);
    max-height: calc(var(--app-height, 100dvh) - 84px);
}
:is(#shop-modal, #inventory-modal, #statistics-modal) .menu-context {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-width: 0;
    min-height: 44px;
    flex: 0 0 auto;
    margin: 0 0 12px;
    padding: 8px 12px;
    border: 1px solid #dcc17b;
    border-radius: 8px;
    background: #183e32;
    color: #fff1cd;
    font-size: 14px;
    font-weight: 800;
    line-height: 1.4;
    text-align: center;
    overflow-wrap: anywhere;
}
:is(#shop-modal, #statistics-modal) .modal-body,
#inventory-modal .inv-container {
    margin: 0;
    padding: 6px;
}

@container (max-width: 280px) {
    :is(#shop-modal, #inventory-modal, #statistics-modal) .modal-title {
        grid-column: 1;
        gap: 4px;
        font-size: 22px !important;
    }
    :is(#shop-modal, #inventory-modal, #statistics-modal) .modal-title .game-emblem {
        width: 28px;
        height: 28px;
    }
    :is(#shop-modal, #inventory-modal, #statistics-modal) .menu-wallet {
        grid-column: 2;
        grid-row: 1;
        justify-self: end;
        gap: 3px;
        padding: 4px 5px;
        font-size: 11px;
    }
    :is(#shop-modal, #inventory-modal, #statistics-modal) .menu-wallet img {
        width: 20px;
        height: 20px;
    }
}

/* A balance must not consume the title or close control's space. */
:is(#shop-modal, #inventory-modal, #statistics-modal, #setting-modal)
    .approved-menu-header:has([data-menu-gold][data-gold-size='long']) {
    grid-template-columns: minmax(0, 1fr) 44px;
}
:is(#shop-modal, #inventory-modal, #statistics-modal, #setting-modal)
    .approved-menu-header:has([data-menu-gold][data-gold-size='long'])
    .modal-title {
    grid-column: 1;
    white-space: nowrap;
}
:is(#shop-modal, #inventory-modal, #statistics-modal, #setting-modal)
    .approved-menu-header:has([data-menu-gold][data-gold-size='long'])
    .menu-wallet {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: start;
}
:is(#shop-modal, #inventory-modal, #statistics-modal, #setting-modal)
    .approved-menu-header:has([data-menu-gold][data-gold-size='long'])
    > .modal-close-x {
    grid-column: 2;
}

@media (max-height: 500px) {
    #story-puzzle-game[data-kind='proverb'] .gameplay-header {
        height: 68px;
        min-height: 68px;
    }
    #story-puzzle-game[data-kind='proverb'] .puzzle-board {
        padding-top: 4px;
    }
    :root[data-layout] #battle-mode-game:not([data-answer-entry='letters']) .quiz-area {
        padding-top: 4px;
    }
    :root[data-layout] #battle-mode-game:not([data-answer-entry='letters']) .question-box {
        min-height: 60px;
        padding: 4px;
    }
    #hangman-game .hangman-content {
        gap: 3px;
        justify-content: safe center;
    }
    #hangman-game .hangman-drawing {
        height: 24px;
    }
    #hangman-game .hangman-word {
        height: 26px;
        min-height: 26px;
        font-size: 18px;
    }
    #hangman-game .hangman-meaning {
        height: 38px;
        font-size: 12px;
    }
    #hangman-status {
        position: absolute;
        width: 1px;
        height: 1px;
        min-height: 0;
        overflow: hidden;
        clip-path: inset(50%);
    }
    :root[data-layout]
        #practice-mode-game
        .practice-memorization-container
        :is(.practice-chip, .practice-memorized-btn, .practice-speak-btn, .practice-nav-btn) {
        height: 52px;
        min-height: 52px;
        padding-block: 5px !important;
        border-width: 6px !important;
        border-image-width: 6px !important;
    }
    :root {
        --choice-height: 48px;
        --choice-font-size: 16px;
        --choice-gap: 5px;
    }
    :root[data-layout]
        :is(#battle-mode-game, #story-puzzle-game)
        :is(.option-btn, .image-action-button).answer-choice {
        padding: 1px 8px !important;
        border-width: 6px !important;
        border-image-width: 6px !important;
    }
    :is(#shop-modal, #inventory-modal, #statistics-modal) .card.rpg-modal {
        height: calc(var(--app-height, 100dvh) - 72px);
        max-height: calc(var(--app-height, 100dvh) - 72px);
    }
    :is(#shop-modal, #inventory-modal, #statistics-modal) .menu-context {
        margin-bottom: 8px;
        font-size: 12px;
    }
    #story-puzzle-game[data-kind='proverb'] #puzzle-prompt {
        min-height: 68px;
        padding: 4px;
        font-size: 17px;
    }
    #battle-mode-game[data-question-kind='idiom'] .question-box {
        min-height: 60px;
        padding: 4px;
    }
    #battle-mode-game[data-question-kind='idiom'] .q-text {
        font-size: 17px;
    }
}
.q-text,
.practice-word-text,
.practice-meaning-text,
.practice-explanation-text {
    -webkit-user-select: text;
    user-select: text;
}
