/**
 * 移动端完美适配 - 无横向滚动版本
 * 简洁、清晰、美观，完全自适应
 */

/* ========== 移动端全局 ========== */
@media (max-width: 768px) {
  body {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
  }
  
  .container {
    padding: 12px;
  }
}

/* ========== Header ========== */
@media (max-width: 768px) {
  .site-header {
    padding: 10px 0;
  }
  
  .header-container {
    padding: 0 12px;
    gap: 10px;
  }
  
  .logo a {
    font-size: 16px;
    font-weight: 700;
  }
  
  .nav-sources {
    gap: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  
  .nav-sources::-webkit-scrollbar {
    display: none;
  }
  
  .nav-tab {
    padding: 8px 14px;
    font-size: 13px;
    min-width: 70px;
    flex-shrink: 0;
  }
}

/* ========== Hero Cards - 2列 ========== */
@media (max-width: 768px) {
  .hero-cards {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 16px;
  }
  
  .hero-card {
    padding: 16px 12px;
  }
  
  .hero-label {
    font-size: 11px;
    margin-bottom: 8px;
  }
  
  .hero-value {
    font-size: 20px;
  }
  
  .hero-value .formula {
    font-size: 16px;
  }
}

/* ========== 子导航 ========== */
@media (max-width: 768px) {
  .sub-nav {
    padding: 8px;
    gap: 5px;
    margin-bottom: 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .sub-nav::-webkit-scrollbar {
    display: none;
  }
  
  .sub-nav-item {
    padding: 10px 14px;
    font-size: 13px;
    min-width: 68px;
    flex-shrink: 0;
  }
}

/* ========== 表格通用 ========== */
@media (max-width: 768px) {
  .table-wrap {
    margin-bottom: 16px;
    border-radius: 10px;
  }
  
  .table-header {
    padding: 12px 14px;
  }
  
  .table-header h1 {
    font-size: 16px;
  }
  
  .update-time {
    font-size: 11px;
  }
  
  table {
    width: 100%;
  }
  
  th, td {
    padding: 12px 8px;
    font-size: 12px;
  }
}

/* ========== 开奖结果页 - 3列自适应 ========== */
@media (max-width: 768px) {
  #resultTable th:nth-child(1),
  #resultTable td:nth-child(1) {
    width: 30%;
    padding-left: 12px;
  }
  
  #resultTable th:nth-child(2),
  #resultTable td:nth-child(2) {
    width: 46%;
    /* 收紧中间列内边距，避免挤压时间列 */
    padding-left: 8px !important;
    padding-right: 8px !important;
  }
  
  #resultTable th:nth-child(3),
  #resultTable td:nth-child(3) {
    width: 24%;
    padding-right: 12px;
  }
  
  /* 固定布局，防止列宽被内容撑破 */
  #resultTable { table-layout: fixed; }

  .numbers-box {
    gap: 3px;
  }
  
  .number {
    width: 24px;
    height: 24px;
    font-size: 11px;
  }
  
  .total {
    min-width: 32px;
    height: 26px;
    font-size: 13px;
  }
  
  .plus, .equal {
    font-size: 11px;
  }
  
  .col-time {
    font-size: 12px;
    white-space: nowrap;
    letter-spacing: 0.2px;
    color: var(--color-gray-600);
  }
  /* 仅移动端隐藏日期（保留时:分:秒），避免长期号被遮挡 */
  #resultTable .col-time .time-sub { display: none; }
  #resultTable .col-period {
    font-size: 12px;
    letter-spacing: 0;
    white-space: nowrap;       /* 水平排列，不换行 */
    overflow: hidden;
    text-overflow: clip;       /* 不使用省略号，尽量挤压其他列 */
  }

  /* 行条纹，提升可读性 */
  #resultTable tbody tr:nth-child(odd) { background: #fafafa; }
}

/* ========== 历史查询页 - 简洁清晰布局 ========== */
@media (max-width: 768px) {
  /* 保持表格结构，优化显示 */
  #historyTable {
    font-size: 13px;
  }
  
  #historyTable thead {
    background: var(--color-gray-50);
  }
  
  #historyTable th {
    padding: 10px 6px;
    font-size: 11px;
    font-weight: 700;
    color: var(--color-gray-700);
    border-bottom: 2px solid var(--color-gray-200);
  }
  
  #historyTable td {
    padding: 12px 6px;
    border-bottom: 1px solid var(--color-gray-100);
    vertical-align: middle;
  }
  
  /* 期号列 */
  #historyTable th:nth-child(1),
  #historyTable td:nth-child(1) {
    width: 20%;
    text-align: left;
    padding-left: 10px;
    font-weight: 700;
    color: var(--color-primary);
    font-size: 12px;
  }
  
  /* 前中尾球列 */
  #historyTable th:nth-child(2),
  #historyTable th:nth-child(3),
  #historyTable th:nth-child(4),
  #historyTable td:nth-child(2),
  #historyTable td:nth-child(3),
  #historyTable td:nth-child(4) {
    width: 12%;
    text-align: center;
  }
  
  /* 数字样式 - 简洁无背景 */
  #historyTable .col-num {
    font-size: 18px;
    font-weight: 700;
    color: var(--color-primary);
    font-family: 'Courier New', monospace;
  }
  
  /* 和值列 */
  #historyTable th:nth-child(5),
  #historyTable td:nth-child(5) {
    width: 16%;
    text-align: center;
    padding: 8px 4px;
  }
  
  /* 和值 - 简洁样式 */
  #historyTable .total-small {
    display: inline-block;
    min-width: 32px;
    height: 24px;
    line-height: 24px;
    padding: 0 8px;
    font-size: 14px;
    font-weight: 700;
    border-radius: 6px;
    background: var(--color-success);
    color: white;
    font-family: 'Courier New', monospace;
  }
  
  /* 隐藏形态标签 */
  #historyTable .shape-badges-inline {
    display: none !important;
  }
  
  /* 时间列 - 显示日期+时间 */
  #historyTable th:nth-child(6),
  #historyTable td:nth-child(6) {
    width: 28%;
    text-align: right;
    padding-right: 10px;
    font-size: 10px;
    color: var(--color-gray-500);
    line-height: 1.3;
  }
  
  /* 显示时间和日期 */
  #historyTable .col-time .time-main {
    font-size: 11px;
    font-weight: 600;
    color: var(--color-gray-700);
  }
  
  #historyTable .col-time .time-sub {
    font-size: 9px;
    color: var(--color-gray-400);
    margin-top: 2px;
  }
  
  /* 行条纹 */
  #historyTable tbody tr:nth-child(even) {
    background: var(--color-gray-50);
  }
  
  /* 工具栏优化 */
  .toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 10px;
    border-radius: 10px;
  }
  
  .toolbar select,
  .toolbar input {
    grid-column: span 2;
    border-radius: 8px;
    border: 1px solid var(--color-gray-200);
    padding: 10px 12px;
    font-size: 13px;
  }
  
  .toolbar button {
    border-radius: 8px;
    padding: 10px;
    font-size: 13px;
    font-weight: 600;
  }
}

/* ========== 走势图 - 只显示核心列 ========== */
@media (max-width: 768px) {
  /* 隐藏次要列，只显示核心数据 */
  #trendTable th:nth-child(n+7):nth-child(-n+10),
  #trendTable td:nth-child(n+7):nth-child(-n+10) {
    display: none;
  }
  
  /* 显示的列：期号、和值、小、大、单、双、庄、闲、和（共9列） */
  #trendTable th:nth-child(1),
  #trendTable td:nth-child(1) {
    width: 14%;
  }
  
  #trendTable th:nth-child(2),
  #trendTable td:nth-child(2) {
    width: 11%;
    font-weight: 700;
    white-space: nowrap;   /* 表头和值保持一行水平排列 */
  }
  
  #trendTable th:nth-child(3),
  #trendTable th:nth-child(4),
  #trendTable th:nth-child(5),
  #trendTable th:nth-child(6),
  #trendTable th:nth-child(11),
  #trendTable th:nth-child(12),
  #trendTable th:nth-child(13),
  #trendTable td:nth-child(3),
  #trendTable td:nth-child(4),
  #trendTable td:nth-child(5),
  #trendTable td:nth-child(6),
  #trendTable td:nth-child(11),
  #trendTable td:nth-child(12),
  #trendTable td:nth-child(13) {
    width: 10.7%;
  }
  
  .badge-mini {
    height: 20px;
    font-size: 9px;
    padding: 0 5px;
  }
}

/* ========== 预测页面 - 卡片式布局 ========== */
@media (max-width: 768px) {
  .predict-warning {
    padding: 12px 14px;
    margin-bottom: 12px;
  }
  
  .predict-warning h3 {
    font-size: 14px;
  }
  
  .predict-warning p {
    font-size: 12px;
  }
  
  .predict-tabs {
    padding: 10px;
    gap: 6px;
    margin-bottom: 12px;
  }
  
  .predict-tab {
    flex: 1;
    padding: 12px 10px;
    font-size: 13px;
  }
  
  .predict-header {
    flex-direction: column;
    padding: 14px;
    gap: 12px;
  }
  
  .predict-stats {
    flex-direction: column;
    gap: 10px;
  }
  
  .stat-item {
    display: flex;
    justify-content: space-between;
    background: var(--color-gray-50);
    padding: 10px 12px;
    border-radius: 6px;
  }
  
  .stat-item .label {
    font-size: 11px;
    margin: 0;
  }
  
  .stat-item .value {
    font-size: 18px;
  }
  
  /* 预测表格 - 移动端仅显示 期号/号码/预测/结果/时间，隐藏“杀组合+结果” */
  #predictTable1 th:nth-child(n+5):nth-child(-n+6),
  #predictTable2 th:nth-child(n+5):nth-child(-n+6),
  #predictTable3 th:nth-child(n+5):nth-child(-n+6),
  #predictTable1 td:nth-child(n+5):nth-child(-n+6),
  #predictTable2 td:nth-child(n+5):nth-child(-n+6),
  #predictTable3 td:nth-child(n+5):nth-child(-n+6) {
    display: none;
  }
  
  /* 显示：期号、号码、杀组合、结果、时间（5列） */
  #predictTable1,
  #predictTable2,
  #predictTable3 {
    width: 100%;
  }
  
  #predictTable1 th,
  #predictTable2 th,
  #predictTable3 th,
  #predictTable1 td,
  #predictTable2 td,
  #predictTable3 td {
    font-size: 12px;
    padding: 10px 6px;
  }
  
  .result-correct,
  .result-partial,
  .result-wrong,
  .result-waiting {
    padding: 4px 10px;
    font-size: 11px;
  }
}

/* ========== 工具栏 ========== */
@media (max-width: 768px) {
  .toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 10px;
    border-radius: 10px;
  }
  
  .toolbar select,
  .toolbar input {
    grid-column: span 2;
    width: 100%;
    padding: 10px 12px;
    font-size: 13px;
  }
  
  .toolbar button {
    width: 100%;
    padding: 10px 0;
    font-size: 13px;
    background: #fff;
    color: var(--color-primary);
    border: 1px solid var(--color-primary);
  }
}

/* ========== 分页器 ========== */
@media (max-width: 768px) {
  #pager {
    padding: 12px;
    gap: 10px;
  }
  
  #pager button {
    padding: 10px 16px;
    font-size: 13px;
  }
  
  #pageInfo {
    font-size: 12px;
  }
}

/* ========== 和值统计 ========== */
@media (max-width: 768px) {
  #sumGrid {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }
  
  .sum-card {
    padding: 14px 10px;
  }
  
  .sum-card .value {
    font-size: 20px;
  }
  
  .sum-card .count {
    font-size: 11px;
  }
}

@media (max-width: 480px) {
  #sumGrid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ========== 趣味游戏页面 ========== */
@media (max-width: 768px) {
  .scratch-container {
    padding: 20px;
    margin-bottom: 24px;
    border-radius: 12px;
  }
  
  .scratch-container h2 {
    font-size: 18px;
    margin-bottom: 10px;
  }
  
  .scratch-container > p {
    font-size: 13px;
    margin-bottom: 16px;
  }
  
  .scratch-card {
    height: 200px;
  }
  
  .scratch-result .result-numbers {
    font-size: 32px;
    margin-bottom: 12px;
  }
  
  .scratch-result .result-badges {
    gap: 6px;
  }
  
  .scratch-result .result-badges .badge {
    height: 24px;
    font-size: 10px;
    padding: 0 8px;
  }
  
  .flip-container {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
  }
  
  .flip-card {
    height: 140px !important;
  }
  
  .flip-number {
    font-size: 16px !important;
  }
  
  .flip-badges {
    gap: 4px !important;
  }
  
  .flip-badges .badge {
    height: 20px !important;
    font-size: 9px !important;
    padding: 0 6px !important;
  }
}

/* ========== 首页 ========== */
@media (max-width: 768px) {
  .hero-section {
    padding: 40px 20px;
    margin-bottom: 24px;
  }
  
  .hero-section h1 {
    font-size: 28px;
  }
  
  .hero-section p {
    font-size: 15px;
  }
  
  .source-grid,
  .features-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
}

/* ========== Footer移动端极简优化 ========== */
@media (max-width: 768px) {
  .site-footer {
    margin-top: 32px;
    padding: 20px 0 16px 0;
  }
  
  /* 隐藏前两个section，只保留帮助中心 */
  .footer-section:nth-child(1),
  .footer-section:nth-child(2) {
    display: none;
  }
  
  .footer-container {
    grid-template-columns: 1fr;
    gap: 0;
    padding: 0 16px;
    margin-bottom: 16px;
  }
  
  .footer-section {
    text-align: center;
  }
  
  .footer-section h3 {
    font-size: 14px;
    margin-bottom: 10px;
    padding-bottom: 8px;
  }
  
  .footer-section h3::after {
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
  }
  
  .footer-section ul {
    display: flex;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
  }
  
  .footer-section li {
    margin-bottom: 0;
  }
  
  .footer-section a {
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 6px;
    background: rgba(99, 102, 241, 0.1);
  }
  
  .footer-section a:hover {
    transform: none;
    background: rgba(99, 102, 241, 0.2);
  }
  
  .footer-section p {
    display: none;
  }
  
  .footer-bottom {
    padding-top: 16px;
  }
  
  .footer-bottom p {
    font-size: 10px;
    padding: 0 16px;
    line-height: 1.5;
  }
}

/* ========== 触摸优化 ========== */
@media (hover: none) and (pointer: coarse) {
  button, a, .nav-tab, .sub-nav-item {
    min-height: 44px;
  }
}

/* ========== 安全区域适配 ========== */
@supports (padding: max(0px)) {
  @media (max-width: 768px) {
    .site-header {
      padding-left: max(0px, env(safe-area-inset-left));
      padding-right: max(0px, env(safe-area-inset-right));
    }
    
    .container {
      padding-left: max(12px, env(safe-area-inset-left));
      padding-right: max(12px, env(safe-area-inset-right));
    }
  }
}
