:root {
    --cell: 30px;
    --coordw: 20px;
    --coordh: 16px;
  }
  /* ---------- 深色主题（默认） ---------- */
  body {
    --bgA: #1e3a5f;      --bgB: #0f172a;
    --card: #1e293b;     --panel: #0f172a;
    --glass: rgba(30, 41, 59, .85);
    --border: rgba(148,163,184,.15);
    --border2: rgba(148,163,184,.3);
    --accent: #10b981;   --accentH: #34d399;  --accent2: #34d399;
    --btnText: #062a1e;
    --btn2: #334155;     --btn2h: #475569;
    --ok: #34d399;       --bad: #f87171;
    --text: #e2e8f0;     --muted: #94a3b8;
    --hint: #64748b;     --hint2: #94a3b8;
    --faceA: #334155;    --faceB: #1e293b;
    --cellA: #5b6b81;    --cellB: #475569;
    --cellAltA: #53627a; --cellAltB: #3f4d63;
    --open: #16202f;     --openAlt: #1a2536;
    --openShadow: rgba(0,0,0,.5);
    --pressed: #223047;
    --done: #3d4b61;
    --c1: #60a5fa; --c2: #4ade80; --c3: #f87171; --c4: #c084fc;
    --c5: #fbbf24; --c6: #2dd4bf; --c7: #f472b6; --c8: #94a3b8;
    --cellHi: rgba(255,255,255,.22);
    --cellDrop: rgba(0,0,0,.45);
    --shadowBar: 0 8px 24px rgba(0,0,0,.35);
    --shadowPanel: 0 12px 40px rgba(0,0,0,.5);
  }
  /* ---------- 浅色主题 ---------- */
  body.light {
    --bgA: #dbeafe;      --bgB: #eef2f7;
    --card: #ffffff;     --panel: #f1f5f9;
    --glass: rgba(255,255,255,.9);
    --border: rgba(71,85,105,.18);
    --border2: rgba(71,85,105,.35);
    --accent: #059669;   --accentH: #047857;  --accent2: #059669;
    --btnText: #ffffff;
    --btn2: #e2e8f0;     --btn2h: #cbd5e1;
    --ok: #059669;       --bad: #dc2626;
    --text: #1e293b;     --muted: #475569;
    --hint: #64748b;     --hint2: #475569;
    --faceA: #f8fafc;    --faceB: #dbe3ec;
    --cellA: #ccd6e3;    --cellB: #aebdd0;
    --cellAltA: #c4cfdf; --cellAltB: #a5b5c9;
    --open: #e9eef5;     --openAlt: #e1e8f1;
    --openShadow: rgba(0,0,0,.12);
    --pressed: #d3dce8;
    --done: #b6c2d2;
    --c1: #2563eb; --c2: #16a34a; --c3: #dc2626; --c4: #9333ea;
    --c5: #d97706; --c6: #0d9488; --c7: #db2777; --c8: #64748b;
    --cellHi: rgba(255,255,255,.6);
    --cellDrop: rgba(71,85,105,.28);
    --shadowBar: 0 6px 18px rgba(51,65,85,.1);
    --shadowPanel: 0 10px 28px rgba(51,65,85,.14);
  }
  * { box-sizing: border-box; margin: 0; padding: 0; }
  /* 触屏：消除双击缩放检测带来的点击延迟/吞点击（笑脸偶发没反应的元凶） */
  button, select, input, #face, #flagToggle, #helpBox summary { touch-action: manipulation; }
  body {
    font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
    background: radial-gradient(1200px 800px at 50% -10%, var(--bgA) 0%, var(--bgB) 55%) fixed;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: safe center;   /* 内容超宽时靠左起排，浏览器原生滚动条可达全部内容 */
    padding: 4px 12px;
    color: var(--text);
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }
  /* 棋盘元素：多加一层禁选中/禁长按菜单（部分手机浏览器只认前缀写法） */
  .cell, .coord, .led, #face, #flagToggle, #btnUndo {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }
  h1 {
    font-size: 19px; letter-spacing: 1px;
    margin-right: 6px;
    white-space: nowrap;
    background: linear-gradient(90deg, #34d399, #60a5fa);
    -webkit-background-clip: text; background-clip: text; color: transparent;
  }

  /* ---------- 工具栏 ---------- */
  .toolbar {
    background: var(--glass);
    backdrop-filter: blur(6px);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 16px;
    margin-bottom: 4px;
    display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center;
    max-width: 96vw;
    box-shadow: var(--shadowBar);
    font-size: 13px;
  }
  .toolbar label { color: var(--muted); font-weight: 600; }
  .toolbar select, .toolbar input {
    font-size: 13px; padding: 6px 9px;
    background: var(--panel); color: var(--text);
    border: 1px solid var(--border2);
    border-radius: 7px; outline: none;
  }
  .toolbar select:focus, .toolbar input:focus { border-color: var(--accent); }
  .toolbar input[type=number] { width: 60px; }
  #seedInput { width: 118px; font-family: Consolas, monospace; letter-spacing: 1px; }
  .toolbar button {
    font-size: 13px; padding: 7px 14px;
    background: var(--accent); color: var(--btnText);
    font-weight: 700;
    border: none; border-radius: 7px; cursor: pointer;
    transition: background .15s, transform .1s;
  }
  .toolbar button:hover { background: var(--accentH); }
  .toolbar button:active { transform: scale(.96); }
  .toolbar button.secondary { background: var(--btn2); color: var(--text); font-weight: 600; }
  .toolbar button.secondary:hover { background: var(--btn2h); }
  #customRow { display: none; gap: 6px; align-items: center; color: var(--muted); }
  #customRow.show { display: flex; }
  /* 桌面：设置区平铺在工具栏里；⚙️ 按钮隐藏 */
  .tb-more { display: contents; }
  #btnMore { display: none; }

  /* ---------- 主布局：棋盘 + 侧边栏 ---------- */
  .layout {
    display: flex; gap: 16px;
    align-items: flex-start; justify-content: center;
    flex-wrap: wrap;
  }

  .game {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px;
    box-shadow: var(--shadowPanel);
  }
  .game.sticky {
    border-color: rgba(16,185,129,.6);
    box-shadow: var(--shadowPanel), 0 0 14px rgba(16,185,129,.35);
  }
  /* 震动只加在棋盘上，不能加在 .game 上——
     transform 会劫持内部 fixed 状态栏的定位基准，导致手机上状态栏闪跳 */
  .game.shake .board-wrap { animation: shake .4s; }
  @keyframes shake {
    0%,100% { transform: translateX(0); }
    20% { transform: translateX(-7px); } 40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); } 80% { transform: translateX(3px); }
  }
  .status {
    display: flex; justify-content: space-between; align-items: center;
    background: var(--panel);
    border-radius: 10px;
    padding: 8px 12px;
    margin-bottom: 12px;
  }
  .led {
    background: #000;
    color: #ff3b3b;
    font-family: Consolas, "Courier New", monospace;
    font-weight: bold; font-size: 26px; letter-spacing: 3px;
    padding: 2px 8px; min-width: 78px; text-align: center;
    border-radius: 6px;
    border: 1px solid #333;
    text-shadow: 0 0 6px rgba(255,59,59,.6);
  }
  #face {
    width: 46px; height: 46px; font-size: 27px; line-height: 1;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(var(--faceA), var(--faceB));
    border: 1px solid var(--border2);
    border-radius: 50%; cursor: pointer;
    transition: transform .1s;
  }
  #face:hover { transform: scale(1.08); }
  #face:active { transform: scale(.92); }

  /* 即时 tooltip（原生 title 延迟太久） */
  [data-tip] { position: relative; }
  [data-tip]:hover { z-index: 30; }   /* 高于坐标标尺等棋盘元素，浮层不被遮挡 */
  [data-tip]:hover::after {
    content: attr(data-tip);
    position: absolute;
    top: calc(100% + 8px);
    left: 50%; transform: translateX(-50%);
    background: var(--panel); color: var(--text);
    border: 1px solid var(--border2);
    padding: 5px 10px; border-radius: 8px;
    font-size: 12px; font-weight: 400;
    white-space: nowrap;
    z-index: 10;
    box-shadow: 0 4px 12px rgba(0,0,0,.3);
    pointer-events: none;
  }

  /* 触屏专用：插旗模式开关（桌面隐藏） */
  #flagToggle {
    display: none;
    width: 46px; height: 46px; font-size: 22px;
    align-items: center; justify-content: center;
    background: linear-gradient(var(--faceA), var(--faceB));
    border: 1px solid var(--border2);
    border-radius: 12px;
    cursor: pointer;
  }
  #flagToggle.on {
    border-color: var(--accent);
    background: rgba(16,185,129,.25);
    box-shadow: 0 0 10px rgba(16,185,129,.4);
  }
  @media (pointer: coarse) {
    #flagToggle { display: flex; }
    .mouse-hint { display: none; }
  }
  .touch-hint { display: none; }
  @media (pointer: coarse) { .touch-hint { display: block; } }

  .board-wrap { border-radius: 8px; }
  #board { display: grid; gap: 3px; width: max-content; padding: 2px; }

  /* 坐标标尺 */
  .coord {
    display: flex; align-items: center; justify-content: center;
    font-size: 10px; color: var(--hint);
    font-family: Consolas, monospace;
  }
  .coord::after { content: attr(data-ch); }
  .coord.top    { height: var(--coordh); position: sticky; top: 0; background: var(--card); z-index: 2; }
  .coord.left   { width: var(--coordw); position: sticky; left: 0; background: var(--card); z-index: 2; }
  .coord.corner { height: var(--coordh); width: var(--coordw); position: sticky; top: 0; left: 0; background: var(--card); z-index: 3; }

  .cell {
    width: var(--cell); height: var(--cell);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: calc(var(--cell) * .55);
    border-radius: 6px;
    touch-action: manipulation;   /* 取消双击缩放延迟，保留拖动和双指缩放 */
    background: linear-gradient(var(--cellA), var(--cellB));
    box-shadow: inset 0 1px 0 var(--cellHi), 0 1px 2px var(--cellDrop);
    cursor: pointer;
    transition: filter .08s;
  }
  .cell.alt { background: linear-gradient(var(--cellAltA), var(--cellAltB)); }
  .cell:not(.revealed):hover { filter: brightness(1.2); }
  .cell:not(.revealed):active { filter: brightness(.85); }
  .cell.revealed {
    background: var(--open);
    box-shadow: inset 0 1px 4px var(--openShadow);
    border-radius: 4px;
    cursor: default;
    animation: pop .14s ease-out;
  }
  .cell.revealed.alt { background: var(--openAlt); }
  .cell.pressed, .cell.pressed:hover {
    background: var(--pressed);
    box-shadow: inset 0 2px 5px var(--openShadow);
    filter: none;
  }
  @keyframes pop { from { transform: scale(.6); opacity: .4; } to { transform: scale(1); opacity: 1; } }
  /* 格子内容（数字/雷/旗）全部用伪元素渲染：不产生 DOM 文本，
     长按复制类功能（夸克等）抓不到任何可选中的文字 */
  .cell::after { content: attr(data-ch); }
  .cell.flagged::after { animation: drop .18s ease-out; }
  @keyframes drop { from { transform: translateY(-8px) scale(1.3); } to { transform: none; } }

  /* 触屏：最后点击的格子（手指遮挡看不到点了哪里） */
  .cell.last { outline: 2px dashed #f59e0b; outline-offset: -2px; }
  .cell.hint-safe { outline: 3px solid var(--ok); outline-offset: -3px; }
  .cell.hint-mine { outline: 3px solid var(--bad); outline-offset: -3px; }
  .cell.mine-hit { background: #7f1d1d !important; box-shadow: 0 0 10px rgba(255,60,60,.8); }
  .cell.wrong-flag { position: relative; }
  .cell.wrong-flag::before {
    content: "✕"; color: var(--bad); position: absolute; font-size: 22px;
    text-shadow: 0 0 4px #000;
  }
  .c1 { color: var(--c1); } .c2 { color: var(--c2); } .c3 { color: var(--c3); }
  .c4 { color: var(--c4); } .c5 { color: var(--c5); } .c6 { color: var(--c6); }
  .c7 { color: var(--c7); } .c8 { color: var(--c8); }
  /* 已完成的数字：周围旗数匹配且无未处理格子，变暗提示无需再操作 */
  .cell.done { color: var(--done); }

  /* ---------- 侧边信息栏 ---------- */
  .side {
    width: 240px;
    background: var(--glass);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px 16px;
    display: flex; flex-direction: column; gap: 10px;
    font-size: 13px;
    color: var(--muted);
    box-shadow: var(--shadowPanel);
  }
  .side-title {
    font-weight: 700; color: var(--text); font-size: 14px;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
  }
  .kv { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
  .kv b { color: var(--accent2); font-family: Consolas, monospace; letter-spacing: 1px; text-align: right; }
  #msg { min-height: 20px; font-weight: 700; }
  #msg.win { color: var(--ok); }
  #msg.lose { color: var(--bad); }
  /* 撤回按钮：常驻状态栏（笑脸旁），踩雷时出现 */
  #btnUndo {
    display: none;
    width: 46px; height: 46px; font-size: 22px; line-height: 1;
    align-items: center; justify-content: center;
    background: #f59e0b;
    border: none; border-radius: 50%;
    cursor: pointer;
    transition: background .15s, transform .1s;
  }
  #btnUndo:hover { background: #fbbf24; }
  #btnUndo:active { transform: scale(.92); }
  #btnUndo.show { display: flex; }
  .side-hint {
    font-size: 12px; line-height: 1.8; color: var(--hint);
    border-top: 1px solid var(--border);
    padding-top: 10px;
  }
  .side-hint b { color: var(--hint2); }
  #helpBox summary {
    cursor: pointer;
    font-size: 12px; font-weight: 600;
    color: var(--hint2);
    border-top: 1px solid var(--border);
    padding-top: 10px;
    user-select: none;
  }
  #helpBox .side-hint:first-of-type { border-top: none; padding-top: 6px; }

  /* ---------- 小屏 / 触屏适配（含手机横屏） ---------- */
  @media (max-width: 640px), ((pointer: coarse) and (max-width: 1024px)) {
    body { padding: 56px 6px 8px; }   /* 顶部给状态栏留位，实际高度由 JS 动态测量覆盖 */
    h1 { font-size: 16px; }
    .toolbar {
      padding: 8px 10px; gap: 8px;
      width: 100%; font-size: 12px;
      margin-bottom: 4px;
    }
    .toolbar select, .toolbar input { padding: 8px 8px; }
    .toolbar button { padding: 10px 6px; flex: 1 1 auto; }
    #seedInput { flex: 1; width: auto; }
    /* 设置区默认收起，点 ⚙️ 展开 */
    #btnMore { display: block; }
    .tb-more { display: none; }
    .tb-more.open {
      display: flex; flex-wrap: wrap; gap: 8px;
      width: 100%; align-items: center;
      padding-top: 8px;
      border-top: 1px solid var(--border);
    }
    /* 棋盘比屏幕宽时：从左对齐保证第 1 列可达；窄棋盘靠 margin:auto 居中 */
    .layout { gap: 10px; width: 100%; justify-content: flex-start; }
    .game { padding: 8px; border-radius: 10px; margin: 0 auto; }
    /* 状态栏悬浮：位置和缩放由 JS 按视觉视口实时更新（跟随捏合缩放/平移） */
    .status {
      position: fixed; top: 0; left: 0;
      transform-origin: 0 0;
      transform: translate(6px, 4px);
      width: calc(100vw - 12px);
      margin-bottom: 0;
      padding: 4px 8px;
      z-index: 40;
      background: var(--glass);
      backdrop-filter: blur(8px);
      box-shadow: 0 4px 14px rgba(0,0,0,.3);
    }
    .led { font-size: 16px; min-width: 52px; letter-spacing: 1px; padding: 1px 5px; }
    #face { width: 38px; height: 38px; font-size: 20px; }
    #flagToggle { width: 38px; height: 38px; font-size: 17px; border-radius: 10px; }
    #btnUndo { width: 38px; height: 38px; font-size: 18px; }
    /* 手机：标尺跟随棋盘滚动（不吸附），避免压住边缘格子挡点击 */
    .coord.top, .coord.left, .coord.corner { position: static; }
    .side { width: 100%; padding: 10px 12px; }
  }
