@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;
}

/* 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);
}

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

#turn-indicator {
    font-family: 'Caveat', cursive;
    font-size: 32px;
    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: 120px;
    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;
}

/* Attack Mode Selector */
#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: 110;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.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);
}

#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 */
#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: 80px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.25));
}

.hp-bar-background {
    position: relative;
    height: 18px;
    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: 9px;
    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;
}

.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);
}

footer {
    position: fixed;
    bottom: 0;
    right: 0;
    padding: 12px 15px;
    text-align: center;
    font-size: 11px;
    color: #666;
    background: rgba(245, 235, 224, 0.8);
    z-index: 101;
}

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

footer a:hover {
    color: #1a1a1a;
}

/* 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);
}

/* Mobile-first responsive design */
@media (max-width: 768px) {
    .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: 24px;
    }
    
    #round-counter {
        font-size: 14px;
    }
    
    #attack-mode-selector {
        bottom: 90px;
        right: 10px;
        padding: 10px;
    }
    
    .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: 70px;
    }
    
    .hp-bar-background {
        height: 16px;
    }
    
    .hp-bar-text {
        font-size: 8px;
    }
    
    .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;
    }
    
    #attack-mode-selector {
        bottom: 130px;
    }
    
    #controls {
        display: none;
    }
}

/* Landscape mobile optimization */
@media (max-width: 768px) and (orientation: landscape) {
    .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;
    }
    
    #attack-mode-selector {
        bottom: 70px;
        right: 10px;
        padding: 8px;
    }
    
    .attack-mode-btn {
        padding: 8px 14px;
    }
    
    footer {
        bottom: 0;
    }
}