/* ============================================================
   鸟鸣对对碰 · Birdsong Match
   设计系统：自然、低饱和、现代独立游戏风格
   ============================================================ */

/* ---------- 设计 tokens ---------- */
:root {
  /* 颜色 */
  --bg: #f5f2eb;                /* 暖白底 */
  --bg-soft: #efebe1;
  --surface: #ffffff;
  --surface-2: #faf8f3;
  --ink: #2c2a25;               /* 深暖灰（主文字） */
  --ink-2: #6f6a60;             /* 次级文字 */
  --ink-3: #a09a8e;             /* 弱化文字 */
  --brand: #4c6b4a;             /* 森林绿（主色） */
  --brand-deep: #3c563b;
  --brand-ink: #2f4530;
  --sage: #a9c0a0;              /* 鼠尾草绿 */
  --sage-soft: #e3ebdf;
  --olive: #8b9171;
  --beige: #e7e1d3;
  --positive: #5f8a5c;          /* 正确（柔和绿） */
  --positive-bg: #e6efe2;
  --negative: #c47b5f;          /* 错误（柔和陶土） */
  --negative-bg: #f6e6de;
  --border: #e5dfd2;
  --border-strong: #d6cfc0;

  /* 圆角 */
  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-xl: 28px;
  --r-full: 999px;

  /* 阴影（克制） */
  --shadow-xs: 0 1px 2px rgba(44, 42, 37, .05);
  --shadow-sm: 0 2px 6px rgba(44, 42, 37, .07);
  --shadow-md: 0 8px 24px rgba(44, 42, 37, .10);
  --shadow-lg: 0 20px 56px rgba(44, 42, 37, .18);

  /* 动效 */
  --ease: cubic-bezier(.4, 0, .2, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-flip: cubic-bezier(.4, .15, .2, 1);
  --t-fast: 150ms;
  --t-base: 220ms;
  --t-flip: 520ms;

  /* 字体 */
  --font: "Inter", system-ui, -apple-system, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

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

.hidden { display: none !important; }

body {
  font-family: var(--font);
  color: var(--ink);
  margin: 0;
  padding: 0;
  background:
    radial-gradient(1100px 460px at 50% -8%, #eef0e5 0%, rgba(238, 240, 229, 0) 62%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 30px 16px 56px;
}

/* ---------- Header ---------- */
.site-header { margin: 0 0 26px; }
.brand { display: flex; align-items: center; justify-content: center; gap: 12px; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px;
  border-radius: var(--r-md);
  background: linear-gradient(165deg, #55744f, #3b5238);
  color: #fff;
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, .12);
}
.brand-text { text-align: left; }
.brand-text h1 {
  font-size: 21px; font-weight: 700; letter-spacing: .01em;
  margin: 0; line-height: 1.2;
}
.subtitle { font-size: 12.5px; color: var(--ink-3); margin: 3px 0 0; }

/* ---------- 通用动画 ---------- */
.menu-screen, .game-screen { animation: fade-up .4s var(--ease-out); }

/* ---------- 菜单页 ---------- */
.menu-intro { margin-bottom: 28px; text-align: center; }
.menu-intro h2 { font-size: 20px; font-weight: 700; margin: 0 0 6px; }
.menu-desc { font-size: 14px; color: var(--ink-2); margin: 0; }

.menu-modes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  max-width: 620px;
  margin: 0 auto;
}
.mode-card {
  position: relative;
  display: flex; flex-direction: column; align-items: flex-start;
  text-align: left; gap: 7px;
  padding: 22px 22px 20px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-lg);
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  font-family: inherit;
  transition: transform .18s var(--ease), box-shadow .18s var(--ease), border-color .18s var(--ease);
}
.mode-card:hover {
  transform: translateY(-4px);
  border-color: var(--sage);
  box-shadow: var(--shadow-md);
}
.mode-card:active { transform: translateY(-1px); }
.mode-card:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }
.mode-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 42px; height: 42px;
  border-radius: var(--r-md);
  background: var(--sage-soft);
  color: var(--brand-deep);
  margin-bottom: 5px;
}
.mode-title { font-size: 17px; font-weight: 700; color: var(--ink); }
.mode-sub { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.mode-desc { font-size: 12.5px; color: var(--ink-3); line-height: 1.55; margin: 0; }
.mode-desc b { color: var(--ink-2); font-weight: 600; }
.mode-cta {
  display: inline-flex; align-items: center; gap: 5px;
  margin-top: auto; padding-top: 11px;
  font-size: 13px; font-weight: 600; color: var(--brand);
}
.mode-cta svg { transition: transform .18s var(--ease); }
.mode-card:hover .mode-cta svg { transform: translateX(3px); }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 17px;
  border-radius: var(--r-full);
  font-size: 14px; font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .16s var(--ease), border-color .16s var(--ease),
              color .16s var(--ease), transform .12s var(--ease), box-shadow .16s var(--ease);
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn-primary {
  background: var(--brand);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--brand-deep); box-shadow: var(--shadow-md); }
.btn-ghost {
  background: var(--surface);
  color: var(--ink-2);
  border-color: var(--border-strong);
}
.btn-ghost:hover { color: var(--ink); border-color: var(--ink-3); background: var(--surface-2); }
.icon-only { padding: 9px; }

/* ---------- 游戏页 ---------- */
.game-screen {
  max-width: 520px;
  margin: 0 auto;
  width: 100%;
  display: flex; flex-direction: column; gap: 15px;
}

.game-topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.status-pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  font-size: 12px; color: var(--ink-2);
  box-shadow: var(--shadow-xs);
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ink-3);
  transition: background .2s var(--ease);
}
.status-dot.loading { background: #c9a24a; animation: pulse 1.2s ease-in-out infinite; }
.status-dot.ready { background: var(--positive); }
.status-dot.playing { background: var(--positive); animation: pulse 1s ease-in-out infinite; }
.status-dot.done { background: var(--ink-3); }
.status-text { font-weight: 500; }

.mode-label-row { text-align: center; }
.mode-label {
  display: inline-block;
  padding: 5px 14px;
  background: var(--sage-soft);
  color: var(--brand-deep);
  border-radius: var(--r-full);
  font-size: 12.5px; font-weight: 600;
}

/* 计分 / 进度 */
.stats-row { display: flex; gap: 12px; }
.stat {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-xs);
}
.stat-label {
  font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-3); font-weight: 600;
}
.stat-value-wrap { display: flex; align-items: baseline; }
.stat-value {
  font-size: 27px; font-weight: 700; color: var(--ink);
  font-variant-numeric: tabular-nums; line-height: 1.1;
}
.stat-total { font-size: 14px; color: var(--ink-3); font-weight: 600; margin-left: 2px; }
#score { display: inline-block; }
#score.bump { animation: bump .34s var(--ease-out); }

#score-delta {
  display: inline-block;
  margin-left: 9px;
  font-size: 15px; font-weight: 700;
  min-width: 36px;
  opacity: 0;
}
#score-delta.show { animation: float-up 1.15s var(--ease) forwards; }
#score-delta.plus { color: var(--positive); }
#score-delta.minus { color: var(--negative); }

/* ---------- 卡牌网格 ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: clamp(9px, 2.2vw, 14px);
  width: 100%;
}

.card {
  position: relative;
  aspect-ratio: 1;
  perspective: 900px;
  cursor: pointer;
  transition: transform .18s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.card:not(.flipped):hover { transform: translateY(-3px); }
.card:not(.flipped):active { transform: translateY(-1px) scale(.98); }
.card:focus-visible { outline: none; }

.card-inner {
  position: absolute; inset: 0;
  transition: transform var(--t-flip) var(--ease-flip);
  transform-style: preserve-3d;
}
.card.flipped .card-inner { transform: rotateY(180deg); }

.card-face {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--r-md);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4px; padding: 8px;
  overflow: hidden;
}

.card-back {
  background: linear-gradient(165deg, #55744f, #3b5238);
  color: rgba(255, 255, 255, .9);
  border: 1px solid rgba(255, 255, 255, .1);
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, .1);
  transition: box-shadow .18s var(--ease);
}
.card:not(.flipped):hover .card-back { box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255, 255, 255, .1); }
.card-back-icon { display: inline-flex; opacity: .85; }

.card-front {
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  transform: rotateY(180deg);
  box-shadow: var(--shadow-sm);
  transition: background .28s var(--ease), border-color .28s var(--ease), box-shadow .28s var(--ease);
}
.card.first .card-front {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--sage-soft), var(--shadow-sm);
}

.card-wave {
  display: inline-flex; align-items: center; justify-content: center;
  height: 22px;
  transition: opacity .2s var(--ease), transform .2s var(--ease);
}
.wave-bars { display: inline-flex; align-items: center; gap: 3px; height: 22px; }
.wave-bar {
  width: 3px;
  border-radius: 2px;
  background: var(--olive);
  transform-origin: center;
  transform: scaleY(.5);
}
.card.playing .wave-bar {
  animation-name: eq;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
}
.wave-bar:nth-child(1) { height: 12px; animation-duration: .9s;  animation-delay: -.2s; }
.wave-bar:nth-child(2) { height: 20px; animation-duration: 1.1s; animation-delay: -.5s; }
.wave-bar:nth-child(3) { height: 8px;  animation-duration: .8s;  animation-delay: -.35s; }
.wave-bar:nth-child(4) { height: 18px; animation-duration: 1.25s; animation-delay: -.7s; }
.wave-bar:nth-child(5) { height: 14px; animation-duration: .95s; animation-delay: -.1s; }
.card.matched .wave-bar { animation-play-state: paused; }
.card-check { display: none; color: var(--positive); }

.bird-name {
  font-size: clamp(10.5px, 3vw, 13px);
  font-weight: 700; line-height: 1.2; text-align: center;
  color: var(--ink); padding: 0 2px;
  opacity: 0; transition: opacity .25s var(--ease) .05s;
}
.bird-latin {
  font-size: clamp(8.5px, 2.4vw, 10px);
  font-style: italic; color: var(--ink-2); text-align: center;
  line-height: 1.25; word-break: break-word;
  opacity: 0; transition: opacity .25s var(--ease) .1s;
}

/* 已配对 */
.card.matched .card-front {
  background: var(--positive-bg);
  border-color: var(--positive);
  box-shadow: var(--shadow-sm);
}
.card.matched .card-wave { opacity: 0; transform: scale(.6); }
.card.matched .card-check { display: inline-flex; animation: pop .3s var(--ease-out); }
.card.matched .bird-name,
.card.matched .bird-latin { opacity: 1; }

/* 未配对（错误） */
.card.wrong { animation: shake .42s var(--ease); }
.card.wrong .card-front { background: var(--negative-bg); border-color: var(--negative); }

/* ---------- 结算弹窗 ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(43, 41, 36, .38);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  z-index: 30; padding: 20px;
}
.overlay:not(.hidden) { animation: fade-in .28s var(--ease); }
.overlay-box {
  width: min(360px, 100%);
  background: var(--surface);
  border-radius: var(--r-xl);
  padding: 30px 28px 26px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: pop-in .4s var(--ease-out);
}
.overlay-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--positive-bg); color: var(--positive);
  margin-bottom: 12px;
}
.overlay-box h2 { font-size: 20px; margin: 0 0 8px; color: var(--ink); }
.overlay-score { font-size: 15px; color: var(--ink-2); margin: 0 0 22px; }
.overlay-score strong {
  font-size: 27px; color: var(--ink); margin-left: 5px;
  font-variant-numeric: tabular-nums;
}
.overlay-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.game-hint { font-size: 12px; color: var(--ink-3); margin: 2px 0 0; text-align: center; }

/* ---------- 关键帧 ---------- */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(14px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes eq { 0%, 100% { transform: scaleY(.35); } 50% { transform: scaleY(1); } }
@keyframes float-up {
  0% { opacity: 0; transform: translateY(8px) scale(.9); }
  22% { opacity: 1; transform: translateY(0) scale(1); }
  78% { opacity: 1; transform: translateY(-4px); }
  100% { opacity: 0; transform: translateY(-12px); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-4px); }
  40%, 80% { transform: translateX(4px); }
}
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.14); } 100% { transform: scale(1); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }

/* ---------- 移动端微调 ---------- */
@media (max-width: 420px) {
  .app { padding: 20px 12px 44px; }
  .brand-text h1 { font-size: 19px; }
  .game-topbar { gap: 6px; }
  .status-text { display: none; }  /* 保留圆点，空间不足时隐藏文字 */
  .status-pill { padding: 7px; }
}

/* ---------- 减少动效偏好 ---------- */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
