/* 共享样式：主题色、按钮、对话框、盘面网格基类。
   主题色沿用 xilin.dev 的 logo：蓝 #007cff → 紫 #802aca → 红 #ff2847 */
:root {
  --primary: #007cff;
  --accent: #ff2847;
  --violet: #802aca;

  --bg: #f4f6fa;
  --surface: #ffffff;
  --cell: #ffffff;
  --text: #10131a;
  --muted: #6a7387;
  --line: #d9deea;
  --grid: #9aa3b8;
  --shadow: 0 1px 2px rgba(16, 19, 26, .06), 0 8px 24px rgba(16, 19, 26, .06);
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1017;
    --surface: #161a24;
    --cell: #1b2130;
    --text: #eef1f7;
    --muted: #8b94a8;
    --line: #2c3344;
    --grid: #4a5468;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

/* 带 display 的类会盖掉浏览器默认的 [hidden]{display:none}，兜一层。
   sudoku 踩过这个坑：遮罩层 JS 里查 el.hidden 是 true，视觉上却还在，只有截图看得出来。 */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-text-size-adjust: 100%;
}

.view { max-width: 860px; margin: 0 auto; padding: 14px; }

/* ---- 顶栏 ---- */
.topbar {
  display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap;
}
.brand { width: 28px; height: 28px; flex: none; }
.topbar h1 { margin: 0; font-size: 18px; font-weight: 700; flex: 1; }
.home-link {
  font-size: 14px; color: var(--primary); text-decoration: none; font-weight: 600;
}
.home-link:hover { text-decoration: underline; }

/* ---- 卡片 ---- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 12px;
}
.label {
  margin: 0 0 8px; font-size: 13px; font-weight: 600;
  color: var(--muted); letter-spacing: .04em;
}
.hint { margin: 8px 0 0; font-size: 12px; color: var(--muted); }
.status { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---- 按钮 ---- */
.btn {
  font: inherit; font-weight: 600; padding: 10px 15px; min-height: 42px;
  border-radius: 11px; border: 1px solid transparent; cursor: pointer;
  transition: filter .15s, background .15s;
  color: var(--text); background: var(--bg);
}
.btn:active { filter: brightness(.93); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { color: #fff; background: linear-gradient(135deg, var(--primary) 0%, var(--violet) 130%); }
.btn-outline { color: var(--primary); background: transparent; border-color: var(--primary); }
.btn-ghost { color: var(--muted); background: transparent; border-color: var(--line); }
.btn-sm { padding: 6px 11px; font-size: 13px; min-height: 34px; }

/* ---- 控制条 ---- */
.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.controls .select { flex: 0 1 auto; }
/* 标签和它的下拉框要一起换行，否则窄屏上会拆成「标签在上一行、框在下一行」 */
.field { display: flex; align-items: center; gap: 7px; flex: none; }
.lbl { font-size: 13px; color: var(--muted); flex: none; }
.spacer { flex: 1; }

.select {
  padding: 9px 11px; font: inherit; font-size: 14px; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  outline: none; cursor: pointer;
}
.select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0, 124, 255, .16); }
.select option:disabled { color: var(--muted); }

.switch {
  display: flex; align-items: center; gap: 7px; font-size: 13px;
  color: var(--muted); flex: none; cursor: pointer;
}
.switch input { width: 17px; height: 17px; accent-color: var(--primary); }

/* ---- 计时器 ---- */
.timer {
  font-variant-numeric: tabular-nums; font-weight: 700; font-size: 17px;
  letter-spacing: .02em;
}

/* ---- 对话框（胜负弹窗、生成进度） ---- */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(3px);
  padding: 16px;
}
.dialog {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 24px; text-align: center; max-width: 340px; width: 100%;
}
.dialog h2 {
  margin: 0 0 6px; font-size: 22px;
  background: linear-gradient(135deg, var(--primary), var(--violet));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.dialog h2.lose {
  background: none; color: var(--accent);
  -webkit-text-fill-color: var(--accent);
}
.dialog p { margin: 4px 0; font-size: 14px; color: var(--muted); }
.dialog .big {
  font-size: 30px; font-weight: 700; color: var(--text);
  font-variant-numeric: tabular-nums; margin: 10px 0;
}
.dialog-actions { display: flex; gap: 8px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }

.spinner {
  width: 30px; height: 30px; margin: 10px auto;
  border: 3px solid var(--line); border-top-color: var(--primary);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 3s; }
}

/* ---- 盘面通用 ---- */
/* 注意：这里不能用 flex + justify-content:center。
   内容比容器宽时，居中会把溢出的一半推到 scrollWidth 之外，那部分永远滚不到 ——
   实测 20×20 盘面在 375px 宽的屏幕上有 24px 是够不着的。
   改成块级 + margin:auto，窄时靠左溢出、宽时仍然居中。 */
.board-wrap {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}
.board-wrap > * { margin-inline: auto; width: max-content; }
.board {
  --cell-size: 28px;
  display: grid; gap: 0;
  touch-action: none;           /* 拖拽填格时不要触发页面滚动 */
  user-select: none; -webkit-user-select: none;
  flex: none;
}

/* ---- 首页 ---- */
.games { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.game-card {
  display: block; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; transition: transform .15s, box-shadow .15s;
}
.game-card:hover { transform: translateY(-2px); }
.game-card h2 { margin: 0 0 6px; font-size: 19px; }
.game-card p { margin: 0; font-size: 13px; color: var(--muted); }
.game-card .tag {
  display: inline-block; margin-top: 10px; padding: 3px 9px;
  font-size: 11px; font-weight: 600; border-radius: 999px;
  color: var(--primary); background: color-mix(in srgb, var(--primary) 12%, transparent);
}
.game-card .tag.extern { color: var(--muted); background: color-mix(in srgb, var(--muted) 12%, transparent); }
.game-icon { width: 40px; height: 40px; margin-bottom: 10px; display: block; }
