/* Mobile First CSS Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    height: 100%;
    width: 100%;
    overflow: hidden;
    position: fixed;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Main Container - Mobile First */
#game-container {
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

/* HUD - Mobile First Design - COMPRESSED */
#hud {
    position: sticky;
    top: 0;
    width: 100%;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.98) 0%, rgba(250, 250, 255, 0.98) 100%);
    backdrop-filter: blur(20px);
    padding: env(safe-area-inset-top, 4px) 6px 4px 6px;
    border-bottom: 2px solid #8b5cf6;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 4px;
}

#hud-left {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    flex: 1;
}

#hud-right {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 6px;
    width: auto;
}

/* Coin Display - Mobile Optimized & COMPRESSED */
#coins-display {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 16px;
    font-weight: bold;
    color: #f59e0b;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
}

.coin-icon {
    font-size: 18px;
    animation: rotate 3s linear infinite;
}

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

.coin-amount {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 900;
}

#selected-seed {
    font-size: 12px;
    font-weight: 600;
    color: #10b981;
    display: flex;
    align-items: center;
    gap: 3px;
}

.label {
    color: #6b7280;
    display: none; /* Hide label on mobile to save space */
}

.seed-name {
    color: #059669;
    font-weight: 700;
}

#help-text {
    display: none; /* Hide help text on mobile to save space */
}

/* Buttons - Mobile Touch Targets COMPRESSED */
.btn-reset {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    border: none;
    padding: 6px 10px;
    border-radius: 15px;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.2);
    min-height: 32px;
    min-width: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    touch-action: manipulation;
}

.btn-reset:active {
    transform: scale(0.95);
}

.btn-icon {
    font-size: 14px;
}

.toggle-container {
    display: flex;
    align-items: center;
    gap: 3px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: #6b7280;
    padding: 6px 10px;
    border-radius: 15px;
    background: rgba(255, 255, 255, 0.8);
    min-height: 32px;
    touch-action: manipulation;
}

.toggle-label {
    display: none; /* Hide text label on mobile */
}

.toggle-container:active {
    background: rgba(255, 255, 255, 1);
}

.btn-harvest-all {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: white;
    border: none;
    padding: 5px 8px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 11px;
    font-weight: bold;
    box-shadow: 0 2px 6px rgba(251, 191, 36, 0.2);
    min-height: 28px;
    touch-action: manipulation;
}

.btn-harvest-all:active {
    transform: scale(0.95);
}

/* Game Area - Mobile Layout */
#game-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: linear-gradient(135deg, #a5f3fc 0%, #c7d2fe 50%, #fde68a 100%);
    position: relative;
    overflow: hidden;
}

/* Canvas Container - Mobile Square Grid - FIXED FOR NO OVERLAP */
.canvas-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 5px 5px 120px 5px; /* Add bottom padding to account for seed shop */
    position: relative;
}

#game-canvas {
    display: block;
    width: 100%;
    height: auto;
    max-width: calc(100vw - 10px);
    max-height: calc(100vh - 220px); /* Reduced to account for seed shop + HUD */
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

/* Seed Shop - Mobile Bottom Sheet - THIN & NON-OVERLAPPING */
#seed-shop {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 110px; /* Reduced from 180px to not overlap game */
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.98) 0%, rgba(250, 250, 255, 0.98) 100%);
    backdrop-filter: blur(20px);
    border-top: 2px solid #8b5cf6;
    border-radius: 16px 16px 0 0;
    z-index: 500;
    display: flex;
    flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom, 0);
    transition: height 0.3s ease;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.08);
}

#seed-shop.expanded {
    height: 60vh;
    max-height: 500px;
}

.shop-header {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    padding: 6px 8px;
    text-align: center;
    border-radius: 16px 16px 0 0;
    cursor: pointer;
    position: relative;
}

.shop-header::before {
    content: '';
    position: absolute;
    top: 3px;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 3px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 2px;
}

.shop-header h3 {
    font-size: 13px;
    margin: 0;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
}

.shop-subtitle {
    font-size: 9px;
    opacity: 0.8;
    margin-top: 1px;
}

/* Seed List - Horizontal Scroll for Mobile */
#seed-list {
    display: flex;
    gap: 10px;
    padding: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    flex: 1;
}

/* Hide scrollbar but keep functionality */
#seed-list::-webkit-scrollbar {
    height: 0;
}

/* Seed Card - Mobile Optimized COMPACT */
.seed-card {
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    padding: 4px 6px;
    min-width: 80px;
    scroll-snap-align: start;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    touch-action: manipulation;
}

.seed-card:active {
    transform: scale(0.95);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.seed-card.selected {
    border-color: #10b981;
    background: linear-gradient(135deg, #f0fdf4, #dcfce7);
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

.seed-emoji {
    font-size: 24px;
}

.seed-name {
    font-size: 10px;
    font-weight: 700;
    color: #374151;
    text-align: center;
}

.seed-price {
    font-size: 11px;
    font-weight: bold;
    color: #f59e0b;
}

.seed-time {
    font-size: 9px;
    color: #6b7280;
}

.seed-roi {
    font-size: 9px;
    font-weight: 600;
    padding: 1px 4px;
    border-radius: 4px;
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
}

/* Message Popup */
#message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.9), rgba(31, 41, 55, 0.9));
    color: white;
    padding: 16px 24px;
    border-radius: 16px;
    font-size: 16px;
    font-weight: bold;
    text-align: center;
    z-index: 2000;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    animation: messageSlide 0.3s ease;
    max-width: 90vw;
}

#message.hidden {
    display: none;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translate(-50%, -40%) scale(0.8);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

/* Particle Effects */
#particle-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 999;
}

.particle {
    position: absolute;
    font-size: 24px;
    animation: particleFloat 2s ease-out forwards;
}

@keyframes particleFloat {
    0% {
        opacity: 1;
        transform: translateY(0) scale(0);
    }
    50% {
        transform: translateY(-30px) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(-60px) scale(0.5);
    }
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 3000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
}

.modal.show {
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: linear-gradient(135deg, #ffffff, #f0fdf4);
    border-radius: 20px;
    padding: 20px;
    max-width: 95vw;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.modal-content h2 {
    text-align: center;
    color: #10b981;
    font-size: 20px;
    margin-bottom: 16px;
}

.tutorial-steps {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.step {
    background: white;
    border-radius: 10px;
    padding: 12px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 10px;
}

.step-icon {
    font-size: 28px;
    min-width: 40px;
    text-align: center;
}

.step h3 {
    color: #8b5cf6;
    font-size: 14px;
    margin: 0 0 4px 0;
}

.step p {
    color: #6b7280;
    font-size: 12px;
    line-height: 1.4;
    margin: 0;
}

.modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-start, .btn-quick {
    padding: 12px 20px;
    border: none;
    border-radius: 16px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    min-height: 44px;
    width: 100%;
    touch-action: manipulation;
}

.btn-start {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    box-shadow: 0 3px 10px rgba(16, 185, 129, 0.3);
}

.btn-quick {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: white;
    box-shadow: 0 3px 10px rgba(251, 191, 36, 0.3);
}

.btn-start:active, .btn-quick:active {
    transform: scale(0.95);
}

/* Tablet Styles - 768px and up */
@media (min-width: 768px) {
    #hud {
        padding: 16px 20px;
        flex-direction: row;
        justify-content: space-between;
    }
    
    #hud-left {
        flex-direction: column;
        align-items: flex-start;
        width: auto;
    }
    
    #hud-right {
        width: auto;
    }
    
    #coins-display {
        font-size: 28px;
    }
    
    .coin-icon {
        font-size: 32px;
    }
    
    #selected-seed {
        font-size: 16px;
    }
    
    .label {
        display: inline; /* Show label on tablet */
    }
    
    .toggle-label {
        display: inline; /* Show toggle label on tablet */
    }
    
    #help-text {
        display: block; /* Show help text on tablet */
        font-size: 13px;
        text-align: left;
    }
    
    .btn-reset {
        padding: 10px 16px;
        font-size: 14px;
        min-height: 44px;
    }
    
    .toggle-container {
        padding: 10px 14px;
        font-size: 14px;
        min-height: 44px;
    }
    
    .canvas-container {
        padding: 20px;
    }
    
    #game-canvas {
        max-height: calc(100vh - 280px);
    }
    
    #seed-shop {
        height: 200px;
    }
    
    #seed-shop.expanded {
        height: 70vh;
        max-height: 600px;
    }
    
    .shop-header h3 {
        font-size: 20px;
    }
    
    .seed-card {
        min-width: 120px;
        padding: 10px;
    }
    
    .seed-emoji {
        font-size: 40px;
    }
    
    .seed-name {
        font-size: 14px;
    }
}

/* Desktop Styles - 1024px and up */
@media (min-width: 1024px) {
    #game-area {
        flex-direction: row;
    }
    
    .canvas-container {
        flex: 1;
        padding: 30px;
    }
    
    #game-canvas {
        max-width: min(600px, calc(100vh - 200px));
        max-height: calc(100vh - 200px);
    }
    
    /* Desktop Side Panel Layout */
    #seed-shop {
        position: relative;
        width: 320px;
        height: 100%;
        border-top: none;
        border-left: 3px solid #8b5cf6;
        border-radius: 0;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
        transition: none;
    }
    
    #seed-shop.expanded {
        height: 100%;
        max-height: 100%;
    }
    
    .shop-header {
        border-radius: 0;
        cursor: default;
    }
    
    .shop-header::before {
        display: none;
    }
    
    .shop-header h3 {
        font-size: 22px;
    }
    
    .shop-subtitle {
        font-size: 12px;
    }
    
    #seed-list {
        flex-direction: column;
        overflow-x: hidden;
        overflow-y: auto;
        padding: 15px;
        gap: 12px;
    }
    
    #seed-list::-webkit-scrollbar {
        width: 8px;
        height: auto;
    }
    
    #seed-list::-webkit-scrollbar-track {
        background: #f3f4f6;
        border-radius: 4px;
    }
    
    #seed-list::-webkit-scrollbar-thumb {
        background: linear-gradient(135deg, #8b5cf6, #7c3aed);
        border-radius: 4px;
    }
    
    .seed-card {
        min-width: auto;
        width: 100%;
        flex-direction: row;
        justify-content: space-between;
        padding: 12px;
        min-height: 80px;
    }
    
    .seed-card:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }
    
    .seed-card:active {
        transform: scale(1);
    }
    
    .btn-reset {
        padding: 12px 24px;
        font-size: 16px;
    }
    
    .btn-harvest-all {
        padding: 10px 18px;
        font-size: 14px;
    }
    
    #coins-display {
        font-size: 32px;
    }
    
    .coin-icon {
        font-size: 36px;
    }
    
    #selected-seed {
        font-size: 18px;
    }
    
    #help-text {
        display: block; /* Show help text on desktop */
        font-size: 14px;
    }
    
    .label {
        display: inline; /* Show label on desktop */
    }
    
    .toggle-label {
        display: inline; /* Show toggle label on desktop */
    }
}

/* Ensure touch targets meet appropriate size */
@media (max-width: 767px) {
    /* Mobile: smaller targets for compressed layout */
    button, .toggle-container {
        min-height: 32px;
        touch-action: manipulation;
    }
    .seed-card {
        min-height: auto;
        touch-action: manipulation;
    }
}

@media (min-width: 768px) {
    /* Tablet/Desktop: standard touch target sizes */
    button, .toggle-container, .seed-card {
        min-height: 44px;
        touch-action: manipulation;
    }
}

/* Prevent bounce scrolling on iOS */
#game-container {
    position: fixed;
    overflow: hidden;
    -webkit-overflow-scrolling: touch;
}

/* Safe area support for notched devices */
@supports (padding: env(safe-area-inset-top)) {
    #hud {
        padding-top: calc(10px + env(safe-area-inset-top));
    }
    
    #seed-shop {
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }
}

/* Animations */
.coin-animation {
    animation: coinPop 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes coinPop {
    0% { transform: scale(1) rotate(0deg); }
    50% { transform: scale(1.3) rotate(180deg); }
    100% { transform: scale(1) rotate(360deg); }
}

/* Prevent text selection on mobile */
@media (hover: none) and (pointer: coarse) {
    body {
        -webkit-user-select: none;
        user-select: none;
    }
}