/* ============================================================
   puzzle.sendafun.com — Lights Out
   THEME TOKENS：做第 2 个游戏时只改这个 :root 色板即可换皮肤
   ============================================================ */
:root {
  /* 房间底色（深夜开灯的感觉） */
  --bg: #0d1420;
  --bg-glow: #1a2436;
  --surface: #182136;
  --surface-2: #22304a;
  --border: #2c3b56;

  /* 文字 */
  --text: #e9eef7;
  --text-dim: #8ea2bd;

  /* 灯：亮=琥珀，灭=暗蓝灰 */
  --lit: #ffb84d;
  --lit-soft: #ffd98a;
  --lit-strong: #ff942e;
  --lit-glow: rgba(255, 184, 77, .45);
  --off: #26324a;
  --off-border: #35465f;

  /* 强调（提示/聚焦） */
  --accent: #4dc9f6;

  --radius: 14px;
  --font: "Segoe UI", system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}

/* ============ 基础 ============ */
* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1100px 520px at 50% -8%, var(--bg-glow) 0%, transparent 60%),
    var(--bg);
  background-attachment: fixed;
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main {
  width: min(640px, 100% - 32px);
  margin: 0 auto;
  flex: 1;
}

a { color: var(--accent); }

button { font: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: 8px;
  top: -48px;
  background: var(--surface-2);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  z-index: 10;
  transition: top .15s;
}
.skip-link:focus { top: 8px; }

/* ============ 页头 ============ */
.site-head {
  text-align: center;
  padding: 28px 16px 8px;
}
.site-head__brand {
  margin: 0 0 6px;
  font-size: 13px;
  letter-spacing: .04em;
  color: var(--text-dim);
}
.site-head__title {
  margin: 0;
  font-size: clamp(34px, 7vw, 52px);
  font-weight: 700;
  letter-spacing: -.01em;
}
.site-head__tagline {
  margin: 8px 0 0;
  color: var(--text-dim);
  font-size: 15px;
  max-width: 34em;
  margin-inline: auto;
}

/* ============ 广告位（部署时替换 .ad-slot__code 内容） ============ */
.ad-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 6px;
  margin: 18px 0;
  border: 1px dashed var(--border);
  border-radius: 12px;
  color: var(--text-dim);
  background: rgba(255, 255, 255, .02);
  font-size: 13px;
}
.ad-slot--top { min-height: 90px; }
.ad-slot--bottom { min-height: 240px; }
.ad-slot__code { width: 100%; }

/* ============ 游戏区 ============ */
.game {
  background: linear-gradient(180deg, rgba(255,255,255,.03), rgba(255,255,255,0));
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px 18px 14px;
  margin: 16px 0;
  box-shadow: 0 18px 40px rgba(0,0,0,.35);
}

/* 状态栏 */
.stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 18px;
  padding: 0 2px 14px;
}
.stats__label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
}
.stats__num output {
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.stats__group { display: flex; flex-direction: column; gap: 4px; }

.seg {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}
.seg__btn {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  padding: 8px 14px;
  min-height: 44px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.seg__btn:hover { color: var(--text); }
.seg__btn.is-active {
  background: var(--lit);
  color: #3a2500;
  font-weight: 600;
}

/* 棋盘 */
.board-wrap { display: flex; justify-content: center; }
.board {
  --n: 5;
  display: grid;
  grid-template-columns: repeat(var(--n), minmax(0, 1fr));
  gap: clamp(6px, 1.6vw, 10px);
  width: min(460px, 100%);
  padding: clamp(10px, 2.4vw, 16px);
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: inset 0 2px 12px rgba(0,0,0,.35);
}

.cell {
  appearance: none;
  border: 1px solid var(--off-border);
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  background: var(--off);
  box-shadow: inset 0 2px 6px rgba(0,0,0,.4);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background .1s, box-shadow .1s, transform .1s;
}
.cell:hover { filter: brightness(1.15); }
.cell:active { transform: scale(.96); }

.cell.is-on {
  border-color: var(--lit-strong);
  background: radial-gradient(circle at 32% 28%, var(--lit-soft) 0%, var(--lit) 55%, var(--lit-strong) 100%);
  box-shadow:
    0 0 16px var(--lit-glow),
    inset 0 0 10px rgba(255, 255, 255, .28);
}

.cell.is-hint {
  box-shadow:
    0 0 0 3px var(--accent),
    0 0 22px rgba(77, 201, 246, .65);
  animation: hint-pulse 1.3s ease-out 2;
}
@keyframes hint-pulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--accent), 0 0 22px rgba(77,201,246,.65); }
  50% { box-shadow: 0 0 0 3px var(--accent), 0 0 6px rgba(77,201,246,.35); }
}

/* 胜利时整盘呼吸一下 */
.board.is-won .cell { animation: win-glow .9s ease-out both; }
@keyframes win-glow {
  0% { filter: brightness(2); transform: scale(1.03); }
  100% { filter: brightness(1); transform: scale(1); }
}

/* 按钮组 */
.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
}
.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 18px;
  min-height: 44px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .12s, transform .1s;
  touch-action: manipulation;
}
.btn:hover { background: #2a3a58; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn--primary {
  background: var(--lit);
  border-color: var(--lit-strong);
  color: #3a2500;
  font-weight: 600;
}
.btn--primary:hover { background: var(--lit-soft); }
.btn--icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 12px;
}
.ico { width: 20px; height: 20px; fill: currentColor; }
.ico--off { display: none; }
.btn.is-muted .ico--on { display: none; }
.btn.is-muted .ico--off { display: block; }

.game-msg {
  min-height: 20px;
  margin: 10px 0 0;
  text-align: center;
  font-size: 14px;
  color: var(--text-dim);
}

/* ============ 玩法说明 ============ */
.howto {
  background: rgba(255, 255, 255, .03);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px 20px;
  margin: 8px 0 16px;
}
.howto h2 { margin: 0 0 8px; font-size: 19px; }
.howto p { margin: 0 0 8px; color: var(--text-dim); }
.howto p:last-child { margin-bottom: 0; }
.howto strong { color: var(--text); }

/* ============ 页脚 ============ */
.site-foot {
  width: min(640px, 100% - 32px);
  margin: 8px auto 0;
  padding: 20px 0 26px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  justify-content: center;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}
.site-foot p { margin: 0; }

/* ============ 胜利面板 ============ */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 10, 18, .78);
  padding: 16px;
  z-index: 20;
}
.overlay[hidden] { display: none; }

.overlay__card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 26px 28px 22px;
  width: min(360px, 100%);
  text-align: center;
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
  animation: card-in .25s ease-out;
}
@keyframes card-in {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to { opacity: 1; transform: none; }
}
.overlay__card h2 { margin: 0 0 14px; font-size: 24px; color: var(--lit); }

.win-stats {
  list-style: none;
  margin: 0 0 10px;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.win-stats li {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 6px;
}
.win-stats span {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
}
.win-stats output {
  display: block;
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.win-note { margin: 0 0 16px; font-size: 14px; color: var(--text-dim); }
.win-note.is-record { color: var(--lit); font-weight: 600; }
.win-actions { display: flex; gap: 10px; justify-content: center; }

.noscript {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 20px;
  text-align: center;
  z-index: 50;
}

/* ============ 响应式 ============ */
@media (max-width: 480px) {
  .game { padding: 14px 12px 12px; }
  .controls { gap: 8px; }
  .btn { padding: 10px 14px; font-size: 15px; }
  .stats { gap: 10px 14px; }
  .win-stats { grid-template-columns: repeat(3, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
