/* ========== 全局样式 ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: linear-gradient(180deg, #e8f4f8 0%, #d4e8ed 100%);
}

/* ========== 游戏容器 ========== */
#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 640px;
    margin: 0 auto;
    overflow: hidden;
}

/* ========== 背景层 ========== */
#background-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    z-index: 0;
}

/* ========== 场景层 ========== */
#scene-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    overflow: hidden;
}

/* ========== UI 层 ========== */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    pointer-events: none;
}

#ui-layer > * {
    pointer-events: auto;
}

/* ========== 顶部栏 ========== */
#top-bar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 70px;
    background: linear-gradient(180deg, #8B5A2B 0%, #6B4423 100%);
    display: flex;
    align-items: center;
    padding: 0 12px;
    border-bottom: 3px solid #5a3d1b;
    z-index: 10;
}

#player-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid gold;
    background-size: cover;
    background-position: center;
    margin-right: 10px;
    flex-shrink: 0;
}

#game-title {
    flex: 1;
    color: white;
    font-size: 18px;
    font-weight: bold;
    text-align: center;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

#top-actions {
    display: flex;
    gap: 8px;
    margin-left: 10px;
}

.top-action-btn {
    width: 36px;
    height: 36px;
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 18px;
    cursor: pointer;
    transition: transform 0.1s, background 0.2s;
}

.top-action-btn:active {
    transform: scale(0.95);
    background: rgba(255,255,255,0.3);
}

/* ========== 资源栏 ========== */
#resource-bar {
    position: absolute;
    top: 75px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    padding: 6px 12px;
    background: rgba(0,0,0,0.5);
    border-radius: 20px;
    backdrop-filter: blur(4px);
    z-index: 9;
}

.resource-item {
    display: flex;
    align-items: center;
    gap: 4px;
    color: white;
    font-size: 14px;
    font-weight: 500;
    padding: 0 8px;
}

.resource-icon {
    font-size: 16px;
}

.resource-value {
    min-width: 40px;
    text-align: right;
}

/* ========== 弹窗层 ========== */
#popup-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(2px);
}

.popup-content {
    background: white;
    border-radius: 16px;
    padding: 20px;
    max-width: 90%;
    max-height: 80%;
    overflow: auto;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    animation: popupIn 0.3s ease-out;
}

@keyframes popupIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #eee;
}

.popup-title {
    font-size: 20px;
    font-weight: bold;
    color: #333;
}

.popup-close {
    width: 32px;
    height: 32px;
    background: #f5f5f5;
    border: none;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background 0.2s;
}

.popup-close:hover {
    background: #e0e0e0;
}

/* ========== 加载层 ========== */
#loading-layer {
    position: absolute;
    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: 999;
}

.loading-content {
    text-align: center;
    color: white;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

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

.loading-text {
    font-size: 16px;
}

/* ========== 提示层 ========== */
#toast-layer {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 200;
    pointer-events: none;
}

.toast {
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 12px 24px;
    border-radius: 24px;
    font-size: 16px;
    margin-top: 10px;
    animation: toastIn 0.3s ease-out, toastOut 0.3s ease-in 2s forwards;
}

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

@keyframes toastOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-20px);
    }
}

/* ========== 农场场景 ========== */
#farm-scene {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding-top: 120px;
    overflow-y: auto;
}

.farm-container {
    position: relative;
    width: 100%;
    min-height: 100%;
    padding-bottom: 100px;
}

/* ========== 种植区 ========== */
#plant-area {
    position: relative;
    width: 380px;
    margin: 0 auto;
    padding: 20px;
    background: rgba(139, 69, 19, 0.3);
    border-radius: 20px;
    border: 3px solid #8B4513;
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.1);
}

.land-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

/* ========== 土地块 ========== */
.land-slot {
    position: relative;
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, #8B4513 0%, #654321 100%);
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.2s;
    overflow: hidden;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.land-slot:active {
    transform: scale(0.95);
}

.land-slot.locked {
    background: #666;
    cursor: not-allowed;
}

.land-slot.locked::after {
    content: '🔒';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    opacity: 0.5;
}

.soil-texture {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20"><rect fill="%23654321" width="20" height="20"/><circle fill="%238B4513" cx="5" cy="5" r="2"/><circle fill="%238B4513" cx="15" cy="15" r="2"/></svg>');
    opacity: 0.5;
    border-radius: 10px;
}

/* ========== 植物 ========== */
.plant {
    position: absolute;
    bottom: 5px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 60px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: bottom center;
    pointer-events: none;
    transition: transform 0.3s ease;
}

.plant.stage-1 { height: 20px; }
.plant.stage-2 { height: 35px; }
.plant.stage-3 { height: 50px; }
.plant.stage-4 { height: 60px; }

.plant.ready {
    animation: plantReady 1s ease-in-out infinite;
}

@keyframes plantReady {
    0%, 100% { transform: translateX(-50%) scale(1); }
    50% { transform: translateX(-50%) scale(1.1); }
}

/* ========== 建筑 ========== */
#buildings-area {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.building {
    position: relative;
    cursor: pointer;
    transition: transform 0.1s;
}

.building:active {
    transform: scale(0.95);
}

.building-house {
    width: 120px;
    height: 100px;
    background-image: url('../assets/images/buildings/house.png');
    background-size: contain;
    background-repeat: no-repeat;
}

.building-doghouse {
    width: 80px;
    height: 60px;
    background-image: url('../assets/images/buildings/doghouse.png');
    background-size: contain;
    background-repeat: no-repeat;
}

/* ========== 底部按钮栏 ========== */
#bottom-actions {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 80px;
    background: linear-gradient(0deg, rgba(0,0,0,0.8) 0%, transparent 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    padding-bottom: 20px;
    z-index: 10;
}

.bottom-btn {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
    border: 3px solid #fff;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    transition: transform 0.1s, box-shadow 0.2s;
}

.bottom-btn:active {
    transform: scale(0.95);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* ========== 响应式 ========== */
@media (max-width: 480px) {
    #plant-area {
        width: 340px;
    }
    
    .land-slot {
        width: 70px;
        height: 70px;
    }
    
    #resource-bar {
        width: 90%;
    }
}