/* WINK — 전투 화면 / 결과 / 설정 / 디버그 스타일 */

:root {
    --fx-scale: 1;
    --shake-scale: .6;
    --tile-hidden: #24345a;
    --tile-hidden-top: #35496f;
    --tile-revealed: #0b1426;
}

[hidden] {
    display: none !important;
}

body.in-battle .app-shell {
    display: none;
}

/* ------------------------------------------------------------ 로비 추가분 */

.record-block {
    margin-top: 12px;
    padding: 11px 12px;
    border-radius: 11px;
    background: #060b17aa;
    color: var(--muted);
    font-size: .74rem;
    line-height: 1.65;
}

.record-block b {
    color: var(--cyan);
    font-size: .68rem;
    letter-spacing: .1em;
}

.record-block span {
    color: #8fa0c2;
    font-size: .68rem;
}

.loadout-list {
    margin-top: 12px;
}

.loadout-row {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    color: var(--muted);
    font-size: .78rem;
}

.loadout-row b {
    color: var(--text);
}

.loadout-icons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #253651;
}

.loadout-icons img,
.loadout-icons i {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border: 1px solid #2f4266;
    border-radius: 8px;
    background: #0a1224;
    object-fit: contain;
    color: var(--cyan);
    font-style: normal;
}

.node-lock,
.node-crown {
    position: absolute;
    right: -6px;
    bottom: -4px;
    font-size: .8rem;
    text-shadow: 0 2px 4px #000;
}

.node-crown {
    top: -22px;
    right: auto;
    left: 50%;
    bottom: auto;
    translate: -50% 0;
    color: var(--amber);
}

.stage-node.just-unlocked {
    animation: unlock-pop 2.2s ease;
}

@keyframes unlock-pop {
    0% { scale: .6; filter: brightness(3); }
    30% { scale: 1.3; }
    100% { scale: 1; }
}

/* ------------------------------------------------------------ 전투 셸 */

.battle-screen {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    color: var(--text);
    background: #03060f;
    font-family: "Segoe UI", "Malgun Gothic", system-ui, sans-serif;
    overflow: hidden;
}

.battle-bg {
    position: absolute;
    inset: 0;
    z-index: 0;
    background: url("assets/backgrounds/battle-arena.png") center / cover no-repeat;
}

.battle-bg::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, #020617cc, #020617a8 45%, #020617e0);
}

.battle-screen.boss-fight .battle-bg::after {
    background: linear-gradient(180deg, #1a0408cc, #020617a8 45%, #12030ae8);
}

.battle-screen > *:not(.battle-bg) {
    position: relative;
    z-index: 2;
}

.battle-screen.shaking {
    animation: battle-shake .26s ease;
}

@keyframes battle-shake {
    0%, 100% { translate: 0 0; }
    20% { translate: calc(-7px * var(--shake-power, 1)) calc(3px * var(--shake-power, 1)); }
    50% { translate: calc(6px * var(--shake-power, 1)) calc(-4px * var(--shake-power, 1)); }
    80% { translate: calc(-3px * var(--shake-power, 1)) 0; }
}

/* 점멸 효과 줄이기 — 반복 점멸과 화면 흔들림만 없애고 색·형태 구분은 그대로 남긴다 (07 문서 §8). */
html.reduce-flash .battle-screen.shaking {
    animation: none;
}

html.reduce-flash .tile.hint {
    animation: none;
    box-shadow: 0 0 0 2px var(--amber);
}

html.reduce-flash .tile.wrong,
html.reduce-flash .tile.danger,
html.reduce-flash .tile.pop {
    animation: none;
}

html.reduce-flash .tile.chord-deny {
    animation: none;
    box-shadow: inset 0 0 0 2px var(--red);
}

.battle-screen.paused::after {
    content: "PAUSED · Esc";
    position: absolute;
    inset: 0;
    z-index: 30;
    display: grid;
    place-items: center;
    background: #020617cc;
    font-size: 1.6rem;
    letter-spacing: .3em;
}

/* ------------------------------------------------------------ 상단 HUD */

.battle-top {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: start;
    gap: 18px;
    padding: 12px clamp(14px, 2.6vw, 34px);
    background: linear-gradient(180deg, #050b18e6, #050b1800);
}

.actor-block {
    min-width: 0;
}

.actor-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 6px;
    font-size: .78rem;
}

.actor-head strong {
    letter-spacing: .12em;
}

.actor-head span {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.actor-block.enemy .actor-head {
    flex-direction: row-reverse;
}

.hp-bar {
    height: 13px;
    overflow: hidden;
    border: 1px solid #3b4f74;
    border-radius: 99px;
    background: #0a1120;
}

.hp-bar i {
    display: block;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #3fd39a, #62e6ad);
    box-shadow: 0 0 12px #62e6ad66;
    transition: width .35s ease;
}

.hp-bar.enemy i {
    background: linear-gradient(90deg, #ff6a4d, #ffb03a);
    box-shadow: 0 0 12px #ff782c66;
}

.status-row {
    display: flex;
    gap: 6px;
    margin-top: 7px;
    min-height: 26px;
}

.actor-block.enemy .status-row {
    justify-content: flex-end;
}

.status-chip {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 7px;
    border: 1px solid #3a5079;
    border-radius: 7px;
    background: #0b1426d9;
    font-size: .68rem;
}

.status-chip img {
    width: 18px;
    height: 18px;
    object-fit: contain;
}

.status-chip i {
    font-style: normal;
    color: var(--cyan);
}

.round-block {
    display: grid;
    justify-items: center;
    gap: 2px;
    min-width: 116px;
    padding: 8px 14px;
    border: 1px solid #34476b;
    border-radius: 12px;
    background: #0a1120d9;
}

.round-block small {
    color: var(--muted);
    font-size: .6rem;
    letter-spacing: .2em;
}

.round-block strong {
    font-size: 1.5rem;
    line-height: 1;
}

.phase-tag {
    color: var(--amber);
    font-size: .58rem;
    letter-spacing: .16em;
}

.ghost-button {
    margin-top: 4px;
    padding: 4px 10px;
    border: 1px solid #3b4f74;
    border-radius: 7px;
    background: #0c1529;
    color: var(--muted);
    font-size: .66rem;
    cursor: pointer;
}

/* ------------------------------------------------------------ 본문 3분할 */

.battle-body {
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(190px, 250px) minmax(0, 1fr) minmax(210px, 300px);
    align-items: center;
    gap: clamp(10px, 2vw, 28px);
    padding: 0 clamp(14px, 2.6vw, 34px);
}

.gauge-panel {
    display: grid;
    gap: 10px;
    align-content: center;
}

.gauge-card {
    padding: 11px 13px;
    border: 1px solid #2b3d5e;
    border-radius: 13px;
    background: #08101fd9;
}

.gauge-card small {
    display: flex;
    justify-content: space-between;
    color: var(--amber);
    font-size: .6rem;
    letter-spacing: .15em;
}

.gauge-card small i {
    color: #5f7194;
    font-style: normal;
}

.bomb-gauge,
.item-slots {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin-top: 9px;
    min-height: 44px;
}

.gauge-empty {
    margin: 4px 0 0;
    color: #64769a;
    font-size: .68rem;
    line-height: 1.4;
}

.gauge-slot,
.item-slot {
    position: relative;
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid #35496f;
    border-radius: 10px;
    background: #0c162b;
}

.gauge-slot img,
.item-slot img {
    width: 78%;
    height: 78%;
    object-fit: contain;
}

.gauge-slot b,
.item-slot b {
    position: absolute;
    right: -3px;
    bottom: -5px;
    padding: 1px 5px;
    border: 1px solid #4a5f88;
    border-radius: 6px;
    background: #060c18;
    font-size: .62rem;
}

.gauge-slot.bomb-critical { border-color: #ff7a45; box-shadow: 0 0 12px #ff7a4555; }
.gauge-slot.bomb-freeze { border-color: #63d8ff; box-shadow: 0 0 12px #63d8ff55; }
.gauge-slot.bomb-pierce { border-color: #ffd166; box-shadow: 0 0 12px #ffd16655; }

.item-slot {
    cursor: pointer;
    transition: scale .15s ease;
}

.item-slot i {
    color: var(--cyan);
    font-size: 1.3rem;
    font-style: normal;
}

.item-slot:hover:not(:disabled) {
    scale: 1.06;
}

.item-slot:disabled {
    opacity: .35;
    cursor: not-allowed;
}

.combo-text {
    display: block;
    margin-top: 7px;
    font-size: 1.22rem;
    font-variant-numeric: tabular-nums;
}

.combo-text.hot {
    color: var(--amber);
    text-shadow: 0 0 14px #ffbd4288;
}

.combo-track {
    height: 4px;
    margin-top: 7px;
    overflow: hidden;
    border-radius: 99px;
    background: #22314e;
}

.combo-track i {
    display: block;
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--cyan), var(--amber));
    transition: width .2s ease;
}

.damage-card strong {
    display: block;
    margin-top: 5px;
    color: var(--amber);
    font-size: 1.85rem;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 0 18px #ff9b2f55;
}

.damage-card span {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: .68rem;
}

/* ------------------------------------------------------------ 보드 */

/* 보드는 높이에 맞춘 정사각형으로 잡아 세로로 넘치지 않게 한다.
   타이머는 보드 바로 위에 둔다 — 남은 시간과 보드를 한 시선에 담기 위한 배치다. */
.board-stage {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    justify-items: center;
    align-content: stretch;
    height: 100%;
    min-height: 0;
    gap: 8px;
}

.board-wrap {
    position: relative;
    height: 100%;
    aspect-ratio: 1;
    max-width: 100%;
    margin: 0 auto;
}

/* board-frame.png의 투명한 구멍은 이미지 기준 18% 안쪽에 있다 (측정값 656/1024). */
.board-grid {
    position: absolute;
    inset: 18%;
    display: grid;
    grid-template-columns: repeat(var(--cols, 8), 1fr);
    grid-auto-rows: 1fr; /* 행 높이를 균등 분배해 타일을 정사각형으로 만든다 */
    gap: clamp(2px, .5vh, 5px);
    padding: 6px;
    border-radius: 10px;
    background: #050a15cc;
    /* 보드 안에서만 브라우저 기본 동작을 막는다 (12 문서 §11) */
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    transition: box-shadow .15s ease;
}

/* BOMB 모드 피드백 — 색 외에 외곽선과 폭탄 실루엣을 함께 쓴다 (12 문서 §8) */
html.bomb-mode .board-grid {
    box-shadow: 0 0 0 2px var(--orange), 0 0 26px #ff782c55;
}

.board-frame {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
    filter: drop-shadow(0 12px 22px #000a);
}

.hide-board-frame .board-frame,
.board-wrap.big-board .board-frame {
    display: none;
}

.hide-board-frame .board-grid,
.hide-board-frame .board-veil,
.board-wrap.big-board .board-grid,
.board-wrap.big-board .board-veil {
    inset: 0;
}

/* 타일이 많아지면 간격과 모서리를 줄여 숫자에 쓸 면적을 남긴다. */
.board-wrap.big-board .board-grid {
    gap: clamp(1px, .35vh, 3px);
    padding: 4px;
}

.board-wrap.big-board .tile {
    border-radius: 4px;
}

.tile {
    position: relative;
    display: grid;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: linear-gradient(180deg, var(--tile-hidden-top), var(--tile-hidden));
    box-shadow: inset 0 -2px 0 #16223c, inset 0 1px 0 #ffffff22;
    color: var(--text);
    cursor: pointer;
    font-weight: 900;
    font-size: clamp(.85rem, 2.1vh, 1.35rem);
    /* 배경은 전환하지 않는다 — chord 미리보기처럼 즉시 바뀌어야 하는 상태가 있다. */
    transition: filter .12s ease;
}

.tile:hover:not(.revealed):not(.marked):not(.blocked) {
    filter: brightness(1.35);
}

.tile:focus-visible {
    outline: 2px solid var(--cyan);
    outline-offset: 1px;
}

.tile .tile-face {
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.tile.revealed {
    background: var(--tile-revealed);
    box-shadow: inset 0 0 0 1px #1c2b47;
    cursor: default;
}

.tile.revealed.covered {
    background: linear-gradient(180deg, #2f5d3f, #17361f);
    color: #a9e6bd;
}

.tile.marked img {
    width: 84%;
    height: 84%;
    object-fit: contain;
}

.tile.marked {
    background: radial-gradient(circle, #2b1c12, #120a06);
    box-shadow: inset 0 0 0 1px #6c4a26;
    cursor: default;
}

.tile.bomb-critical { box-shadow: inset 0 0 0 1px #ff7a45, 0 0 12px #ff7a4544; }
.tile.bomb-freeze { box-shadow: inset 0 0 0 1px #63d8ff, 0 0 12px #63d8ff44; }
.tile.bomb-pierce { box-shadow: inset 0 0 0 1px #ffd166, 0 0 12px #ffd16644; }

.tile.blocked {
    background: repeating-linear-gradient(45deg, #1b2438, #1b2438 5px, #141c2d 5px, #141c2d 10px);
    color: #7688aa;
    cursor: not-allowed;
}

.tile.block-seal { color: #c69bff; box-shadow: inset 0 0 0 1px #6b46a8; }
.tile.block-lock { color: #9aa8c4; box-shadow: inset 0 0 0 1px #495b7d; }
.tile.block-scorch { color: #ff9060; background: repeating-linear-gradient(45deg, #3a1408, #3a1408 5px, #240d05 5px, #240d05 10px); }

.tile.n1 { color: #6fb4ff; }
.tile.n2 { color: #66e5a4; }
.tile.n3 { color: #ff8a7a; }
.tile.n4 { color: #c39bff; }
.tile.n5 { color: #ffc857; }
.tile.n6 { color: #5fe3e3; }
.tile.n7 { color: #ff9ed0; }
.tile.n8 { color: #d6dff0; }

.number-shapes .tile.revealed .tile-face::after {
    display: block;
    font-size: .5em;
    line-height: 1;
    opacity: .85;
}

.number-shapes .tile.n1 .tile-face::after { content: "•"; }
.number-shapes .tile.n2 .tile-face::after { content: "••"; }
.number-shapes .tile.n3 .tile-face::after { content: "▲"; }
.number-shapes .tile.n4 .tile-face::after { content: "■"; }
.number-shapes .tile.n5 .tile-face::after { content: "★"; }
.number-shapes .tile.n6 .tile-face::after { content: "✦"; }
.number-shapes .tile.n7 .tile-face::after { content: "✚"; }
.number-shapes .tile.n8 .tile-face::after { content: "✸"; }

.tile.hint {
    animation: hint-pulse .6s ease-in-out infinite alternate;
}

@keyframes hint-pulse {
    from { box-shadow: 0 0 0 2px #ffbd4288; }
    to { box-shadow: 0 0 16px 4px #ffbd42; }
}

.tile.wrong,
.tile.danger {
    animation: tile-wrong .28s ease 2;
    background: linear-gradient(180deg, #7a2020, #46110f);
}

.tile.wrong::after {
    content: "✕";
    position: absolute;
    color: #ff6b5b;
    font-size: 1.1em;
}

@keyframes tile-wrong {
    0%, 100% { translate: 0 0; }
    50% { translate: 3px 0; }
}

/* 양쪽 클릭(chord) — 열 수 있는 인접 칸을 미리 보여준다 */
/* 눌린 것처럼 평평하게 만들고 밝기를 올려 기본 타일과 확실히 구분한다. */
.tile.chord-preview {
    background: #6d8ac4;
    box-shadow: inset 0 0 0 2px #cfe2ff, 0 0 12px #7fb4ff66;
}

.tile.chord-preview.ready {
    background: #4fc08d;
    box-shadow: inset 0 0 0 2px #d6ffe9, 0 0 14px #62e6ad88;
}

.tile.chord-origin {
    box-shadow: inset 0 0 0 3px #9fc6ff;
}

.tile.chord-origin.ready {
    box-shadow: inset 0 0 0 3px #62e6ad;
}

.tile.chord-deny {
    animation: chord-deny .3s ease;
}

@keyframes chord-deny {
    50% { box-shadow: inset 0 0 0 2px var(--red); }
}

.tile.preview-reveal {
    filter: brightness(1.45);
}

.tile.preview-mark {
    box-shadow: inset 0 0 0 2px var(--orange);
}

.tile.preview-mark::before {
    content: "";
    position: absolute;
    inset: 12%;
    background: url("assets/icons/bombs/normal-bomb.png") center / contain no-repeat;
    opacity: .6;
    pointer-events: none;
}

.tile.pop {
    animation: tile-pop .3s ease;
}

@keyframes tile-pop {
    50% { scale: 1.22; filter: brightness(1.6); }
}

.tile.scorch-warn {
    animation: tile-pop .4s ease;
}

.board-grid.flicker-hidden .tile.revealed .tile-face {
    opacity: 0;
}

.board-grid.flicker-soft .tile.revealed .tile-face {
    opacity: .55;
}

.board-grid.debug-xray .tile.hidden.debug-bomb {
    background: linear-gradient(180deg, #6b2f8c, #35164a);
}

.board-meta {
    display: flex;
    justify-content: center;
    gap: 20px;
    color: var(--muted);
    font-size: .7rem;
}

.board-help {
    margin: 0;
    color: #5a6c90;
    font-size: .66rem;
}

/* ------------------------------------------------------------ 몬스터 */

.enemy-stage {
    display: grid;
    justify-items: center;
    gap: 12px;
}

.intent-card {
    width: 100%;
    padding: 11px 13px;
    border: 1px solid #4a3a6b;
    border-radius: 13px;
    background: #120c22d9;
    text-align: center;
    transition: scale .2s ease, box-shadow .2s ease;
}

.intent-card[data-kind="attack"] { border-color: #7a3b3b; background: #1d0d10d9; }
.intent-card[data-kind="guard"] { border-color: #3b5f7a; background: #0b1a24d9; }
.intent-card[data-kind="disrupt"] { border-color: #6b4a2a; background: #211508d9; }

.intent-card.firing {
    scale: 1.06;
    box-shadow: 0 0 26px #ff782c66;
}

.intent-card small {
    color: var(--muted);
    font-size: .58rem;
    letter-spacing: .18em;
}

.intent-main {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 5px 0 2px;
}

.intent-main i {
    font-size: 1.1rem;
    font-style: normal;
}

.intent-main strong {
    font-size: 1rem;
}

.intent-card span {
    color: var(--amber);
    font-size: .76rem;
}

.enemy-portrait {
    position: relative;
    width: 100%;
    height: clamp(220px, 40vh, 420px);
    display: grid;
    place-items: center;
    transition: filter .12s ease, translate .12s ease;
}

.enemy-portrait::after {
    content: "";
    position: absolute;
    left: 18%;
    right: 18%;
    bottom: 4%;
    height: 22px;
    border-radius: 50%;
    background: #02040ab0;
    filter: blur(9px);
}

.enemy-portrait img {
    position: relative;
    z-index: 2;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 18px 14px #000a);
}

.enemy-portrait.hit {
    filter: brightness(2.4) saturate(.3);
    translate: 8px 0;
}

/* ------------------------------------------------------------ 하단 */

.battle-bottom {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 18px;
    padding: 10px clamp(14px, 2.6vw, 34px) 16px;
    background: linear-gradient(0deg, #050b18e6, #050b1800);
}

.bottom-left {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-self: start;
}

.bottom-left .ghost-button {
    padding: 9px 16px;
}

/* ------------------------------------------------------------ 터치 조작 */

.touch-controls {
    display: none;
}

html[data-input-mode="touch"] .touch-controls {
    display: flex;
}

.bomb-button {
    flex-direction: column;
    align-items: center;
    gap: 1px;
    min-width: 104px;
    min-height: 76px;
    padding: 8px 14px;
    border: 1px solid #7a5a2a;
    border-radius: 14px;
    background: linear-gradient(180deg, #2a1f10, #150d05);
    color: #ffcf8a;
    cursor: pointer;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.bomb-button img {
    width: 26px;
    height: 26px;
    object-fit: contain;
}

.bomb-button span {
    font-size: .78rem;
    font-weight: 900;
    letter-spacing: .12em;
}

.bomb-button small {
    color: #b9946a;
    font-size: .6rem;
}

.bomb-button.active {
    border-color: var(--amber);
    background: linear-gradient(180deg, #ffb43b, #d85a1c);
    color: #1a0b03;
    box-shadow: 0 0 22px #ff782c88;
}

.bomb-button.active small {
    color: #4a2a08;
}

.bomb-button.locked::after {
    content: "🔒";
    position: absolute;
    top: 4px;
    right: 8px;
    font-size: .7rem;
}

.bomb-button {
    position: relative;
}

/* 좌우 반전 배치 */
html.swap-touch-side .battle-bottom {
    direction: rtl;
}

html.swap-touch-side .battle-bottom > * {
    direction: ltr;
}

/* ------------------------------------------------------------ 공격 타이머 (보드 위) */

.timer-block {
    width: 100%;
    max-width: 520px;
    display: grid;
    gap: 5px;
}

.timer-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
}

.timer-head small {
    color: var(--muted);
    font-size: .58rem;
    letter-spacing: .18em;
}

.timer-head strong {
    font-size: 1.5rem;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.timer-bar {
    height: 12px;
    overflow: hidden;
    border: 1px solid #3b4f74;
    border-radius: 99px;
    background: #0a1120;
}

.timer-bar i {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 99px;
    background: linear-gradient(90deg, #2ea8d8, var(--cyan));
    box-shadow: 0 0 12px #4dd9ff66;
}

/* 임박 — 색·굵기·박동·보드 테두리를 한꺼번에 바꿔 놓치지 않게 한다. */
.timer-block.urgent .timer-head strong {
    color: var(--red);
    font-size: 2rem;
    animation: timer-pulse .5s ease-in-out infinite alternate;
}

.timer-block.urgent .timer-bar {
    height: 16px;
    border-color: var(--red);
}

.timer-block.urgent .timer-bar i {
    background: linear-gradient(90deg, #c02b1d, var(--red));
    box-shadow: 0 0 16px #ff4d3daa;
}

@keyframes timer-pulse {
    to { scale: 1.1; }
}

/* 남은 초를 보드 위에 한 번씩 띄운다. 가장 집중해야 할 3초라서
   숫자를 읽는 데 방해되지 않도록 작게, 옅게, 짧게 스친다. */
.urgent-count {
    position: absolute;
    inset: 0;
    z-index: 4;
    display: grid;
    place-items: center;
    color: var(--red);
    font-size: clamp(3rem, 11vh, 6rem);
    font-weight: 1000;
    text-shadow: 0 0 30px #ff4d3daa, 0 4px 14px #000;
    opacity: 0;
    pointer-events: none;
}

.urgent-count.show {
    animation: urgent-count .65s ease-out forwards;
}

@keyframes urgent-count {
    0% { opacity: 0; scale: 1.4; }
    20% { opacity: .3; scale: 1; }
    100% { opacity: 0; scale: .95; }
}

.board-stage.urgent .board-grid {
    box-shadow: 0 0 0 2px var(--red), 0 0 32px #ff4d3d66;
    animation: board-urgent .5s ease-in-out infinite alternate;
}

@keyframes board-urgent {
    to { box-shadow: 0 0 0 3px var(--red), 0 0 46px #ff4d3daa; }
}

/* 점멸 효과 줄이기 — 박동만 끄고 색과 크기 차이는 남긴다. */
html.reduce-flash .timer-block.urgent .timer-head strong,
html.reduce-flash .board-stage.urgent .board-grid {
    animation: none;
}

html.reduce-flash .urgent-count.show {
    animation: none;
    opacity: .4;
}

/* ------------------------------------------------------------ 보드 활성 / 비활성 */

/* 공격 페이즈가 아니면 보드를 눌러도 반응하지 않는다는 것을 색으로 먼저 알린다. */
.board-veil {
    position: absolute;
    inset: 18%;
    z-index: 3;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: #050a15b3;
    opacity: 0;
    pointer-events: none;
}

.board-veil span {
    padding: 7px 18px;
    border: 1px solid #46597d;
    border-radius: 99px;
    background: #0a1120e6;
    color: var(--muted);
    font-size: .7rem;
    letter-spacing: .22em;
}

/* 전환 없이 즉시 바꾼다. 눌러도 되는지 아닌지는 흐릿한 중간 상태가 없어야 한다. */
.board-wrap.inactive .board-veil {
    opacity: 1;
}

.board-wrap.inactive .board-grid {
    filter: saturate(.35) brightness(.72);
    pointer-events: none;
}

.board-wrap.inactive .tile,
.board-wrap.ready .tile {
    cursor: default;
}

/* 카운트 중 — 다음 보드를 미리 읽어야 하므로 가리지 않고 입력만 막는다. */
.board-wrap.ready .board-grid {
    pointer-events: none;
    box-shadow: 0 0 0 2px var(--amber), 0 0 26px #ffbd4244;
}

.ready-count {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: grid;
    place-items: center;
    color: var(--amber);
    font-size: clamp(4rem, 16vh, 8rem);
    font-weight: 1000;
    letter-spacing: .06em;
    text-shadow: 0 0 36px #ffbd42aa, 0 5px 16px #000;
    opacity: 0;
    pointer-events: none;
}

.ready-count.show {
    animation: ready-count .62s ease-out forwards;
}

@keyframes ready-count {
    0% { opacity: 0; scale: 1.45; }
    22% { opacity: .82; scale: 1; }
    100% { opacity: 0; scale: .96; }
}

html.reduce-flash .ready-count.show {
    animation: none;
    opacity: .7;
}

.attack-button {
    justify-self: end;
    min-width: 210px;
    padding: 14px 22px;
    border: 1px solid #ffce69;
    border-radius: 13px;
    background: linear-gradient(180deg, #ffb43b, #d85a1c);
    color: #1a0b03;
    box-shadow: 0 10px 26px #ff782c55, inset 0 1px #fff2b5;
    cursor: pointer;
    font-weight: 1000;
}

.attack-button span,
.attack-button small {
    display: block;
}

.attack-button span {
    font-size: 1.05rem;
    letter-spacing: .18em;
}

.attack-button small {
    margin-top: 2px;
    font-size: .7rem;
}

.attack-button:disabled {
    border-color: #50596a;
    background: #232a36;
    color: #7e899c;
    box-shadow: none;
    cursor: not-allowed;
}

/* ------------------------------------------------------------ 연출 레이어 */

.fx-layer {
    position: fixed;
    inset: 0;
    z-index: 90;
    pointer-events: none;
}

.projectile {
    position: absolute;
    width: 44px;
    height: 44px;
    object-fit: contain;
    filter: drop-shadow(0 0 10px #ffbd4288);
}

.float-text {
    position: absolute;
    translate: -50% -50%;
    color: var(--text);
    font-size: 1.5rem;
    font-weight: 1000;
    text-shadow: 0 3px 8px #000;
    animation: float-up .9s ease forwards;
}

.float-text.damage { color: #ffd166; }
.float-text.crit { color: #ff7a45; font-size: 2rem; }
.float-text.warn { color: #ff6b5b; }
.float-text.buff { color: var(--cyan); font-size: 1.1rem; }

@keyframes float-up {
    0% { opacity: 0; translate: -50% -20%; }
    20% { opacity: 1; }
    100% { opacity: 0; translate: -50% -170%; }
}

.battle-banner {
    position: absolute;
    z-index: 25;
    left: 50%;
    top: 26%;
    display: grid;
    justify-items: center;
    gap: 3px;
    translate: -50% 0;
    padding: 12px 30px;
    border: 1px solid #4d6591;
    border-radius: 13px;
    background: #060d1ce8;
    opacity: 0;
    pointer-events: none;
    text-align: center;
}

.battle-banner strong {
    font-size: 1.3rem;
    letter-spacing: .16em;
}

.battle-banner span {
    color: var(--muted);
    font-size: .78rem;
}

.battle-banner.show {
    animation: banner-in 1.4s ease forwards;
}

@keyframes banner-in {
    0% { opacity: 0; scale: .9; }
    15%, 75% { opacity: 1; scale: 1; }
    100% { opacity: 0; scale: 1.02; }
}

/* ------------------------------------------------------------ 결과 화면 */

.result-screen,
.overlay-screen {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: grid;
    place-items: center;
    padding: 20px;
    background: #02040bd9;
    backdrop-filter: blur(5px);
}

.result-card,
.overlay-card {
    width: min(520px, 100%);
    max-height: 92vh;
    overflow-y: auto;
    padding: 24px;
    border: 1px solid var(--panel-border);
    border-radius: 20px;
    background: linear-gradient(160deg, #101a30f5, #070c19f8);
    box-shadow: 0 30px 60px #000c;
}

.result-kicker {
    color: var(--cyan);
    font-size: .68rem;
    font-weight: 900;
    letter-spacing: .3em;
}

.result-screen[data-outcome="defeat"] .result-kicker {
    color: var(--red);
}

.result-card h2 {
    margin: 6px 0 10px;
    font-size: 1.5rem;
}

.result-stars {
    margin-bottom: 14px;
    color: var(--amber);
    font-size: 1.6rem;
    letter-spacing: .12em;
}

.result-stats {
    display: grid;
    gap: 4px;
    margin: 0 0 14px;
    padding: 14px;
    list-style: none;
    border-radius: 12px;
    background: #060b17aa;
}

.result-stats li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: .82rem;
}

.result-stats span {
    color: var(--muted);
}

.result-hint {
    margin: 0 0 14px;
    padding: 12px 14px;
    border-left: 3px solid var(--amber);
    border-radius: 0 10px 10px 0;
    background: #ffbd420f;
    color: #e2e9f7;
    font-size: .8rem;
    line-height: 1.6;
}

.result-rewards {
    display: grid;
    gap: 8px;
    margin-bottom: 16px;
}

.star-goals {
    display: grid;
    gap: 3px;
    color: var(--muted);
    font-size: .75rem;
}

.star-goals .goal.done {
    color: var(--amber);
}

.reward-chip {
    padding: 9px 12px;
    border: 1px solid #2f4a6e;
    border-radius: 10px;
    background: #0b192e;
    color: var(--cyan);
    font-size: .8rem;
}

.reward-chip.unlock {
    border-color: var(--amber);
    color: var(--amber);
}

.result-actions {
    display: grid;
    gap: 8px;
}

.result-actions .hunt-button,
.result-actions .secondary-button {
    margin-top: 0;
}

/* ------------------------------------------------------------ 설정 */

.overlay-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.overlay-head h2 {
    margin: 0;
    font-size: 1.25rem;
}

.setting-row {
    display: grid;
    grid-template-columns: 1fr 150px;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid #1e2b45;
    font-size: .85rem;
}

.setting-row.toggle {
    grid-template-columns: 1fr auto;
}

.setting-row select,
.setting-row input[type="range"] {
    width: 100%;
}

.setting-row select {
    padding: 7px 9px;
    border: 1px solid #3b4f74;
    border-radius: 8px;
    background: #0c1529;
    color: var(--text);
}

.setting-row input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--cyan);
}

.setting-row input[type="range"] {
    accent-color: var(--cyan);
}

.overlay-actions {
    display: grid;
    gap: 8px;
    margin-top: 18px;
}

.overlay-actions .secondary-button {
    margin-top: 0;
}

.overlay-note {
    margin: 14px 0 0;
    color: var(--muted);
    font-size: .72rem;
}

.overlay-note b {
    color: var(--amber);
}

/* ------------------------------------------------------------ 디버그 */

.debug-panel {
    position: fixed;
    z-index: 95;
    right: 12px;
    top: 12px;
    width: min(430px, 92vw);
    max-height: 88vh;
    overflow-y: auto;
    padding: 14px;
    border: 1px solid #3d5578;
    border-radius: 13px;
    background: #050a14f5;
    box-shadow: 0 20px 40px #000c;
    font-size: .74rem;
}

.debug-panel header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    color: var(--amber);
    letter-spacing: .18em;
}

.debug-panel header button {
    border: 0;
    background: none;
    color: var(--muted);
    cursor: pointer;
}

.debug-info {
    display: grid;
    gap: 4px;
    margin-bottom: 10px;
}

.debug-info > div {
    display: grid;
    grid-template-columns: 74px 1fr;
    gap: 8px;
}

.debug-info span {
    color: #5f7194;
    font-size: .64rem;
    letter-spacing: .1em;
}

.debug-info b {
    color: #cfdcf2;
    font-weight: 500;
    word-break: break-all;
}

.debug-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

.debug-buttons button {
    padding: 6px 10px;
    border: 1px solid #3b4f74;
    border-radius: 7px;
    background: #101c33;
    color: #c8d6ee;
    cursor: pointer;
    font-size: .68rem;
}

.debug-buttons button:hover {
    background: #17263f;
}

.debug-output {
    margin: 0 0 8px;
    padding: 9px;
    max-height: 150px;
    overflow: auto;
    border-radius: 8px;
    background: #01040a;
    color: #86d0a5;
    font-family: Consolas, "Courier New", monospace;
    font-size: .64rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
}

.debug-output.tall {
    max-height: 220px;
    color: #9fb6d8;
}

/* ------------------------------------------------------------ 반응형 */

@media (max-width: 1180px) {
    .battle-body {
        grid-template-columns: minmax(170px, 220px) minmax(0, 1fr) minmax(180px, 240px);
    }

}

/* 모바일 전투 화면 — 몬스터 20~25% / 보드 50~55% / 조작 20~25% (12 문서 §7) */
@media (max-width: 900px) {
    .battle-body {
        grid-template-columns: 1fr;
        grid-template-areas: "enemy" "board" "gauge";
        grid-template-rows: auto minmax(0, 1fr) auto;
        align-content: stretch;
        gap: 8px;
        overflow: hidden;
        padding: 0 8px 6px;
    }

    .enemy-stage {
        grid-area: enemy;
        grid-template-columns: 1fr auto;
        align-items: center;
        gap: 8px;
    }

    .intent-card {
        width: auto;
        padding: 7px 10px;
        text-align: left;
    }

    .intent-main {
        justify-content: flex-start;
        margin: 2px 0 0;
    }

    /* 보드에 최대한 폭을 주려고 몬스터와 게이지를 압축한다 */
    .enemy-portrait {
        height: 13vh;
        max-height: 112px;
        width: 30vw;
    }

    .intent-card small {
        font-size: .52rem;
    }

    .intent-main strong {
        font-size: .88rem;
    }

    .intent-card span {
        font-size: .68rem;
    }

    .board-stage {
        grid-area: board;
        gap: 4px;
        min-height: 0;
        grid-template-rows: auto minmax(0, 1fr) auto;
        align-content: stretch;
    }

    .board-meta {
        gap: 12px;
        font-size: .62rem;
    }

    .board-help {
        display: none;
    }

    .board-frame {
        display: none;
    }

    .board-grid,
    .board-veil {
        inset: 0;
    }

    .board-grid {
        gap: 2px;
        padding: 3px;
    }

    /* 폭탄 게이지 · 콤보 · 피해를 한 줄, 아이템을 아래 줄에 둔다 */
    .gauge-panel {
        grid-area: gauge;
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto auto;
        gap: 6px;
        overflow: visible;
        align-content: start;
    }

    .gauge-card {
        padding: 6px 8px;
    }

    .gauge-card:nth-child(4) {
        grid-column: 1 / -1;
    }

    .damage-card span {
        display: none;
    }

    .gauge-card small {
        font-size: .54rem;
    }

    .bomb-gauge,
    .item-slots {
        margin-top: 4px;
        min-height: 34px;
        flex-wrap: nowrap;
    }

    .gauge-slot,
    .item-slot {
        width: 34px;
        height: 34px;
    }

    .damage-card strong {
        margin-top: 2px;
        font-size: 1.15rem;
    }

    .combo-text {
        margin-top: 4px;
        font-size: .95rem;
    }

    .combo-track {
        margin-top: 4px;
    }

    .battle-top {
        padding: 8px 10px 4px;
        gap: 10px;
    }

    .round-block {
        min-width: 84px;
        padding: 5px 9px;
    }

    .battle-bottom {
        gap: 10px;
        padding: 8px 10px max(10px, env(safe-area-inset-bottom));
    }

    .attack-button {
        min-width: 118px;
        padding: 12px 14px;
    }

    .timer-head strong {
        font-size: 1.25rem;
    }

    .timer-block.urgent .timer-head strong {
        font-size: 1.6rem;
    }

    .timer-bar {
        height: 10px;
    }

    .timer-block.urgent .timer-bar {
        height: 14px;
    }
}

/* 터치 모드에서는 타일 터치 영역을 최대한 확보한다 (12 문서 §7) */
html[data-input-mode="touch"] .tile {
    min-width: 40px;
    min-height: 40px;
}

html[data-input-mode="touch"] .board-help {
    display: none;
}

html[data-input-mode="touch"] .bottom-left .ghost-button {
    padding: 8px 10px;
    font-size: .6rem;
}

@media (max-width: 420px) {
    html[data-input-mode="touch"] .tile {
        min-width: 0;
        min-height: 0;
    }

    .bomb-button {
        min-width: 88px;
        min-height: 68px;
    }

    .attack-button {
        min-width: 104px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .battle-screen.shaking,
    .tile.pop,
    .tile.wrong,
    .stage-node.just-unlocked {
        animation: none !important;
    }
}
