/* =============================================
   IDMeta · H5 Mobile Enhancements
   Premium mobile-first experience
   ============================================= */

/* ========== iOS Safe Area + Touch ========== */
@supports (padding: env(safe-area-inset-bottom)) {
  .mobile-bottom-nav {
    padding-bottom: calc(env(safe-area-inset-bottom) + 4px) !important;
    height: calc(68px + env(safe-area-inset-bottom)) !important;
  }

  .main-content {
    padding-bottom: calc(90px + env(safe-area-inset-bottom)) !important;
  }
}

/* ========== Enhanced Bottom Tab Bar ========== */
@media (max-width: 768px) {
  .mobile-bottom-nav {
    height: 68px;
    background: rgba(10, 14, 26, 0.96);
    border-top: 1px solid rgba(212, 168, 83, 0.12);
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.5);
  }

  .bottom-nav-item {
    position: relative;
    padding: 8px 4px 4px;
    min-width: 52px;
    gap: 3px;
    font-size: 0.62rem;
    font-weight: 500;
    letter-spacing: 0.3px;
    border-radius: 8px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
  }

  .bottom-nav-item .nav-icon {
    font-size: 1.35rem;
    transition: transform 0.2s ease;
  }

  .bottom-nav-item.active {
    color: var(--accent-gold);
  }

  .bottom-nav-item.active .nav-icon {
    transform: scale(1.15);
    filter: drop-shadow(0 0 8px rgba(212, 168, 83, 0.5));
  }

  /* Active indicator dot */
  .bottom-nav-item.active::after {
    content: '';
    position: absolute;
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    background: var(--accent-gold);
    border-radius: 50%;
    box-shadow: 0 0 6px var(--accent-gold);
  }

  /* Tap feedback */
  .bottom-nav-item:active:not(.disabled) {
    background: rgba(212, 168, 83, 0.08);
    transform: scale(0.95);
    transition: transform 0.1s ease;
  }

  /* ========== Mobile Header Enhanced ========== */
  .mobile-header {
    height: 56px;
    padding: 0 16px;
    background: rgba(10, 14, 26, 0.96);
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.4);
  }

  .mobile-title {
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: 1px;
  }

  .menu-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    -webkit-tap-highlight-color: transparent;
  }

  .menu-btn:active {
    background: rgba(212, 168, 83, 0.1);
  }

  /* ========== Main Content Mobile ========== */
  .main-content {
    padding: 68px 14px 88px;
  }

  /* ========== Page Header Mobile ========== */
  .page-header {
    padding: 14px 0 16px;
  }

  .header-icon {
    font-size: 2.2rem;
    margin-bottom: 6px;
  }

  .page-header h1 {
    font-size: 1.3rem;
    letter-spacing: 2px;
  }

  .page-header p {
    font-size: 0.78rem;
    letter-spacing: 1.5px;
  }

  /* ========== Card Mobile ========== */
  .card {
    padding: 18px 14px;
    margin-bottom: 14px;
    border-radius: 14px;
    /* Disable hover effects on touch */
    -webkit-tap-highlight-color: transparent;
  }

  .card:hover {
    border-color: var(--border-glass);
    box-shadow: var(--shadow-card);
    transform: none;
  }

  .card-title {
    font-size: 1rem;
    margin-bottom: 14px;
    gap: 6px;
  }

  /* ========== Forms - Touch Optimized ========== */
  .form-group input,
  .form-group select {
    padding: 14px 14px;
    font-size: 16px;
    /* Prevents iOS zoom */
    border-radius: 10px;
    min-height: 48px;
    /* Apple HIG minimum touch target */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
  }

  .form-group select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23999' stroke-width='2' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
  }

  .form-group label {
    font-size: 0.8rem;
    padding-bottom: 2px;
  }

  /* ========== Buttons - Touch Optimized ========== */
  .btn-primary,
  .btn-secondary {
    min-height: 50px;
    font-size: 1rem;
    border-radius: 12px;
    letter-spacing: 2px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  .btn-primary:hover {
    transform: none;
    box-shadow: none;
  }

  .btn-primary:active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
  }

  .btn-secondary:hover {
    transform: none;
  }

  /* ========== Quick Buttons (Fantui etc.) ========== */
  .quick-btn {
    font-size: 0.85rem;
    padding: 10px 16px;
    min-height: 44px;
    border-radius: 22px;
    -webkit-tap-highlight-color: transparent;
  }

  /* ========== Chat Container Mobile ========== */
  .chat-container {
    max-height: 50vh;
    border-radius: 12px;
  }

  .chat-input-area {
    gap: 8px;
  }

  .chat-input {
    font-size: 16px;
    /* Prevents iOS zoom */
    padding: 12px 14px;
    min-height: 44px;
  }

  .chat-send-btn {
    min-width: 64px;
    min-height: 44px;
    font-size: 0.9rem;
    border-radius: 10px;
    -webkit-tap-highlight-color: transparent;
  }

  /* ========== Bazi Pillars Mobile ========== */
  .bazi-pillars {
    gap: 6px;
    margin: 16px 0;
  }

  .pillar-tg .char,
  .pillar-dz .char {
    font-size: 1.5rem;
  }

  .pillar-tg {
    padding: 14px 6px 10px;
  }

  .pillar-dz {
    padding: 10px 6px 10px;
  }

  .pillar-canggan {
    padding: 6px 4px 8px;
  }

  .canggan-item {
    font-size: 0.65rem;
  }

  .pillar-label {
    font-size: 0.68rem;
    margin-bottom: 6px;
  }

  .pillar-shishen {
    font-size: 0.65rem;
    margin-bottom: 4px;
  }

  /* Disable pillar hover on touch */
  .pillar:hover .pillar-box {
    border-color: var(--border-glass);
    box-shadow: none;
    transform: none;
  }

  .pillar.day-master:hover .pillar-box {
    border-color: var(--accent-gold);
    box-shadow: 0 0 15px var(--accent-gold-glow);
    transform: none;
  }

  /* ========== Wuxing Chart Mobile ========== */
  .wuxing-chart {
    gap: 8px;
    margin: 14px 0 8px;
  }

  .wuxing-ring {
    width: 44px;
    height: 44px;
    font-size: 1.1rem;
  }

  .wuxing-label {
    font-size: 0.7rem;
  }

  .wuxing-count {
    font-size: 0.72rem;
  }

  /* ========== Meta Info Mobile ========== */
  .meta-item {
    padding: 8px 12px;
  }

  .meta-item .label {
    font-size: 0.68rem;
  }

  .meta-item .value {
    font-size: 0.85rem;
  }

  /* ========== Dayun Timeline Mobile ========== */
  .dayun-timeline {
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    padding: 8px 0;
  }

  .dayun-block {
    scroll-snap-align: start;
    width: 76px;
    flex-shrink: 0;
    padding: 10px 4px;
  }

  .dayun-block .dy-gz {
    font-size: 1.1rem;
  }

  /* ========== Sidebar Mobile Fix ========== */
  .sidebar {
    background: #0a0e1e !important;
    /* 完全不透明，避免 Safari blur 问题 */
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    z-index: 100 !important;
    /* 确保在 overlay 之上 */
    pointer-events: auto !important;
  }

  .sidebar-overlay {
    z-index: 90 !important;
    /* 在 sidebar 之下 */
  }

  .sidebar-overlay.active {
    /* 不使用 backdrop-filter，iOS Safari 会导致文字模糊 */
    background: rgba(0, 0, 0, 0.55);
  }

  .sidebar.open {
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.6);
  }

  /* ========== Toast Mobile ========== */
  #toast {
    bottom: 90px !important;
    max-width: calc(100vw - 32px) !important;
    font-size: 0.88rem !important;
  }

  /* ========== Loading Overlay Mobile ========== */
  .loading-spinner .bagua {
    font-size: 2.5rem;
  }

  .loading-spinner p {
    font-size: 0.9rem;
    letter-spacing: 2px;
  }

  /* ========== Table Mobile Scroll ========== */
  table {
    font-size: 0.78rem;
  }

  /* ========== Auth Modal Mobile ========== */
  .auth-modal-content {
    width: calc(100vw - 32px);
    max-width: 380px;
    padding: 24px 20px;
    border-radius: 16px;
  }

  /* ========== Footer Mobile ========== */
  .main-footer {
    padding: 16px 0;
    font-size: 0.72rem;
  }

  /* ========== Cooperation Cards Mobile ========== */
  .hezuo-target-card {
    padding: 12px !important;
    margin-bottom: 10px !important;
  }

  /* ========== K-line Chart Mobile ========== */
  #kline-chart-wrap {
    height: 350px !important;
  }

  /* ========== Liuyao Layout ========== */
  .liuyao-layout {
    grid-template-columns: 1fr !important;
  }

  /* ========== Mingpan Tabs Mobile ========== */
  .mingpan-tabs {
    flex-wrap: wrap;
    gap: 6px;
  }

  .mingpan-tab {
    font-size: 0.82rem;
    padding: 8px 14px;
    min-height: 40px;
  }

  /* ========== Portrait Image Mobile ========== */
  #portrait-img {
    max-width: 100% !important;
  }

  /* ========== Smooth Scroll + Overscroll ========== */
  html {
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
  }
}

/* ========== Small Phone (<=400px) ========== */
@media (max-width: 400px) {
  .main-content {
    padding: 62px 10px 80px;
  }

  .card {
    padding: 14px 12px;
    border-radius: 12px;
  }

  .card-title {
    font-size: 0.92rem;
  }

  .page-header h1 {
    font-size: 1.15rem;
  }

  .header-icon {
    font-size: 1.8rem;
  }

  .pillar-tg .char,
  .pillar-dz .char {
    font-size: 1.3rem;
  }

  .bottom-nav-item {
    font-size: 0.58rem;
    min-width: 44px;
  }

  .bottom-nav-item .nav-icon {
    font-size: 1.2rem;
  }

  .wuxing-ring {
    width: 38px;
    height: 38px;
    font-size: 1rem;
  }
}