/* Kittens vs Turtles - Mobile Tower Defense Game Styles */

/* ==========================================================================
   RESET & BASE STYLES
   ========================================================================== */

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

html, body {
    height: 100%;
    overflow: hidden;
    font-family: 'Arial', 'Helvetica', sans-serif;
    font-size: 16px;
    line-height: 1.4;
    background: #2c3e50;
    color: #ecf0f1;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    position: fixed;
    width: 100%;
    height: 100%;
    touch-action: manipulation;
}

/* ==========================================================================
   LAYOUT & CONTAINERS
   ========================================================================== */

.game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.game-canvas {
    flex: 1;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #a8e6cf;
    border: none;
    outline: none;
}

/* ==========================================================================
   SCREENS & NAVIGATION
   ========================================================================== */

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease-in-out;
    z-index: 10;
}

.screen.active {
    opacity: 1;
    visibility: visible;
}

.screen.overlay {
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    z-index: 100;
}

/* ==========================================================================
   LOADING SCREEN
   ========================================================================== */

#loading-screen {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    text-align: center;
}

.loading-title {
    font-size: 2.5rem;
    font-weight: bold;
    margin-bottom: 1rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.loading-subtitle {
    font-size: 1.2rem;
    opacity: 0.8;
    margin-bottom: 2rem;
}

.loading-progress {
    width: 300px;
    height: 8px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 1rem;
}

.loading-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #00b894, #74b9ff);
    width: 0%;
    transition: width 0.3s ease;
}

.loading-text {
    font-size: 0.9rem;
    opacity: 0.7;
}

/* ==========================================================================
   MAIN MENU
   ========================================================================== */

#main-menu {
    background: linear-gradient(135deg, #a8e6cf 0%, #7fcdcd 100%);
    color: #2c3e50;
}

.game-title {
    font-size: 3rem;
    font-weight: bold;
    text-align: center;
    margin-bottom: 2rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

.game-subtitle {
    font-size: 1.2rem;
    text-align: center;
    margin-bottom: 3rem;
    opacity: 0.8;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
}

/* ==========================================================================
   BUTTONS
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 120px;
    min-height: 44px; /* Touch-friendly minimum */
    touch-action: manipulation;
    user-select: none;
    position: relative;
    overflow: hidden;
}

.btn:before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.btn:hover:before {
    left: 100%;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: linear-gradient(135deg, #74b9ff 0%, #0984e3 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(116, 185, 255, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 6px 20px rgba(116, 185, 255, 0.4);
    transform: translateY(-2px);
}

.btn-secondary {
    background: linear-gradient(135deg, #fd79a8 0%, #e84393 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(253, 121, 168, 0.3);
}

.btn-success {
    background: linear-gradient(135deg, #00b894 0%, #00a085 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(0, 184, 148, 0.3);
}

.btn-warning {
    background: linear-gradient(135deg, #fdcb6e 0%, #e17055 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(253, 203, 110, 0.3);
}

.btn-danger {
    background: linear-gradient(135deg, #ff7675 0%, #d63031 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(255, 118, 117, 0.3);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.btn-small {
    padding: 8px 16px;
    font-size: 0.9rem;
    min-height: 36px;
}

.btn-large {
    padding: 16px 32px;
    font-size: 1.2rem;
    min-height: 52px;
}

/* ==========================================================================
   LEVEL SELECTION
   ========================================================================== */

#level-select {
    background: linear-gradient(135deg, #a8e6cf 0%, #7fcdcd 100%);
    color: #2c3e50;
    padding: 20px;
}

.level-selection-header {
    text-align: center;
    margin-bottom: 2rem;
}

.level-selection-title {
    font-size: 2rem;
    font-weight: bold;
    margin-bottom: 0.5rem;
}

.difficulty-selector {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 2rem;
}

.difficulty-btn {
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 600;
    min-height: 44px;
}

.difficulty-btn.active {
    background: #74b9ff;
    color: white;
    box-shadow: 0 4px 15px rgba(116, 185, 255, 0.3);
}

.levels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: 15px;
    max-width: 600px;
    margin: 0 auto;
    padding: 0 20px;
}

.level-button {
    aspect-ratio: 1;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-weight: bold;
    background: rgba(255, 255, 255, 0.9);
    color: #2c3e50;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.level-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.level-button.locked {
    background: rgba(0, 0, 0, 0.3);
    color: rgba(255, 255, 255, 0.5);
    cursor: not-allowed;
}

.level-button.boss {
    background: linear-gradient(135deg, #fd79a8 0%, #e84393 100%);
    color: white;
}

.level-number {
    font-size: 1.2rem;
    margin-bottom: 4px;
}

.level-stars {
    display: flex;
    gap: 2px;
    font-size: 0.8rem;
}

.star {
    color: #f1c40f;
}

.star.empty {
    color: rgba(0, 0, 0, 0.2);
}

/* ==========================================================================
   GAME HUD
   ========================================================================== */

.game-hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 50;
    padding: 10px;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.7), transparent);
    color: white;
}

.hud-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.hud-stats {
    display: flex;
    gap: 20px;
    align-items: center;
}

.hud-stat {
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: bold;
}

.hud-controls {
    display: flex;
    gap: 10px;
}

.wave-progress {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    height: 8px;
    overflow: hidden;
    flex: 1;
    margin: 0 20px;
}

.wave-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #74b9ff, #00b894);
    border-radius: 10px;
    transition: width 0.3s ease;
}

/* ==========================================================================
   GAME SCREEN & CANVAS
   ========================================================================== */

#game-screen {
    /* This is already a flex column from .screen, but we override justify-content */
    justify-content: flex-start; 
}

#game-screen-container {
    flex-grow: 1; /* Make the container take up all available vertical space */
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #1a202c; /* Dark background for the game area */
    overflow: hidden; /* Hide anything that spills out */
    position: relative;
}

#game-canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain; /* Scales the canvas to fit while maintaining aspect ratio */
}


/* ==========================================================================
   TOWER SHOP
   ========================================================================== */

.tower-shop {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 40;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.9), rgba(0, 0, 0, 0.6));
    padding: 15px;
    color: white;
}

.tower-shop-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    max-width: 400px;
    margin: 0 auto;
}

.tower-shop-item {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid transparent;
    border-radius: 8px;
    padding: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    min-height: 80px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    touch-action: manipulation;
}

.tower-shop-item:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: #74b9ff;
}

.tower-shop-item.selected {
    border-color: #00b894;
    background: rgba(0, 184, 148, 0.2);
}

.tower-shop-item.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.tower-icon {
    font-size: 2rem;
    margin-bottom: 5px;
}

.tower-cost {
    font-size: 0.9rem;
    font-weight: bold;
    color: #f1c40f;
}

.tower-name {
    font-size: 0.8rem;
    opacity: 0.8;
}

/* ==========================================================================
   MODALS & DIALOGS
   ========================================================================== */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    backdrop-filter: blur(5px);
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: white;
    border-radius: 16px;
    padding: 30px;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
    color: #2c3e50;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    transform: scale(0.8);
    transition: transform 0.3s ease;
}

.modal.active .modal-content {
    transform: scale(1);
}

.modal-header {
    margin-bottom: 20px;
}

.modal-title {
    font-size: 1.8rem;
    font-weight: bold;
    margin-bottom: 10px;
}

.modal-subtitle {
    opacity: 0.7;
    font-size: 1rem;
}

.modal-body {
    margin-bottom: 20px;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ==========================================================================
   NOTIFICATIONS
   ========================================================================== */

.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    background: #2c3e50;
    color: white;
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    transform: translateX(400px);
    transition: transform 0.3s ease;
    max-width: 300px;
}

.notification.show {
    transform: translateX(0);
}

.notification.success {
    background: #00b894;
}

.notification.warning {
    background: #fdcb6e;
    color: #2c3e50;
}

.notification.error {
    background: #ff7675;
}

/* ==========================================================================
   SETTINGS SCREEN
   ========================================================================== */

.settings-screen {
    background: linear-gradient(135deg, #636e72 0%, #2d3436 100%);
    color: white;
    padding: 20px;
}

.settings-content {
    max-width: 500px;
    margin: 0 auto;
}

.settings-section {
    margin-bottom: 30px;
}

.settings-section h3 {
    font-size: 1.2rem;
    margin-bottom: 15px;
    color: #74b9ff;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding: 10px 0;
}

.setting-label {
    font-weight: 500;
}

.slider {
    width: 120px;
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.3);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #74b9ff;
    cursor: pointer;
}

.toggle {
    position: relative;
    width: 50px;
    height: 24px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.toggle.active {
    background: #74b9ff;
}

.toggle::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s ease;
}

.toggle.active::after {
    transform: translateX(26px);
}

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

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

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-10px); }
    60% { transform: translateY(-5px); }
}

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

@keyframes slideInLeft {
    from {
        transform: translateX(-100%);
    }
    to {
        transform: translateX(0);
    }
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
    }
    to {
        transform: translateX(0);
    }
}

.animate-pulse {
    animation: pulse 2s infinite;
}

.animate-bounce {
    animation: bounce 1s infinite;
}

.animate-fadeInUp {
    animation: fadeInUp 0.5s ease;
}

.animate-slideInLeft {
    animation: slideInLeft 0.3s ease;
}

.animate-slideInRight {
    animation: slideInRight 0.3s ease;
}

/* ==========================================================================
   RESPONSIVE DESIGN
   ========================================================================== */

/* Mobile Portrait */
@media (max-width: 480px) {
    .game-title {
        font-size: 2rem;
    }
    
    .level-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 10px;
    }
    
    .tower-shop-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
    }
    
    .modal-content {
        padding: 20px;
        margin: 20px;
    }
    
    .hud-stats {
        gap: 10px;
    }
    
    .hud-stat {
        font-size: 0.9rem;
    }
}

/* Mobile Landscape */
@media (max-height: 500px) and (orientation: landscape) {
    .tower-shop {
        display: flex;
        flex-direction: column;
        height: 100vh;
        width: 200px;
        left: auto;
        right: 0;
        bottom: 0;
        background: linear-gradient(to left, rgba(0, 0, 0, 0.9), rgba(0, 0, 0, 0.6));
    }
    
    .tower-shop-grid {
        grid-template-columns: repeat(2, 1fr);
        max-width: none;
        flex: 1;
    }
    
    .game-hud {
        right: 200px;
    }
}

/* Tablet */
@media (min-width: 768px) {
    .level-grid {
        grid-template-columns: repeat(8, 1fr);
        max-width: 800px;
    }
    
    .tower-shop-grid {
        max-width: 500px;
        gap: 15px;
    }
    
    .modal-content {
        max-width: 600px;
    }
}

/* Desktop */
@media (min-width: 1024px) {
    .game-container {
        max-width: 1024px;
        max-height: 768px;
        margin: 0 auto;
        border-radius: 8px;
        overflow: hidden;
        box-shadow: 0 10px 50px rgba(0, 0, 0, 0.3);
    }
    
    body {
        display: flex;
        align-items: center;
        justify-content: center;
        background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    }
}

/* ==========================================================================
   ACCESSIBILITY
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus indicators */
.btn:focus,
.tower-shop-item:focus,
.level-button:focus {
    outline: 3px solid #74b9ff;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn {
        border: 2px solid currentColor;
    }
    
    .modal-content {
        border: 3px solid #2c3e50;
    }
}

/* ==========================================================================
   UTILITY CLASSES
   ========================================================================== */

.hidden {
    display: none !important;
}

.invisible {
    visibility: hidden !important;
}

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

.text-left {
    text-align: left;
}

.text-right {
    text-align: right;
}

.font-bold {
    font-weight: bold;
}

.opacity-50 {
    opacity: 0.5;
}

.opacity-75 {
    opacity: 0.75;
}

.mb-10 {
    margin-bottom: 10px;
}

.mb-20 {
    margin-bottom: 20px;
}

.mt-10 {
    margin-top: 10px;
}

.mt-20 {
    margin-top: 20px;
}

.flex {
    display: flex;
}

.flex-column {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-center {
    justify-content: center;
}

.gap-10 {
    gap: 10px;
}

.gap-20 {
    gap: 20px;
}

/* ==========================================================================
   DARK MODE (Optional)
   ========================================================================== */

@media (prefers-color-scheme: dark) {
    .modal-content {
        background: #2c3e50;
        color: #ecf0f1;
    }
    
    .level-button {
        background: rgba(255, 255, 255, 0.1);
        color: #ecf0f1;
    }
    
    .tower-shop-item {
        background: rgba(255, 255, 255, 0.05);
    }
}