/* ===================================
   神通 - Battle System CSS
   崩壊:スターレイル風 ダークテーマ
   =================================== */

/* --- Design Tokens --- */
:root {
    --battle-bg-1: #06060f;
    --battle-bg-2: #0f0a24;
    --battle-bg-3: #0a1628;
    --panel-bg: rgba(12, 12, 30, 0.15);
    --panel-bg-light: rgba(25, 25, 55, 0.15);
    --panel-border: rgba(100, 110, 200, 0.18);
    --panel-border-light: rgba(140, 150, 220, 0.25);
    --bt-text: #e0e0f0;
    --bt-text-dim: #7878a0;
    --bt-text-gold: #fbbf24;
    --bt-text-bright: #ffffff;

    /* Element Colors */
    --elem-fire: #ff6b35;
    --elem-fire-glow: rgba(255, 107, 53, 0.45);
    --elem-water: #3b9df6;
    --elem-water-glow: rgba(59, 157, 246, 0.45);
    --elem-thunder: #b065f7;
    --elem-thunder-glow: rgba(176, 101, 247, 0.45);
    --elem-geo: #e8b30e;
    --elem-geo-glow: rgba(232, 179, 14, 0.45);
    --elem-grass: #2dd46a;
    --elem-grass-glow: rgba(45, 212, 106, 0.45);
    --elem-none: #94a3b8;
    --elem-none-glow: rgba(148, 163, 184, 0.35);

    /* Bars */
    --hp-high: #34d399;
    --hp-mid: #fbbf24;
    --hp-low: #ef4444;
    --energy-fill: #f59e0b;
    --energy-glow: rgba(245, 158, 11, 0.5);
    --toughness-fill: #cbd5e1;
    --toughness-glow: rgba(203, 213, 225, 0.3);
    --sp-active: #60a5fa;
    --sp-inactive: rgba(40, 40, 70, 0.8);

    /* Rarity */
    --rarity-5: #c8841a;
    --rarity-4: #9b59b6;
    --rarity-3: #2980b9;
}

/* --- Reset --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

body {
    font-family: 'Inter', 'Noto Sans JP', sans-serif;
    background: #06060f !important;
    color: var(--bt-text);
    overflow: hidden;
    overflow-x: hidden;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    -webkit-tap-highlight-color: transparent;
    position: relative;
}

/* Star-field background - 戰闘中は不要なので表示しない */
body::before {
    display: none;
}

/* 全画面背景画像 */
#battle-bg-layer {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-color: #06060f;
    transition: background-image 0.5s ease;
}

#battle-bg-layer::before {
    content: '';
    position: absolute;
    inset: 0;
    background: none;
    pointer-events: none;
}

/* --- Screen Container --- */
#battle-app {
    position: relative;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
}

/* ================================
   PARTY SELECT SCREEN
   ================================ */
.party-select-screen {
    padding: 20px;
    padding-bottom: 0;
    overflow: hidden;
}

.ps-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-shrink: 0;
}

.ps-header h1 {
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: 2px;
    background: linear-gradient(90deg, #e8c96a, #fbbf24, #f59e0b);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.ps-back-btn {
    background: rgba(12, 12, 30, 0.05);
    border: 1px solid var(--panel-border);
    color: var(--bt-text);
    padding: 8px 18px;
    border-radius: 0;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-block;
}

.ps-back-btn:hover {
    background: var(--panel-bg-light);
    border-color: var(--panel-border-light);
}

/* Character Roster */
.char-roster {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-bottom: 20px;
    scrollbar-width: thin;
    scrollbar-color: rgba(100, 100, 180, 0.3) transparent;
}

.char-roster-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    padding: 10px;
}

.char-card {
    position: relative;
    height: 140px;
    border-radius: 0;
    cursor: pointer;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    background: rgba(5, 5, 16, 0.3);
    border: 2px solid rgba(100, 110, 200, 0.2);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
}

.char-card-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.char-card-bg img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 20%;
    transition: transform 0.5s;
}

.char-card:hover .char-card-bg img {
    transform: scale(1.08);
}

.char-card-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to right, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0.1) 40%, rgba(0, 0, 0, 0.4) 100%);
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.8);
    pointer-events: none;
}

.char-card:hover {
    transform: translateY(-4px);
    border-color: var(--panel-border-light);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
}

.char-card.selected {
    border-color: var(--bt-text-gold);
    box-shadow: 0 0 25px rgba(251, 191, 36, 0.4), 0 10px 25px rgba(0, 0, 0, 0.6);
}

.char-card-check {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 28px;
    height: 28px;
    background: var(--bt-text-gold);
    color: #000;
    font-size: 1rem;
    font-weight: 900;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.2s ease-out;
}

.char-card-content {
    position: absolute;
    bottom: 12px;
    left: 15px;
    right: 15px;
    z-index: 2;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    pointer-events: none;
}

.char-card-name {
    font-size: 0.95rem;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 2px 6px #000, 0 0 10px rgba(0, 0, 0, 0.8);
    letter-spacing: 1px;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.char-card-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    min-width: 0;
}

.char-card-stars {
    color: var(--bt-text-gold);
    font-size: 0.85rem;
    letter-spacing: 2px;
    text-shadow: 0 2px 4px #000;
}

.char-card-level {
    font-weight: 800;
    font-size: 0.85rem;
    color: #e2e8f0;
    text-shadow: 0 2px 4px #000;
    background: rgba(0, 0, 0, 0.5);
    padding: 2px 8px;
    border-radius: 0;
    flex-shrink: 0;
}

.no-chars-msg {
    text-align: center;
    padding: 60px 20px;
    color: var(--bt-text-dim);
    font-size: 1.1rem;
    line-height: 1.8;
}

.no-chars-msg a {
    color: var(--bt-text-gold);
    text-decoration: underline;
}

/* Party Slots Bar */
.party-bar {
    flex-shrink: 0;
    background: rgba(12, 12, 30, 0.05);
    border-top: 1px solid var(--panel-border);
    padding: 14px 20px;
    display: flex;
    align-items: center;
    gap: 15px;
}

.party-slots {
    display: flex;
    gap: 10px;
    flex: 1;
}

.party-slot {
    width: 56px;
    height: 56px;
    border: 2px dashed rgba(100, 110, 200, 0.3);
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    color: rgba(100, 110, 200, 0.3);
    transition: all 0.3s;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    background: rgba(10, 10, 25, 0.5);
}

.party-slot.filled {
    border-style: solid;
    border-color: var(--panel-border-light);
    background: var(--panel-bg-light);
}

.party-slot.filled img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 0;
}

.party-slot .slot-remove {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    background: #ef4444;
    color: #fff;
    border-radius: 50%;
    font-size: 0.65rem;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-weight: bold;
    z-index: 2;
}

.party-slot.filled:hover .slot-remove {
    display: flex;
}

.start-battle-btn {
    background: linear-gradient(135deg, #fbbf24, #f59e0b, #d97706);
    border: none;
    color: #000;
    padding: 14px 36px;
    border-radius: 0;
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.25s;
    box-shadow: 0 4px 20px rgba(251, 191, 36, 0.35);
    white-space: nowrap;
}

.start-battle-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 28px rgba(251, 191, 36, 0.5);
}

.start-battle-btn:active {
    transform: scale(0.97);
}

.start-battle-btn:disabled {
    background: rgba(60, 60, 80, 0.6);
    color: var(--bt-text-dim);
    cursor: not-allowed;
    box-shadow: none;
}

/* ================================
   STAGE SELECT SCREEN
   ================================ */
.stage-select-screen {
    padding: 20px;
    overflow-y: auto;
}

.ss-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
}

.ss-header h1 {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: 2px;
    color: var(--bt-text-bright);
}

.stage-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: 700px;
    margin: 0 auto;
}

.stage-card {
    background: rgba(12, 12, 30, 0.05);
    border: 1px solid var(--panel-border);
    border-radius: 0;
    padding: 20px;
    cursor: pointer;
    transition: all 0.25s;
    position: relative;
    overflow: hidden;
}

.stage-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, transparent 60%, rgba(100, 110, 200, 0.05));
    pointer-events: none;
}

.stage-card:hover {
    transform: translateY(-3px);
    border-color: var(--panel-border-light);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

.stage-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
}

.stage-name {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--bt-text-bright);
}

.stage-difficulty {
    color: var(--bt-text-gold);
    font-size: 0.85rem;
    font-weight: 700;
}

.stage-desc {
    font-size: 0.85rem;
    color: var(--bt-text-dim);
    margin-bottom: 12px;
    line-height: 1.5;
}

.stage-enemies-preview {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.stage-enemy-tag {
    background: rgba(40, 40, 70, 0.8);
    border: 1px solid rgba(100, 110, 200, 0.15);
    padding: 4px 10px;
    border-radius: 0;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--bt-text);
}

.stage-rec-level {
    font-size: 0.8rem;
    color: var(--bt-text-dim);
    margin-top: 10px;
}

/* ================================
   BATTLE SCREEN
   ================================ */
.battle-screen {
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    overflow: hidden;
    background-color: transparent;
    transition: transform 0.5s ease;
}

/* モバイル縦画面での強制横画面回転対応 */


/* --- 撤退ボタン --- */
.battle-retreat-btn {
    position: absolute;
    top: 15px;
    left: 10px;
    width: 110px;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 20px 8px 14px;
    background: linear-gradient(90deg, rgba(30, 20, 50, 0.85) 0%, rgba(20, 10, 35, 0.75) 100%);
    border: none;
    border-left: 3px solid rgba(239, 68, 68, 0.7);
    clip-path: polygon(0 0, 100% 0, calc(100% - 12px) 100%, 0 100%);
    color: #fca5a5;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 2px;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(4px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}

.battle-retreat-btn:hover {
    background: linear-gradient(90deg, rgba(60, 20, 30, 0.9) 0%, rgba(40, 10, 20, 0.85) 100%);
    border-left-color: rgba(239, 68, 68, 1);
    color: #fff;
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.3), 0 2px 10px rgba(0, 0, 0, 0.5);
}

.battle-retreat-btn:active {
    transform: scale(0.97);
}

.retreat-icon {
    font-size: 1rem;
    line-height: 1;
}

.retreat-label {
    line-height: 1;
}

/* --- Battle Main Content (Party Left, Enemies Right) --- */
.battle-main-content {
    flex: 1;
    display: flex;
    flex-direction: row;
    min-height: 0;
    position: relative;
    z-index: 10;
    gap: 0;
    width: 100%;
    container-type: inline-size;
    container-name: battleMain;
}

@container battleMain (max-width: 850px) {
    .party-panel {
        transform: scale(0.85);
        transform-origin: left center;
    }
}

@container battleMain (max-width: 700px) {
    .party-panel {
        transform: scale(0.75);
        transform-origin: left center;
    }
}

/* --- Party Panel (Floating overlay, bottom-left) --- */
.party-panel {
    position: absolute;
    left: 0;
    bottom: 80px;
    width: 250px;
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px 10px 10px 10px;
    background: transparent;
    justify-content: flex-end;
    overflow: visible;
    pointer-events: auto;
}

.party-panel::-webkit-scrollbar {
    display: none;
}

.pm-wrap {
    display: flex;
    width: 100%;
    padding: 1px;
    clip-path: polygon(8px 0, 100% 0, calc(100% - 8px) 100%, 0 100%);
    background: transparent;
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    cursor: pointer;
}

.pm-wrap:hover {
    transform: scale(1.02) translateX(4px);
}

.pm-wrap.active-turn {
    background: var(--bt-text-gold);
    box-shadow: 0 0 16px rgba(251, 191, 36, 0.25);
}

.pm-wrap.dead-member {
    opacity: 0.35;
    filter: grayscale(1);
    cursor: not-allowed;
    pointer-events: none;
}

.party-member {
    position: relative;
    width: 100%;
    height: 68px;
    background: rgba(0, 0, 0, 0.85);
    clip-path: polygon(7.5px 0, 100% 0, calc(100% - 7.5px) 100%, 0 100%);
    border-left: 3px solid rgba(100, 110, 200, 0.4);
    border-right: 1px solid rgba(100, 110, 200, 0.15);
    display: flex;
    align-items: center;
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.pm-wrap:hover .party-member {
    border-left-color: rgba(140, 150, 220, 0.7);
    background: rgba(10, 15, 25, 0.9);
}

.pm-wrap.active-turn .party-member {
    border-left: none;
    border-right: none;
    background: rgba(15, 20, 25, 0.95);
}

/* Status icons display */
.pm-status-icons {
    display: inline-flex;
    gap: 3px;
    align-items: center;
    margin-left: 6px;
    margin-right: auto;
    z-index: 5;
    flex-shrink: 0;
}

.pm-status-icon {
    width: 14px;
    height: 14px;
    object-fit: contain;
}

/* --- Battle Field --- */
.battle-field {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    background: none;
    min-width: 0;
}

/* SP Display */
.sp-display {
    position: absolute;
    top: 15px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 6px;
    z-index: 20;
    background: rgba(5, 5, 20, 0.45);
    padding: 6px 14px;
    border-radius: 0;
    border: 1px solid var(--panel-border);
}

.sp-label {
    font-size: 0.8rem;
    font-weight: 800;
    color: var(--sp-active);
    letter-spacing: 1px;
}

.sp-orb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--sp-inactive);
    border: 1px solid rgba(100, 110, 200, 0.2);
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.sp-orb.active {
    background: var(--sp-active);
    box-shadow: 0 0 10px rgba(96, 165, 250, 0.6);
    border-color: var(--sp-active);
}

/* Turn Indicator */
.turn-indicator {
    position: absolute;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.85rem;
    font-weight: 800;
    color: #fff;
    z-index: 20;
    background: rgba(5, 5, 20, 0.45);
    padding: 6px 16px;
    border-radius: 0;
    border: 1px solid var(--panel-border);
    letter-spacing: 1px;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    white-space: nowrap;
}

/* --- Enemy Area (Centered large single target) --- */
.enemy-area {
    flex: 1;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    align-content: center;
    justify-content: center;
    gap: 30px;
    padding: 20px;
    position: relative;
    overflow: hidden;
    min-height: 0;
    background: transparent;
}

.enemy-unit {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    position: relative;
    flex: 0 1 auto;
    min-width: 0;
    width: auto;
}

.enemy-unit:hover {
    transform: scale(1.03);
}

.enemy-unit.targeted .enemy-body {
    box-shadow: 0 0 40px rgba(239, 68, 68, 0.6);
    border-color: rgba(239, 68, 68, 0.8);
}

.enemy-unit.dead {
    opacity: 0.15;
    pointer-events: none;
    filter: grayscale(1) blur(2px);
}

.enemy-body {
    width: clamp(120px, 25vmin, 240px);
    height: clamp(120px, 25vmin, 240px);
    border-radius: 0;
    border: 4px solid #ff6464;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(2rem, 5vmin, 5rem);
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
    background: linear-gradient(135deg, rgba(200, 80, 100, 0.8), rgba(160, 40, 120, 0.9));
    box-shadow: 0 0 50px rgba(255, 100, 100, 0.7), 0 15px 40px rgba(0, 0, 0, 0.9), inset 0 0 30px rgba(255, 150, 150, 0.3);
    flex-shrink: 0;
    color: #fff;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}

.enemy-body img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.enemy-body.broken {
    animation: breakPulse 0.6s ease-out;
    border-color: rgba(255, 200, 0, 0.7);
    box-shadow: 0 0 45px rgba(255, 200, 0, 0.4);
}

.enemy-name {
    font-size: 1.2rem;
    font-weight: 900;
    color: #ffdd99;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.9), 0 0 15px rgba(255, 100, 100, 0.5);
    text-align: center;
    letter-spacing: 1.5px;
    margin-top: 8px;
}

.enemy-level {
    font-size: 0.8rem;
    color: var(--bt-text-dim);
    margin-left: 6px;
    font-weight: normal;
}

/* Enemy Bars */
.enemy-bars {
    width: 100%;
    max-width: clamp(120px, 25vmin, 300px);
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-top: 4px;
}

.bar-container {
    width: 100%;
    height: 8px;
    background: rgba(30, 30, 50, 0.85);
    border-radius: 0;
    overflow: hidden;
    position: relative;
}

.bar-fill {
    height: 100%;
    border-radius: 0;
    transition: width 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.bar-fill.hp {
    background: linear-gradient(90deg, var(--hp-high), #5eead4);
}

.bar-fill.hp.mid {
    background: linear-gradient(90deg, var(--hp-mid), #fcd34d);
}

.bar-fill.hp.low {
    background: linear-gradient(90deg, var(--hp-low), #f87171);
}

/* .bar-fill.toughness - 削除済み（靭性ゲージ廃止） */


/* Weakness Icons */
.weakness-icons {
    display: flex;
    gap: 6px;
    justify-content: center;
}

.weakness-icon {
    width: 22px;
    height: 22px;
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 900;
    border: 1px solid rgba(255, 255, 255, 0.25);
}

/* 元素付着バッジ */
.enemy-elem-badges {
    display: flex;
    gap: 5px;
    justify-content: center;
    flex-wrap: wrap;
    min-height: 24px;
}

.elem-badge {
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 900;
    border: 1.5px solid;
    letter-spacing: 0.5px;
    animation: elemFadeIn 0.3s ease-out;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

.fx-badge {
    background: rgba(255, 255, 255, 0.1) !important;
    border-color: rgba(255, 255, 255, 0.4) !important;
    color: #fff !important;
    font-size: 1rem;
    padding: 1px 4px;
    animation: fxPulse 1s ease-in-out infinite;
}

/* 拘束状態の敵 */
.enemy-unit.restrained .enemy-body {
    border-color: #22c55e;
    box-shadow: 0 0 30px rgba(34, 197, 94, 0.7), 0 15px 40px rgba(0, 0, 0, 0.9), inset 0 0 20px rgba(34, 197, 94, 0.2);
    animation: restrainPulse 1s ease-in-out infinite;
}

/* アニメーション */
@keyframes elemFadeIn {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(-4px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes fxPulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.15);
        opacity: 0.85;
    }
}

@keyframes restrainPulse {

    0%,
    100% {
        box-shadow: 0 0 30px rgba(34, 197, 94, 0.7), 0 15px 40px rgba(0, 0, 0, 0.9);
    }

    50% {
        box-shadow: 0 0 50px rgba(34, 197, 94, 1.0), 0 15px 40px rgba(0, 0, 0, 0.9);
    }
}

@keyframes reactionPop {
    0% {
        transform: translate(-50%, -50%) scale(0) rotate(-8deg);
        opacity: 0;
    }

    40% {
        transform: translate(-50%, -50%) scale(1.15) rotate(2deg);
        opacity: 1;
    }

    70% {
        transform: translate(-50%, -50%) scale(0.95) rotate(0deg);
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -55%) scale(1) rotate(0deg);
        opacity: 0;
    }
}

/* リアクションダメージポップ */
.damage-popup.reaction {
    font-size: 4rem;
    font-weight: 900;
    -webkit-text-stroke: 1.5px rgba(0, 0, 0, 0.9);
    text-shadow: 0 4px 10px rgba(0, 0, 0, 0.8), 0 0 15px rgba(251, 191, 36, 0.4);
}

/* --- Battle Bottom Bar (Floating Action Buttons) --- */
.battle-bottom-bar {
    position: absolute;
    bottom: 30px;
    right: 30px;
    z-index: 100;
    pointer-events: none;
    display: flex;
    justify-content: flex-end;
}

/* --- Floating Action Panel --- */
.action-panel {
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: 20px;
    pointer-events: auto;
}

.action-btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 65px;
    height: 65px;
    border-radius: 50%;
    border: none;
    background: rgba(128, 128, 128, 0.4);
    /* 半透明のグレー */
    color: var(--bt-text);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    font-family: inherit;
    padding: 0;
    overflow: hidden;
}

/* 通常攻撃ボタンだけ少し大きく */
.action-btn-basic {
    width: 85px;
    height: 85px;
}

/* 必殺技ボタン: エネルギーが下から貯まる演出 */
.action-btn-ultimate {
    --energy-pct: 0%;
    --energy-color: #a78bfa;
    /* 属性色(デフォルト紫) */
}

.action-btn-ultimate::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: var(--energy-pct);
    background: var(--energy-color);
    opacity: 0.45;
    border-radius: 50%;
    transition: height 0.5s cubic-bezier(0.2, 0.8, 0.2, 1), background 0.5s ease;
    pointer-events: none;
    z-index: 0;
}

/* エネルギー満タン時のパルス光 */
.action-btn-ultimate.energy-full::before {
    opacity: 0.65;
    animation: energyFullPulse 1.5s ease-in-out infinite;
}

.action-btn-ultimate.energy-full {
    box-shadow: 0 0 12px var(--energy-color);
    animation: energyFullGlow 1.5s ease-in-out infinite;
}

@keyframes energyFullPulse {

    0%,
    100% {
        opacity: 0.55;
    }

    50% {
        opacity: 0.8;
    }
}

@keyframes energyFullGlow {

    0%,
    100% {
        box-shadow: 0 0 8px var(--energy-color);
    }

    50% {
        box-shadow: 0 0 20px var(--energy-color), 0 0 35px var(--energy-color);
    }
}

/* アイコンをz-index 1に持ち上げてfillの上に表示する */
.action-btn-ultimate .action-btn-icon {
    position: relative;
    z-index: 1;
}

.action-btn:hover:not(:disabled) {
    transform: scale(1.05);
    background: rgba(160, 160, 160, 0.5);
}

.action-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(0.5);
}

.action-btn-icon {
    width: 60%;
    height: 60%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.action-btn-basic .action-btn-icon {
    width: 65%;
    height: 65%;
}

.action-btn:hover:not(:disabled) .action-btn-icon {
    transform: scale(1.1);
}

/* 情報テキストはボタンの上にフローティング配置 */
.action-btn-info {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: rgba(0, 0, 0, 0.7);
    padding: 4px 8px;
    border-radius: 4px;
    white-space: nowrap;
    opacity: 0.8;
    transition: opacity 0.2s;
    pointer-events: none;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.action-btn:hover:not(:disabled) .action-btn-info {
    opacity: 1;
}

.action-btn-name {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.action-btn-cost {
    font-size: 0.65rem;
    color: var(--bt-text-dim);
}

.action-btn-skill .action-btn-name {
    color: var(--sp-active);
}

.action-btn-ultimate .action-btn-name {
    color: var(--bt-text-gold);
}


.pm-bg-fx {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: radial-gradient(circle at 80% 50%, rgba(150, 100, 255, 0.15), transparent 60%);
    pointer-events: none;
    z-index: 0;
}

.pm-avatar {
    width: 72px;
    height: 100%;
    position: relative;
    z-index: 1;
    overflow: hidden;
    clip-path: polygon(0 0, 100% 0, calc(100% - 10px) 100%, 0 100%);
}

.pm-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scale(1.2);
    transition: transform 0.3s;
}

.party-member:hover .pm-avatar img {
    transform: scale(1.3);
}

.pm-info {
    flex: 1;
    padding: 0 8px 0 4px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    z-index: 1;
    min-width: 0;
}

.pm-name {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--bt-text-bright);
    letter-spacing: 0.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}

.pm-bars {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.pm-hp-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    min-width: 0;
    line-height: 1;
}

.pm-hp-label,
.pm-hp-text {
    color: rgba(226, 232, 240, 0.92);
    font-size: 0.58rem;
    font-weight: 700;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
    white-space: nowrap;
}

.pm-hp-label {
    color: #6ee7b7;
    flex: 0 0 auto;
}

.pm-hp-text {
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: right;
    min-width: 0;
}

.pm-bars .bar-container {
    height: 4px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 0;
}

.pm-bars .bar-fill {
    border-radius: 0;
}

.pm-ult-ready {
    position: absolute;
    top: 50%;
    right: 5px;
    transform: translateY(-50%);
    width: 30px;
    height: 30px;
    background: radial-gradient(circle, var(--bt-text-gold) 0%, transparent 70%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: #fff;
    text-shadow: 0 0 5px #000;
    animation: pulseGlow 1.5s ease-in-out infinite;
    z-index: 2;
}

/* --- Action Cut-in --- */
.action-cutin-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 250;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.6);
    animation: fadeIn 0.2s ease-out;
}

.cutin-bg {
    position: absolute;
    width: 100%;
    height: 35vh;
    background: linear-gradient(90deg, transparent 0%, rgba(10, 0, 30, 0.9) 20%, rgba(10, 0, 30, 0.9) 80%, transparent 100%);
    transform: skewY(-5deg) scaleY(0);
    opacity: 0;
}

.cutin-bg.active {
    animation: cutinBgShow 1.5s cubic-bezier(0.1, 0.9, 0.2, 1) forwards;
}

.cutin-media {
    position: absolute;
    height: 120%;
    max-width: 100%;
    object-fit: cover;
    opacity: 0;
    transform: translateX(-200px) skewX(-10deg);
    filter: drop-shadow(0 0 30px rgba(200, 100, 255, 0.6));
}

.cutin-media.active {
    animation: cutinMediaSlide 1.5s cubic-bezier(0.1, 0.9, 0.2, 1) forwards;
}

.cutin-text-wrap {
    position: absolute;
    right: 10%;
    bottom: 35%;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    transform: translateX(100px);
    opacity: 0;
    /* 背景を少し暗くして文字を際立たせる */
    background: linear-gradient(90deg, transparent 0%, rgba(0, 0, 0, 0.6) 50%, rgba(0, 0, 0, 0.6) 100%);
    padding: 20px 40px;
    border-radius: 0;
}

.cutin-text-wrap.active {
    animation: cutinTextSlide 1.5s cubic-bezier(0.1, 0.9, 0.2, 1) forwards;
}

.cutin-char-name {
    font-size: 1.5rem;
    letter-spacing: 4px;
    text-transform: uppercase;
    color: #e2e8f0;
    text-shadow: 
        -1px -1px 0 #000,  
         1px -1px 0 #000,
        -1px  1px 0 #000,
         1px  1px 0 #000,
         0px  2px 5px rgba(0, 0, 0, 1);
}

.cutin-skill-name {
    font-size: 3.5rem;
    font-weight: 900;
    letter-spacing: 8px;
    color: #ffffff;
    text-shadow: 
        -1px -1px 0 #000,  
         1px -1px 0 #000,
        -1px  1px 0 #000,
         1px  1px 0 #000,
         0px  5px 10px rgba(0, 0, 0, 1), 
         0px  0px 25px var(--elem-color, rgba(150, 50, 255, 0.8));
}

/* Duplicate action-panel styling removed */

/* Target Selection Mode */
.target-mode .enemy-unit:not(.dead) {
    cursor: crosshair;
}

.target-mode .enemy-unit:not(.dead):hover .enemy-body {
    border-color: #ef4444;
    box-shadow: 0 0 25px rgba(239, 68, 68, 0.4);
}

.target-hint {
    position: absolute;
    bottom: 50%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    color: var(--bt-text);
    padding: 8px 18px;
    border-radius: 0;
    font-size: 0.85rem;
    font-weight: 600;
    z-index: 30;
    white-space: nowrap;
    pointer-events: none;
    animation: fadeSlideUp 0.3s ease-out;
}

/* ================================
   DAMAGE & EFFECTS
   ================================ */

/* Damage Popup */
.damage-popup {
    position: absolute;
    font-weight: 900;
    font-size: 3.5rem;
    z-index: 100;
    pointer-events: none;
    color: #cbd5e1;
    -webkit-text-stroke: 1.5px rgba(0, 0, 0, 0.8);
    text-shadow: 0 4px 6px rgba(0, 0, 0, 0.8);
    animation: damageFloat 1s cubic-bezier(0.1, 0.9, 0.2, 1) forwards;
}

.damage-popup.crit {
    font-size: 5rem;
    -webkit-text-stroke: 2px rgba(0, 0, 0, 0.9);
    text-shadow: 0 6px 12px rgba(0, 0, 0, 0.9), 0 0 20px rgba(234, 88, 12, 0.9);
}

.damage-popup.heal {
    font-size: 3.5rem;
    color: #a7f3d0;
    -webkit-text-stroke: 1.5px rgba(0, 0, 0, 0.8);
    text-shadow: 0 4px 6px rgba(0, 0, 0, 0.8), 0 0 10px rgba(5, 150, 105, 0.6);
}

.damage-popup.elem-fire {
    color: #f97316;
}

.damage-popup.elem-water {
    color: #38bdf8;
}

.damage-popup.elem-thunder {
    color: #d8b4fe;
}

.damage-popup.elem-geo {
    color: #fcd34d;
}

.damage-popup.elem-grass {
    color: #4ade80;
}

.damage-popup.elem-ice {
    color: #bae6fd;
}

.damage-popup.elem-none {
    color: #cbd5e1;
}

/* Skill Flash Overlay */
.skill-flash {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    pointer-events: none;
    animation: flashFade 0.4s ease-out forwards;
}

/* Ultimate Cutin */
.ultimate-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease-out;
}

.ultimate-cutin {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    animation: ultCutinSlide 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.ultimate-cutin img {
    max-height: 55vh;
    max-width: 80vw;
    object-fit: contain;
    filter: drop-shadow(0 0 40px rgba(251, 191, 36, 0.4));
}

.ultimate-cutin-name {
    font-size: 2rem;
    font-weight: 900;
    letter-spacing: 4px;
    color: #fbbf24;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}

.ultimate-cutin-skill {
    font-size: 1.1rem;
    color: var(--bt-text);
    font-weight: 600;
    letter-spacing: 2px;
}

/* Hit Shake */
.hit-shake {
    animation: hitShake 0.35s ease-out;
}

/* Break Effect */
.break-flash {
    animation: breakFlash 0.8s ease-out;
}

/* Shield Display */
.shield-indicator {
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border: 2px solid var(--elem-geo);
    border-radius: 0;
    pointer-events: none;
    animation: shieldPulse 2s ease-in-out infinite;
    opacity: 0.6;
}

/* ================================
   RESULT SCREEN
   ================================ */
.result-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 30px;
    background: radial-gradient(ellipse at 50% 40%, rgba(20, 20, 50, 0.95), rgba(6, 6, 15, 0.98));
    z-index: 300;
}

.result-title {
    font-size: 3rem;
    font-weight: 900;
    letter-spacing: 6px;
    animation: resultAppear 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.result-title.victory {
    color: #fbbf24;
    text-shadow: 0 0 20px rgba(251, 191, 36, 0.6);
    animation: resultAppear 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.result-title.defeat {
    color: #ef4444;
    text-shadow: 0 0 30px rgba(239, 68, 68, 0.5);
}

.result-stats {
    display: flex;
    gap: 30px;
    animation: fadeSlideUp 0.6s 0.3s ease-out backwards;
}

.result-stat {
    text-align: center;
}

.result-stat-value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--bt-text-bright);
}

.result-stat-label {
    font-size: 0.8rem;
    color: var(--bt-text-dim);
    margin-top: 4px;
}

.result-btn {
    background: rgba(12, 12, 30, 0.05);
    border: 1px solid var(--panel-border);
    color: var(--bt-text);
    padding: 14px 40px;
    border-radius: 0;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.25s;
    animation: fadeSlideUp 0.6s 0.5s ease-out backwards;
}

.result-btn:hover {
    background: var(--panel-bg-light);
    border-color: var(--bt-text-gold);
    box-shadow: 0 0 20px rgba(251, 191, 36, 0.2);
}

/* Battle Log */
.battle-log {
    position: absolute;
    bottom: 140px;
    right: 15px;
    width: 220px;
    max-height: 140px;
    overflow-y: auto;
    z-index: 15;
    display: flex;
    flex-direction: column-reverse;
    gap: 2px;
    pointer-events: none;
    scrollbar-width: none;
}

.battle-log::-webkit-scrollbar {
    display: none;
}

.log-entry {
    font-size: 0.68rem;
    color: rgba(200, 200, 220, 0.6);
    padding: 2px 8px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 0;
    animation: fadeIn 0.3s ease-out;
    line-height: 1.4;
}

/* ================================
   KOSO MODE & STORY
   ================================ */

/* Stage Tabs */
.stage-tabs {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 20px;
}

.stage-tab {
    background: transparent;
    border: none;
    color: var(--bt-text-dim);
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    padding: 8px 16px;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
}

.stage-tab:hover {
    color: var(--bt-text-bright);
}

.stage-tab.active {
    color: var(--bt-text-gold);
    border-bottom-color: var(--bt-text-gold);
    text-shadow: 0 0 10px rgba(251, 191, 36, 0.4);
}

/* Koso Cards (Parallelogram Banner) */
.koso-card {
    position: relative;
    width: 100%;
    max-width: 700px;
    height: 180px;
    margin: 0 auto 30px;
    background: rgba(10, 10, 15, 0.4);
    clip-path: polygon(15px 0, 100% 0, calc(100% - 15px) 100%, 0 100%);
    cursor: pointer;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
}

.koso-card::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 5px;
    background: linear-gradient(90deg, #990000, #ff3333, #990000);
    box-shadow: 0 0 15px #ff3333;
    z-index: 5;
}

.koso-card.locked {
    filter: grayscale(1) brightness(0.4);
    cursor: not-allowed;
}

.koso-card:not(.locked):hover {
    transform: scale(1.02);
}

.koso-card-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.koso-card-bg img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.7;
    transition: transform 0.5s;
}

.koso-card:not(.locked):hover .koso-card-bg img {
    transform: scale(1.05);
}

.koso-card-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, rgba(10, 0, 0, 0.9) 0%, rgba(20, 0, 0, 0.5) 40%, transparent 100%);
}

.koso-card-content {
    position: relative;
    z-index: 2;
    padding-left: 60px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.koso-floor {
    font-size: 1.4rem;
    font-weight: 900;
    color: #fca5a5;
    text-shadow: 2px 2px 0 #450a0a;
    letter-spacing: 2px;
}

.koso-title {
    font-size: 2.5rem;
    font-weight: 900;
    color: #fff;
    text-shadow: 2px 2px 0 #7f1d1d, 0 0 20px #ef4444;
    letter-spacing: 4px;
}

.koso-desc {
    font-size: 0.9rem;
    color: #d1d5db;
    line-height: 1.4;
    max-width: 60%;
}

.koso-clear-time {
    position: absolute;
    right: 40px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.7);
    padding: 10px 20px;
    font-size: 1.1rem;
    font-weight: 700;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Story Overlay */
.story-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 400;
    background: #000;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.story-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    opacity: 0.6;
}

.story-character {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    height: 80vh;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    pointer-events: none;
}

.story-character img {
    max-height: 100%;
    max-width: 100%;
    object-fit: contain;
}

.story-textbox {
    position: relative;
    z-index: 2;
    margin: 50px auto 20px;
    width: 90%;
    max-width: 900px;
    background: #46505c;
    border: 2px solid #a5f3fc;
    border-radius: 0;
    padding: 30px 30px 25px;
    min-height: 150px;
    box-shadow: 0 0 20px rgba(0, 255, 255, 0.5), inset 0 0 50px rgba(0, 120, 150, 0.6);
    cursor: pointer;
}

.story-speaker {
    position: absolute;
    top: -42px;
    left: -2px;
    background: #596775;
    border: 2px solid #a5f3fc;
    border-bottom: none;
    padding: 8px 40px;
    font-size: 1.25rem;
    font-weight: 800;
    color: #22d3ee;
    text-shadow: 0 0 8px rgba(34, 211, 238, 0.6);
    box-shadow: 0 -5px 15px rgba(0, 255, 255, 0.4), inset 0 10px 20px rgba(0, 120, 150, 0.3);
}

.story-text {
    font-size: 1.1rem;
    line-height: 1.6;
    color: #fff;
    text-shadow: 0 1px 3px #000;
}

.story-next-hint {
    position: absolute;
    bottom: 15px;
    right: 20px;
    font-size: 0.8rem;
    color: var(--bt-text-dim);
    animation: pulseGlow 1.5s infinite;
}

/* ================================
   ANIMATIONS
   ================================ */

@keyframes starTwinkle {
    0% {
        opacity: 0.8;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.7;
    }
}

@keyframes damageFloat {
    0% {
        opacity: 1;
        transform: scale(0.5) translateY(0);
    }

    15% {
        opacity: 1;
        transform: scale(1.3) translateY(-15px);
    }

    30% {
        opacity: 1;
        transform: scale(1.0) translateY(-25px);
    }

    80% {
        opacity: 1;
        transform: scale(1.0) translateY(-40px);
    }

    100% {
        opacity: 0;
        transform: scale(0.9) translateY(-50px);
    }
}

@keyframes hitShake {

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

    15% {
        transform: translateX(-8px) rotate(-1deg);
    }

    30% {
        transform: translateX(7px) rotate(1deg);
    }

    45% {
        transform: translateX(-5px);
    }

    60% {
        transform: translateX(4px);
    }

    75% {
        transform: translateX(-2px);
    }
}

@keyframes flashFade {
    0% {
        opacity: 0.6;
    }

    100% {
        opacity: 0;
    }
}

@keyframes pulseGlow {

    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.15);
        opacity: 0.85;
    }
}

@keyframes fadeIn {
    0% {
        opacity: 0;
    }

    100% {
        opacity: 1;
    }
}

@keyframes fadeSlideUp {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes resultAppear {
    0% {
        opacity: 0;
        transform: scale(0.5) translateY(30px);
    }

    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes shimmerGold {
    0% {
        background-position: -200% 0;
    }

    100% {
        background-position: 200% 0;
    }
}

@keyframes ultCutinSlide {
    0% {
        opacity: 0;
        transform: scale(1.3) translateY(30px);
    }

    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes breakPulse {
    0% {
        transform: scale(1);
    }

    30% {
        transform: scale(1.08);
    }

    100% {
        transform: scale(1);
    }
}

@keyframes breakFlash {
    0% {
        box-shadow: 0 0 0 rgba(255, 200, 0, 0);
    }

    30% {
        box-shadow: 0 0 40px rgba(255, 200, 0, 0.6);
    }

    100% {
        box-shadow: 0 0 0 rgba(255, 200, 0, 0);
    }
}

@keyframes shieldPulse {

    0%,
    100% {
        opacity: 0.4;
    }

    50% {
        opacity: 0.7;
    }
}

@keyframes slideUp {
    0% {
        transform: translateY(100%);
    }

    100% {
        transform: translateY(0);
    }
}

@keyframes cutinBgShow {
    0% {
        transform: skewY(-5deg) scaleY(0);
        opacity: 0;
    }

    15% {
        transform: skewY(-5deg) scaleY(1);
        opacity: 1;
    }

    85% {
        transform: skewY(-5deg) scaleY(1);
        opacity: 1;
    }

    100% {
        transform: skewY(-5deg) scaleY(0);
        opacity: 0;
    }
}

@keyframes cutinMediaSlide {
    0% {
        transform: translateX(-200px) skewX(-10deg);
        opacity: 0;
        filter: drop-shadow(0 0 30px rgba(200, 100, 255, 0.6)) blur(10px);
    }

    15% {
        transform: translateX(0) skewX(0);
        opacity: 1;
        filter: drop-shadow(0 0 30px rgba(200, 100, 255, 0.6)) blur(0);
    }

    85% {
        transform: translateX(50px) skewX(0);
        opacity: 1;
        filter: drop-shadow(0 0 30px rgba(200, 100, 255, 0.6)) blur(0);
    }

    100% {
        transform: translateX(200px) skewX(10deg);
        opacity: 0;
        filter: drop-shadow(0 0 30px rgba(200, 100, 255, 0.6)) blur(10px);
    }
}

@keyframes cutinTextSlide {
    0% {
        transform: translateX(100px);
        opacity: 0;
    }

    20% {
        transform: translateX(0);
        opacity: 1;
    }

    85% {
        transform: translateX(-20px);
        opacity: 1;
    }

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

/* ================================
   RESPONSIVE (Tablet & Mobile)
   ================================ */

/* Tablet / Large Mobile - 768px以下 (横持ち・デスクトップ・回転後のエミュレーションを含む) */
@media (max-width: 768px) {

    /* Battle Screen Layout */
    .battle-footer {
        flex-direction: column;
        max-height: none;
        min-height: auto;
        padding: 8px;
    }

    /* Party Panel - サイズ調整 */
    .party-panel {
        width: 240px;
        padding: 8px;
        gap: 8px;
        justify-content: flex-start;
    }

    .pm-wrap {
        width: 240px;
        min-width: 240px;
        flex-shrink: 0;
    }

    .party-member {
        width: 100%;
        height: 60px;
    }

    .pm-avatar {
        width: 80px;
    }

    .pm-info {
        padding: 0 10px;
    }

    .pm-name {
        font-size: 0.8rem;
    }

    .pm-hp-text {
        font-size: 0.6rem;
    }

    /* Action Panel - スケール調整 */
    .action-panel {
        gap: 12px;
    }

    .action-btn {
        width: 55px;
        height: 55px;
    }

    .action-btn-basic {
        width: 75px;
        height: 75px;
    }

    .action-btn-icon {
        font-size: 1.5rem;
    }

    .action-btn-basic .action-btn-icon {
        font-size: 2rem;
    }

    .action-btn-info {
        transform: translateX(-50%) scale(0.9);
    }

    /* Battle Field */
    .enemy-area {
        gap: 8px;
        padding: 8px 5px;
        flex-wrap: wrap;
    }

    .enemy-body {
        width: 180px;
        height: 180px;
    }

    .enemy-name {
        font-size: 1rem;
    }

    .enemy-bars {
        max-width: 160px;
    }

    /* Action Order Bar */
    .action-order-bar {
        min-height: 50px;
        padding: 6px 10px;
    }

    .ao-icon {
        width: 38px;
        height: 38px;
        font-size: 0.65rem;
    }

    /* Cutin Display */
    .cutin-media {
        height: 60vh;
        max-width: 90%;
    }

    .cutin-text-wrap {
        right: 5%;
        bottom: 20%;
        padding: 15px 25px;
    }

    .cutin-char-name {
        font-size: 1rem;
        letter-spacing: 2px;
    }

    .cutin-skill-name {
        font-size: 2rem;
        letter-spacing: 4px;
    }

    .ultimate-cutin img {
        max-height: 50vh;
        max-width: 80vw;
    }

    /* Party Select Screen */
    .party-select-screen {
        padding: 15px;
    }

    .ps-header {
        margin-bottom: 15px;
    }

    .ps-header h1 {
        font-size: 1.3rem;
    }

    .char-roster-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 12px;
    }

    .char-card {
        height: 110px;
    }

    .char-card-name {
        font-size: 1rem;
    }

    .party-bar {
        padding: 12px 15px;
        gap: 12px;
    }

    .party-slot {
        width: 50px;
        height: 50px;
    }

    .start-battle-btn {
        padding: 12px 24px;
        font-size: 0.95rem;
    }

    /* Result Screen */
    .result-title {
        font-size: 2rem;
    }

    .result-stats {
        gap: 20px;
    }

    .result-stat-value {
        font-size: 1.5rem;
    }

    /* Stage Select */
    .stage-list {
        max-width: 100%;
    }

    .stage-card {
        padding: 15px;
    }

    .stage-name {
        font-size: 1rem;
    }

    /* Battle Log */
    .battle-log {
        width: 200px;
        max-height: 100px;
        font-size: 0.6rem;
    }

    /* SP Display */
    .sp-display {
        padding: 4px 8px;
        gap: 4px;
    }

    .sp-orb {
        width: 12px;
        height: 12px;
    }
}

/* Mobile - 480px以下 (縦画面または非常に幅の狭い画面でのオーバーライド) */
@media (max-width: 480px) {

    /* General */
    .screen {
        padding: 12px !important;
    }

    /* Party Panel */
    .party-panel {
        width: 180px;
        flex-shrink: 0;
        padding: 4px;
        gap: 4px;
    }

    .pm-avatar {
        width: 60px;
    }

    .pm-name {
        font-size: 0.7rem;
    }

    .pm-bars .bar-container {
        height: 3px;
    }

    /* Action Panel - スケール調整 */
    .action-panel {
        gap: 10px;
    }

    .action-btn {
        width: 50px;
        height: 50px;
    }

    .action-btn-basic {
        width: 65px;
        height: 65px;
    }

    .action-btn-icon {
        font-size: 1.3rem;
    }

    .action-btn-basic .action-btn-icon {
        font-size: 1.8rem;
    }

    .action-btn-info {
        transform: translateX(-50%) scale(0.8);
    }

    /* Battle Field */
    .enemy-area {
        gap: 20px;
        padding: 30px 15px;
        flex-wrap: wrap;
        align-items: center;
        background: transparent;
        min-height: 0;
    }

    .enemy-unit {
        flex-shrink: 0;
    }

    .enemy-body {
        width: 200px;
        height: 200px;
        border: 3px solid #ff6464;
        background: linear-gradient(135deg, rgba(200, 80, 100, 0.8), rgba(160, 40, 120, 0.9));
        box-shadow: 0 0 50px rgba(255, 100, 100, 0.7), 0 15px 40px rgba(0, 0, 0, 0.9), inset 0 0 30px rgba(255, 150, 150, 0.3);
        font-size: 4rem;
        color: #fff;
    }

    .enemy-name {
        font-size: 1.1rem;
        color: #ffdd99;
    }

    .enemy-bars {
        max-width: 180px;
    }

    .bar-container {
        height: 6px;
    }

    /* Action Order */
    .action-order-bar {
        min-height: 45px;
        padding: 4px 8px;
        gap: 4px;
    }

    .action-order-label {
        font-size: 0.6rem;
    }

    .ao-icon {
        width: 34px;
        height: 34px;
        font-size: 0.6rem;
    }

    /* Turn Indicator & SP Display */
    .turn-indicator {
        font-size: 0.7rem;
        padding: 4px 10px;
    }

    .sp-display {
        top: 8px;
        right: 10px;
        padding: 3px 6px;
        gap: 3px;
    }

    .sp-label {
        font-size: 0.6rem;
    }

    .sp-orb {
        width: 10px;
        height: 10px;
    }

    /* Party Select */
    .ps-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        margin-bottom: 12px;
    }

    .ps-header h1 {
        font-size: 1.1rem;
    }

    .ps-back-btn {
        font-size: 0.8rem;
        padding: 6px 12px;
    }

    .char-roster-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 10px;
    }

    .char-card {
        height: 95px;
    }

    .char-card-name {
        font-size: 0.9rem;
    }

    .char-card-level {
        font-size: 0.7rem;
    }

    /* Party Bar */
    .party-bar {
        flex-direction: column;
        padding: 10px 12px;
        gap: 10px;
    }

    .party-slots {
        width: 100%;
        gap: 8px;
    }

    .party-slot {
        width: 48px;
        height: 48px;
    }

    .start-battle-btn {
        width: 100%;
        padding: 10px 20px;
        font-size: 0.9rem;
    }

    /* Result Screen */
    .result-title {
        font-size: 1.6rem;
    }

    .result-stats {
        gap: 15px;
        flex-direction: column;
    }

    .result-stat-value {
        font-size: 1.2rem;
    }

    .result-btn {
        padding: 10px 20px;
        font-size: 0.9rem;
    }

    /* Cutin Display - Mobile */
    .cutin-media {
        height: 50vh;
        max-width: 85%;
    }

    .cutin-text-wrap {
        right: 3%;
        bottom: 15%;
        padding: 12px 18px;
    }

    .cutin-char-name {
        font-size: 0.85rem;
        letter-spacing: 1.5px;
    }

    .cutin-skill-name {
        font-size: 1.5rem;
        letter-spacing: 2px;
    }

    .ultimate-cutin img {
        max-height: 40vh;
        max-width: 75vw;
    }

    /* Stage Select */
    .ss-header {
        flex-direction: column;
        gap: 10px;
        margin-bottom: 15px;
    }

    .ss-header h1 {
        font-size: 1rem;
    }

    .stage-tabs {
        gap: 10px;
        margin-bottom: 15px;
    }

    .stage-tab {
        font-size: 1rem;
        padding: 6px 12px;
    }

    .stage-list {
        max-width: 100%;
    }

    .stage-card {
        padding: 12px;
    }

    .stage-name {
        font-size: 0.9rem;
    }

    .stage-desc {
        font-size: 0.75rem;
    }

    /* Battle Log */
    .battle-log {
        width: 150px;
        max-height: 80px;
        top: 50px;
        font-size: 0.55rem;
    }

    .log-entry {
        padding: 1px 5px;
    }
}

/* Extra Small - 360px以下 */
@media (max-width: 360px) {
    .party-slot {
        width: 40px;
        height: 40px;
    }

    .start-battle-btn {
        padding: 8px 15px;
        font-size: 0.8rem;
    }

    .pm-avatar {
        width: 40px;
        height: 40px;
    }

    .enemy-body {
        width: 60px;
        height: 60px;
    }

    .pm-wrap {
        width: 140px;
        min-width: 140px;
    }

    .pm-avatar {
        width: 50px;
    }

    .char-card {
        height: 85px;
    }

    .enemy-body {
        width: 160px;
        height: 160px;
        border: 3px solid #ff6464;
        font-size: 3.5rem;
        background: linear-gradient(135deg, rgba(200, 80, 100, 0.8), rgba(160, 40, 120, 0.9));
        box-shadow: 0 0 40px rgba(255, 100, 100, 0.6), 0 10px 30px rgba(0, 0, 0, 0.9);
    }

    .enemy-name {
        font-size: 0.95rem;
        color: #ffdd99;
    }

    .enemy-bars {
        max-width: 140px;
    }

    .enemy-area {
        gap: 15px;
        padding: 20px 10px;
        min-height: 350px;
    }

    .action-btn-icon {
        width: 24px;
        height: 24px;
    }

    /* Cutin Display - Extra Small */
    .cutin-media {
        height: 45vh;
        max-width: 80%;
    }

    .cutin-text-wrap {
        right: 2%;
        bottom: 12%;
        padding: 10px 14px;
    }

    .cutin-char-name {
        font-size: 0.7rem;
        letter-spacing: 1px;
    }

    .cutin-skill-name {
        font-size: 1.1rem;
        letter-spacing: 1.5px;
    }
}

/* Landscape / Small Height Devices (e.g. mobile rotated) */
@media (max-height: 600px) {
    .koso-card {
        height: 120px;
        max-width: 600px;
        margin-bottom: 15px;
    }

    .koso-title {
        font-size: 1.6rem;
    }

    .koso-floor {
        font-size: 1.1rem;
    }

    .koso-desc {
        font-size: 0.8rem;
    }

    .koso-card-content {
        padding-left: 30px;
    }

    .char-card {
        height: 110px;
    }

    .party-slot {
        width: 48px;
        height: 48px;
    }

    .start-battle-btn {
        padding: 10px 24px;
        font-size: 0.9rem;
    }

    .ps-header {
        margin-bottom: 10px;
    }

    .ps-header h1 {
        font-size: 1.3rem;
    }

    .ss-header {
        margin-bottom: 10px;
    }

    .ss-header h1 {
        font-size: 1.3rem;
    }

    .stage-card {
        padding: 12px;
    }

    .stage-name {
        font-size: 1rem;
    }
}

/* Forced Landscape overrides (since max-height won't trigger on physical portrait devices) */
.force-landscape .koso-card {
    height: 120px;
    max-width: 600px;
    margin-bottom: 15px;
}

.force-landscape .koso-title {
    font-size: 1.6rem;
}

.force-landscape .koso-floor {
    font-size: 1.1rem;
}

.force-landscape .koso-desc {
    font-size: 0.8rem;
}

.force-landscape .koso-card-content {
    padding-left: 30px;
}

.force-landscape .char-card {
    height: 110px;
}

.force-landscape .party-slot {
    width: 48px;
    height: 48px;
}

.force-landscape .start-battle-btn {
    padding: 10px 24px;
    font-size: 0.9rem;
}

.force-landscape .ps-header {
    margin-bottom: 10px;
}

.force-landscape .ps-header h1 {
    font-size: 1.3rem;
}

.force-landscape .ss-header {
    margin-bottom: 10px;
}

.force-landscape .ss-header h1 {
    font-size: 1.3rem;
}

.force-landscape .stage-card {
    padding: 12px;
}

.force-landscape .stage-name {
    font-size: 1rem;
}


/* Fix party bar and grid in forced landscape */
.force-landscape .party-bar {
    flex-direction: row !important;
}

.force-landscape .start-battle-btn {
    width: auto !important;
}

.force-landscape .char-roster-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)) !important;
}

.force-landscape .char-card-content {
    left: 10px;
    right: 10px;
}

/* Also apply to generic max-height media query if the device is physically horizontal */
@media (max-height: 600px) {
    .party-bar {
        flex-direction: row !important;
    }

    .start-battle-btn {
        width: auto !important;
    }

    .char-roster-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)) !important;
    }

    .char-card-content {
        left: 10px;
        right: 10px;
    }
}


/* Force-landscape: Fix char roster card display */
.force-landscape .char-roster-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important;
    gap: 8px !important;
}

.force-landscape .char-card {
    height: 120px !important;
}

.force-landscape .char-card-content {
    left: 8px !important;
    right: 8px !important;
    bottom: 6px !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 2px !important;
}

.force-landscape .char-card-name {
    font-size: 0.72rem !important;
    letter-spacing: 0.5px !important;
    max-width: 100% !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

.force-landscape .char-card-info {
    flex-direction: row !important;
    align-items: center !important;
    gap: 6px !important;
}

.force-landscape .char-card-stars {
    font-size: 0.65rem !important;
    letter-spacing: 1px !important;
}

.force-landscape .char-card-level {
    font-size: 0.65rem !important;
    padding: 1px 5px !important;
}

/* Also apply if viewport height is small (physically landscape devices) */
@media (max-height: 600px) {
    .char-roster-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important;
        gap: 8px !important;
    }

    .char-card {
        height: 120px !important;
    }

    .char-card-content {
        left: 8px !important;
        right: 8px !important;
        bottom: 6px !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 2px !important;
    }

    .char-card-name {
        font-size: 0.72rem !important;
        letter-spacing: 0.5px !important;
    }

    .char-card-info {
        flex-direction: row !important;
        align-items: center !important;
        gap: 6px !important;
    }

    .char-card-stars {
        font-size: 0.65rem !important;
        letter-spacing: 1px !important;
    }

    .char-card-level {
        font-size: 0.65rem !important;
        padding: 1px 5px !important;
    }
}

/* --- Battle Modal (Retreat Confirmation) --- */
.battle-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 5, 10, 0.85);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.battle-modal.hidden {
    display: none;
}

.battle-modal-content {
    background: linear-gradient(135deg, rgba(20, 25, 45, 0.95), rgba(10, 15, 30, 0.98));
    border: 1px solid rgba(255, 100, 100, 0.3);
    padding: 30px 40px;
    min-width: 320px;
    text-align: center;
    box-shadow: 0 0 40px rgba(0,0,0,0.9), inset 0 0 20px rgba(255,50,50,0.05);
    clip-path: polygon(0 0, 100% 0, 100% calc(100% - 15px), calc(100% - 15px) 100%, 0 100%);
    animation: resultAppear 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.battle-modal-content h2 {
    color: #ff6b6b;
    margin-top: 0;
    font-size: 1.6rem;
    letter-spacing: 2px;
    margin-bottom: 20px;
    border-bottom: 1px solid rgba(255, 100, 100, 0.2);
    padding-bottom: 10px;
}

.battle-modal-content p {
    color: #e2e8f0;
    margin: 20px 0 30px;
    font-size: 1.1rem;
}

.battle-modal-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.btn-wrap {
    display: inline-flex;
    padding: 1px;
    clip-path: polygon(0 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%);
    transition: all 0.2s ease;
}

.btn-wrap-cancel {
    background: rgba(100, 110, 200, 0.4);
}

.btn-wrap-cancel:hover {
    background: rgba(100, 110, 200, 0.8);
}

.btn-wrap-confirm {
    background: rgba(239, 68, 68, 0.5);
}

.btn-wrap-confirm:hover {
    background: rgba(239, 68, 68, 0.9);
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.4);
}

.battle-modal-btn {
    background: transparent;
    padding: 9px 24px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    transition: all 0.2s ease;
    clip-path: polygon(0 0, 100% 0, 100% calc(100% - 7.5px), calc(100% - 7.5px) 100%, 0 100%);
    border: none;
    outline: none;
}

.battle-modal-btn.cancel {
    color: #cbd5e1;
    background: #141725;
}

.btn-wrap-cancel:hover .battle-modal-btn.cancel {
    background: #1e243b;
    color: #fff;
}

.battle-modal-btn.confirm {
    color: #fca5a5;
    background: #201317;
}

.btn-wrap-confirm:hover .battle-modal-btn.confirm {
    background: #33161c;
    color: #fff;
}

/* ===================================
   蒼白の結晶 (Crystal) UI
   =================================== */

.pm-crystals {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 4px;
    flex-wrap: wrap;
}

.crystal-gems {
    display: flex;
    gap: 4px;
    align-items: center;
}

.crystal-gem {
    width: 10px;
    height: 12px;
    background: rgba(30, 40, 80, 0.7);
    border: 1px solid rgba(100, 150, 255, 0.3);
    clip-path: polygon(50% 0%, 100% 30%, 100% 70%, 50% 100%, 0% 70%, 0% 30%);
    transition: all 0.3s ease;
}

.crystal-gem.active {
    background: linear-gradient(135deg, #7dd3fc, #38bdf8, #0ea5e9);
    border-color: rgba(125, 211, 252, 0.8);
    box-shadow:
        0 0 6px rgba(56, 189, 248, 0.9),
        0 0 12px rgba(14, 165, 233, 0.5),
        inset 0 1px 2px rgba(255, 255, 255, 0.4);
    animation: crystal-pulse 1.5s ease-in-out infinite alternate;
}

@keyframes crystal-pulse {
    0% {
        box-shadow:
            0 0 5px rgba(56, 189, 248, 0.8),
            0 0 10px rgba(14, 165, 233, 0.4);
    }
    100% {
        box-shadow:
            0 0 10px rgba(56, 189, 248, 1.0),
            0 0 20px rgba(14, 165, 233, 0.7),
            0 0 30px rgba(125, 211, 252, 0.3);
    }
}

.crystal-buff-icon {
    font-size: 0.62rem;
    background: rgba(14, 165, 233, 0.2);
    border: 1px solid rgba(56, 189, 248, 0.4);
    border-radius: 3px;
    padding: 1px 4px;
    color: #7dd3fc;
    white-space: nowrap;
    cursor: help;
}
