/* Base styles for Emoji Card Battle */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #1a1a2e;
    color: #e6e6e6;
    min-height: 100vh;
    overflow-x: hidden;
}

#game-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

#hud {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #2d2d44;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

#battle-field {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 400px;
    margin-bottom: 20px;
}

#enemy-area, #player-area {
    width: 45%;
    height: 100%;
    background-color: #2d2d44;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

#hand {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    min-height: 100px;
    justify-content: center;
}

/* Turn controls */
#turn-controls {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}

#end-turn-btn {
    padding: 12px 32px;
    font-size: 16px;
    font-weight: bold;
    color: #ffffff;
    background: linear-gradient(135deg, #5a5aff, #3a3acc);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s, background-color 0.2s;
    box-shadow: 0 4px 16px rgba(90, 90, 255, 0.4);
    letter-spacing: 1px;
}

#end-turn-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(90, 90, 255, 0.6);
    background: linear-gradient(135deg, #6a6aff, #4a4acc);
}

#end-turn-btn:active {
    transform: translateY(0);
    box-shadow: 0 4px 16px rgba(90, 90, 255, 0.4);
}

#end-turn-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.card {
    width: 100px;
    height: 150px;
    background-color: #3a3a5a;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, background-color 0.3s;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    position: relative;
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
}

.card.playable {
    background-color: #4a4a7a;
    border: 2px solid #5a9cff;
}

.card.unplayable {
    background-color: #2a2a4a;
    opacity: 0.7;
}

.card.feedback-success {
    background-color: #4a8a4a;
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(74, 138, 74, 0.8);
    animation: pulse 0.5s;
}

.card.feedback-failure {
    background-color: #8a4a4a;
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(138, 74, 74, 0.8);
    animation: pulse 0.5s;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.card-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 10px;
    position: relative;
}

.card-emoji {
    font-size: 48px;
    margin-bottom: 10px;
}

.card-name {
    font-weight: bold;
    margin-bottom: 5px;
    text-align: center;
    font-size: 14px;
}

.card-stats {
    font-size: 12px;
    text-align: center;
    color: #cccccc;
}

/* Mana cost badge on cards */
.card-mana-cost {
    position: absolute;
    top: 6px;
    left: 6px;
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, #1a4a8a, #2196f3);
    border: 2px solid #5a9cff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    color: #ffffff;
    text-shadow: 0 0 3px rgba(0, 0, 0, 0.8);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
    z-index: 10;
}

/* Health bar styles */
.hud-block {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 220px;
}

.hud-block-title {
    font-size: 13px;
    font-weight: bold;
    color: #aaaacc;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 2px;
}

.bar-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.bar-icon {
    font-size: 14px;
    width: 20px;
    text-align: center;
}

.bar-track {
    flex: 1;
    height: 18px;
    background-color: #1a1a2e;
    border-radius: 9px;
    overflow: hidden;
    border: 1px solid #3a3a5a;
    min-width: 120px;
}

.mana-track {
    border-color: #2a4a7a;
}

.bar-fill {
    height: 100%;
    width: 100%;
    border-radius: 9px;
    transition: width 0.4s ease-in-out, background-color 0.4s ease-in-out;
}

/* HP colour states */
.bar-fill.hp-green {
    background: linear-gradient(90deg, #2d7a2d, #4caf50);
    box-shadow: 0 0 6px rgba(76, 175, 80, 0.5);
}

.bar-fill.hp-orange {
    background: linear-gradient(90deg, #b36200, #ff9800);
    box-shadow: 0 0 6px rgba(255, 152, 0, 0.5);
}

.bar-fill.hp-red {
    background: linear-gradient(90deg, #7a1a1a, #f44336);
    box-shadow: 0 0 6px rgba(244, 67, 54, 0.6);
    animation: lowHpPulse 1s ease-in-out infinite;
}

/* Mana bar always blue */
.bar-fill.mana-fill {
    background: linear-gradient(90deg, #1a4a8a, #2196f3);
    box-shadow: 0 0 6px rgba(33, 150, 243, 0.4);
}

.bar-value {
    font-size: 12px;
    color: #cccccc;
    min-width: 48px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

@keyframes lowHpPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* legacy selectors kept for safety */
.health-bar-container { display: flex; align-items: center; gap: 10px; }
.health-bar-label { font-weight: bold; color: #cccccc; }
.health-bar { flex: 1; height: 20px; background-color: #2a2a4a; border-radius: 10px; overflow: hidden; }
.health-bar-fill { height: 100%; width: 100%; transition: width 0.5s ease-in-out; }

/* Floating damage numbers */
.floating-damage-number {
    position: absolute;
    font-size: 24px;
    font-weight: bold;
    pointer-events: none;
    z-index: 1000;
}

.float-up {
    animation: floatUp 1s forwards;
}

/* Animation classes */
.flash-red {
    animation: flashRed 0.5s;
}

.screen-shake {
    animation: screenShake 0.3s;
}

.victory-pulse {
    animation: victoryPulse 2s infinite;
}

.defeat-pulse {
    animation: defeatPulse 2s infinite;
}

.card-click-press {
    animation: cardClickPress 0.2s;
}

#deck {
    display: flex;
    gap: 10px;
    min-height: 50px;
}

/* Ensure health bars are visible */
#player-stats, #enemy-stats {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ─── Enemy / Player graphics in battle-field ─── */
#enemy-area, #player-area {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

#enemy-graphic, #player-graphic {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

#enemy-emoji {
    font-size: 96px;
    line-height: 1;
    animation: enemyBob 1.8s ease-in-out infinite;
    filter: drop-shadow(0 8px 16px rgba(0,200,0,0.3));
}

#player-emoji {
    font-size: 80px;
    line-height: 1;
    animation: playerIdle 2.4s ease-in-out infinite;
    filter: drop-shadow(0 8px 16px rgba(100,100,255,0.3));
}

#enemy-name, #player-name {
    font-size: 13px;
    font-weight: bold;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: #aaaacc;
}

@keyframes enemyBob {
    0%, 100% { transform: translateY(0) scale(1); }
    40%       { transform: translateY(-14px) scale(1.05); }
    60%       { transform: translateY(-10px) scale(1.03); }
}

@keyframes playerIdle {
    0%, 100% { transform: translateY(0); }
    50%       { transform: translateY(-6px); }
}

/* Flash enemy red when hit */
#enemy-area.hit {
    animation: enemyHit 0.35s ease-out;
}

@keyframes enemyHit {
    0%   { filter: brightness(1); }
    30%  { filter: brightness(2.5) sepia(1) hue-rotate(-30deg); }
    100% { filter: brightness(1); }
}

/* ─── Game Over Overlay ─── */
.game-over-hidden {
    display: none;
}

.game-over-visible {
    display: flex;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.82);
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

#game-over-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 48px 56px;
    border-radius: 16px;
    text-align: center;
    min-width: 340px;
    animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popIn {
    from { transform: scale(0.7); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}

.victory-box {
    background: linear-gradient(160deg, #1a3a1a, #0d200d);
    border: 2px solid #4caf50;
    box-shadow: 0 0 40px rgba(76, 175, 80, 0.5);
}

.defeat-box {
    background: linear-gradient(160deg, #3a1a1a, #200d0d);
    border: 2px solid #f44336;
    box-shadow: 0 0 40px rgba(244, 67, 54, 0.5);
}

#game-over-emoji {
    font-size: 80px;
    animation: bounceIn 0.6s ease-out;
}

@keyframes bounceIn {
    0%   { transform: scale(0) rotate(-20deg); }
    60%  { transform: scale(1.2) rotate(5deg); }
    100% { transform: scale(1) rotate(0deg); }
}

#game-over-title {
    font-size: 42px;
    font-weight: 900;
    letter-spacing: 3px;
    margin: 0;
    color: #ffffff;
    text-shadow: 0 0 20px currentColor;
}

.victory-box #game-over-title { color: #4caf50; }
.defeat-box  #game-over-title { color: #f44336; }

#game-over-subtitle {
    font-size: 16px;
    color: #cccccc;
    margin: 0;
}

#game-over-stats {
    width: 100%;
    background: rgba(255,255,255,0.05);
    border-radius: 10px;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    color: #dddddd;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    padding-bottom: 6px;
}

.stat-row:last-child { border-bottom: none; padding-bottom: 0; }

#game-over-btn {
    margin-top: 8px;
    padding: 14px 40px;
    font-size: 16px;
    font-weight: bold;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    background: linear-gradient(135deg, #5a5aff, #3a3acc);
    color: #fff;
    letter-spacing: 1px;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 4px 16px rgba(90, 90, 255, 0.4);
}

#game-over-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(90, 90, 255, 0.6);
}

#game-over-btn:active {
    transform: translateY(0);
}

#game-over-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

#game-over-retry, #game-over-continue {
    padding: 12px 24px;
    font-size: 14px;
    font-weight: bold;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}

#game-over-retry {
    background: linear-gradient(135deg, #6a6a6a, #4a4a4a);
    color: #fff;
    box-shadow: 0 4px 12px rgba(100, 100, 100, 0.4);
}

#game-over-retry:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(100, 100, 100, 0.6);
}

#game-over-continue {
    background: linear-gradient(135deg, #5a5aff, #3a3acc);
    color: #fff;
    box-shadow: 0 4px 16px rgba(90, 90, 255, 0.4);
}

#game-over-continue:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(90, 90, 255, 0.6);
}

/* ─── Level Select Screen ─── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    align-items: center;
    justify-content: center;
    z-index: 9000;
    animation: fadeIn 0.3s ease-out;
}

.modal-content {
    background: linear-gradient(160deg, #2d2d44, #1a1a2e);
    border-radius: 16px;
    border: 2px solid #3a3a5a;
    box-shadow: 0 0 40px rgba(90, 90, 255, 0.3);
    max-width: 900px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid #3a3a5a;
}

.modal-header h2 {
    margin: 0;
    color: #ffffff;
    font-size: 24px;
    letter-spacing: 1px;
}

.modal-close {
    background: none;
    border: none;
    color: #aaaaaa;
    font-size: 32px;
    cursor: pointer;
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: background-color 0.2s, color 0.2s;
}

.modal-close:hover {
    background-color: #3a3a5a;
    color: #ffffff;
}

.level-select-content {
    padding: 24px;
}

.progress-summary {
    margin-bottom: 24px;
    text-align: center;
}

.progress-summary p {
    margin-bottom: 10px;
    color: #cccccc;
    font-size: 14px;
}

.progress-bar {
    height: 12px;
    background-color: #1a1a2e;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid #3a3a5a;
    max-width: 400px;
    margin: 0 auto;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #4caf50, #8bc34a);
    border-radius: 6px;
    transition: width 0.5s ease-in-out;
    box-shadow: 0 0 10px rgba(76, 175, 80, 0.5);
}

.levels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
}

.level-card {
    background: linear-gradient(160deg, #3a3a5a, #2d2d44);
    border-radius: 12px;
    border: 2px solid #4a4a7a;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
    cursor: pointer;
}

.level-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.level-card-completed {
    border-color: #4caf50;
}

.level-card-completed:hover {
    border-color: #8bc34a;
}

.level-card-current {
    border-color: #2196f3;
    box-shadow: 0 0 20px rgba(33, 150, 243, 0.3);
}

.level-card-current:hover {
    border-color: #64b5f6;
}

.level-card-locked {
    border-color: #3a3a5a;
    opacity: 0.7;
    cursor: not-allowed;
}

.level-card-locked:hover {
    transform: none;
}

.level-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid #4a4a7a;
}

.level-number {
    font-size: 12px;
    font-weight: bold;
    color: #8888aa;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.level-status-icon {
    font-size: 16px;
}

.level-card-body {
    padding: 16px;
}

.level-name {
    margin: 0 0 8px 0;
    font-size: 18px;
    color: #ffffff;
}

.level-description {
    margin: 0 0 12px 0;
    font-size: 13px;
    color: #aaaaaa;
    line-height: 1.4;
}

.level-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
}

.level-difficulty {
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.level-enemy {
    color: #cccccc;
}

.btn-start-level {
    width: 100%;
    padding: 12px;
    font-size: 14px;
    font-weight: bold;
    color: #ffffff;
    background: linear-gradient(135deg, #5a5aff, #3a3acc);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 4px 12px rgba(90, 90, 255, 0.3);
}

.btn-start-level:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(90, 90, 255, 0.5);
}

.btn-start-level:active {
    transform: translateY(0);
}

.campaign-complete {
    margin-top: 24px;
    text-align: center;
    padding: 20px;
    background: linear-gradient(160deg, #1a3a1a, #0d200d);
    border-radius: 12px;
    border: 2px solid #4caf50;
}

.campaign-complete h3 {
    margin: 0 0 16px 0;
    color: #4caf50;
    font-size: 20px;
}

.btn-secondary {
    padding: 10px 24px;
    font-size: 14px;
    font-weight: bold;
    color: #ffffff;
    background: linear-gradient(135deg, #6a6a6a, #4a4a4a);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}

.btn-secondary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(100, 100, 100, 0.4);
}

/* Level select button in HUD */
#new-run-btn {
    padding: 8px 16px;
    font-size: 13px;
    font-weight: bold;
    color: #ffffff;
    background: linear-gradient(135deg, #5a5aff, #3a3acc);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 2px 8px rgba(90, 90, 255, 0.3);
}

#new-run-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(90, 90, 255, 0.5);
}

#round-info {
    font-weight: bold;
    color: #ffd700;
    text-shadow: 0 0 5px rgba(255, 215, 0, 0.5);
}