/* 游戏来了 · 全站公共样式
 * 风格：扁平卡通手绘 —— 粗描边、实心投影、圆润字体、每个游戏一套主题色
 * 主题色由 body[data-game] 决定，组件统一使用 --theme / --theme-2 / --theme-soft
 */
:root {
  /* 线条与文字 */
  --ink: #2d2a4a;
  --text: #2d2a4a;
  --text-dim: #6e6a8f;
  --line: rgba(45, 42, 74, 0.16);

  /* 纸面 */
  --paper: #ffffff;
  --surface: #ffffff;
  --surface-2: #f3f0fa;
  --surface-3: #e6e1f3;

  /* 主题（首页默认，各游戏覆盖） */
  --theme: #ff7a45;
  --theme-2: #ffd23f;
  --theme-ink: #ffffff;
  --theme-soft: #fff1e3;
  --bg: var(--theme-soft);

  --accent: var(--theme);
  --accent-ink: var(--theme-ink);
  --good: #2fbf71;
  --bad: #ff4d5e;

  /* 卡通描边与投影 */
  --bw: 3px;
  --outline: var(--bw) solid var(--ink);
  --pop: 0 4px 0 var(--ink);
  --pop-sm: 0 3px 0 var(--ink);
  --shadow: 0 4px 0 var(--ink);
  --shadow-lg: 0 6px 0 var(--ink), 0 18px 40px rgba(45, 42, 74, 0.25);
  --radius: 18px;

  --font: "Fredoka", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --font-display: "ZCOOL KuaiLe", "Fredoka", "PingFang SC", "Microsoft YaHei", sans-serif;
  color-scheme: light;
}

/* ---------- 各游戏主题色 ---------- */
[data-game="2048"]        { --theme: #ff8a3d; --theme-2: #ffd23f; --theme-soft: #fff0e0; }
[data-game="sudoku"]      { --theme: #4b7bff; --theme-2: #8fd3ff; --theme-soft: #e7efff; }
[data-game="minesweeper"] { --theme: #27b36b; --theme-2: #b6ec5a; --theme-soft: #e2f6e6; }
[data-game="tetris"]      { --theme: #8b5cf6; --theme-2: #ff6fb5; --theme-soft: #efe8ff; }
[data-game="snake"]       { --theme: #f5b400; --theme-2: #6dd34f; --theme-soft: #fff7d6; --theme-ink: #2d2a4a; }
[data-game="klotski"]     { --theme: #f2483c; --theme-2: #ffc145; --theme-soft: #ffe7e1; }
[data-game="gomoku"]      { --theme: #13b3b0; --theme-2: #ffbf5e; --theme-soft: #def6f4; }
[data-game="memory"]      { --theme: #ff5fa2; --theme-2: #7cd3ff; --theme-soft: #ffe6f1; }

/* --bg 依赖 body 上的主题色，必须在 body 上重新计算 */
body { --bg: var(--theme-soft); --accent: var(--theme); --accent-ink: var(--theme-ink); }

/* ---------- 深色（夜间游戏厅） ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #0d0b1a;
    --text: #f4f1ff;
    --text-dim: #aaa5c8;
    --line: rgba(255, 255, 255, 0.12);
    --paper: #2c2846;
    --surface: #2c2846;
    --surface-2: #38335a;
    --surface-3: #454070;
    --good: #43d68a;
    --bad: #ff6b78;
    --shadow-lg: 0 6px 0 var(--ink), 0 18px 40px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
  :root:not([data-theme="light"]) body { --bg: color-mix(in srgb, var(--theme) 14%, #1a1730); }
}
:root[data-theme="dark"] {
  --ink: #0d0b1a;
  --text: #f4f1ff;
  --text-dim: #aaa5c8;
  --line: rgba(255, 255, 255, 0.12);
  --paper: #2c2846;
  --surface: #2c2846;
  --surface-2: #38335a;
  --surface-3: #454070;
  --good: #43d68a;
  --bad: #ff6b78;
  --shadow-lg: 0 6px 0 var(--ink), 0 18px 40px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}
:root[data-theme="dark"] body { --bg: color-mix(in srgb, var(--theme) 14%, #1a1730); }

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
[hidden] { display: none !important; }
.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background-color: var(--bg);
  /* 手绘感波点底纹 */
  background-image:
    radial-gradient(color-mix(in srgb, var(--theme) 22%, transparent) 2px, transparent 2.6px),
    radial-gradient(color-mix(in srgb, var(--theme-2) 26%, transparent) 1.6px, transparent 2.2px);
  background-size: 34px 34px, 34px 34px;
  background-position: 0 0, 17px 17px;
  color: var(--text);
  font-family: var(--font);
  font-weight: 500;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

a { color: inherit; }
button { font: inherit; color: inherit; }

/* 卡通标题字体：ZCOOL KuaiLe 只有常规体；加载失败时回退字体用粗体 */
.font-display,
.brand, .gbar-title, .overlay h2, .sheet-head h2 {
  font-family: var(--font-display);
  font-weight: 700 !important;
}

.wrap {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ---------- 品牌 ---------- */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  font-family: var(--font-display);
  font-size: 26px;
  line-height: 1;
  color: var(--text);
}
.brand-logo { width: 42px; height: 42px; flex: none; }

/* ---------- 按钮（实心卡通按钮，按下会“压扁”） ---------- */
.icon-btn,
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: var(--outline);
  background: var(--paper);
  color: var(--text);
  box-shadow: var(--pop-sm);
  cursor: pointer;
  text-decoration: none;
  font-weight: 700;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
  transition: transform .08s ease, box-shadow .08s ease, background-color .15s ease, filter .15s ease;
}
.icon-btn:active,
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.icon-btn:focus-visible,
.btn:focus-visible { outline: 3px solid var(--theme); outline-offset: 3px; }

.icon-btn {
  flex: none;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 14px;
  font-size: 19px;
  font-family: var(--font);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }

.btn {
  height: 44px;
  padding: 0 16px;
  border-radius: 14px;
  font-size: 16px;
}
.btn:hover { filter: brightness(0.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: var(--pop-sm); }
.btn svg { width: 19px; height: 19px; }
.btn.primary { background: var(--theme); color: var(--theme-ink); }
.btn.secondary { background: var(--theme-2); color: #2d2a4a; }
.btn.active { background: var(--theme-2); color: #2d2a4a; }
.btn.sm { height: 36px; padding: 0 12px; font-size: 14px; border-radius: 12px; }
.btn.block { width: 100%; }

/* 分段选择（难度等） */
.seg {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  border-radius: 14px;
  background: var(--paper);
  border: var(--outline);
  box-shadow: var(--pop-sm);
}
.seg button {
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-dim);
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease;
}
.seg button[aria-pressed="true"] {
  background: var(--theme);
  color: var(--theme-ink);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.15);
}

/* ---------- 主题 / 声音开关图标 ---------- */
.theme-toggle .sun { display: none; }
.theme-toggle .moon { display: block; }
:root[data-theme="dark"] .theme-toggle .sun { display: block; }
:root[data-theme="dark"] .theme-toggle .moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .moon { display: none; }
}
.sound-toggle .off { display: none; }
.sound-toggle.muted .on { display: none; }
.sound-toggle.muted .off { display: block; }
.sound-toggle.muted { color: var(--text-dim); }

/* ---------- 游戏页通用框架 ---------- */
.game-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 12px calc(16px + env(safe-area-inset-bottom));
}

/* 顶栏：主题色“招牌” */
.gbar {
  width: 100%;
  max-width: var(--stage-max, 520px);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 12px 0 12px;
}
.gbar > :first-child { justify-self: start; display: flex; gap: 8px; }
.gbar-title {
  margin: 0;
  padding: 4px 18px 6px;
  border: var(--outline);
  border-radius: 999px;
  background: var(--theme);
  color: var(--theme-ink);
  box-shadow: var(--pop-sm);
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: 0.04em;
  white-space: nowrap;
  transform: rotate(-2deg);
}
.gbar-actions { display: flex; gap: 8px; justify-content: flex-end; }

.gmain {
  width: 100%;
  max-width: var(--stage-max, 520px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* 数据条：分数 / 时间 / 步数 */
.stats { display: flex; align-items: center; gap: 8px; }
.stats .btns { display: flex; gap: 8px; flex: none; align-self: stretch; }
.stats .btns .btn { height: auto; min-height: 50px; }
.stat {
  position: relative;
  flex: 1;
  min-width: 0;
  padding: 5px 10px 6px;
  border-radius: 14px;
  background: var(--paper);
  border: var(--outline);
  box-shadow: var(--pop-sm);
  text-align: center;
}
.stat-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--theme);
  letter-spacing: 0.06em;
  line-height: 1.3;
}
:root[data-theme="dark"] .stat-label { color: color-mix(in srgb, var(--theme) 70%, white); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .stat-label { color: color-mix(in srgb, var(--theme) 70%, white); }
}
.stat-value {
  display: block;
  font-size: 21px;
  font-weight: 700;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 操作按钮行 */
.gcontrols {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.gcontrols .grow { flex: 1; }
.gcontrols .btns { display: flex; gap: 8px; }

/* 游戏区域 */
.stage { position: relative; width: 100%; }

/* 结果层：半透明遮罩 + 居中的卡通卡片 .overlay-card（site.js 会自动包一层） */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 12px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--bg) 45%, transparent);
  animation: fade-in 250ms ease 150ms backwards;
}
.overlay-card {
  display: grid;
  justify-items: center;
  gap: 12px;
  width: min(320px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 22px 18px 20px;
  text-align: center;
  border: var(--outline);
  border-radius: 24px;
  background: var(--paper);
  box-shadow: var(--shadow-lg);
  animation: pop-in 340ms cubic-bezier(.2, 1.4, .4, 1) 150ms backwards;
}
.overlay h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(30px, 9vw, 40px);
  line-height: 1.1;
  color: var(--theme);
  -webkit-text-stroke: 1.5px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 3px 0 var(--ink);
}
.overlay p { margin: 0; font-size: 15px; font-weight: 600; color: var(--text-dim); }
.overlay .row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { transform: scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- 弹窗（玩法 / 设置） ---------- */
dialog.sheet {
  width: min(440px, calc(100% - 24px));
  max-height: min(82vh, 660px);
  margin: auto;
  padding: 0;
  border: var(--outline);
  border-radius: 24px;
  background: var(--paper);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  overflow: auto;
}
dialog.sheet:focus { outline: none; }
dialog.sheet::backdrop { background: rgba(28, 22, 50, 0.5); }
dialog.sheet[open] { animation: sheet-in 260ms cubic-bezier(.2, 1.3, .4, 1); }
@keyframes sheet-in { from { transform: translateY(24px) scale(.94); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 12px 12px 20px;
  background: var(--theme);
  color: var(--theme-ink);
  border-bottom: var(--outline);
}
.sheet-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 24px;
  line-height: 1.2;
}
.sheet-head .icon-btn { width: 36px; height: 36px; border-radius: 12px; font-size: 16px; }
.sheet-body { padding: 16px 20px 20px; }
.tips { margin: 0; padding: 0; list-style: none; display: grid; gap: 12px; }
.tips li {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 12px;
  align-items: center;
  font-size: 15px;
  color: var(--text);
}
.tips li > b:first-child {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  border: 2.5px solid var(--ink);
  background: var(--theme-soft);
  color: #2d2a4a;
  font-size: 16px;
}
.tips strong { color: var(--theme); }
kbd {
  display: inline-block;
  min-width: 20px;
  padding: 0 5px;
  border-radius: 6px;
  border: 2px solid var(--ink);
  border-bottom-width: 3px;
  background: var(--paper);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

/* ---------- 新游戏 / 设置弹窗里的选项 ----------
 * <div class="choices">
 *   <button class="choice" aria-pressed="true"><span class="choice-icon">🙂</span><span><b>简单</b><small>9×9 · 10 个雷</small></span></button>
 * </div>
 */
.sheet-label {
  margin: 16px 0 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.06em;
}
.sheet-label:first-child { margin-top: 0; }
.choices { display: grid; gap: 10px; }
.choices.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.choices.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.choice {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 58px;
  padding: 10px 14px;
  border: var(--outline);
  border-radius: 16px;
  background: var(--paper);
  color: var(--text);
  box-shadow: var(--pop-sm);
  text-align: left;
  cursor: pointer;
  transition: transform .08s ease, box-shadow .08s ease;
}
.choice:active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.choice:focus-visible { outline: 3px solid var(--theme); outline-offset: 3px; }
.choice-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  background: var(--theme-soft);
  color: #2d2a4a;
  font-size: 19px;
}
.choice b { display: block; font-size: 17px; line-height: 1.25; }
.choice small { display: block; font-size: 13px; font-weight: 600; color: var(--text-dim); line-height: 1.3; }
.choice[aria-pressed="true"] { background: var(--theme); color: var(--theme-ink); }
.choice[aria-pressed="true"] small { color: inherit; opacity: .85; }
.choice[aria-pressed="true"] .choice-icon { background: #fff; }

/* 开关行：<label class="switch-row"><span>穿墙</span><input type="checkbox" class="switch"></label> */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border: var(--outline);
  border-radius: 16px;
  background: var(--paper);
  box-shadow: var(--pop-sm);
  font-weight: 700;
  cursor: pointer;
}
.switch-row small { display: block; font-size: 13px; font-weight: 600; color: var(--text-dim); }
.switch {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  position: relative;
  width: 54px;
  height: 32px;
  margin: 0;
  border: var(--outline);
  border-radius: 999px;
  background: var(--surface-3);
  cursor: pointer;
  transition: background-color .15s ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--ink);
  border-radius: 50%;
  background: #fff;
  transition: transform .18s cubic-bezier(.2, 1.4, .4, 1);
}
.switch:checked { background: var(--theme); }
.switch:checked::after { transform: translateX(22px); }
.switch:focus-visible { outline: 3px solid var(--theme); outline-offset: 3px; }

.sheet-foot { margin-top: 18px; display: grid; gap: 10px; }

/* 难度小标签（主界面上显示当前难度，点击打开新游戏弹窗） */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 40px;
  padding: 0 14px;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  background: var(--theme-soft);
  color: #2d2a4a;
  box-shadow: var(--pop-sm);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  transition: transform .08s ease, box-shadow .08s ease;
}
.chip:active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }

@media (max-width: 400px) {
  .stats .btns .btn { padding: 0 10px; }
  .stats .btns .btn:not(.icon-only) svg { display: none; }
}
@media (max-width: 380px) {
  .btn { padding: 0 12px; font-size: 15px; }
  .stat-value { font-size: 18px; }
  .seg button { padding: 0 9px; font-size: 13px; }
  .gbar-title { font-size: 21px; padding: 3px 14px 5px; }
}
@media (max-width: 360px) {
  .gbar .icon-btn { width: 36px; height: 36px; border-radius: 12px; }
  .gbar { gap: 6px; }
  .gbar-actions, .gbar > :first-child { gap: 6px; }
  .gbar-title { font-size: 19px; }
  .stats { gap: 6px; }
  .stat { padding: 5px 6px 6px; }
  .stat-label { letter-spacing: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-delay: 0ms !important; transition-duration: 1ms !important; }
}
