/* ============================================================
   apps/iterate.html 样式（P0-4-T17 <style> 块外联）
   - 页面 style="..." 与 on* 仍在本页（P0-4-T18 整改）
   ============================================================ */

/* Design Token：项目级 Glassmorphism 规范（与 topbar.8d4aa38f.css 一致） */
:root {
  --glass-bg-light:           rgba(255, 255, 255, 0.55);
  --glass-border-light:        rgba(15, 23, 42, 0.06);
  --glass-highlight-light:     rgba(255, 255, 255, 0.6);
  --glass-shadow-light:        rgba(15, 23, 42, 0.06);
  --glass-bg-dark:             rgba(10, 14, 39, 0.72);
  --glass-border-dark:         rgba(255, 255, 255, 0.06);
  --glass-highlight-dark:      rgba(255, 255, 255, 0.08);
  --glass-shadow-dark:         rgba(0, 0, 0, 0.32);
  --glass-blur:                blur(20px) saturate(180%);
}

  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
  html, body { height: 100%; }
  body {
    background:
      radial-gradient(ellipse 80% 60% at 50% 0%, rgba(99,102,241,0.06) 0%, transparent 60%),
      var(--bg-page);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    font-weight: 400;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    display: flex; flex-direction: column; min-height: 100vh;
  }
  a { color: inherit; text-decoration: none; }
  button { font: inherit; cursor: pointer; }

  :root {
    --bg-page:    #fafbfc;
    --bg-card:    #ffffff;
    --bg-soft:    #eff6ff;
    --bg-muted:   #f3f4f6;
    --text-primary:   #0f172a;
    --text-secondary: #475569;
    --text-muted:     #64748b;
    --text-hint:      #94a3b8;
    --border:        #dbeafe;
    --border-soft:   #e5e7eb;
    --border-input:  #cbd5e1;
    --accent:        #3b82f6;
    --accent-hover:  #2563eb;
    --success: #10b981;
    --danger:  #dc2626;
    --warning: #f59e0b;
  }

  /* 原顶栏「返回游戏」入口下移（顶栏已换共享组件） */
  .back-btn {
    display: inline-block; margin-bottom: 14px;
    padding: 6px 14px; border-radius: 999px; font-size: 13px;
    border: 1px solid var(--border-input); background: #fff; color: var(--text-primary);
  }
  .back-btn:hover { background: var(--bg-soft); }

  main { flex: 1; padding: 28px 24px 64px; }
  .container { max-width: 880px; margin: 0 auto; }

  /* 标题 + 玩法 */
  .head { text-align: center; margin-bottom: 28px; }
  .head h1 { font-size: 28px; font-weight: 600; color: var(--text-primary); margin-bottom: 6px; letter-spacing: 0.04em; }
  .head .sub { color: var(--text-muted); font-size: 14px; line-height: 1.6; max-width: 640px; margin: 0 auto; }

  /* 难度选择 */
  .diff-row { display: flex; gap: 8px; justify-content: center; margin: 18px 0 24px; flex-wrap: wrap; }
  .diff-btn {
    padding: 10px 22px; border-radius: 999px; font-size: 14px;
    border: 1px solid var(--border-input); background: #fff; color: var(--text-secondary);
    transition: all 0.15s;
  }
  .diff-btn:hover { border-color: var(--accent); color: var(--accent); }
  .diff-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

  /* 状态栏 */
  .status-bar {
    display: flex; gap: 0; justify-content: center; flex-wrap: wrap;
    background: var(--bg-card); border: 1px solid var(--border-soft); border-radius: 12px;
    padding: 4px; margin-bottom: 16px;
  }
  .stat { flex: 1; min-width: 120px; padding: 12px 18px; text-align: center; border-right: 1px solid var(--border-soft); }
  .stat:last-child { border-right: 0; }
  .stat-label { font-size: 12px; color: var(--text-muted); letter-spacing: 0.06em; }
  .stat-value { font-size: 18px; font-weight: 600; color: var(--text-primary); margin-top: 4px; font-variant-numeric: tabular-nums; }
  .stat-value.warn { color: var(--danger); }

  /* 棋盘 */
  .board-wrap {
    background: var(--bg-card); border: 1px solid var(--border-soft); border-radius: 14px;
    padding: 24px; display: flex; align-items: center; justify-content: center;
  }
  .board {
    display: grid; gap: 6px;
    --cell: 64px;
    --gap: 6px;
  }
  .board[data-size="4"] { --cell: 64px; }
  .board[data-size="5"] { --cell: 56px; }
  .board[data-size="6"] { --cell: 50px; }
  @media (max-width: 540px) {
    .board[data-size="4"] { --cell: 50px; }
    .board[data-size="5"] { --cell: 42px; }
    .board[data-size="6"] { --cell: 36px; }
  }
  .cell {
    width: var(--cell); height: var(--cell);
    background: #f3f4f6; border: 1px solid #e5e7eb; border-radius: 8px;
    cursor: pointer; transition: background 0.18s, transform 0.12s, border-color 0.18s;
    display: flex; align-items: center; justify-content: center;
    user-select: none; -webkit-tap-highlight-color: transparent;
  }
  .cell.black { background: #1f2937; border-color: #0f172a; }
  .cell:active { transform: scale(0.94); }
  .cell.tip-hint {
    animation: tip-blink 1.2s ease-in-out 3;
    box-shadow: 0 0 0 3px #fbbf24, 0 0 12px rgba(251,191,36,0.4);
    z-index: 2;
  }
  @keyframes tip-blink {
    0%, 100% { box-shadow: 0 0 0 3px #fbbf24, 0 0 12px rgba(251,191,36,0.4); }
    50%      { box-shadow: 0 0 0 6px #f59e0b, 0 0 24px rgba(245,158,11,0.7); }
  }
  .cell.flipping { transition: background 0.18s, transform 0.12s, border-color 0.18s; }

  /* 操作按钮组 */
  .ops-row {
    display: flex; gap: 10px; justify-content: center; margin-top: 18px; flex-wrap: wrap;
  }
  .btn {
    padding: 10px 20px; border-radius: 999px; font-size: 14px;
    border: 1px solid var(--border-input); background: #fff; color: var(--text-primary);
    transition: all 0.15s;
  }
  .btn:hover { background: var(--bg-soft); }
  .btn:disabled { opacity: 0.5; cursor: not-allowed; }
  .btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
  .btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
  .btn-warn { background: #fff; color: var(--warning); border-color: #fcd34d; }
  .btn-warn:hover { background: #fffbeb; }
  .btn-warn:disabled { color: var(--text-hint); border-color: var(--border-soft); background: #fff; }
  .btn-ghost { background: transparent; color: var(--text-muted); }

  /* 弹窗 */
  .modal-bg {
    position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5);
    display: none; align-items: center; justify-content: center; z-index: 100;
  }
  .modal-bg.active { display: flex; }
  .modal {
    background: #fff; border-radius: 16px; padding: 28px;
    width: 90%; max-width: 440px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.18);
  }
  .modal-title { font-size: 20px; font-weight: 600; margin-bottom: 14px; }
  .modal-text { font-size: 14px; color: var(--text-secondary); line-height: 1.7; margin-bottom: 20px; }
  .modal-text b { color: var(--text-primary); }
  .modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
  .stat-row {
    display: flex; gap: 18px; padding: 12px 0; border-top: 1px solid var(--border-soft);
    border-bottom: 1px solid var(--border-soft); margin: 14px 0 20px;
  }
  .stat-row .stat-mini { display: flex; flex-direction: column; }
  .stat-row .stat-mini .l { font-size: 11px; color: var(--text-muted); }
  .stat-row .stat-mini .v { font-size: 16px; font-weight: 600; color: var(--text-primary); font-variant-numeric: tabular-nums; }

  /* 提示 */
  .toast {
    position: fixed; top: 24px; left: 50%; transform: translateX(-50%);
    background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 8px;
    font-size: 14px; z-index: 200; opacity: 0; transition: opacity 0.2s;
  }
  .toast.show { opacity: 1; }
  .toast.error { background: var(--danger); }
  .toast.success { background: var(--success); }

  @media (max-width: 540px) {
    main { padding: 18px 12px 40px; }
    .board-wrap { padding: 14px; }
    .board { --gap: 4px; gap: 4px; }
    .stat { min-width: 80px; padding: 8px 6px; }
    .stat-value { font-size: 15px; }
  }
