:root {
  --bg1: #0f172a;
  --accent: #6366f1;
  --accent2: #8b5cf6;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --card-bg: rgba(30,41,59,0.88);
  --cell: 32px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 800px at 20% -10%, rgba(99,102,241,0.25), transparent 60%),
    radial-gradient(1000px 700px at 110% 20%, rgba(139,92,246,0.22), transparent 55%),
    linear-gradient(160deg, var(--bg1), #0b1120);
  background-attachment: fixed;
}

#app { min-height: 100vh; }

/* 屏幕切换 */
.screen { display: none; padding: 24px; min-height: 100vh; }
.screen.active { display: flex; flex-direction: column; align-items: center; justify-content: center; }
#screen-game.active { justify-content: flex-start; padding-top: 20px; }

/* 主菜单 */
.menu-card { text-align: center; animation: fadeUp .5s ease; }
.game-title {
  font-size: 72px; margin: 0 0 4px; letter-spacing: 4px;
  background: linear-gradient(90deg, #fbbf24, #f97316, #ef4444);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 10px 30px rgba(251,146,60,.35));
}
.game-subtitle { color: var(--muted); margin: 0 0 36px; font-size: 18px; }

/* 按钮 */
.btn {
  cursor: pointer; border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.06); color: var(--text);
  padding: 11px 22px; font-size: 15px; border-radius: 12px;
  transition: all .18s ease; backdrop-filter: blur(6px);
}
.btn:hover { background: rgba(255,255,255,.14); transform: translateY(-2px); }
.btn:active { transform: translateY(0); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none; box-shadow: 0 8px 24px rgba(99,102,241,.4);
}
.btn-primary:hover { box-shadow: 0 10px 30px rgba(99,102,241,.55); background: linear-gradient(135deg, #7c7ff2, #9d6ff5); }
.btn-lg { padding: 14px 40px; font-size: 18px; margin: 8px; min-width: 220px; }
.btn-ghost { background: transparent; border-color: rgba(255,255,255,.2); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; min-width: 160px; }

/* 面板 */
.panel {
  background: var(--card-bg); border: 1px solid rgba(255,255,255,.1);
  border-radius: 20px; padding: 32px 36px; max-width: 640px; width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,.45); animation: fadeUp .4s ease;
}
.panel h2 { margin: 0 0 24px; font-size: 28px; }
.panel-wide { max-width: 780px; }

/* 难度 */
.diff-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-bottom: 18px; }
.diff-btn {
  cursor: pointer; border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.05); color: var(--text);
  border-radius: 16px; padding: 20px 12px; transition: all .18s ease;
  display: flex; flex-direction: column; gap: 6px;
}
.diff-btn span { font-size: 20px; font-weight: 600; }
.diff-btn small { color: var(--muted); }
.diff-btn:hover { background: rgba(99,102,241,.22); border-color: var(--accent); transform: translateY(-2px); }
.custom-panel { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.custom-panel[hidden] { display: none; }
.custom-panel label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.custom-panel input {
  width: 80px; padding: 8px; border-radius: 10px; border: 1px solid rgba(255,255,255,.15);
  background: rgba(255,255,255,.06); color: var(--text);
}

/* 游戏 */
.game-top { display: flex; align-items: center; gap: 24px; margin-bottom: 14px; }
.stat {
  background: rgba(0,0,0,.35); border: 1px solid rgba(255,255,255,.1);
  padding: 6px 16px; border-radius: 10px; font-size: 20px; font-weight: 700;
  min-width: 90px; text-align: center;
}
.stat-label { margin-right: 6px; }
.face { font-size: 30px; background: none; border: none; cursor: pointer; transition: transform .15s; }
.face:hover { transform: scale(1.15); }

#board-wrap { overflow: auto; max-width: 96vw; padding: 8px; border-radius: 14px; background: rgba(0,0,0,.25); }
#board {
  position: relative;
  display: grid; gap: 0; margin: 0 auto;
  border-radius: 8px; overflow: hidden;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
#board::before {
  content: ''; position: absolute; inset: 0; z-index: 0;
  background-image: var(--board-bg, none);
  background-size: cover; background-position: center;
  opacity: var(--reveal-opacity, 0.25);
  pointer-events: none;
}
.cell {
  position: relative; z-index: 1;
  width: var(--cell); height: var(--cell);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: calc(var(--cell) * 0.52);
  user-select: none; cursor: pointer;
  touch-action: manipulation; -webkit-touch-callout: none;
  border: 1px solid rgba(255,255,255,.08);
  background: linear-gradient(145deg, #3b4a63, #2a3548);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.14), inset 0 -1px 0 rgba(0,0,0,.25);
}
.cell:hover { filter: brightness(1.12); }
.cell.revealed {
  background: transparent; cursor: default;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.10);
  text-shadow: 0 1px 2px rgba(0,0,0,.65), 0 0 6px rgba(255,255,255,.55);
}
.cell.revealed:hover { filter: none; }
.cell.blur { background: rgba(255,255,255,.28); backdrop-filter: blur(var(--cell-blur, 7px)); -webkit-backdrop-filter: blur(var(--cell-blur, 7px)); }
.cell.mine { background: rgba(239,68,68,.55); }
.cell.mine-clicked { background: rgba(239,68,68,.85); }
.cell.n1 { color: #60a5fa; }
.cell.n2 { color: #34d399; }
.cell.n3 { color: #f87171; }
.cell.n4 { color: #c084fc; }
.cell.n5 { color: #fb923c; }
.cell.n6 { color: #22d3ee; }
.cell.n7 { color: #f9fafb; }
.cell.n8 { color: #9ca3af; }

.game-bottom { display: flex; justify-content: space-between; align-items: center; width: 100%; max-width: 760px; margin-top: 14px; color: var(--muted); }

/* 设置 */
.set-section { margin-bottom: 24px; padding-bottom: 20px; border-bottom: 1px solid rgba(255,255,255,.08); }
.set-section h3 { margin: 0 0 8px; font-size: 18px; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.6; margin: 0 0 12px; }
.hint code { background: rgba(255,255,255,.1); padding: 1px 6px; border-radius: 6px; }
.group-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.group-item {
  display: flex; align-items: center; gap: 14px; padding: 12px;
  background: rgba(0,0,0,.22); border: 1px solid rgba(255,255,255,.1); border-radius: 14px;
}
.group-item.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.group-item.disabled { opacity: .45; }
.group-check { display: flex; align-items: center; flex-shrink: 0; }
.group-check input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.group-thumbs { display: flex; gap: 8px; }
.group-thumbs img { width: 64px; height: 40px; object-fit: cover; border-radius: 8px; border: 1px solid rgba(255,255,255,.2); }
.group-info { flex: 1; }
.group-info .gname { font-weight: 600; }
.group-info small { color: var(--muted); display: block; }
.group-actions { display: flex; gap: 8px; }
.mini-btn { padding: 7px 12px; font-size: 13px; border-radius: 9px; cursor: pointer; border: 1px solid rgba(255,255,255,.15); background: rgba(255,255,255,.08); color: var(--text); }
.mini-btn:hover { background: rgba(255,255,255,.18); }
.mini-btn.danger:hover { background: rgba(239,68,68,.3); }
.upload-form { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.field input[type=text] { padding: 9px; border-radius: 10px; border: 1px solid rgba(255,255,255,.15); background: rgba(255,255,255,.06); color: var(--text); }
.field input[type=file] { color: var(--muted); font-size: 12px; }
.radio-row { display: flex; gap: 20px; flex-wrap: wrap; }
.radio-row label { display: flex; gap: 6px; align-items: center; cursor: pointer; }
.opacity-row { display: flex; align-items: center; gap: 12px; }
.opacity-row input[type=range] { flex: 1; max-width: 320px; accent-color: var(--accent); }
.opacity-val { min-width: 48px; text-align: right; font-weight: 700; }
.storage-status { color: var(--muted); font-size: 13px; margin-top: 10px; min-height: 18px; }
.storage-status.ok { color: #34d399; }

/* 胜利浮层 */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(5,8,20,.88);
  animation: fadeIn .3s ease;
}
.overlay[hidden] { display: none; }
.win-inner { text-align: center; padding: 20px; }
.card-wrap { position: relative; display: inline-block; transform-origin: 0 0; }
.float-card {
  position: relative; margin: 0 auto; width: min(78vw, 460px);
  aspect-ratio: 8/5; border-radius: 18px; overflow: hidden;
  box-shadow: 0 30px 80px rgba(0,0,0,.65);
  animation: cardFloat .9s cubic-bezier(.22,1.4,.36,1) both;
  border: 4px solid rgba(255,255,255,.25);
  touch-action: none;
  user-select: none;
}
.float-card.panning canvas { cursor: grabbing; }
.float-card img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.float-card canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.win-hint { margin: 20px 0 16px; font-size: 18px; font-weight: 600; }
.win-actions { display: flex; gap: 12px; justify-content: center; }

/* 动画 */
@keyframes fadeUp { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes cardFloat {
  0% { opacity: 0; transform: translateY(140px) scale(.55) rotate(-8deg); }
  60% { opacity: 1; transform: translateY(-14px) scale(1.04) rotate(2deg); }
  100% { opacity: 1; transform: translateY(0) scale(1) rotate(0deg); }
}

@media (max-width: 560px) {
  .game-title { font-size: 52px; }
  .panel { padding: 24px 18px; }
}
