/* ═══════════════════════════════════════════════════════════════
   Battle Puzzle Rush — CSS
   Fullscreen overlay for chess puzzle rush during dragon battles
   ═══════════════════════════════════════════════════════════════ */

/* ── Overlay ── */
.puzzle-rush-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.92);
    backdrop-filter: blur(12px);
    animation: prOverlayIn 0.4s ease-out;
}

@keyframes prOverlayIn {
    from { opacity: 0; transform: scale(1.05); }
    to   { opacity: 1; transform: scale(1); }
}

.puzzle-rush-overlay.closing {
    animation: prOverlayOut 0.3s ease-in forwards;
}
@keyframes prOverlayOut {
    to { opacity: 0; transform: scale(0.95); }
}

/* ── Header ── */
.pr-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 560px;
    padding: 0 8px;
    margin-bottom: 10px;
    gap: 12px;
}

.pr-title {
    font-size: 1.1rem;
    font-weight: 800;
    color: #fff;
    text-shadow: 0 0 12px rgba(255, 215, 0, 0.4);
    white-space: nowrap;
}

.pr-title .pr-icon {
    font-size: 1.3rem;
    margin-right: 6px;
}

.pr-stats {
    display: flex;
    align-items: center;
    gap: 10px;
}

.pr-stat {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    font-size: 0.85rem;
    font-weight: 700;
    color: #fff;
}

.pr-stat-icon {
    font-size: 1rem;
}

.pr-solved-count {
    color: #2ecc71;
    min-width: 18px;
    text-align: center;
    transition: transform 0.15s;
}

.pr-solved-count.bump {
    transform: scale(1.4);
    color: #FFD700;
}

/* ── Timer Bar ── */
.pr-timer-bar {
    width: 100%;
    max-width: 560px;
    height: 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.1);
    margin-bottom: 12px;
    overflow: hidden;
}

.pr-timer-fill {
    height: 100%;
    border-radius: 4px;
    background: linear-gradient(90deg, #2ecc71, #27ae60);
    transition: width 0.1s linear, background 0.5s;
    box-shadow: 0 0 8px rgba(46, 204, 113, 0.5);
}

.pr-timer-fill.warning {
    background: linear-gradient(90deg, #f1c40f, #e67e22);
    box-shadow: 0 0 8px rgba(241, 196, 15, 0.5);
}

.pr-timer-fill.danger {
    background: linear-gradient(90deg, #e74c3c, #c0392b);
    box-shadow: 0 0 8px rgba(231, 76, 60, 0.5);
    animation: prTimerPulse 0.5s ease-in-out infinite;
}

@keyframes prTimerPulse {
    50% { opacity: 0.7; }
}

.pr-timer-text {
    text-align: center;
    font-size: 0.8rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.6);
    margin-top: 2px;
    margin-bottom: 6px;
}

/* ── Board Container ── */
.pr-board-container {
    position: relative;
    width: min(85vw, 420px);
    height: min(85vw, 420px);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6), 0 0 0 2px rgba(255, 215, 0, 0.3);
}

/* Force Chessground's cg-wrap to fill the container */
.pr-board-container .cg-wrap {
    width: 100% !important;
    height: 100% !important;
}

.pr-board-container cg-board {
    border-radius: 8px;
}

/* ── Intro Notification ── */
.pr-intro-overlay {
    position: fixed;
    inset: 0;
    z-index: 10001;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(12px);
    animation: prOverlayIn 0.3s ease-out;
}

.pr-intro-card {
    background: linear-gradient(145deg, rgba(39, 174, 96, 0.95), rgba(46, 204, 113, 0.9));
    border-radius: 20px;
    padding: 28px 36px;
    text-align: center;
    max-width: 380px;
    width: 90vw;
    box-shadow: 0 20px 60px rgba(46, 204, 113, 0.4), 0 0 0 2px rgba(255, 255, 255, 0.15);
    animation: prBannerIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.pr-intro-icon {
    font-size: 3rem;
    margin-bottom: 8px;
}

.pr-intro-title {
    font-size: 1.5rem;
    font-weight: 900;
    color: #fff;
    margin-bottom: 8px;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.pr-intro-desc {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.9);
    line-height: 1.5;
    margin-bottom: 16px;
}

.pr-intro-rules {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.pr-intro-rule {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 8px 14px;
    font-size: 0.82rem;
    font-weight: 700;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.pr-intro-start-btn {
    display: inline-block;
    padding: 10px 32px;
    border-radius: 24px;
    background: linear-gradient(135deg, #fff, #f0f0f0);
    color: #27ae60;
    font-size: 1rem;
    font-weight: 800;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s, box-shadow 0.2s;
}

.pr-intro-start-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.pr-intro-skip {
    display: block;
    margin-top: 12px;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.8rem;
    cursor: pointer;
    font-family: inherit;
}

.pr-intro-skip:hover {
    color: rgba(255, 255, 255, 0.8);
}

/* ── Feedback Flash ── */
.pr-feedback {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    font-weight: 900;
    pointer-events: none;
    z-index: 10;
    opacity: 0;
}

.pr-feedback.correct {
    background: rgba(46, 204, 113, 0.25);
    color: #2ecc71;
    animation: prFeedbackFlash 0.6s ease-out forwards;
}

.pr-feedback.wrong {
    background: rgba(231, 76, 60, 0.25);
    color: #e74c3c;
    animation: prFeedbackFlash 0.6s ease-out forwards, prShake 0.3s ease-out;
}

@keyframes prFeedbackFlash {
    0% { opacity: 1; transform: scale(0.8); }
    60% { opacity: 1; transform: scale(1.1); }
    100% { opacity: 0; transform: scale(1); }
}

@keyframes prShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    50% { transform: translateX(8px); }
    75% { transform: translateX(-4px); }
}

/* ── Penalty Flash ── */
.pr-penalty {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2rem;
    font-weight: 900;
    color: #e74c3c;
    text-shadow: 0 0 20px rgba(231, 76, 60, 0.6);
    pointer-events: none;
    z-index: 10002;
    animation: prPenalty 1s ease-out forwards;
}

@keyframes prPenalty {
    0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    70% { opacity: 1; }
    100% { opacity: 0; transform: translate(-50%, -80%) scale(0.8); }
}

/* ── Footer Actions ── */
.pr-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 14px;
}

.pr-skip-btn {
    padding: 8px 24px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.08);
    border: 1.5px solid rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.pr-skip-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

/* ── Puzzle Info ── */
.pr-puzzle-info {
    text-align: center;
    margin-bottom: 4px;
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.5);
    font-weight: 500;
}

/* ── Result Banner (after rush) ── */
.pr-result-banner {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10001;
    padding: 20px 40px;
    border-radius: 16px;
    text-align: center;
    background: linear-gradient(135deg, rgba(46, 204, 113, 0.9), rgba(39, 174, 96, 0.95));
    border: 2px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 10px 40px rgba(46, 204, 113, 0.5);
    animation: prBannerIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.pr-result-banner.no-buff {
    background: linear-gradient(135deg, rgba(149, 165, 166, 0.9), rgba(127, 140, 141, 0.95));
    box-shadow: 0 10px 40px rgba(149, 165, 166, 0.3);
}

@keyframes prBannerIn {
    from { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
    to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.pr-result-title {
    font-size: 1.5rem;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    margin-bottom: 4px;
}

.pr-result-detail {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.85);
    font-weight: 600;
}

/* ── Move indicator (whose turn) ── */
.pr-turn-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-bottom: 6px;
    font-size: 0.82rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.7);
}

.pr-turn-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.pr-turn-dot.white { background: #fff; }
.pr-turn-dot.black { background: #333; }

/* ── Mobile responsive ── */
@media (max-width: 480px) {
    .pr-board-container {
        width: min(92vw, 360px);
        height: min(92vw, 360px);
    }

    .pr-header {
        max-width: 92vw;
        flex-wrap: wrap;
        justify-content: center;
        gap: 6px;
    }

    .pr-title {
        font-size: 0.95rem;
    }

    .pr-stat {
        font-size: 0.78rem;
        padding: 3px 8px;
    }

    .pr-result-banner {
        padding: 16px 24px;
        width: 85vw;
    }
}

/* ═══════════════════════════════════════════════
   SIDE PANEL MODE — puzzle board during battle
   ═══════════════════════════════════════════════ */

.pr-side-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 8px 8px 0 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.pr-side-title {
    font-size: 0.85rem;
    font-weight: 800;
    color: #ffd700;
}

.pr-side-counter {
    font-size: 0.8rem;
    font-weight: 700;
    color: #2ecc71;
}

.pr-side-progress {
    padding: 4px 10px 6px;
    background: rgba(0, 0, 0, 0.2);
}

.pr-side-progress-text {
    text-align: center;
    font-size: 0.7rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 3px;
}

.pr-side-progress-bar {
    height: 5px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.1);
    overflow: hidden;
}

.pr-side-progress-fill {
    height: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, #2ecc71, #27ae60);
    transition: width 0.3s;
}

/* ── Split Screen Battle Layout ── */
.ba-split-screen {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 9000;
    background: rgba(0, 0, 0, 0.95);
}

.ba-split-battle {
    flex: 6;
    position: relative;
    overflow: hidden;
}

/* Override fixed positioning when inside split-screen */
.ba-split-battle .ba-scene {
    position: absolute !important;
    inset: 0 !important;
    z-index: 1 !important;
}

.ba-split-puzzle {
    flex: 4;
    max-width: 420px;
    background: linear-gradient(180deg, rgba(15, 12, 41, 0.98), rgba(10, 8, 30, 0.98));
    border-left: 2px solid rgba(255, 215, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ba-split-puzzle .pr-board-container {
    width: 100% !important;
    height: 0 !important;
    padding-bottom: 100% !important;
    position: relative !important;
    border-radius: 0;
    box-shadow: none;
}

.ba-split-puzzle .pr-board-container .cg-wrap {
    position: absolute !important;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
}

.ba-split-puzzle .pr-turn-indicator {
    margin: 4px 0;
    font-size: 0.72rem;
}

.ba-split-puzzle .pr-feedback {
    font-size: 2rem;
}

/* ── Spell Bar ── */
.ba-spell-bar {
    padding: 4px 6px;
    background: linear-gradient(145deg, rgba(20, 16, 50, 0.95), rgba(15, 12, 40, 0.95));
    border-top: 1px solid rgba(255, 215, 0, 0.1);
    flex-shrink: 0;
}

.ba-spell-energy {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 3px;
    font-size: 0.6rem;
    color: rgba(255, 255, 255, 0.7);
}

.ba-spell-energy-bar {
    flex: 1;
    height: 5px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    overflow: hidden;
}

.ba-spell-energy-fill {
    height: 100%;
    background: linear-gradient(90deg, #f39c12, #f1c40f);
    border-radius: 3px;
    transition: width 0.3s ease;
    box-shadow: 0 0 4px rgba(241, 196, 15, 0.4);
}

.ba-spell-energy-fill.full {
    background: linear-gradient(90deg, #2ecc71, #27ae60);
    box-shadow: 0 0 8px rgba(46, 204, 113, 0.6);
    animation: spellPulse 1.5s ease-in-out infinite;
}

@keyframes spellPulse {
    0%, 100% { box-shadow: 0 0 4px rgba(46, 204, 113, 0.4); }
    50% { box-shadow: 0 0 10px rgba(46, 204, 113, 0.8); }
}

.ba-spell-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 3px;
}

.ba-spell-btn {
    padding: 4px 2px;
    border-radius: 6px;
    border: 1px solid transparent;
    font-size: 0.58rem;
    font-weight: 700;
    cursor: not-allowed;
    transition: all 0.3s ease;
    font-family: inherit;
    text-align: center;
    line-height: 1.1;
    opacity: 0.4;
    background: rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.4);
}

.ba-spell-btn.ready {
    opacity: 1;
    cursor: pointer;
    animation: spellReady 2s ease-in-out infinite;
}

.ba-spell-btn.heal.ready {
    background: linear-gradient(135deg, #00b894, #00cec9);
    color: #fff;
    border-color: rgba(0, 206, 201, 0.4);
    box-shadow: 0 2px 12px rgba(0, 206, 201, 0.3);
}

.ba-spell-btn.attack.ready {
    background: linear-gradient(135deg, #e74c3c, #fd79a8);
    color: #fff;
    border-color: rgba(253, 121, 168, 0.4);
    box-shadow: 0 2px 12px rgba(231, 76, 60, 0.3);
}

.ba-spell-btn.shield.ready {
    background: linear-gradient(135deg, #2980b9, #3498db);
    color: #fff;
    border-color: rgba(52, 152, 219, 0.4);
    box-shadow: 0 2px 12px rgba(52, 152, 219, 0.3);
}

.ba-spell-btn.thunder.ready {
    background: linear-gradient(135deg, #f39c12, #f1c40f);
    color: #1a1a2e;
    border-color: rgba(241, 196, 15, 0.4);
    box-shadow: 0 2px 12px rgba(241, 196, 15, 0.3);
}

.ba-spell-btn.poison.ready {
    background: linear-gradient(135deg, #8e44ad, #9b59b6);
    color: #fff;
    border-color: rgba(155, 89, 182, 0.4);
    box-shadow: 0 2px 12px rgba(155, 89, 182, 0.3);
}

.ba-spell-btn.megaheal.ready {
    background: linear-gradient(135deg, #d4a017, #f1c40f);
    color: #1a1a2e;
    border-color: rgba(241, 196, 15, 0.5);
    box-shadow: 0 2px 16px rgba(241, 196, 15, 0.4);
}

.ba-spell-btn.ready:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.ba-spell-btn .spell-icon {
    font-size: 0.85rem;
    display: block;
    margin-bottom: 0px;
}

.ba-spell-btn .spell-cost {
    font-size: 0.5rem;
    opacity: 0.7;
    display: block;
    margin-top: 1px;
}

@keyframes spellReady {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.03); }
}

/* Spell cast flash effect */
.ba-spell-cast {
    animation: spellCast 0.4s ease-out;
}

@keyframes spellCast {
    0% { transform: scale(1); }
    30% { transform: scale(0.9); opacity: 0.5; }
    100% { transform: scale(1); opacity: 1; }
}

/* Intervention effect flash on battle */
.ba-heal-flash {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center, rgba(0, 206, 201, 0.3), transparent 70%);
    pointer-events: none;
    z-index: 100;
    animation: baFlashFade 1s ease-out forwards;
}

.ba-attack-flash {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center, rgba(231, 76, 60, 0.3), transparent 70%);
    pointer-events: none;
    z-index: 100;
    animation: baFlashFade 1s ease-out forwards;
}

@keyframes baFlashFade {
    0% { opacity: 1; }
    100% { opacity: 0; }
}

/* Mobile portrait: optimized battle + puzzle layout */
@media (max-width: 768px) {
    .ba-split-screen {
        flex-direction: column;
    }
    .ba-split-battle {
        flex: 1;
    }
    .ba-split-puzzle {
        flex: none;
        max-width: 100%;
        height: 320px;
        border-left: none;
        border-top: 2px solid rgba(255, 215, 0, 0.15);
        flex-direction: row;
        flex-wrap: wrap;
    }
    /* Increase chess board width by ~20% */
    .ba-split-puzzle .pr-board-container {
        width: 250px !important;
        padding-bottom: 250px !important;
    }
    .ba-spell-bar {
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    /* ── Hide battle log on mobile ── */
    .ba-log {
        display: none !important;
    }

    /* ── Shrink dragon arena ── */
    .ba-field-3d {
        padding: 2px 4px !important;
    }
    .ba-team-row {
        gap: 4px !important;
        padding: 2px 0 !important;
    }
    .ba-arena-center {
        margin: 2px auto !important;
        height: 2px !important;
    }
    /* Shrink dragon cards */
    .ba-dragon-3d {
        width: 60px !important;
        height: 60px !important;
    }
    .ba-dragon {
        gap: 1px !important;
    }
    .ba-dragon-bar {
        width: 50px !important;
        height: 4px !important;
    }
    .ba-dragon-name {
        font-size: 0.42rem !important;
        max-width: 60px !important;
        padding: 0px 3px !important;
    }
    .ba-dragon-lv {
        font-size: 0.35rem !important;
    }
    .ba-dragon-shadow {
        width: 30px !important;
        height: 6px !important;
    }
    .ba-dragon-emoji {
        font-size: 1.5rem !important;
    }
    /* Shrink dragon aura */
    .ba-dragon-3d::before {
        inset: -8px !important;
    }
    /* Compact HUD */
    .ba-hud {
        padding: 4px 8px !important;
    }
    .ba-hud-side {
        font-size: 0.6rem !important;
    }
    .ba-hud-turn {
        font-size: 0.6rem !important;
        padding: 2px 8px !important;
    }
}

