/* 小公主的乘法魔法卡 · 浅色萌系主题
   适配优先级：手机竖屏 > iPad 横竖屏 > 桌面 */

:root {
  --pink: #ff8fb1;
  --pink-deep: #f56d9a;
  --pink-soft: #ffd9e7;
  --lav: #b9a2f7;
  --lav-soft: #eee7ff;
  --cream: #fff6e4;
  --sky: #dff0ff;
  --ink: #5b4a68;
  --ink-soft: #93839f;
  --card-bg: rgba(255, 255, 255, .92);
  --shadow: 0 14px 34px rgba(190, 140, 180, .18), 0 3px 10px rgba(190, 140, 180, .10);
  --font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", "Comic Sans MS", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background:
    radial-gradient(circle at 10% 8%, rgba(255, 214, 232, .85), transparent 38%),
    radial-gradient(circle at 92% 6%, rgba(219, 236, 255, .95), transparent 42%),
    radial-gradient(circle at 50% 100%, rgba(235, 226, 255, .9), transparent 58%),
    linear-gradient(180deg, #fffafc 0%, #fff5fb 48%, #f7f4ff 100%);
  background-attachment: fixed;
}

button { font-family: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 3px solid var(--lav); outline-offset: 3px; }

/* ---------- 背景装饰 ---------- */
.sky { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }

.cloud {
  position: absolute; font-size: 42px; opacity: .5;
  animation: float 9s ease-in-out infinite;
}
.cloud-a { top: 12%; left: 6%; }
.cloud-b { top: 26%; right: 7%; font-size: 34px; animation-delay: -3s; }
.cloud-c { bottom: 14%; left: 4%; font-size: 30px; animation-delay: -6s; }

.star { position: absolute; color: #ffc2da; animation: twinkle 3.4s ease-in-out infinite; }
.star-a { top: 9%; left: 26%; font-size: 20px; }
.star-b { top: 18%; right: 24%; font-size: 15px; animation-delay: -.9s; color: #cdb8ff; }
.star-c { top: 64%; left: 12%; font-size: 17px; animation-delay: -1.8s; color: #ffd98a; }
.star-d { bottom: 9%; right: 16%; font-size: 22px; animation-delay: -2.5s; }
.star-e { top: 45%; right: 6%; font-size: 13px; animation-delay: -1.3s; color: #cdb8ff; }

.bubble { position: absolute; border-radius: 50%; filter: blur(1px); opacity: .5; }
.bubble-a { width: 16px; height: 16px; top: 34%; left: 10%; background: #ffd3e5; }
.bubble-b { width: 11px; height: 11px; top: 72%; right: 11%; background: #d8c9ff; }
.bubble-c { width: 9px; height: 9px; top: 8%; right: 38%; background: #ffe6a8; }

@keyframes float { 0%, 100% { transform: translateY(0) } 50% { transform: translateY(-12px) } }
@keyframes twinkle { 0%, 100% { opacity: .35; transform: scale(.85) } 50% { opacity: 1; transform: scale(1.15) } }

/* ---------- 顶栏 ---------- */
.topbar {
  position: relative; z-index: 2;
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px 14px;
  padding: 12px clamp(14px, 4vw, 28px);
  background: rgba(255, 255, 255, .55);
  border-bottom: 1px solid rgba(255, 255, 255, .9);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}

.brand { display: flex; align-items: center; gap: 7px; font-weight: 800; font-size: 17px; white-space: nowrap; }
.brand-crown { font-size: 22px; }

.stats { display: flex; align-items: center; gap: 14px; flex: 1 1 auto; justify-content: center; flex-wrap: wrap; }
.stat { display: flex; align-items: baseline; gap: 6px; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12px; color: var(--ink-soft); }
.stat strong { font-size: 21px; color: var(--pink-deep); font-weight: 900; }

.hearts { display: flex; gap: 3px; font-size: 21px; line-height: 1; }
.heart { display: inline-block; transition: transform .3s, opacity .3s, filter .3s; }
.heart.is-lost { filter: grayscale(1); opacity: .3; transform: scale(.82); }
.heart.is-popping { animation: heartPop .45s ease; }
@keyframes heartPop { 0% { transform: scale(1.4) } 60% { transform: scale(.8) } 100% { transform: scale(.82) } }

.top-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn, .pill-btn {
  min-height: 44px; border: 2px solid #fff; border-radius: 999px;
  background: rgba(255, 255, 255, .85); color: var(--ink);
  box-shadow: 0 4px 12px rgba(190, 140, 180, .14);
  font-weight: 700; transition: transform .15s, background .2s;
}
.icon-btn { width: 44px; font-size: 20px; padding: 0; }
.pill-btn { padding: 0 16px; font-size: 14px; }
.icon-btn:active, .pill-btn:active { transform: scale(.94); background: #fff; }
.icon-btn.is-muted { opacity: .55; }

/* ---------- 舞台 / 三屏 ---------- */
.stage { position: relative; z-index: 1; flex: 1; display: flex; align-items: center; justify-content: center; padding: 14px clamp(14px, 4vw, 28px) 26px; }
.screen { display: none; width: 100%; align-items: center; justify-content: center; }
.screen.is-active { display: flex; animation: screenIn .35s ease both; }
@keyframes screenIn { from { opacity: 0; transform: translateY(12px) } to { opacity: 1; transform: none } }

/* ---------- 通用卡片 / 按钮 ---------- */
.hero-card {
  width: min(100%, 400px);
  padding: 32px 26px 26px;
  text-align: center;
  background: var(--card-bg);
  border: 2px solid #fff;
  border-radius: 36px;
  box-shadow: var(--shadow);
}
.hero-crown { font-size: 56px; line-height: 1.1; animation: float 5s ease-in-out infinite; }
.hero-card h1 { margin: 10px 0 8px; font-size: clamp(28px, 7.2vw, 38px); line-height: 1.35; letter-spacing: 1px; }
.hero-card h1 span { color: var(--pink-deep); text-shadow: 0 2px 0 #ffe4ef; }
.hero-sub { margin: 0 0 20px; font-size: 15px; color: var(--ink-soft); }

.best-chip {
  display: inline-block; margin: 0 auto 22px; padding: 9px 18px;
  font-size: 14px; color: #a57528; background: var(--cream);
  border: 1px solid #ffe7b8; border-radius: 999px;
}
.best-chip b { font-size: 18px; font-variant-numeric: tabular-nums; }

.hero-note { margin: 18px 0 0; font-size: 12px; line-height: 1.8; color: var(--ink-soft); }

.primary-btn {
  display: block; width: 100%; min-height: 60px;
  border: none; border-radius: 999px;
  font-size: 20px; font-weight: 800; letter-spacing: 1px; color: #fff;
  background: linear-gradient(135deg, #ffb0cb 0%, var(--pink) 45%, #f77fae 100%);
  box-shadow: 0 8px 0 #f2c2d5, 0 14px 24px rgba(245, 109, 154, .3);
  transition: transform .15s, box-shadow .15s, filter .2s;
}
.primary-btn:active:not(:disabled) { transform: translateY(5px); box-shadow: 0 3px 0 #f2c2d5, 0 6px 14px rgba(245, 109, 154, .25); }
.primary-btn:disabled { filter: grayscale(.55); opacity: .6; box-shadow: 0 6px 0 #e6d9e0; cursor: default; }

/* ---------- 翻卡 ---------- */
.card-scene { width: min(100%, 420px); height: clamp(464px, 68dvh, 580px); perspective: 1400px; }
.card { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform .62s cubic-bezier(.2, .8, .25, 1); }
.card.is-flipped { transform: rotateY(180deg); }
.card.is-wrong { animation: shake .42s ease; }
@keyframes shake { 0%, 100% { transform: rotateY(180deg) rotate(0) } 25% { transform: rotateY(180deg) rotate(-2.5deg) } 75% { transform: rotateY(180deg) rotate(2.5deg) } }

.card-face {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center;
  padding: 20px;
  background: var(--card-bg);
  border: 2px solid #fff; border-radius: 34px;
  box-shadow: var(--shadow);
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  pointer-events: none;
}
.card:not(.is-flipped) .card-front, .card.is-flipped .card-back { pointer-events: auto; }
.card-front::before, .card-back::before {
  content: ""; position: absolute; inset: 8px; border-radius: 28px;
  border: 2px dashed rgba(255, 175, 205, .55); pointer-events: none;
}
.card-back { transform: rotateY(180deg); background: linear-gradient(165deg, #fff7fc 0%, #fff 55%, #f6f1ff 100%); }

.card-ribbon {
  padding: 7px 18px; font-size: 13px; color: var(--pink-deep); font-weight: 700;
  background: var(--pink-soft); border-radius: 999px;
}
.card-ribbon b { font-variant-numeric: tabular-nums; }

.question {
  display: flex; align-items: baseline; justify-content: center; flex-wrap: wrap; gap: 6px;
  margin: 16px 0 0; font-size: clamp(32px, 8.4vw, 46px); font-weight: 900;
  font-variant-numeric: tabular-nums; line-height: 1.2;
}
.question .op { color: var(--pink); font-size: .8em; }
.answer-box {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 78px; height: 62px; padding: 0 10px;
  border-bottom: 4px dashed var(--pink); color: var(--ink);
  background: rgba(255, 233, 243, .6); border-radius: 14px 14px 6px 6px;
}
.answer-box.is-empty { color: #cdb9d8; }
.answer-box.is-error { animation: shakeX .35s ease; }
@keyframes shakeX { 0%,100% { transform: translateX(0) } 25% { transform: translateX(-6px) } 75% { transform: translateX(6px) } }

.input-tip { margin: 10px 0 6px; min-height: 20px; font-size: 13px; color: var(--ink-soft); }
.input-tip.is-warn { color: var(--pink-deep); font-weight: 700; }

.keypad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  width: 100%; margin-top: auto; margin-bottom: 14px;
}
.keypad button {
  height: 58px; border: 2px solid #fff; border-radius: 18px;
  font-size: 26px; font-weight: 800; color: var(--ink);
  font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, #fff 0%, #fff2f8 100%);
  box-shadow: 0 4px 0 #f3dce7, 0 6px 12px rgba(190, 140, 180, .12);
  transition: transform .12s, box-shadow .12s, background .18s;
}
.keypad button:active { transform: translateY(3px); box-shadow: 0 1px 0 #f3dce7; background: #ffe6f1; }
.keypad .key-fn { font-size: 18px; color: var(--pink-deep); background: linear-gradient(180deg, #fff 0%, #f4eeff 100%); box-shadow: 0 4px 0 #e5dbf7, 0 6px 12px rgba(160, 140, 200, .12); }
.keypad .key-fn:active { background: #e9deff; box-shadow: 0 1px 0 #e5dbf7; }

.flip-btn { flex: 0 0 auto; }

/* 卡背 */
.result-emoji { font-size: 64px; line-height: 1; margin-top: auto; animation: popIn .45s cubic-bezier(.2, 1.5, .5, 1) both; }
@keyframes popIn { from { transform: scale(.3); opacity: 0 } to { transform: scale(1); opacity: 1 } }
.card-back h2 { margin: 12px 0 4px; font-size: 27px; color: var(--pink-deep); }
.correct-answer { margin: 12px 0 2px; font-size: 32px; font-weight: 900; font-variant-numeric: tabular-nums; }
.your-answer { margin: 4px 0; font-size: 15px; color: var(--ink-soft); }
.result-note { margin: 8px 0 0; font-size: 15px; color: var(--ink); }
.card-back .primary-btn { margin-top: auto; flex: 0 0 auto; }

/* 结算页 */
.end-card h1 { margin-bottom: 16px; }
.record-badge {
  display: inline-block; margin: 0 auto 16px; padding: 8px 20px;
  font-size: 15px; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, #ffc46b, #ff8fb1); border-radius: 999px;
  box-shadow: 0 6px 16px rgba(255, 143, 177, .35);
  animation: glow 1.6s ease-in-out infinite;
}
.record-badge[hidden] { display: none; }
@keyframes glow { 0%,100% { transform: scale(1) } 50% { transform: scale(1.06) } }

.score-ring {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 148px; height: 148px; margin: 0 auto 20px;
  border-radius: 50%; background: #fff;
  border: 8px solid var(--pink-soft);
  box-shadow: inset 0 0 0 3px #fff, 0 8px 20px rgba(190, 140, 180, .18);
}
.score-ring span { font-size: 46px; font-weight: 900; color: var(--pink-deep); line-height: 1.1; font-variant-numeric: tabular-nums; }
.score-ring small { font-size: 12px; color: var(--ink-soft); }

/* 撒花 */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 5; overflow: hidden; }
.confetti span {
  position: absolute; top: -30px; font-size: 22px;
  animation: fall linear forwards;
}
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); opacity: .1 } }

/* ---------- 响应式 ---------- */
@media (min-width: 768px) {
  .card-scene { width: 440px; height: 580px; }
  .card-face { padding: 26px; }
  .question { font-size: 50px; }
  .answer-box { min-width: 92px; height: 68px; }
  .keypad { gap: 12px; }
  .keypad button { height: 64px; font-size: 28px; }
  .hero-card { width: 440px; padding: 40px 36px 30px; }
  .hero-crown { font-size: 66px; }
  .topbar { gap: 10px 20px; }
}

@media (max-width: 420px) {
  .brand-text { display: none; }
  .topbar { gap: 8px; padding: 10px 14px; }
  .stats { gap: 10px; }
  .stat strong { font-size: 19px; }
  .hearts { font-size: 18px; }
  .pill-btn { padding: 0 12px; font-size: 13px; }
}

@media (max-height: 720px) {
  .card-scene { height: 456px; }
  .card-face { padding: 13px 16px; }
  .question { margin-top: 10px; font-size: 32px; }
  .answer-box { min-width: 66px; height: 52px; }
  .input-tip { margin: 6px 0 4px; }
  .keypad { gap: 7px; margin-bottom: 10px; }
  .keypad button { height: 54px; font-size: 23px; }
  .flip-btn, .primary-btn { min-height: 54px; font-size: 18px; }
  .result-emoji { font-size: 52px; }
  .correct-answer { font-size: 27px; }
}

@media (max-height: 540px) {
  .card-scene { height: 400px; }
  .card-face { padding: 10px 14px; }
  .card-ribbon { padding: 4px 14px; font-size: 12px; }
  .question { margin-top: 4px; font-size: 27px; }
  .answer-box { height: 44px; min-width: 58px; }
  .input-tip { min-height: 16px; font-size: 12px; margin: 3px 0; }
  .keypad { gap: 5px; margin-bottom: 8px; }
  .keypad button { height: 48px; font-size: 20px; }
  .primary-btn { min-height: 48px; font-size: 17px; }
  .result-emoji { font-size: 42px; }
  .card-back h2 { font-size: 21px; margin: 6px 0 2px; }
  .correct-answer { font-size: 23px; margin: 6px 0 2px; }
  .result-note { font-size: 13px; }
  .hero-card { padding: 18px 24px; }
  .hero-crown { font-size: 40px; }
  .hero-card h1 { font-size: 25px; margin: 4px 0; }
  .hero-sub { margin-bottom: 10px; }
  .best-chip { margin-bottom: 12px; }
  .hero-note { margin-top: 10px; }
  .score-ring { width: 104px; height: 104px; margin-bottom: 12px; }
  .score-ring span { font-size: 34px; }
}

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