/* ===== MOBILE OPTIMIZED CSS =====
   移动端优先优化 - 基于现有 style.css */

@media (max-width: 768px) {
  :root {
    --pixel-size: 3px;
    --plot-size: 44px;  /* 移动端格子大小 */
  }

  /* ===== TOP BAR 优化 - 方案B ===== */
  #top-bar {
    height: 48px;
    padding: 6px 10px;
    flex-wrap: nowrap;
    justify-content: space-between;
    gap: 8px;
  }

  .top-left, .top-center, .top-right {
    gap: 6px;
  }

  /* 金币 - 左侧 */
  .gold-display {
    padding: 6px 10px;
    min-width: auto;
    gap: 4px;
  }

  #gold-amount {
    font-size: 11px !important;
    color: #ffd700 !important;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
    min-width: 40px;
  }

  .stat-label { display: none; }

  /* 日期/天气 - 中间并排显示 */
  .top-center {
    flex-direction: row !important;
    align-items: center;
    gap: 6px;
    flex: 1;
    justify-content: center;
  }

  .date-display {
    padding: 5px 8px;
    font-size: 9px;
    white-space: nowrap;
  }

  .weather-display {
    padding: 5px 8px;
    font-size: 9px;
    display: flex;
    align-items: center;
    gap: 4px;
  }

  .forecast { display: none; }

  /* 速度控制 - 折叠式菜单 */
  .speed-controls {
    display: flex !important;
    align-items: center;
    gap: 2px;
    position: relative;
  }

  .speed-toggle {
    font-size: 9px !important;
    padding: 4px 8px !important;
    min-width: 32px;
    min-height: 28px;
    background: linear-gradient(180deg, #6a9a4c 0%, #4a7a2c 100%);
    border: 2px solid #3a6a1c;
    border-radius: 6px;
    color: #fff;
    font-weight: bold;
  }

  .speed-menu {
    display: flex;
    gap: 1px;
    background: rgba(0,0,0,0.8);
    padding: 4px;
    border-radius: 8px;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  }

  .speed-menu.hidden {
    display: none !important;
  }

  .speed-menu .speed-btn {
    font-size: 8px !important;
    padding: 3px 6px !important;
    min-width: 26px;
    min-height: 26px;
    border-width: 2px;
    background: linear-gradient(180deg, #8aaa6c 0%, #6a9a4c 100%);
    border-color: #4a7a2c;
    color: #fff;
  }

  .speed-menu .speed-btn.active {
    background: linear-gradient(180deg, #ffe8a0 0%, #ffd860 100%);
    border-color: #c8a020;
    color: #5a4a1c;
  }

  /* 睡觉按钮 - 独立突出 */
  .sleep-btn {
    font-size: 9px;
    padding: 6px 10px;
    white-space: nowrap;
    background: linear-gradient(180deg, #7a6add 0%, #5a4acd 100%);
  }

  /* ===== GAME AREA 优化 ===== */
  #game-area {
    flex: 1;
    min-height: 0;
    height: calc(100vh - 48px - 160px); /* 留出 top(48px) + bottom(160px) 更多空间给底部栏 */
    max-height: calc(100vh - 48px - 160px);
    overflow: auto;
    padding-bottom: 20px; /* 额外底部内边距 */
  }

  /* 农场容器 - 全宽 */
  #farm-container {
    padding: 8px;
    padding-bottom: 20px; /* 底部额外空间 */
    width: 100%;
    min-height: 100%; /* 确保最小高度 */
    display: flex;
    justify-content: center;
    align-items: flex-start; /* 从顶部开始而不是居中 */
    overflow: visible;
    -webkit-overflow-scrolling: touch;
  }

  /* 农场网格 - 自适应 */
  .farm-grid {
    gap: 1px !important;
    padding: 2px !important;
    /* 移动端自适应宽度 */
    width: fit-content !important;
    max-width: 100% !important;
    margin: 0 auto !important;
    background: #3a5a1c !important;
    border: 2px solid #2a4a0c !important;
    box-shadow: none !important;
    display: grid !important;
  }

  /* 格子大小 - 根据屏幕计算 */
  .plot {
    width: var(--plot-size) !important;
    height: var(--plot-size) !important;
    min-width: 36px !important;
    min-height: 36px !important;
    max-width: 48px !important;
    max-height: 48px !important;
    position: relative !important;
    box-sizing: border-box !important;
  }

  /* ===== BOTTOM BAR 优化 - 核心改进 ===== */
  #bottom-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: auto;
    max-height: 45vh;
    min-height: 130px;
    padding: 8px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 8px));
    z-index: 50;
    background: linear-gradient(0deg, rgba(90,64,32,0.98) 0%, rgba(90,64,32,0.95) 100%);
    border-top: 4px solid #3a2a1a;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  /* 工具栏 - 固定在底部最上方 */
  .tool-bar {
    flex-direction: row !important;
    justify-content: space-around;
    gap: 8px;
  }

  .tool-section {
    flex-direction: row !important;
    align-items: center;
    gap: 6px;
    flex: 1;
    justify-content: center;
  }

  .section-label { display: none; }

  /* 工具按钮 - 增大触摸区域 */
  .tool-btn {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center;
    gap: 4px !important;
    padding: 10px !important;
    min-width: 64px !important;
    min-height: 70px !important;
    font-size: 8px;
    border-radius: 12px;
    box-shadow: 
      inset -2px -2px 0 rgba(0,0,0,0.15),
      inset 2px 2px 0 rgba(255,255,255,0.3),
      3px 3px 0 rgba(0,0,0,0.3);
  }

  .tool-btn.active {
    background: linear-gradient(180deg, #ffe8a0 0%, #ffd860 100%) !important;
    border-color: #c8a020 !important;
    box-shadow: 
      0 0 0 3px rgba(255,215,0,0.5),
      inset 2px 2px 0 rgba(0,0,0,0.1),
      3px 3px 0 rgba(0,0,0,0.3) !important;
  }

  .tool-btn .tool-emoji {
    font-size: 26px !important;
    line-height: 1;
  }

  .tool-btn span {
    display: block !important;
    font-size: 8px !important;
    text-align: center;
    line-height: 1.2;
  }

  /* 种子区 - 移动端隐藏，改用弹窗 */
  .seed-section {
    display: none !important;
  }

  /* 种子选择弹窗 - 底部弹出 */
  .seed-selector-overlay {
    align-items: flex-end !important;
    padding: 0 !important;
  }

  .seed-selector-modal.modal {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: 45vh !important;
    border-radius: 20px 20px 0 0 !important;
    margin: 0 !important;
    animation: slide-up 0.3s ease-out;
  }

  @keyframes slide-up {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }

  .seed-selector-modal.modal .modal-header {
    padding: 16px 20px;
    border-radius: 20px 20px 0 0;
  }

  .seed-selector-modal.modal .modal-header h2 {
    font-size: 14px !important;
  }

  .seed-selector-modal.modal .modal-body {
    padding: 16px;
    max-height: calc(45vh - 60px) !important;
    overflow-y: auto;
  }

  .seed-selector-list {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 12px;
    padding: 8px;
  }

  .seed-selector-list:empty {
    display: none !important;
  }

  /* 种子空状态 */
  .seed-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 20px;
    text-align: center;
    gap: 12px;
  }

  .seed-empty-state.hidden {
    display: none !important;
  }

  .seed-empty-state .empty-icon {
    font-size: 48px;
    opacity: 0.5;
    animation: float 2s ease-in-out infinite;
  }

  @keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
  }

  .seed-empty-state p {
    font-size: 14px;
    color: #5a4a1c;
    margin: 0;
  }

  .seed-empty-state .empty-hint {
    font-size: 12px;
    color: #8a7a4c;
  }

  .seed-empty-state .go-shop-btn {
    margin-top: 8px;
    padding: 12px 24px;
    font-size: 12px;
    background: linear-gradient(180deg, #ffd860 0%, #ffc840 100%);
    border-color: #c8a020;
  }

  .seed-selector-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px 12px;
    background: var(--panel-bg);
    border: 3px solid var(--panel-border);
    border-radius: 16px;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.1s;
  }

  .seed-selector-item:active {
    transform: scale(0.95);
  }

  .seed-selector-item.active {
    background: linear-gradient(180deg, #c8ffc8 0%, #a0ffa0 100%);
    border-color: #4a8a2c;
    box-shadow: 
      0 0 0 3px rgba(74,138,44,0.5),
      inset 0 0 10px rgba(74,138,44,0.2);
  }

  .seed-selector-item.no-seeds {
    opacity: 0.4;
    border-style: dashed;
  }

  .seed-selector-item .seed-emoji {
    font-size: 32px;
    line-height: 1;
  }

  .seed-selector-item .seed-name {
    font-size: 10px;
    text-align: center;
    color: var(--text-dark);
    font-weight: bold;
  }

  .seed-selector-item .seed-count {
    font-size: 10px;
    color: #666;
    background: rgba(0,0,0,0.1);
    padding: 4px 10px;
    border-radius: 12px;
  }

  .seed-selector-item .seed-price {
    font-size: 9px;
    color: #b8860b;
    background: rgba(255,215,0,0.2);
    padding: 2px 8px;
    border-radius: 10px;
  }

  /* ===== SIDE BUTTONS - 移到左侧 ===== */
  .side-buttons {
    position: fixed;
    left: 8px;
    bottom: calc(140px + env(safe-area-inset-bottom, 8px));
    top: auto;
    right: auto;
    transform: none;
    flex-direction: column;
    gap: 8px;
    z-index: 60;
  }

  .side-btn {
    width: 48px;
    height: 48px;
    font-size: 20px;
    background: rgba(240,232,208,0.95);
    border: 3px solid var(--panel-border);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 
      inset -2px -2px 0 rgba(0,0,0,0.15),
      inset 2px 2px 0 rgba(255,255,255,0.3),
      3px 3px 8px rgba(0,0,0,0.3);
  }

  .side-btn:active {
    transform: scale(0.92);
  }

  /* ===== MODALS - 全屏 ===== */
  .modal {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    border: none !important;
    border-radius: 0 !important;
  }

  .modal-header {
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 10;
  }

  .modal-header h2 {
    font-size: 12px !important;
  }

  .modal-body {
    padding: 12px;
    height: calc(100% - 60px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* 商店商品 - 卡片布局 */
  .shop-items {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px;
  }

  .shop-item {
    flex-direction: column !important;
    padding: 12px !important;
  }

  .shop-item-header {
    flex: none;
    width: 100%;
    justify-content: center;
  }

  .shop-item-emoji {
    font-size: 28px !important;
  }

  .shop-item-name {
    font-size: 9px !important;
    text-align: center;
  }

  .shop-item-info {
    font-size: 7px !important;
    text-align: center;
  }

  .shop-item-buy {
    width: 100%;
    justify-content: center;
    margin-top: 8px;
  }

  .shop-item-buy input {
    width: 50px !important;
  }

  .shop-item-buy .pixel-btn {
    flex: 1;
    font-size: 9px !important;
  }

  /* ===== NOTIFICATIONS ===== */
  .notification {
    left: 10px;
    right: 10px;
    max-width: none;
    bottom: calc(160px + env(safe-area-inset-bottom, 8px));
    top: auto;
  }

  .achievement-popup {
    left: 10px;
    right: 10px;
    transform: translateY(-20px);
  }

  /* ===== TOUCH FEEDBACK ===== */
  .plot {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .plot:active {
    transform: scale(0.92);
  }

  .pixel-btn:active {
    transform: scale(0.95) translate(1px, 1px);
  }

  /* 种植动画 */
  @keyframes plant-flash {
    0% { opacity: 1; transform: scale(0.5); }
    50% { opacity: 0.8; transform: scale(1.2); }
    100% { opacity: 0; transform: scale(1.5); }
  }

  @keyframes plant-pop {
    0% { transform: scale(0) translateY(10px); }
    50% { transform: scale(1.3) translateY(-5px); }
    100% { transform: scale(1) translateY(0); }
  }
}

/* ===== 极小屏幕优化 ===== */
@media (max-width: 380px) {
  :root {
    --plot-size: 42px;
  }

  .tool-btn {
    min-width: 56px !important;
    min-height: 65px !important;
    padding: 8px !important;
  }

  .tool-btn .tool-emoji {
    font-size: 22px !important;
  }

  .tool-btn span {
    font-size: 7px !important;
  }

  .seed-item {
    min-width: 54px !important;
    min-height: 64px !important;
    padding: 8px !important;
  }

  .seed-item .seed-emoji {
    font-size: 18px !important;
  }
}

/* ===== 横屏优化 ===== */
@media (orientation: landscape) and (max-height: 500px) {
  #top-bar {
    height: 42px;
    padding: 4px 10px;
  }

  #game-area {
    height: calc(100vh - 42px - 80px);
  }

  #bottom-bar {
    height: 80px;
    max-height: 80px;
    min-height: 80px;
    flex-direction: row;
  }

  .tool-bar {
    flex-direction: row !important;
  }

  .tool-btn span {
    display: none !important;
  }

  .seed-section::before {
    display: none;
  }

  .seed-list {
    flex-direction: row !important;
  }

  .side-buttons {
    bottom: 90px;
  }

  .notification {
    bottom: 90px;
  }
}

/* ===== 安全区域适配 (iPhone X+) ===== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  #bottom-bar {
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }
}
