@import url('https://fonts.googleapis.com/css2?family=Caveat:wght@400;600;700&family=JetBrains+Mono:wght@400;600&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Georgia', serif;
    background: #e8ddd0;
    background-image: 
        repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(139, 115, 85, 0.03) 2px, rgba(139, 115, 85, 0.03) 4px),
        repeating-linear-gradient(90deg, transparent, transparent 2px, rgba(139, 115, 85, 0.03) 2px, rgba(139, 115, 85, 0.03) 4px);
    color: #1a1a1a;
    overflow: hidden;
}

/* Unit Phrase Display */
.unit-phrase {
    position: fixed;
    pointer-events: none;
    z-index: 60;
    
    transform: translate(-50%, -100%);
    
    background: rgba(245, 235, 224, 0.95);
    border: 2px solid #4a3520;
    border-radius: 8px;
    padding: 6px 12px;
    
    font-family: 'Caveat', cursive;
    font-size: 16px;
    font-weight: 600;
    color: #4a3520;
    text-align: center;
    white-space: pre-wrap;
    max-width: 120px;
    line-height: 1.2;
    
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    
    animation: phraseFadeIn 0.2s ease-out;
}

.unit-phrase.flip-phrase {
    background: rgba(255, 215, 0, 0.95);
    border-color: #d4a574;
    color: #7f1d1d;
    font-weight: 700;
    font-size: 18px;
    box-shadow: 0 3px 12px rgba(212, 167, 116, 0.4);
}

.unit-phrase.ranged-penalty-phrase {
    background: rgba(255, 100, 100, 0.95);
    border-color: #dc2626;
    color: #7f1d1d;
    font-weight: 700;
    font-size: 14px;
    max-width: 180px;
    box-shadow: 0 3px 12px rgba(220, 38, 38, 0.4);
}

.unit-phrase.campfire-rest-phrase {
    background: rgba(100, 220, 130, 0.95);
    border-color: #22c55e;
    color: #166534;
    font-weight: 700;
    font-size: 14px;
    max-width: 220px;
    box-shadow: 0 3px 12px rgba(34, 197, 94, 0.4);
}

.unit-phrase.fade-out {
    animation: phraseFadeOut 0.3s ease-out forwards;
}

@keyframes phraseFadeIn {
    from {
        opacity: 0;
        transform: translate(-50%, -120%);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -100%);
    }
}

@keyframes phraseFadeOut {
    from {
        opacity: 1;
        transform: translate(-50%, -100%);
    }
    to {
        opacity: 0;
        transform: translate(-50%, -80%);
    }
}

/* Campfire frame styling */
.campfire-frame {
    animation: campfireGlow 1s ease-in-out infinite alternate;
}

@keyframes campfireGlow {
    0% {
        box-shadow: 0 8px 32px rgba(255, 100, 0, 0.4);
    }
    100% {
        box-shadow: 0 8px 48px rgba(255, 150, 50, 0.6);
    }
}

/* Hedgey wizard fade-in animation on game load */
@keyframes hedgeyFadeInOut {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5);
    }
    30% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.1);
    }
    50% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    70% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.05);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }
}

/* Instructions Overlay */
.instructions-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(26, 26, 26, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    cursor: pointer;
    animation: fadeIn 0.3s ease-out;
}

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

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

.instructions-card {
    background: #f5ebe0;
    background-image: 
        repeating-linear-gradient(0deg, transparent, transparent 1px, rgba(139, 115, 85, 0.05) 1px, rgba(139, 115, 85, 0.05) 2px);
    border: 3px solid #4a3520;
    border-radius: 12px;
    padding: 40px;
    max-width: 600px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    animation: slideUp 0.4s ease-out;
}

@keyframes slideUp {
    from {
        transform: translateY(30px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.instructions-card h2 {
    font-family: 'Caveat', cursive;
    font-size: 42px;
    font-weight: 700;
    color: #4a3520;
    margin-bottom: 24px;
    text-align: center;
    letter-spacing: 1px;
}

.instructions-card p {
    font-size: 18px;
    line-height: 1.8;
    margin-bottom: 16px;
    color: #1a1a1a;
}

.instructions-card p:last-of-type {
    margin-bottom: 0;
}

.instructions-card strong {
    color: #4a3520;
    font-weight: 700;
}

.instructions-card a {
    color: #4a3520;
    text-decoration: underline;
    transition: color 0.2s ease;
}

.instructions-card a:hover {
    color: #1a1a1a;
}

.tap-hint {
    margin-top: 32px;
    text-align: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    color: #666;
    opacity: 0.7;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 0.8; }
}

#hud {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 80px;
    background: #f5ebe0;
    background-image: 
        repeating-linear-gradient(0deg, transparent, transparent 1px, rgba(139, 115, 85, 0.05) 1px, rgba(139, 115, 85, 0.05) 2px);
    border-bottom: 2px solid #8b7355;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    padding-top: calc(10px + env(safe-area-inset-top));
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

#hud-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

#hud-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

#logo-container {
    flex-shrink: 0;
}

#game-logo {
    max-height: 42px;
    width: auto;
    height: auto;
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
}

.info-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1.5px solid #4a3520;
    background: #f5ebe0;
    color: #4a3520;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.info-btn:hover {
    background: #4a3520;
    color: #f5ebe0;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

/* Hide add friend button in multiplayer mode */
.info-btn.mp-hide.multiplayer-active {
    display: none;
}

/* Hide add friend button in story mode */
.info-btn.arcade-only.story-mode {
    display: none;
}

#turn-info {
    display: flex;
    gap: 8px 14px;
    align-items: center;
    flex-wrap: wrap;
}

#turn-indicator {
    font-family: 'Caveat', cursive;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: 1px;
}

#round-counter {
    font-size: 16px;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    opacity: 0.8;
}

#game-container {
    position: fixed;
    top: 80px;
    left: 0;
    right: 0;
    bottom: 115px;
    display: flex;
}

#scene-container {
    flex: 1;
    position: relative;
}

#right-panel {
    width: 250px;
    background: #f5ebe0;
    background-image: 
        repeating-linear-gradient(0deg, transparent, transparent 1px, rgba(139, 115, 85, 0.05) 1px, rgba(139, 115, 85, 0.05) 2px);
    border-left: 2px solid #8b7355;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.05);
}

.panel-section {
    padding: 20px;
    border-bottom: 1px solid #c4a77d;
}

.panel-section:last-child {
    border-bottom: none;
}

.panel-section h3 {
    font-family: 'Caveat', cursive;
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 15px;
    color: #4a3520;
    letter-spacing: 0.5px;
}

#unit-stats {
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    line-height: 1.8;
}

#unit-stats div {
    padding: 5px;
    border-radius: 3px;
    background: rgba(139, 115, 85, 0.08);
    margin-bottom: 5px;
    border-left: 2px solid transparent;
}

/* Orbit Joystick (bottom left) */
#orbit-joystick {
    position: fixed;
    bottom: 130px;
    left: 20px;
    z-index: 105;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

#joystick-outer {
    width: 90px;
    height: 90px;
    background: #f5ebe0;
    background-image: 
        repeating-linear-gradient(0deg, transparent, transparent 1px, rgba(139, 115, 85, 0.05) 1px, rgba(139, 115, 85, 0.05) 2px);
    border: 2px solid #4a3520;
    border-radius: 50%;
    position: relative;
    cursor: grab;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    touch-action: none;
    user-select: none;
}

#joystick-outer:active {
    cursor: grabbing;
}

#joystick-inner {
    width: 36px;
    height: 36px;
    background: #4a3520;
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
    transition: transform 0.1s ease-out;
}

.joystick-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 600;
    color: #4a3520;
    text-align: center;
    letter-spacing: 1px;
}

/* Zoom Control (bottom middle) */
#zoom-control {
    position: fixed;
    bottom: 130px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 105;
    background: #f5ebe0;
    background-image: 
        repeating-linear-gradient(0deg, transparent, transparent 1px, rgba(139, 115, 85, 0.05) 1px, rgba(139, 115, 85, 0.05) 2px);
    border: 2px solid #4a3520;
    border-radius: 8px;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 180px;
}

.zoom-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 600;
    color: #4a3520;
    letter-spacing: 1px;
}

#zoom-slider {
    width: 140px;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(139, 115, 85, 0.2);
    border-radius: 3px;
    outline: none;
}

#zoom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: #4a3520;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: transform 0.1s ease;
}

#zoom-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

#zoom-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: #4a3520;
    border-radius: 50%;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: transform 0.1s ease;
}

#zoom-slider::-moz-range-thumb:hover {
    transform: scale(1.1);
}

.zoom-buttons {
    display: flex;
    gap: 8px;
}

.zoom-btn {
    width: 32px;
    height: 32px;
    background: rgba(139, 115, 85, 0.1);
    border: 1.5px solid #8b7355;
    border-radius: 6px;
    color: #4a3520;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.zoom-btn:hover {
    background: #4a3520;
    color: #f5ebe0;
    transform: translateY(-2px);
}

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

/* Attack Mode Selector (appears when unit selected) */
#attack-mode-selector {
    position: fixed;
    bottom: 130px;
    right: 20px;
    background: #f5ebe0;
    background-image: 
        repeating-linear-gradient(0deg, transparent, transparent 1px, rgba(139, 115, 85, 0.05) 1px, rgba(139, 115, 85, 0.05) 2px);
    border: 2px solid #4a3520;
    border-radius: 8px;
    padding: 15px;
    z-index: 120;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* On small screens where footer overlaps, make attack selector translucent */
@media (max-height: 700px) {
    #attack-mode-selector {
        bottom: 110px;
        background: rgba(245, 235, 224, 0.85);
        backdrop-filter: blur(4px);
    }
    
    #attack-mode-selector .attack-mode-btn {
        background: rgba(139, 115, 85, 0.15);
    }
    
    #attack-mode-selector .attack-mode-btn.active {
        background: rgba(74, 53, 32, 0.85);
    }
}

.attack-mode-title {
    font-family: 'Caveat', cursive;
    font-size: 18px;
    font-weight: 700;
    color: #4a3520;
    text-align: center;
    margin-bottom: 10px;
    letter-spacing: 0.5px;
}

.attack-mode-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    margin-bottom: 8px;
    background: rgba(139, 115, 85, 0.1);
    border: 1.5px solid #8b7355;
    border-radius: 6px;
    color: #4a3520;
    font-family: 'Georgia', serif;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 160px;
}

.attack-mode-btn:last-child {
    margin-bottom: 0;
}

.attack-mode-btn:hover:not(:disabled) {
    background: rgba(139, 115, 85, 0.2);
    border-color: #4a3520;
    transform: translateX(-3px);
}

.attack-mode-btn.active {
    background: #4a3520;
    border-color: #4a3520;
    color: #f5ebe0;
    box-shadow: 0 2px 8px rgba(74, 53, 32, 0.3);
}

.attack-mode-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.attack-icon {
    font-size: 20px;
}

.attack-label {
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Event Log */
#event-log-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 120px;
    background: #f5ebe0;
    background-image: 
        repeating-linear-gradient(0deg, transparent, transparent 1px, rgba(139, 115, 85, 0.05) 1px, rgba(139, 115, 85, 0.05) 2px);
    border-top: 2px solid #8b7355;
    z-index: 90;
    overflow: hidden;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
}

/* Unit Selection Footer */
#unit-selection-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 115px;
    background: #f5ebe0;
    background-image: 
        repeating-linear-gradient(0deg, transparent, transparent 1px, rgba(139, 115, 85, 0.05) 1px, rgba(139, 115, 85, 0.05) 2px);
    border-top: 2px solid #8b7355;
    z-index: 90;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0 10px 10px 60px;
}

.inventory-btn {
    position: absolute;
    left: 10px;
    bottom: 35px;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    border: 2px solid #4a3520;
    background: #f5ebe0;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    z-index: 95;
}

.inventory-btn:hover {
    background: #4a3520;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.inventory-box {
    position: fixed;
    bottom: 130px;
    left: 10px;
    background: #f5ebe0;
    background-image: 
        repeating-linear-gradient(0deg, transparent, transparent 1px, rgba(139, 115, 85, 0.05) 1px, rgba(139, 115, 85, 0.05) 2px);
    border: 2px solid #4a3520;
    border-radius: 8px;
    padding: 12px 16px;
    z-index: 120;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    min-width: 180px;
}

.inventory-title {
    font-family: 'Caveat', cursive;
    font-size: 18px;
    font-weight: 700;
    color: #4a3520;
    text-align: center;
    margin-bottom: 10px;
    letter-spacing: 0.5px;
}

.inventory-coins {
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    font-weight: 600;
    color: #4a3520;
    margin-bottom: 10px;
}

.inventory-coin-count {
    color: #d4a520;
}

.inventory-book-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 4px;
}

.book-slot {
    width: 28px;
    height: 28px;
    background: rgba(139, 115, 85, 0.1);
    border: 1px solid #8b7355;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    position: relative;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
}

.book-slot-count {
    position: absolute;
    bottom: 0;
    right: 0;
    background: rgba(74, 53, 32, 0.9);
    color: #f5ebe0;
    font-size: 8px;
    font-weight: 700;
    padding: 1px 3px;
    border-radius: 3px 0 3px 0;
    line-height: 1;
    min-width: 10px;
    text-align: center;
}

#unit-cards-container {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    justify-content: flex-start;
    height: 100%;
    padding-top: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(139, 115, 85, 0.3) transparent;
}

#unit-cards-container::-webkit-scrollbar {
    height: 6px;
}

#unit-cards-container::-webkit-scrollbar-track {
    background: transparent;
}

#unit-cards-container::-webkit-scrollbar-thumb {
    background: rgba(139, 115, 85, 0.3);
    border-radius: 3px;
}

.unit-card {
    width: 70px;
    min-width: 70px;
    height: 95px;
    min-height: 95px;
    background: rgba(120, 170, 255, 0.85);
    border: 2px solid #8b7355;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    position: relative;
    overflow: hidden;
    padding: 18px 2px 4px 2px;
}

.unit-card.team-blue {
    background: rgba(120, 170, 255, 0.85);
}

.unit-card.team-red {
    background: rgba(255, 140, 140, 0.85);
}

/* HP-based background overlay - white grows as HP depletes */
.unit-card::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: var(--hp-missing-percent, 0%);
    background: rgba(255, 255, 255, 0.95);
    transition: width 0.15s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    z-index: 0;
    pointer-events: none;
}

/* Ensure card contents appear above the overlay */
.unit-card > * {
    position: relative;
    z-index: 1;
}

.unit-card-hp {
    font-family: 'JetBrains Mono', monospace;
    font-size: 9px;
    font-weight: 600;
    color: #4a3520;
    position: absolute;
    top: 2px;
    left: 2px;
    white-space: nowrap;
    background: rgba(245, 235, 224, 0.95);
    padding: 1px 4px;
    border-radius: 3px;
    border: 1px solid #8b7355;
    z-index: 5;
}

.unit-card-attack {
    font-family: 'JetBrains Mono', monospace;
    font-size: 9px;
    font-weight: 600;
    color: #4a3520;
    position: absolute;
    top: 2px;
    right: 2px;
    white-space: nowrap;
    background: rgba(245, 235, 224, 0.95);
    padding: 1px 4px;
    border-radius: 3px;
    border: 1px solid #8b7355;
    z-index: 5;
}

.unit-card-name {
    font-family: 'JetBrains Mono', monospace;
    font-size: 9px;
    font-weight: 600;
    color: #4a3520;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 66px;
    margin-top: 2px;
}

.unit-card-class {
    font-family: 'JetBrains Mono', monospace;
    font-size: 7px;
    font-weight: 700;
    color: #4a3520;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 66px;
    text-transform: capitalize;
}

.unit-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.unit-card.selected {
    transform: translateY(-20px);
    border-color: #d4a574;
    box-shadow: 0 6px 16px rgba(212, 165, 116, 0.4);
}

.unit-card.acted {
    opacity: 0.5;
    cursor: not-allowed;
}

.unit-card.acted:hover {
    transform: none;
}

.unit-card-sprite {
    width: 46px;
    height: 46px;
    image-rendering: pixelated;
    object-fit: contain;
    flex-shrink: 0;
    position: relative;
    z-index: 6;
}

.unit-card-team-indicator {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.3);
}

.unit-card-team-indicator.blue {
    background: #1e3a8a;
}

.unit-card-team-indicator.red {
    background: #7f1d1d;
}

/* Unit card flash effects */
.unit-card.flash-attack {
    animation: cardFlashOrange 0.3s ease-out;
}

.unit-card.flash-heal {
    animation: cardFlashGreen 0.3s ease-out;
}

@keyframes cardFlashOrange {
    0%, 100% {
        background: rgba(120, 170, 255, 0.85);
    }
    25%, 75% {
        background: rgba(255, 160, 80, 0.95);
        box-shadow: 0 0 12px rgba(255, 140, 60, 0.6);
    }
}

@keyframes cardFlashGreen {
    0%, 100% {
        background: rgba(120, 170, 255, 0.85);
    }
    25%, 75% {
        background: rgba(100, 220, 130, 0.95);
        box-shadow: 0 0 12px rgba(34, 197, 94, 0.6);
    }
}

/* Red team card flash animations */
.unit-card.team-red.flash-attack {
    animation: cardFlashOrangeRed 0.3s ease-out;
}

.unit-card.team-red.flash-heal {
    animation: cardFlashGreenRed 0.3s ease-out;
}

@keyframes cardFlashOrangeRed {
    0%, 100% {
        background: rgba(255, 140, 140, 0.85);
    }
    25%, 75% {
        background: rgba(255, 160, 80, 0.95);
        box-shadow: 0 0 12px rgba(255, 140, 60, 0.6);
    }
}

@keyframes cardFlashGreenRed {
    0%, 100% {
        background: rgba(255, 140, 140, 0.85);
    }
    25%, 75% {
        background: rgba(100, 220, 130, 0.95);
        box-shadow: 0 0 12px rgba(34, 197, 94, 0.6);
    }
}

#event-log {
    height: 100%;
    padding: 10px 20px;
    overflow-y: auto;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    line-height: 1.6;
    display: flex;
    flex-direction: column;
}

.event-entry {
    padding: 4px 8px;
    margin-bottom: 3px;
    background: rgba(139, 115, 85, 0.08);
    border-radius: 3px;
    white-space: nowrap;
    flex-shrink: 0;
}

.event-entry.flip {
    background: rgba(212, 167, 116, 0.3);
    border-left: 3px solid #d4a774;
    padding-left: 8px;
    font-weight: 600;
    animation: flipPulse 0.5s ease-out;
}

.event-entry.round {
    background: rgba(74, 53, 32, 0.15);
    border-left: 3px solid #4a3520;
    padding-left: 8px;
    font-weight: 600;
}

.event-entry.victory {
    background: rgba(74, 53, 32, 0.25);
    border-left: 3px solid #4a3520;
    padding-left: 8px;
    font-weight: 700;
    font-size: 12px;
}

@keyframes flipPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

#controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: #f5ebe0;
    background-image: 
        repeating-linear-gradient(0deg, transparent, transparent 1px, rgba(139, 115, 85, 0.05) 1px, rgba(139, 115, 85, 0.05) 2px);
    border-top: 2px solid #8b7355;
    align-items: center;
    padding: 0 20px;
    gap: 15px;
    overflow-x: auto;
    z-index: 100;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
}

.btn-primary, .btn-danger {
    padding: 10px 24px;
    font-size: 14px;
    font-weight: 600;
    font-family: 'Georgia', serif;
    border: 1.5px solid #4a3520;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
    white-space: nowrap;
    background: #f5ebe0;
    color: #4a3520;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
    background: #4a3520;
    color: #f5ebe0;
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-danger {
    border-color: #7f1d1d;
    color: #7f1d1d;
}

.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(127, 29, 29, 0.2);
    background: #7f1d1d;
    color: #f5ebe0;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

#coord-display {
    margin-left: auto;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    color: #666;
    white-space: nowrap;
}

#game-over-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(232, 221, 208, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.5s ease-out;
}

#game-over-content {
    text-align: center;
    animation: slideUp 0.5s ease-out;
    padding: 20px;
}

#winner-text {
    font-family: 'Caveat', cursive;
    font-size: 64px;
    font-weight: 700;
    margin-bottom: 20px;
    letter-spacing: 2px;
}

#victory-condition {
    font-family: 'Georgia', serif;
    font-size: 20px;
    margin-bottom: 30px;
    opacity: 0.8;
}

/* Unit Health Bars - INVERTED SYSTEM with wider bar and single-line text */
#unit-health-bars {
    position: fixed;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 50;
    width: 100%;
    height: 100%;
}

.unit-health-bar {
    position: absolute;
    pointer-events: none;
    transform: translate(-50%, -100%);
    min-width: 120px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.25));
}

.hp-bar-background {
    position: relative;
    height: 20px;
    border: 2px solid rgba(0, 0, 0, 0.65);
    border-radius: 6px;
    overflow: hidden;
}

/* Team color base - shows when at full HP */
.hp-bar-background.team-blue {
    background: rgba(120, 170, 255, 0.85);
}

.hp-bar-background.team-red {
    background: rgba(255, 140, 140, 0.85);
}

/* White overlay for missing HP - anchored to right */
.hp-bar-missing {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.95);
    transition: width 0.15s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    z-index: 1;
}

.hp-bar-text {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    font-weight: 700;
    color: rgba(20, 20, 20, 0.95);
    z-index: 2;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
    letter-spacing: 0.3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 4px;
}

.hp-bar-team-dot {
    position: absolute;
    left: 3px;
    top: 50%;
    transform: translateY(-50%);
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #1e3a8a;
    z-index: 3;
    border: 1px solid rgba(26, 26, 26, 0.3);
}

.instructions-footer {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid rgba(139, 115, 85, 0.3);
    text-align: center;
    font-size: 12px;
    color: #666;
}

.instructions-footer a {
    color: #4a3520;
    text-decoration: none;
    transition: color 0.3s ease;
    font-weight: 600;
}

.instructions-footer a:hover {
    color: #1a1a1a;
}

/* Game Mode Selection Dialog */
.game-mode-card {
    text-align: center;
    max-width: 420px;
    padding: 40px 50px;
}

.game-mode-card h2 {
    font-family: 'Caveat', cursive;
    font-size: 38px;
    font-weight: 700;
    color: #4a3520;
    margin-bottom: 16px;
    letter-spacing: 1px;
}

.game-mode-characters {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 8px;
    margin-bottom: 20px;
    width: 100%;
    padding: 0 10px;
}

.game-mode-sprite {
    flex: 1 1 0;
    max-width: calc((100% - 16px) / 3);
    height: auto;
    aspect-ratio: 1 / 1;
    object-fit: contain;
    image-rendering: pixelated;
}

.game-mode-subtitle {
    font-size: 18px;
    color: #1a1a1a;
    margin-bottom: 28px;
}

.game-mode-buttons {
    display: flex;
    flex-direction: column;
    gap: 14px;
    align-items: center;
}

.game-mode-row {
    display: flex;
    gap: 14px;
    justify-content: center;
}

.game-mode-btn {
    padding: 14px 32px;
    font-size: 18px;
    font-weight: 600;
    font-family: 'Georgia', serif;
    border: 2.5px solid #4a3520;
    border-radius: 10px;
    cursor: pointer;
    background: #f5ebe0;
    color: #4a3520;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
    transition: all 0.25s ease;
    min-width: 130px;
    letter-spacing: 0.5px;
}

.game-mode-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.2);
}

.game-mode-btn:active {
    transform: translateY(-1px);
}

.game-mode-btn.arcade-btn:hover {
    background: #ff6b35;
    border-color: #ff6b35;
    color: #fff;
}

.game-mode-btn.story-btn:hover {
    background: #1e3a8a;
    border-color: #1e3a8a;
    color: #fff;
}

.game-mode-btn.multiplayer-btn {
    min-width: 200px;
}

.game-mode-btn.multiplayer-btn:hover {
    background: #22c55e;
    border-color: #22c55e;
    color: #fff;
}

.game-mode-experimental-divider {
    width: 80%;
    height: 2px;
    background: linear-gradient(90deg, transparent, #8b7355, transparent);
    margin: 20px auto 16px auto;
}

.game-mode-btn.experimental-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 12px 28px;
    background: #2a2a2a;
    border-color: #555;
    color: #ccc;
    min-width: 220px;
}

.game-mode-btn.experimental-btn:hover {
    background: #9333ea;
    border-color: #9333ea;
    color: #fff;
}

.game-mode-btn.experimental-btn .experimental-title {
    font-size: 16px;
    font-weight: 600;
}

.game-mode-btn.experimental-btn .experimental-label {
    font-size: 11px;
    font-weight: 400;
    opacity: 0.7;
    font-style: italic;
}

/* Multiplayer Win/Loss Dialog */
.mp-result-card {
    text-align: center;
    max-width: 400px;
    padding: 40px;
}

.mp-result-card h2 {
    font-family: 'Caveat', cursive;
    font-size: 56px;
    margin-bottom: 24px;
    letter-spacing: 2px;
}

.mp-result-card h2.won {
    color: #22c55e;
    text-shadow: 0 2px 8px rgba(34, 197, 94, 0.3);
}

.mp-result-card h2.lost {
    color: #7f1d1d;
    text-shadow: 0 2px 8px rgba(127, 29, 29, 0.3);
}

.mp-result-image {
    width: 180px;
    height: 180px;
    image-rendering: pixelated;
    object-fit: contain;
    margin-bottom: 24px;
    animation: resultImagePulse 1.5s ease-in-out infinite;
}

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

.mp-result-card p {
    font-family: 'JetBrains Mono', monospace;
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 28px;
    color: #4a3520;
}

.mp-result-card .btn-primary {
    padding: 16px 48px;
    font-size: 20px;
    animation: continueBtnGlow 2s ease-in-out infinite;
}

@keyframes continueBtnGlow {
    0%, 100% { box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15); }
    50% { box-shadow: 0 6px 16px rgba(74, 53, 32, 0.3); }
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(139, 115, 85, 0.1);
}

::-webkit-scrollbar-thumb {
    background: rgba(139, 115, 85, 0.3);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(139, 115, 85, 0.5);
}

/* Hide zoom control on mobile */
@media (max-width: 768px) {
    #zoom-control {
        display: none;
    }
}

/* Mobile-first responsive design */
@media (max-width: 768px) {
    .unit-phrase {
        font-size: 14px;
        padding: 4px 10px;
        max-width: 100px;
    }
    
    .unit-phrase.flip-phrase {
        font-size: 16px;
    }

    .instructions-card {
        padding: 30px 25px;
        max-width: 90%;
    }
    
    .instructions-card h2 {
        font-size: 32px;
        margin-bottom: 18px;
    }
    
    .instructions-card p {
        font-size: 16px;
        line-height: 1.6;
        margin-bottom: 14px;
    }
    
    .tap-hint {
        margin-top: 24px;
        font-size: 12px;
    }

    #hud {
        height: 70px;
        padding: 8px 10px;
        padding-top: calc(8px + env(safe-area-inset-top));
    }
    
    #hud-left {
        gap: 10px;
    }
    
    #game-logo {
        max-height: 36px;
    }
    
    .info-btn {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }
    
    #right-panel {
        display: none;
    }
    
    #game-container {
        right: 0;
        bottom: 80px;
        top: 70px;
    }
    
    #turn-info {
        gap: 6px 10px;
    }
    
    #turn-indicator {
        font-size: 20px;
    }
    
    #round-counter {
        font-size: 14px;
    }
    
    #orbit-joystick {
        bottom: 90px;
        left: 10px;
    }
    
    #joystick-outer {
        width: 70px;
        height: 70px;
    }
    
    #joystick-inner {
        width: 28px;
        height: 28px;
    }
    
    .joystick-label {
        font-size: 10px;
    }
    
    #zoom-control {
        bottom: 90px;
        min-width: 150px;
        padding: 10px 12px;
    }
    
    #zoom-slider {
        width: 110px;
    }
    
    .zoom-btn {
        width: 28px;
        height: 28px;
        font-size: 16px;
    }
    
    #attack-mode-selector {
        bottom: 110px;
        right: 10px;
        padding: 10px;
        z-index: 120;
        background: rgba(245, 235, 224, 0.85);
        backdrop-filter: blur(4px);
    }
    
    #attack-mode-selector .attack-mode-btn {
        background: rgba(139, 115, 85, 0.15);
    }
    
    #attack-mode-selector .attack-mode-btn.active {
        background: rgba(74, 53, 32, 0.85);
    }
    
    .attack-mode-btn {
        padding: 10px 16px;
        font-size: 12px;
        min-width: 140px;
    }
    
    .attack-icon {
        font-size: 18px;
    }
    
    #event-log-container {
        height: 80px;
        bottom: 0;
    }
    
    #event-log {
        font-size: 10px;
        padding: 8px 15px;
    }
    
    #controls {
        display: none;
    }
    
    .unit-health-bar {
        min-width: 100px;
    }
    
    .hp-bar-background {
        height: 18px;
    }
    
    .hp-bar-text {
        font-size: 9px;
    }
    
    .hp-bar-team-dot {
        width: 5px;
        height: 5px;
        left: 2px;
    }
    
    #winner-text {
        font-size: 44px;
    }
    
    #victory-condition {
        font-size: 16px;
    }
    
    footer {
        bottom: 0;
    }
    
    #end-turn-btn {
        flex-shrink: 0;
    }
}

/* Tablet adjustments */
@media (min-width: 769px) and (max-width: 1024px) {
    #right-panel {
        width: 200px;
    }
    
    #game-container {
        bottom: 120px;
    }
    
    #event-log-container {
        height: 120px;
        bottom: 0;
    }
    
    .panel-section {
        padding: 15px;
    }
    
    .panel-section h3 {
        font-size: 20px;
    }
    
    #unit-stats {
        font-size: 12px;
    }
    
    #orbit-joystick {
        bottom: 130px;
    }
    
    #zoom-control {
        bottom: 130px;
    }
    
    #attack-mode-selector {
        bottom: 130px;
    }
    
    #controls {
        display: none;
    }
}

/* Landscape mobile optimization */
@media (max-width: 768px) and (orientation: landscape) {
    .unit-phrase {
        font-size: 13px;
        padding: 3px 8px;
        max-width: 90px;
    }
    
    .unit-phrase.flip-phrase {
        font-size: 15px;
    }

    .instructions-card {
        padding: 20px;
        max-height: 85vh;
        overflow-y: auto;
    }
    
    .instructions-card h2 {
        font-size: 28px;
        margin-bottom: 14px;
    }
    
    .instructions-card p {
        font-size: 14px;
        line-height: 1.5;
        margin-bottom: 10px;
    }
    
    .tap-hint {
        margin-top: 16px;
    }

    #hud {
        height: 60px;
    }
    
    #game-container {
        top: 60px;
        bottom: 60px;
    }
    
    #event-log-container {
        height: 60px;
    }
    
    #controls {
        display: none;
    }
    
    #turn-indicator {
        font-size: 22px;
    }
    
    #round-counter {
        font-size: 13px;
    }
    
    #orbit-joystick {
        bottom: 70px;
        left: 10px;
    }
    
    #joystick-outer {
        width: 60px;
        height: 60px;
    }
    
    #joystick-inner {
        width: 24px;
        height: 24px;
    }
    
    #zoom-control {
        bottom: 70px;
        padding: 8px 10px;
        min-width: 130px;
    }
    
    #zoom-slider {
        width: 90px;
    }
    
    .zoom-btn {
        width: 26px;
        height: 26px;
        font-size: 14px;
    }
    
    #attack-mode-selector {
        bottom: 70px;
        right: 10px;
        padding: 8px;
        z-index: 120;
        background: rgba(245, 235, 224, 0.85);
        backdrop-filter: blur(4px);
    }
    
    #attack-mode-selector .attack-mode-btn {
        background: rgba(139, 115, 85, 0.15);
    }
    
    #attack-mode-selector .attack-mode-btn.active {
        background: rgba(74, 53, 32, 0.85);
    }
    
    .attack-mode-btn {
        padding: 8px 14px;
    }
    
    footer {
        bottom: 0;
    }
}