/* =====================================================
   Plants vs Zombies - Stylesheet
   Modern, vibrant design with glassmorphism effects
   ===================================================== */

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

:root {
    /* Color Palette */
    --primary-green: #2ecc71;
    --dark-green: #1a5f2a;
    --lawn-light: #7cb342;
    --lawn-dark: #558b2f;
    --sky-gradient-start: #87ceeb;
    --sky-gradient-end: #4a90c2;
    --sun-yellow: #ffd93d;
    --sun-orange: #ff9500;
    --zombie-gray: #6b7280;
    --danger-red: #ef4444;
    --glass-bg: rgba(255, 255, 255, 0.15);
    --glass-border: rgba(255, 255, 255, 0.3);

    /* Sizes */
    --cell-size: 70px;
    --header-height: 80px;
    --plant-bar-height: 100px;
}

body {
    font-family: 'Noto Sans SC', sans-serif;
    background: linear-gradient(180deg, var(--sky-gradient-start) 0%, var(--sky-gradient-end) 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* =====================================================
   Game Container
   ===================================================== */
.game-container {
    position: relative;
    width: 100%;
    max-width: 700px;
    padding: 20px;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
    backdrop-filter: blur(10px);
    border-radius: 24px;
    border: 1px solid var(--glass-border);
    box-shadow:
        0 25px 50px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

/* =====================================================
   Header
   ===================================================== */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: linear-gradient(135deg, var(--dark-green), var(--primary-green));
    border-radius: 16px;
    margin-bottom: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.game-title {
    font-size: 1.5rem;
    font-weight: 900;
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    letter-spacing: 1px;
}

.sun-counter {
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, var(--sun-yellow), var(--sun-orange));
    padding: 10px 20px;
    border-radius: 30px;
    font-size: 1.3rem;
    font-weight: 700;
    color: #5c3d00;
    box-shadow:
        0 4px 15px rgba(255, 217, 61, 0.4),
        inset 0 2px 0 rgba(255, 255, 255, 0.3);
    animation: sunPulse 2s ease-in-out infinite;
}

.sun-icon {
    font-size: 1.5rem;
    animation: sunSpin 4s linear infinite;
}

@keyframes sunPulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

@keyframes sunSpin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* =====================================================
   Plant Selection Bar
   ===================================================== */
.plant-bar {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 15px;
    background: var(--glass-bg);
    border-radius: 16px;
    margin-bottom: 15px;
    border: 1px solid var(--glass-border);
}

.plant-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 15px;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.1));
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
    min-width: 80px;
}

.plant-card:hover {
    transform: translateY(-5px);
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.2));
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.plant-card.selected {
    border-color: var(--sun-yellow);
    background: linear-gradient(145deg, rgba(255, 217, 61, 0.3), rgba(255, 149, 0, 0.2));
    box-shadow: 0 0 20px rgba(255, 217, 61, 0.4);
}

.plant-card.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    filter: grayscale(50%);
}

.plant-card.disabled:hover {
    transform: none;
    box-shadow: none;
}

.plant-icon {
    font-size: 2.5rem;
    margin-bottom: 5px;
    filter: drop-shadow(2px 2px 3px rgba(0, 0, 0, 0.3));
}

.plant-cost {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--sun-yellow);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.plant-name {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.9);
    margin-top: 3px;
}

.remove-tool .plant-icon {
    font-size: 2rem;
}

/* Drag and Drop States */
.plant-card.dragging {
    opacity: 0.5;
    transform: scale(0.95);
}

.plant-card {
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

.grid-cell.drop-target {
    background: linear-gradient(145deg, rgba(255, 217, 61, 0.5), rgba(255, 149, 0, 0.4)) !important;
    box-shadow: inset 0 0 15px rgba(255, 217, 61, 0.6);
    animation: dropTargetPulse 0.5s ease-in-out infinite;
}

@keyframes dropTargetPulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

.drag-ghost {
    animation: dragFloat 0.3s ease-in-out infinite alternate;
}

@keyframes dragFloat {
    from {
        transform: translate(-50%, -50%) scale(1.2) rotate(-5deg);
    }

    to {
        transform: translate(-50%, -50%) scale(1.3) rotate(5deg);
    }
}

/* =====================================================
   Game Info
   ===================================================== */
.game-info {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 15px;
    font-size: 0.95rem;
    color: white;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.5);
}

.wave-info,
.zombie-count {
    background: var(--glass-bg);
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid var(--glass-border);
}

/* =====================================================
   Game Board
   ===================================================== */
.game-board {
    display: grid;
    grid-template-columns: repeat(9, var(--cell-size));
    grid-template-rows: repeat(5, var(--cell-size));
    gap: 2px;
    background: linear-gradient(180deg, #8b4513 0%, #654321 100%);
    padding: 8px;
    border-radius: 12px;
    margin: 0 auto;
    box-shadow:
        inset 0 2px 10px rgba(0, 0, 0, 0.3),
        0 8px 25px rgba(0, 0, 0, 0.3);
    position: relative;
}

.grid-cell {
    width: var(--cell-size);
    height: var(--cell-size);
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    transition: all 0.2s ease;
    cursor: pointer;
}

.grid-cell:nth-child(odd) {
    background: linear-gradient(145deg, var(--lawn-light), var(--lawn-dark));
}

.grid-cell:nth-child(even) {
    background: linear-gradient(145deg, var(--lawn-dark), var(--lawn-light));
}

.grid-cell:hover {
    filter: brightness(1.15);
    transform: scale(1.02);
}

.grid-cell.has-plant:hover {
    transform: none;
}

/* =====================================================
   Plants on Grid
   ===================================================== */
.plant {
    font-size: 2.5rem;
    filter: drop-shadow(2px 3px 4px rgba(0, 0, 0, 0.4));
    animation: plantBounce 0.5s ease-out;
    position: relative;
    z-index: 10;
}

@keyframes plantBounce {
    0% {
        transform: scale(0) rotate(-10deg);
    }

    50% {
        transform: scale(1.2) rotate(5deg);
    }

    100% {
        transform: scale(1) rotate(0deg);
    }
}

.plant.sunflower {
    animation: sunflowerSway 2s ease-in-out infinite;
}

@keyframes sunflowerSway {

    0%,
    100% {
        transform: rotate(-5deg);
    }

    50% {
        transform: rotate(5deg);
    }
}

.plant.peashooter {
    animation: peashooterReady 1.5s ease-in-out infinite;
}

@keyframes peashooterReady {

    0%,
    100% {
        transform: translateX(0);
    }

    50% {
        transform: translateX(3px);
    }
}

.plant.wallnut {
    animation: wallnutShake 3s ease-in-out infinite;
}

@keyframes wallnutShake {

    0%,
    100% {
        transform: rotate(0deg);
    }

    25% {
        transform: rotate(-2deg);
    }

    75% {
        transform: rotate(2deg);
    }
}

/* Plant Health Bar */
.plant-health-bar {
    position: absolute;
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%);
    width: 50px;
    height: 5px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 3px;
    overflow: hidden;
}

.plant-health-fill {
    height: 100%;
    background: linear-gradient(90deg, #22c55e, #86efac);
    transition: width 0.3s ease;
}

/* =====================================================
   Zombies
   ===================================================== */
.zombie {
    position: absolute;
    font-size: 2.5rem;
    filter: drop-shadow(3px 3px 5px rgba(0, 0, 0, 0.5));
    z-index: 20;
    transition: left 0.05s linear;
}

.zombie.walking {
    animation: zombieWalk 0.5s steps(2) infinite;
}

@keyframes zombieWalk {

    0%,
    100% {
        transform: translateY(0) rotate(-2deg);
    }

    50% {
        transform: translateY(-3px) rotate(2deg);
    }
}

.zombie.eating {
    animation: zombieEat 0.3s ease-in-out infinite;
}

@keyframes zombieEat {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1) translateX(-5px);
    }
}

.zombie-health-bar {
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 2px;
    overflow: hidden;
}

.zombie-health-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--danger-red), #fca5a5);
    transition: width 0.2s ease;
}

/* =====================================================
   Projectiles
   ===================================================== */
#projectile-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 15;
}

.projectile {
    position: absolute;
    font-size: 1.2rem;
    filter: drop-shadow(1px 1px 2px rgba(0, 0, 0, 0.3));
    animation: projectileFly 0.1s ease-in-out infinite alternate;
}

@keyframes projectileFly {
    from {
        transform: translateY(-1px);
    }

    to {
        transform: translateY(1px);
    }
}

/* =====================================================
   Sun
   ===================================================== */
#sun-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 25;
}

.sun {
    position: absolute;
    font-size: 2rem;
    cursor: pointer;
    pointer-events: auto;
    animation: sunFloat 2s ease-in-out infinite, sunGlow 1s ease-in-out infinite alternate;
    filter: drop-shadow(0 0 10px rgba(255, 217, 61, 0.8));
    transition: transform 0.3s ease;
    z-index: 100;
}

.sun:hover {
    transform: scale(1.3);
}

@keyframes sunFloat {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-8px);
    }
}

@keyframes sunGlow {
    from {
        filter: drop-shadow(0 0 10px rgba(255, 217, 61, 0.6));
    }

    to {
        filter: drop-shadow(0 0 20px rgba(255, 217, 61, 1));
    }
}

.sun.collecting {
    animation: sunCollect 0.5s ease-in forwards;
    pointer-events: none;
}

@keyframes sunCollect {
    to {
        transform: scale(0) rotate(360deg);
        opacity: 0;
    }
}

/* =====================================================
   Game Controls
   ===================================================== */
.game-controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 20px;
}

.control-btn {
    padding: 12px 25px;
    font-size: 1rem;
    font-weight: 700;
    font-family: inherit;
    border: none;
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.start-btn {
    background: linear-gradient(135deg, var(--primary-green), var(--dark-green));
    color: white;
    box-shadow: 0 4px 15px rgba(46, 204, 113, 0.4);
}

.start-btn:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(46, 204, 113, 0.5);
}

.pause-btn {
    background: linear-gradient(135deg, var(--sun-yellow), var(--sun-orange));
    color: #5c3d00;
    box-shadow: 0 4px 15px rgba(255, 217, 61, 0.4);
}

.pause-btn:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(255, 217, 61, 0.5);
}

.restart-btn {
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.restart-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(99, 102, 241, 0.5);
}

.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* =====================================================
   Game Overlay
   ===================================================== */
.game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    border-radius: 24px;
}

.game-overlay.active {
    display: flex;
    animation: overlayFadeIn 0.5s ease-out;
}

@keyframes overlayFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.overlay-content {
    text-align: center;
    padding: 40px;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0.05));
    border-radius: 20px;
    border: 1px solid var(--glass-border);
    animation: overlayContentPop 0.5s ease-out 0.2s both;
}

@keyframes overlayContentPop {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.overlay-content h2 {
    font-size: 2.5rem;
    color: white;
    margin-bottom: 15px;
    text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.5);
}

.overlay-content p {
    font-size: 1.2rem;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 25px;
}

.overlay-btn {
    padding: 15px 35px;
    font-size: 1.1rem;
    font-weight: 700;
    font-family: inherit;
    background: linear-gradient(135deg, var(--primary-green), var(--dark-green));
    color: white;
    border: none;
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 20px rgba(46, 204, 113, 0.5);
}

.overlay-btn:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 30px rgba(46, 204, 113, 0.6);
}

/* =====================================================
   Responsive Design
   ===================================================== */
@media (max-width: 768px) {
    :root {
        --cell-size: 55px;
    }

    body {
        padding: 10px;
        align-items: flex-start;
        padding-top: 20px;
    }

    .game-container {
        padding: 12px;
        border-radius: 16px;
        max-width: 100%;
    }

    .game-header {
        flex-direction: column;
        gap: 10px;
        padding: 12px;
    }

    .game-title {
        font-size: 1.2rem;
    }

    .sun-counter {
        font-size: 1rem;
        padding: 8px 15px;
    }

    .plant-bar {
        flex-wrap: wrap;
        gap: 8px;
        padding: 12px;
    }

    .plant-card {
        padding: 8px 10px;
        min-width: 65px;
        /* Better touch target */
        min-height: 70px;
    }

    .plant-icon {
        font-size: 2rem;
    }

    .game-board {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .control-btn {
        padding: 10px 18px;
        font-size: 0.9rem;
    }

    .game-controls {
        flex-wrap: wrap;
    }
}

@media (max-width: 500px) {
    :root {
        --cell-size: 42px;
    }

    body {
        padding: 5px;
        padding-top: 10px;
    }

    .game-container {
        padding: 8px;
        border-radius: 12px;
    }

    .game-header {
        padding: 10px;
        margin-bottom: 10px;
    }

    .game-title {
        font-size: 1rem;
    }

    .plant-bar {
        gap: 6px;
        padding: 8px;
        margin-bottom: 10px;
    }

    .plant-card {
        padding: 5px 6px;
        min-width: 50px;
        min-height: 60px;
        border-radius: 8px;
    }

    .plant-icon {
        font-size: 1.6rem;
        margin-bottom: 2px;
    }

    .plant-cost {
        font-size: 0.7rem;
    }

    .plant-name {
        font-size: 0.6rem;
    }

    .plant,
    .zombie {
        font-size: 1.6rem;
    }

    .game-info {
        gap: 8px;
        font-size: 0.75rem;
        margin-bottom: 10px;
    }

    .wave-info,
    .zombie-count {
        padding: 5px 10px;
    }

    .game-board {
        padding: 4px;
        border-radius: 8px;
    }

    .game-controls {
        gap: 8px;
        margin-top: 12px;
    }

    .control-btn {
        padding: 8px 14px;
        font-size: 0.8rem;
        border-radius: 20px;
    }

    .sun {
        font-size: 1.6rem;
    }

    .projectile {
        font-size: 1rem;
    }
}

/* Landscape mode for phones */
@media (max-height: 500px) and (orientation: landscape) {
    :root {
        --cell-size: 38px;
    }

    body {
        padding: 5px;
        align-items: flex-start;
    }

    .game-container {
        padding: 8px;
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
        max-width: 100%;
    }

    .game-header {
        flex: 0 0 auto;
        margin-bottom: 0;
        padding: 8px 12px;
    }

    .game-title {
        font-size: 0.9rem;
    }

    .sun-counter {
        font-size: 0.85rem;
        padding: 5px 10px;
    }

    .plant-bar {
        flex: 0 0 auto;
        margin-bottom: 0;
        padding: 6px;
        gap: 4px;
    }

    .plant-card {
        padding: 4px 6px;
        min-width: 45px;
        min-height: 50px;
    }

    .plant-icon {
        font-size: 1.4rem;
    }

    .plant-cost {
        font-size: 0.65rem;
    }

    .plant-name {
        display: none;
    }

    .game-info {
        flex: 0 0 auto;
        margin-bottom: 0;
        font-size: 0.7rem;
    }

    .game-board {
        flex: 1 1 auto;
    }

    .game-controls {
        margin-top: 8px;
        gap: 6px;
    }

    .control-btn {
        padding: 6px 12px;
        font-size: 0.75rem;
    }

    .plant,
    .zombie {
        font-size: 1.4rem;
    }

    .overlay-content {
        padding: 20px;
    }

    .overlay-content h2 {
        font-size: 1.5rem;
        margin-bottom: 8px;
    }

    .overlay-content p {
        font-size: 0.9rem;
        margin-bottom: 12px;
    }
}

/* Touch-friendly enhancements */
@media (hover: none) and (pointer: coarse) {
    .plant-card {
        /* Larger touch targets for mobile */
        min-height: 70px;
    }

    .grid-cell {
        /* Prevent hover effects on touch devices */
        transition: none;
    }

    .grid-cell:hover {
        filter: none;
        transform: none;
    }

    .grid-cell:active {
        filter: brightness(1.15);
    }

    .card:hover {
        transform: none;
    }

    .sun {
        /* Larger touch area for sun collection */
        padding: 10px;
        margin: -10px;
    }

    .control-btn {
        /* Larger touch targets for buttons */
        min-height: 44px;
    }
}