:root {
  --gs-primary: #6366f1;
  --gs-primary-glow: rgba(99, 102, 241, 0.4);
  --gs-accent: #22d3ee;
  --gs-bg: #070b14;
  --gs-surface: rgba(255, 255, 255, 0.04);
  --gs-border: rgba(148, 163, 184, 0.12);
  --gs-text: #f1f5f9;
  --gs-muted: #64748b;
  --gs-radius: 12px;
  --gs-font: "SF Pro Display", "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

body.game-body {
  margin: 0;
  font-family: var(--gs-font);
  color: var(--gs-text);
  background: var(--gs-bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.game-app {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 12px;
}

.game-snake { --gs-primary: #10b981; --gs-primary-glow: rgba(16, 185, 129, 0.35); }
.game-tetris { --gs-primary: #3b82f6; --gs-primary-glow: rgba(59, 130, 246, 0.35); }
.game-puzzle { --gs-primary: #a855f7; --gs-primary-glow: rgba(168, 85, 247, 0.35); }
.game-sokoban { --gs-primary: #f59e0b; --gs-primary-glow: rgba(245, 158, 11, 0.35); }

.game-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.game-stat {
  flex: 1;
  min-width: 64px;
  padding: 8px 10px;
  background: var(--gs-surface);
  border: 1px solid var(--gs-border);
  border-radius: var(--gs-radius);
}

.game-stat-label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--gs-muted);
  margin-bottom: 2px;
}

.game-stat-value {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff;
}

/* 玛丽外壳统计栏像素风示例图标 */
.game-stat-icon {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  image-rendering: pixelated;
  border-radius: 1px;
}
.game-stat-icon--coin {
  background: radial-gradient(circle at 40% 35%, #ffe566 0%, #f8b800 55%, #c07800 100%);
  border: 1px solid #a06000;
  border-radius: 50%;
}
.game-stat-icon--mario {
  background:
    linear-gradient(#e52521 0 0) 3px 0 / 10px 5px no-repeat,
    linear-gradient(#f8a060 0 0) 5px 1px / 6px 3px no-repeat,
    linear-gradient(#2040a0 0 0) 3px 5px / 10px 8px no-repeat;
  background-color: transparent;
}
.game-stat-icon--score {
  background:
    linear-gradient(#c84c0c 0 0) 2px 6px / 12px 8px no-repeat,
    linear-gradient(#f8b800 0 0) 5px 2px / 6px 6px no-repeat;
}
.game-stat-icon--trophy {
  background:
    linear-gradient(#f8b800 0 0) 4px 1px / 8px 5px no-repeat,
    linear-gradient(#c07800 0 0) 6px 6px / 4px 9px no-repeat,
    linear-gradient(#c07800 0 0) 3px 14px / 10px 2px no-repeat;
}

.game-stage {
  margin-bottom: 12px;
  padding: 8px;
  background: var(--gs-surface);
  border: 1px solid var(--gs-border);
  border-radius: var(--gs-radius);
}

.game-canvas-wrap {
  width: 100%;
  margin: 0 auto;
  line-height: 0;
}

.game-canvas-wrap--square { max-width: 400px; aspect-ratio: 1 / 1; }
.game-canvas-wrap--tetris { max-width: 240px; aspect-ratio: 1 / 2; }

.game-canvas-wrap--tetris canvas,
.game-tetris #p2d-canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 240 / 480;
}
.game-canvas-wrap--sokoban { max-width: 100%; }

.game-canvas-wrap--minesweeper {
  max-width: 100%;
  display: inline-block;
}
.game-minesweeper #p2d-canvas,
.game-canvas-wrap--minesweeper canvas {
  image-rendering: pixelated;
}

/* 玛丽：窗口模式画布自适应面板 */
.game-body.game-mario .game-app:not(.game-fs-active) {
  max-width: min(100vw - 24px, 536px);
}
.game-body.game-mario .game-app:not(.game-fs-active) .game-canvas-wrap {
  max-width: 100%;
  overflow: hidden;
}
.game-body.game-mario .game-app:not(.game-fs-active) #p2d-canvas {
  display: block;
  margin: 0 auto;
  width: 100%;
  max-width: 512px;
  height: auto;
  aspect-ratio: 256 / 240;
}

.game-stage canvas {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

.game-stage .game-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
}

.game-footer {
  text-align: center;
}

.game-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 10px;
}

.game-btn {
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: var(--gs-radius);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
}

.game-btn:active:not(:disabled) { transform: scale(0.97); }

.game-btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--gs-primary), #4338ca);
  box-shadow: 0 4px 14px var(--gs-primary-glow);
}

.game-btn-primary:hover:not(:disabled) {
  filter: brightness(1.08);
}

.game-btn-ghost {
  color: var(--gs-text);
  background: var(--gs-surface);
  border: 1px solid var(--gs-border);
}

.game-btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.08);
}

.game-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}

.game-hint {
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--gs-muted);
  line-height: 1.7;
}

.game-hint kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: 0 5px;
  margin: 0 2px;
  font-size: 11px;
  font-family: inherit;
  color: var(--gs-text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--gs-border);
  border-radius: 4px;
}

.game-status {
  margin: 0;
  font-size: 13px;
  min-height: 18px;
  color: var(--gs-muted);
}

.game-status.ok { color: #34d399; }
.game-status.err { color: #f87171; }

/* ── 全屏 Player ── */
.game-fullscreen-btn--float {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 20;
  padding: 6px 12px;
  font-size: 12px;
  opacity: 0.92;
}

.game-app.game-fs-active,
.game-stage.game-fs-active,
.gc-play-stage.game-fs-active {
  position: fixed;
  inset: 0;
  z-index: 99990;
  width: 100vw !important;
  max-width: none !important;
  height: 100vh !important;
  margin: 0 !important;
  padding: 8px !important;
  border-radius: 0 !important;
  border: none !important;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--gs-bg, #070b14);
}

.game-app.game-fs-active .game-hint,
.game-app.game-fs-active .game-status {
  display: none;
}

.game-app.game-fs-active .game-stats {
  flex-shrink: 0;
  margin-bottom: 6px;
}

.game-app.game-fs-active .game-footer {
  flex-shrink: 0;
  margin-top: auto;
  padding-top: 4px;
}

.game-app.game-fs-active .game-stage,
.game-stage.game-fs-active {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0;
  padding: 4px;
}

.game-app.game-fs-active .game-canvas-wrap,
.game-stage.game-fs-active .game-canvas-wrap {
  width: 100%;
  height: 100%;
  max-width: none !important;
  max-height: none !important;
  aspect-ratio: unset !important;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 全屏 canvas 显示尺寸由 game-fullscreen.js 按容器等比计算，内部分辨率与 CSS 1:1 */
.game-app.game-fs-active .game-canvas-wrap canvas,
.game-app.game-fs-active .game-stage canvas,
.game-stage.game-fs-active canvas {
  display: block;
  flex-shrink: 0;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  image-rendering: auto;
  border-radius: 8px;
}

/* 玛丽全屏：勿用窗口 aspect-ratio 拉满宽度，否则高度超出视口被裁切 */
.game-body.game-mario .game-app.game-fs-active #p2d-canvas {
  width: auto;
  height: auto;
  max-width: none;
  aspect-ratio: unset;
}

.game-mario #p2d-canvas,
.game-mario .game-canvas-wrap canvas {
  image-rendering: auto;
}

.gc-play-stage.game-fs-active .gc-iframe {
  max-width: none;
  max-height: none;
}

.gc-play-stage.game-fs-active {
  padding: 0 !important;
  display: block;
}

.gc-play-stage.game-fs-active .gc-iframe {
  width: 100% !important;
  height: 100% !important;
  min-height: 100% !important;
}

.gc-play-stage .gc-fullscreen-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 30;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--gc-font, inherit);
  color: #f8fafc;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 8px;
  cursor: pointer;
  backdrop-filter: blur(8px);
}

.gc-play-stage .gc-fullscreen-btn:hover {
  background: rgba(30, 41, 59, 0.95);
}

body.game-body-fs {
  overflow: hidden;
}

:fullscreen .game-app,
:fullscreen .game-stage,
:fullscreen.gc-play-stage {
  width: 100vw;
  height: 100vh;
  max-width: none;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  width: 100%;
  padding: 8px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: var(--gs-radius);
}

.game-tile {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(16px, 4.5vw, 22px);
  font-weight: 700;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  user-select: none;
  border: none;
  font-family: inherit;
  transition: transform 0.1s ease;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 2px 6px rgba(0, 0, 0, 0.2);
}

.game-tile:hover:not(.empty) { transform: scale(1.03); }

.game-tile.empty {
  background: transparent !important;
  box-shadow: none;
  cursor: default;
}

.game-tile.correct {
  box-shadow: inset 0 0 0 2px rgba(52, 211, 153, 0.55);
}

.game-tile.n2  { background: linear-gradient(145deg, #3b4a6b, #2d3a54); }
.game-tile.n4  { background: linear-gradient(145deg, #4a5a8a, #3a4870); }
.game-tile.n8  { background: linear-gradient(145deg, #6b5b95, #554878); }
.game-tile.n16 { background: linear-gradient(145deg, #8b5cf6, #7c3aed); }
.game-tile.n32 { background: linear-gradient(145deg, #a855f7, #9333ea); }
.game-tile.n64 { background: linear-gradient(145deg, #d946ef, #c026d3); }
.game-tile.n128,
.game-tile.n256,
.game-tile.n512 { background: linear-gradient(145deg, #ec4899, #db2777); font-size: clamp(13px, 3.5vw, 18px); }

/* ── Phoenix2D 测试入口（test.html） ── */
.game-test-mode .game-app {
  padding-top: 4px;
}

.p2d-test-banner {
  max-width: 480px;
  margin: 8px auto 0;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid rgba(251, 191, 36, 0.35);
  background: rgba(251, 191, 36, 0.1);
  color: #fde68a;
  font-size: 11px;
  line-height: 1.45;
  text-align: center;
}

.p2d-test-panel {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 9999;
  max-width: min(280px, calc(100vw - 24px));
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(251, 191, 36, 0.35);
  background: rgba(15, 23, 42, 0.92);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(8px);
}

.p2d-test-panel-title {
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #fbbf24;
}

.p2d-test-panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.p2d-test-btn {
  padding: 6px 10px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: #e2e8f0;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.p2d-test-btn:hover {
  background: rgba(251, 191, 36, 0.15);
  border-color: rgba(251, 191, 36, 0.4);
  color: #fde68a;
}

@media (max-width: 520px) {
  .p2d-test-panel {
    right: 8px;
    left: 8px;
    max-width: none;
  }
}

