/* ===== 像素复古风格 Flappy Bird ===== */

:root {
  --sky: #70c5ce;
  --sky-dark: #4ec0ca;
  --ground: #ded895;
  --ground-edge: #c0b86a;
  --pipe: #5ec84a;
  --pipe-dark: #3a9c2e;
  --pipe-edge: #2a701f;
  --bird-body: #ffd83d;
  --bird-beak: #ff7a1a;
  --bird-eye: #ffffff;
  --bird-eye-pupil: #222;
  --text: #ffffff;
  --text-shadow: #2c3e50;
  --danger: #e74c3c;
  --gold: #f1c40f;
  --silver: #bdc3c7;
  --bronze: #cd7f32;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #2c3e50;
  font-family: 'Press Start 2P', 'PingFang SC', 'Microsoft YaHei', system-ui, -apple-system, sans-serif;
  color: var(--text);
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 20% 20%, #34495e 0%, #2c3e50 60%, #1a252f 100%);
}

#stage {
  position: relative;
  width: min(100vw, 480px);
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.35);
}

#canvas-wrap {
  position: relative;
  flex: 1;
  width: 100%;
  display: flex;
  align-items: stretch;
  justify-content: center;
  overflow: hidden;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(to bottom, var(--sky) 0%, var(--sky-dark) 80%, var(--ground) 80%, var(--ground) 100%);
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

/* ===== Screens ===== */

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  pointer-events: none;
}

.screen.visible {
  display: flex;
  pointer-events: auto;
}

.screen > * {
  pointer-events: auto;
}

/* ===== 开始界面 ===== */

#screen-start {
  background: linear-gradient(180deg, rgba(112, 197, 206, 0.65) 0%, rgba(46, 100, 110, 0.85) 100%);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.title {
  font-size: clamp(36px, 9vw, 56px);
  font-weight: 900;
  margin: 0 0 8px;
  letter-spacing: 4px;
  line-height: 1.1;
  text-shadow:
    4px 4px 0 var(--text-shadow),
    -2px -2px 0 var(--text-shadow),
    2px -2px 0 var(--text-shadow),
    -2px 2px 0 var(--text-shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.title-flap {
  color: var(--bird-body);
}

.title-bird {
  color: var(--pipe);
  font-size: 0.7em;
}

.subtitle {
  font-size: 14px;
  margin: 0 0 28px;
  opacity: 0.9;
}

.difficulty {
  width: 100%;
  max-width: 360px;
  margin-bottom: 22px;
}

.difficulty h2 {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 12px;
  letter-spacing: 1px;
}

.diff-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.diff-btn {
  appearance: none;
  border: 3px solid var(--text-shadow);
  background: rgba(255, 255, 255, 0.15);
  color: var(--text);
  padding: 12px 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
  font-family: inherit;
  border-radius: 4px;
  transition: transform 0.08s, background 0.15s, border-color 0.15s;
  box-shadow: 0 3px 0 var(--text-shadow);
}

.diff-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.diff-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--text-shadow);
}

.diff-btn.active {
  background: var(--bird-body);
  color: var(--text-shadow);
  border-color: var(--bird-beak);
  box-shadow: 0 3px 0 var(--bird-beak);
}

.diff-name {
  font-size: 14px;
  font-weight: 700;
}

.diff-desc {
  font-size: 10px;
  opacity: 0.85;
}

.best-score {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  margin-bottom: 22px;
  padding: 8px 16px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 4px;
}

.best-score strong {
  font-size: 18px;
  color: var(--gold);
}

.primary-btn, .ghost-btn {
  appearance: none;
  font-family: inherit;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
  border-radius: 4px;
  padding: 14px 26px;
  font-size: 14px;
  transition: transform 0.08s, background 0.15s;
  border: 3px solid var(--text-shadow);
}

.primary-btn {
  background: var(--bird-beak);
  color: #fff;
  box-shadow: 0 4px 0 var(--text-shadow);
}

.primary-btn:hover {
  background: #ff8d33;
}

.primary-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--text-shadow);
}

.ghost-btn {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  box-shadow: 0 4px 0 var(--text-shadow);
}

.ghost-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.ghost-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--text-shadow);
}

.hint {
  font-size: 10px;
  opacity: 0.7;
  margin: 16px 0 0;
}

.hint kbd {
  background: rgba(255, 255, 255, 0.15);
  padding: 2px 6px;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  font-family: inherit;
  font-size: 9px;
}

/* ===== HUD ===== */

#screen-hud {
  background: transparent;
  pointer-events: none;
  display: none;
  align-items: flex-start;
  justify-content: stretch;
  padding: 0;
}

#screen-hud.visible {
  display: flex;
  pointer-events: none;
}

.hud-top {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 16px 18px;
  pointer-events: none;
}

.hud-score {
  font-size: clamp(36px, 8vw, 52px);
  font-weight: 900;
  color: var(--text);
  text-shadow:
    3px 3px 0 var(--text-shadow),
    -2px -2px 0 var(--text-shadow),
    2px -2px 0 var(--text-shadow),
    -2px 2px 0 var(--text-shadow);
  pointer-events: none;
}

.hud-pause {
  appearance: none;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  border: 2px solid #fff;
  width: 38px;
  height: 38px;
  font-size: 13px;
  font-weight: 700;
  border-radius: 4px;
  letter-spacing: 2px;
  cursor: pointer;
  pointer-events: auto;
  font-family: inherit;
}

.hud-pause:active {
  transform: scale(0.95);
}

/* ===== 暂停面板 ===== */

#screen-pause {
  background: rgba(0, 0, 0, 0.55);
}

.pause-card {
  background: rgba(46, 100, 110, 0.95);
  padding: 32px 40px;
  border-radius: 8px;
  border: 4px solid var(--text-shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  box-shadow: 0 6px 0 var(--text-shadow);
}

.pause-card h2 {
  margin: 0 0 8px;
  font-size: 20px;
  letter-spacing: 2px;
}

/* ===== 游戏结束面板 ===== */

#screen-over {
  background: rgba(0, 0, 0, 0.65);
  overflow-y: auto;
}

.over-card {
  background: rgba(255, 248, 220, 0.97);
  color: var(--text-shadow);
  border: 4px solid var(--text-shadow);
  border-radius: 8px;
  padding: 22px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 6px 0 var(--text-shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin: auto;
}

.over-title {
  margin: 0;
  font-size: 22px;
  letter-spacing: 2px;
  color: var(--danger);
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.15);
}

.score-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  width: 100%;
}

.score-cell {
  background: var(--bird-body);
  border: 3px solid var(--text-shadow);
  border-radius: 6px;
  padding: 10px 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: 0 3px 0 var(--text-shadow);
}

.score-cell span {
  font-size: 11px;
  font-weight: 700;
  opacity: 0.7;
}

.score-cell strong {
  font-size: 28px;
  font-weight: 900;
}

.medal {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--silver);
  border: 4px solid var(--text-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 900;
  box-shadow: 0 3px 0 var(--text-shadow);
  color: var(--text-shadow);
}

.medal[data-tier="gold"] {
  background: var(--gold);
}

.medal[data-tier="silver"] {
  background: var(--silver);
}

.medal[data-tier="bronze"] {
  background: var(--bronze);
  color: #fff;
}

.medal[data-tier="none"] {
  display: none;
}

.qr-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
}

.qr-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 3px solid var(--text-shadow);
  border-radius: 6px;
  padding: 8px;
}

.qr-cell span {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-shadow);
}

.qr-box {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-box img,
.qr-box canvas,
.qr-box svg {
  width: 100%;
  height: 100%;
  display: block;
}

.over-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
  margin-top: 4px;
}

.over-actions .primary-btn {
  grid-column: 1 / -1;
}

/* 结算 / 分享卡片是浅米色底，ghost-btn 默认白字 + 半透明白底在这里几乎看不清，
   改成深色文字 + 浅色描边的深色配色，primary-btn 再加文字阴影增强对比。 */
.over-actions .ghost-btn,
.share-card .ghost-btn {
  background: rgba(44, 62, 80, 0.08);
  color: var(--text-shadow);
  border-color: var(--text-shadow);
}

.over-actions .ghost-btn:hover,
.share-card .ghost-btn:hover {
  background: rgba(44, 62, 80, 0.18);
}

.over-actions .primary-btn,
.share-card .primary-btn {
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.45);
}

/* ===== 分享面板 ===== */

#screen-share {
  background: rgba(0, 0, 0, 0.8);
  overflow-y: auto;
}

.share-card {
  background: rgba(255, 248, 220, 0.97);
  color: var(--text-shadow);
  border: 4px solid var(--text-shadow);
  border-radius: 8px;
  padding: 18px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin: auto;
  box-shadow: 0 6px 0 var(--text-shadow);
}

.share-card h2 {
  margin: 0;
  font-size: 16px;
}

#share-img {
  width: 100%;
  border: 2px solid var(--text-shadow);
  border-radius: 4px;
  display: block;
  background: #fff;
}

.share-tip {
  font-size: 11px;
  opacity: 0.7;
  text-align: center;
  margin: 0;
}

/* ===== Footer ===== */

.footer {
  position: absolute;
  bottom: 8px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 10px;
  opacity: 0.6;
  pointer-events: auto;
  z-index: 2;
}

.footer a {
  color: var(--bird-body);
  text-decoration: none;
  border-bottom: 1px dashed var(--bird-body);
}

/* ===== Responsive ===== */

@media (max-width: 480px) {
  .title { font-size: 38px; }
  .over-card, .share-card, .pause-card { padding: 16px; max-width: 96vw; }
  .score-cell strong { font-size: 22px; }
}

@media (max-height: 600px) {
  .title { font-size: 30px; }
  .subtitle { margin-bottom: 14px; }
  .difficulty { margin-bottom: 12px; }
  .best-score { margin-bottom: 12px; padding: 6px 12px; }
  .primary-btn { padding: 10px 22px; }
}

@media (orientation: landscape) and (max-height: 500px) {
  #stage { max-width: 640px; }
  .title { font-size: 24px; }
}

/* 安全区 */
@supports (padding: max(0px)) {
  #screen-start, #screen-over, #screen-share, #screen-pause {
    padding-top: max(24px, env(safe-area-inset-top));
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }
  .hud-top {
    padding-top: max(16px, env(safe-area-inset-top));
  }
  .footer {
    bottom: max(8px, env(safe-area-inset-bottom));
  }
}
