/* ── Dungeon World – Game overrides ──────────────────────────
   Base styles come from one-step-dungeon/styles.css
   Here we add dungeon-world specific overrides only
*/

/* Board grid */
.board {
    display: grid;
    grid-template-columns: repeat(var(--cols, 10), var(--cell-size, 40px));
    gap: 0;
    width: fit-content;
    margin: 0 auto;
    image-rendering: pixelated;
}

.cell {
    position: relative;
    width: var(--cell-size, 40px);
    height: var(--cell-size, 40px);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
}

/* モバイル：セルサイズをビューポート幅に合わせて縮小 */
@media (max-width: 440px) {
    :root {
        /* 画面幅÷10列（余白8px×2考慮） */
        --cell-size: clamp(28px, calc((100vw - 16px) / 10), 40px);
    }
}

.cell .sprite {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
}

.cell .glyph {
    font-size: 1.2rem;
    line-height: 1;
    z-index: 1;
}

/* 敵HPバー */
.enemy-hp-bar {
    position: absolute;
    bottom: 2px;
    left: 2px;
    right: 2px;
    height: 3px;
    background: #1a1a1a;
    border-radius: 2px;
    z-index: 3;
}

.enemy-hp-fill {
    height: 100%;
    background: #e05050;
    border-radius: 2px;
    transition: width 0.1s;
}

/* プレイヤー向き矢印 */
.dir-arrow {
    position: absolute;
    z-index: 4;
    width: 0;
    height: 0;
    pointer-events: none;
}

.dir-arrow.dir-up {
    top: 1px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 7px solid rgba(79, 195, 160, 0.8);
}

.dir-arrow.dir-down {
    bottom: 1px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 7px solid rgba(79, 195, 160, 0.8);
}

.dir-arrow.dir-left {
    left: 1px;
    top: 50%;
    transform: translateY(-50%);
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    border-right: 7px solid rgba(79, 195, 160, 0.8);
}

.dir-arrow.dir-right {
    right: 1px;
    top: 50%;
    transform: translateY(-50%);
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    border-left: 7px solid rgba(79, 195, 160, 0.8);
}

/* ── コントロールレイアウト ──────────────────────────────── */

/* メイン操作エリア：十字キー（左）＋向き変更・攻撃（右）を横並び */
.controls-main {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* 十字キー群 */
.controls-dpad {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

/* 十字キー中央のスペーサー（センターを空ける） */
.ctrl-spacer {
    width: 52px;
    height: 52px;
}

/* 右側の向き変更＋攻撃ボタン列 */
.controls-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}

/* 攻撃ボタン */
.ctrl-btn--attack {
    border-color: rgba(232, 95, 92, 0.6);
    background: #2a1a1a;
    font-size: 1.3rem;
}

.ctrl-btn--attack:active {
    background: #3e2222;
}

/* 向き変更モードボタン */
.ctrl-btn--turn {
    font-size: 0.85rem;
    width: 52px;
    height: 52px;
    border-color: rgba(111, 211, 196, 0.4);
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
}

.ctrl-btn--turn .turn-mode-icon {
    font-size: 1.1rem;
    line-height: 1;
}

.ctrl-btn--turn .turn-mode-label {
    font-size: 0.55rem;
    color: inherit;
    opacity: 0.8;
    letter-spacing: 0.01em;
}

.ctrl-btn--turn.active {
    border-color: #f0c040;
    background: rgba(240, 192, 64, 0.2);
    color: #f0c040;
}

/* Undo / Reset ユーティリティボタン行 */
.controls-util-row {
    display: flex;
    gap: 8px;
    width: 100%;
    justify-content: space-between;
    padding: 0 4px;
}

.ctrl-btn--util {
    flex: 1;
    height: 40px;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    border-color: rgba(122, 144, 144, 0.4);
    color: #7a9090;
}

.ctrl-btn--util:active {
    background: #2a3a40;
    color: #e8f0ec;
}

.ctrl-btn--reset {
    border-color: rgba(224, 80, 80, 0.3);
    color: #c06060;
}

.ctrl-btn--reset:active {
    background: #3a2020;
    color: #e05050;
}

/* ヒントテキスト（ボタン群全体の下・右寄せ） */
.turn-mode-hint-line {
    font-size: 0.60rem;
    color: #dddddd;
    text-align: right;
    width: 100%;
    padding-right: 4px;
    margin: 4px 0 0;
    line-height: 1.4;
}

.turn-mode-hint-line.active {
    color: #f0c040;
    font-weight: 600;
}

/* ── バトルアニメーション ────────────────────────────────── */

/* プレイヤー剣（ゼルダ式：隣セルに剣が突き出る） */
.sword-thrust {
    position: absolute;
    inset: 0;
    z-index: 10;
    pointer-events: none;
}

/* 剣本体：指定方向から突き出る光線 */
.sword-thrust::before {
    content: '';
    position: absolute;
    background: linear-gradient(var(--thrust-angle), transparent 0%, #80c8f0 30%, #ffffff 60%, #f2c14e 100%);
    border-radius: 2px;
    box-shadow: 0 0 6px rgba(240, 220, 120, 0.9);
    animation: sword-thrust-anim 0.2s ease-out forwards;
}

/* 向きごとに剣の開始位置・サイズを設定 */
.sword-thrust.dir-right {
    --thrust-angle: 90deg;
}

.sword-thrust.dir-right::before {
    left: 0;
    top: 50%;
    height: 4px;
    width: 100%;
    transform: translateY(-50%) scaleX(0);
    transform-origin: left center;
}

.sword-thrust.dir-left {
    --thrust-angle: 270deg;
}

.sword-thrust.dir-left::before {
    right: 0;
    left: auto;
    top: 50%;
    height: 4px;
    width: 100%;
    transform: translateY(-50%) scaleX(0);
    transform-origin: right center;
}

.sword-thrust.dir-down {
    --thrust-angle: 180deg;
}

.sword-thrust.dir-down::before {
    top: 0;
    left: 50%;
    width: 4px;
    height: 100%;
    transform: translateX(-50%) scaleY(0);
    transform-origin: top center;
}

.sword-thrust.dir-up {
    --thrust-angle: 0deg;
}

.sword-thrust.dir-up::before {
    bottom: 0;
    top: auto;
    left: 50%;
    width: 4px;
    height: 100%;
    transform: translateX(-50%) scaleY(0);
    transform-origin: bottom center;
}

@keyframes sword-thrust-anim {
    0% {
        opacity: 1;
        transform: translateY(-50%) scaleX(0);
    }

    40% {
        opacity: 1;
        transform: translateY(-50%) scaleX(1.1);
    }

    100% {
        opacity: 0;
        transform: translateY(-50%) scaleX(0.8);
    }
}

/* 上下方向の個別キーフレーム */
.sword-thrust.dir-down::before,
.sword-thrust.dir-up::before {
    animation-name: sword-thrust-anim-v;
}

@keyframes sword-thrust-anim-v {
    0% {
        opacity: 1;
        transform: translateX(-50%) scaleY(0);
    }

    40% {
        opacity: 1;
        transform: translateX(-50%) scaleY(1.1);
    }

    100% {
        opacity: 0;
        transform: translateX(-50%) scaleY(0.8);
    }
}

/* ダメージフラッシュ（被ダメージ） */
.damage-flash {
    position: absolute;
    inset: 0;
    background: rgba(232, 95, 92, 0.7);
    z-index: 8;
    animation: damage-flash 0.3s ease-out forwards;
    pointer-events: none;
    border-radius: 2px;
}

@keyframes damage-flash {
    0% {
        opacity: 1;
    }

    100% {
        opacity: 0;
    }
}

/* 敵の体当たりアニメーション */
@keyframes enemy-charge {
    0% {
        transform: translate(0, 0);
    }

    40% {
        transform: var(--charge-dir);
    }

    70% {
        transform: var(--charge-dir);
    }

    100% {
        transform: translate(0, 0);
    }
}

.enemy-charging {
    animation: enemy-charge 0.3s ease-in-out;
}

/* ダメージ数字ポップアップ */
.dmg-popup {
    position: absolute;
    top: 2px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.7rem;
    font-weight: 700;
    color: #f2c14e;
    text-shadow: 0 0 4px #000;
    z-index: 12;
    pointer-events: none;
    animation: dmg-rise 0.6s ease-out forwards;
    white-space: nowrap;
}

.dmg-popup.enemy-dmg {
    color: #ff6060;
}

.dmg-popup.player-dmg {
    color: #f0a020;
}

@keyframes dmg-rise {
    0% {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }

    100% {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
}

/* ── 魔王オーラ（DOM版）─────────────────────────────────────── */
@keyframes dark-lord-aura-ring {
    0% {
        transform: scale(0.85) rotate(0deg);
        opacity: 0.15;
    }

    50% {
        transform: scale(1.15) rotate(180deg);
        opacity: 0.30;
    }

    100% {
        transform: scale(0.85) rotate(360deg);
        opacity: 0.15;
    }
}

@keyframes dark-lord-aura-smoke {
    0%, 100% {
        transform: scaleX(1);
        opacity: 0.10;
    }

    50% {
        transform: scaleX(1.3);
        opacity: 0.22;
    }
}

.dark-lord-aura {
    position: absolute;
    inset: -8px;
    z-index: 1;
    pointer-events: none;
    border-radius: 50%;
    border: 2px solid #f0c040;
    animation: dark-lord-aura-ring 1.6s linear infinite;
    box-shadow: 0 0 12px 4px rgba(240, 192, 64, 0.5);
}

.dark-lord-aura-2 {
    position: absolute;
    inset: -14px;
    z-index: 0;
    pointer-events: none;
    border-radius: 50%;
    border: 1.5px solid rgba(240, 192, 64, 0.4);
    animation: dark-lord-aura-ring 2.2s linear infinite reverse;
    box-shadow: 0 0 18px 6px rgba(240, 192, 64, 0.25);
}

.dark-lord-aura-smoke {
    position: absolute;
    bottom: -4px;
    left: 10%;
    width: 80%;
    height: 8px;
    z-index: 0;
    pointer-events: none;
    border-radius: 50%;
    background: rgba(240, 192, 64, 0.35);
    animation: dark-lord-aura-smoke 1.2s ease-in-out infinite;
    filter: blur(3px);
}

/* ── 石がスイッチの上にある場合のグロー ─────────────────────── */
@keyframes stone-switch-glow {
    0%, 100% {
        filter: brightness(1) saturate(1) hue-rotate(0deg);
    }

    50% {
        filter: brightness(1.8) saturate(5) hue-rotate(80deg);
    }
}

.cell .sprite.stone-on-switch {
    animation: stone-switch-glow 1s ease-in-out infinite;
}

/* ── 鍵スプライト（小さめ・右上に配置） ─────────────────────── */
.cell .sprite.key-sprite {
    position: absolute;
    width: auto;
    height: 50%;
    max-width: 50%;
    top: 3%;
    right: 3%;
    left: auto;
    bottom: auto;
    z-index: 5;
    image-rendering: pixelated;
}

/* ── ドアグロー（鍵取得後に輝く） ─────────────────────────── */
@keyframes door-glow {
    0%, 100% {
        filter: brightness(1) drop-shadow(0 0 0px rgba(255, 200, 100, 0));
    }

    50% {
        filter: brightness(1.6) drop-shadow(0 0 8px rgba(255, 200, 100, 0.95));
    }
}

@keyframes door-open-anim {
    0% {
        transform: scaleX(1);
        opacity: 1;
    }

    60% {
        transform: scaleX(0.1);
        opacity: 0.6;
    }

    100% {
        transform: scaleX(0);
        opacity: 0;
    }
}

.cell .sprite.door-unlocked {
    animation: door-glow 0.8s ease-in-out infinite;
}

.cell .sprite.door-opening {
    animation: door-open-anim 0.35s ease-in forwards;
    transform-origin: left center;
}

/* ── サウンドダイアログ ──────────────────────────────────── */
.sound-dialog {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 600;
}

.sound-dialog.hidden {
    display: none;
}

.sound-dialog-box {
    background: #181d22;
    border: 2px solid #4fc3a0;
    border-radius: 14px;
    padding: 28px 32px;
    max-width: 300px;
    width: 90%;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

.sound-dialog-icon {
    font-size: 2.5rem;
    line-height: 1;
}

.sound-dialog-title {
    font-size: 1.3rem;
    font-weight: 800;
    color: #f0c040;
    letter-spacing: 0.05em;
    margin: 0;
}

.sound-dialog-desc {
    font-size: 0.9rem;
    color: #b0c8c0;
    margin: 0;
}

.sound-dialog-btns {
    display: flex;
    gap: 12px;
    width: 100%;
}

.sound-btn {
    flex: 1;
    padding: 10px 0;
    border-radius: 8px;
    font: inherit;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    border: 2px solid;
    transition: background 0.15s;
}

.sound-btn--on {
    border-color: #4fc3a0;
    background: rgba(79, 195, 160, 0.2);
    color: #4fc3a0;
}

.sound-btn--on:hover, .sound-btn--on:active {
    background: rgba(79, 195, 160, 0.4);
}

.sound-btn--off {
    border-color: #4a5560;
    background: rgba(74, 85, 96, 0.2);
    color: #7a9090;
}

.sound-btn--off:hover, .sound-btn--off:active {
    background: rgba(74, 85, 96, 0.4);
}

/* キーヒント（小） */
.key-hint-small {
    font-size: 0.65rem;
    color: #354047;
    text-align: center;
    margin-top: 4px;
}

/* Equip status */
.hud-equip {
    font-size: 0.72rem;
    color: #7a9090;
    text-align: center;
    min-height: 1.2em;
    padding: 2px 8px;
}

.hud-equip .equip-slot {
    display: inline-block;
    margin: 0 4px;
    padding: 1px 6px;
    border: 1px solid #2a3540;
    border-radius: 4px;
    background: #181d22;
    font-size: 0.7rem;
}

.hud-equip .equip-slot.weapon {
    color: #e05050;
    border-color: #5a2020;
}

.hud-equip .equip-slot.armor {
    color: #4fc3a0;
    border-color: #1a4040;
}

/* Item get dialog */
.item-dialog {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.item-dialog.hidden {
    display: none;
}

.item-dialog-box {
    background: #181d22;
    border: 2px solid #f0c040;
    border-radius: 10px;
    padding: 20px 28px;
    max-width: 280px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.item-dialog-title {
    font-size: 0.75rem;
    color: #7a9090;
    letter-spacing: 0.05em;
}

.item-dialog-name {
    font-size: 1.2rem;
    font-weight: 700;
    color: #f0c040;
}

.item-dialog-desc {
    font-size: 0.82rem;
    color: #b0c8c0;
    line-height: 1.5;
}

.item-dialog-btn {
    padding: 8px 20px;
    border: 1px solid #f0c040;
    background: rgba(240, 192, 64, 0.15);
    color: #f0c040;
    border-radius: 6px;
    font: inherit;
    cursor: pointer;
}

.item-dialog-btn:hover {
    background: rgba(240, 192, 64, 0.3);
}

/* Stage label */
.stage-label {
    font-size: 0.75rem;
    color: #7a9090;
    text-align: center;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

/* HUD row */
.hud {
    display: flex;
    gap: 12px;
    align-items: center;
    font-size: 0.78rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 6px;
}

.hud-hp {
    color: #e05050;
}

.hud-lv {
    color: #4fc3a0;
}

.hud-exp {
    color: #7a9090;
}

.hud-keys {
    color: #f2c14e;
}

/* Controls layout */
.controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
}

.controls-row {
    display: flex;
    gap: 4px;
}

.ctrl-btn {
    width: 52px;
    height: 52px;
    border: 1px solid #2a3540;
    background: #181d22;
    color: #e8f0ec;
    border-radius: 8px;
    font-size: 1.3rem;
    cursor: pointer;
    display: grid;
    place-items: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.ctrl-btn:active {
    background: #2a3a40;
}

/* Message overlay */
.message-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 100;
}

.message-overlay.hidden {
    display: none;
}

.overlay-text {
    font-size: 1.4rem;
    font-weight: 700;
    color: #f0c040;
    text-align: center;
}

.overlay-btn {
    padding: 8px 24px;
    border: 1px solid #4fc3a0;
    background: rgba(79, 195, 160, 0.15);
    color: #4fc3a0;
    border-radius: 6px;
    font: inherit;
    cursor: pointer;
}

.overlay-btn:hover {
    background: rgba(79, 195, 160, 0.3);
}

/* ── エンディングオーバーレイ ────────────────────────────── */
.ending-overlay {
    position: fixed;
    inset: 0;
    background: #000;
    z-index: 500;
    display: flex;
    flex-direction: column;
}

.ending-overlay.hidden {
    display: none;
}

/* フェーズ1 */
.ending-phase1 {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* ステージをDOMボードで表示（ゲーム画面と同一の見た目） */
.ending-stage-board {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0.8;
    pointer-events: none;
    transition: opacity 0.8s ease;
}

/* スタッフロール（中央・全幅・ステージの上に重ねる） */
.ending-scroll-wrap {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 420px;
    max-width: 90%;
    height: 100%;
    overflow: hidden;
    z-index: 20;
    /* 上下フェードマスク */
    mask-image: linear-gradient(to bottom, transparent 0%, black 12%, black 88%, transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 12%, black 88%, transparent 100%);
    /* 半透明の暗い背景（薄め） */
    background: rgba(0, 0, 0, 0.30);
}

.ending-scroll {
    position: absolute;
    bottom: -100%;
    width: 100%;
    padding: 20px 32px;
    text-align: center;
    color: #e8f0ec;
    line-height: 2;
    animation: ending-scroll-up 60s linear forwards;
}

@keyframes ending-scroll-up {
    0% {
        transform: translateY(0);
    }

    100% {
        transform: translateY(-200%);
    }
}

.ending-scroll .scroll-title {
    font-size: 1.6rem;
    font-weight: 900;
    color: #f0c040;
    letter-spacing: 0.1em;
    margin: 40px 0 60px;
    text-shadow: 0 0 20px rgba(240, 192, 64, 0.8);
}

.ending-scroll .scroll-role {
    font-size: 0.65rem;
    color: #7a9090;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin-top: 28px;
}

.ending-scroll .scroll-name {
    font-size: 1rem;
    color: #e8f0ec;
    font-weight: 600;
    margin-bottom: 4px;
}

.ending-scroll .scroll-divider {
    width: 40px;
    height: 1px;
    background: #2e3a42;
    margin: 20px auto;
}

/* フェーズ2 */
.ending-phase2 {
    position: absolute;
    inset: 0;
    background: #0a0a14;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 40px;
    animation: ending-phase2-fadein 2s ease forwards;
}

.ending-phase2.hidden {
    display: none;
}

@keyframes ending-phase2-fadein {
    0% {
        opacity: 0;
    }

    100% {
        opacity: 1;
    }
}

.ending-happy-scene {
    display: flex;
    gap: 48px;
    align-items: flex-end;
}

.ending-big-sprite {
    image-rendering: pixelated;
    width: 96px;
    height: 96px;
    filter: drop-shadow(0 0 16px rgba(240, 192, 64, 0.6));
}

.ending-the-end {
    font-size: 3rem;
    font-weight: 900;
    color: #f0c040;
    letter-spacing: 0.2em;
    text-shadow: 0 0 30px rgba(240, 192, 64, 0.9);
    animation: ending-theend-glow 2s ease-in-out infinite;
}

@keyframes ending-theend-glow {
    0%, 100% {
        text-shadow: 0 0 20px rgba(240, 192, 64, 0.6);
    }

    50% {
        text-shadow: 0 0 40px rgba(240, 192, 64, 1.0), 0 0 80px rgba(240, 192, 64, 0.4);
    }
}