/* ============ 线条小狗闯关记 · 样式 ============ */
:root {
  --cream: #fff6e5;
  --cream-2: #ffedcd;
  --soft: #dec8a8;
  --ink: #4a3826;
  --ink-soft: #8a6f52;
  --orange: #f5a34a;
  --orange-2: #ff9f1c;
  --red: #ef476f;
  --green: #2ec4a0;
  --shadow: 0 10px 30px rgba(74, 56, 38, 0.18);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 15% -10%, #ffe9c2 0%, transparent 55%),
    radial-gradient(1000px 700px at 110% 110%, #ffd9a0 0%, transparent 50%),
    linear-gradient(160deg, #fff3d9 0%, #ffe6bd 55%, #f7d9a4 100%);
  min-height: 100vh;
  overflow-x: hidden;
}

#app {
  width: min(100%, 720px);
  margin: 0 auto;
  padding: 18px 12px 40px;
  position: relative;
}

/* ---------- 通用 ---------- */
.screen { display: none; flex-direction: column; align-items: center; animation: fadeIn .35s ease; }
.screen.active { display: flex; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.btn {
  font: inherit;
  border: none;
  cursor: pointer;
  border-radius: 999px;
  padding: 9px 18px;
  color: var(--ink);
  background: var(--cream);
  box-shadow: 0 4px 0 rgba(74, 56, 38, 0.18);
  transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
  user-select: none;
}
.btn:hover { filter: brightness(1.04); transform: translateY(-1px); }
.btn:active { transform: translateY(1px); box-shadow: 0 1px 0 rgba(74, 56, 38, 0.25); }
.btn.primary {
  background: linear-gradient(135deg, #ffc05c, var(--orange-2));
  color: #5b3200;
  box-shadow: 0 5px 0 #d97f0d, 0 10px 20px rgba(255, 159, 28, 0.35);
}
.btn.ghost { background: rgba(255, 246, 229, 0.82); border: 1.5px solid var(--soft); }
.btn.big { font-size: 20px; padding: 13px 34px; }

.topbar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}
.topbar h2 { font-size: 20px; letter-spacing: 1px; }

.hint { margin-top: 12px; color: var(--ink-soft); font-size: 13px; text-align: center; }

.hidden { display: none !important; }

/* ---------- 标题页 ---------- */
#screen-title { padding-top: 4vh; text-align: center; position: relative; }

.float-dogs { position: relative; height: 150px; width: 100%; margin-bottom: 6px; }
.float {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  box-shadow: var(--shadow);
  animation: floaty 3.2s ease-in-out infinite;
}
.float.f1 { width: 118px; height: 118px; left: 4%; top: 0; }
.float.f2 { width: 92px; height: 92px; left: 58%; top: 34px; animation-delay: .6s; }
.float.f3 { width: 78px; height: 78px; right: 5%; top: 4px; animation-delay: 1.2s; }

@keyframes floaty {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-14px) rotate(3deg); }
}

.logo {
  font-size: clamp(38px, 9vw, 60px);
  line-height: 1.16;
  color: var(--ink);
  letter-spacing: 4px;
  text-shadow: 3px 3px 0 rgba(255, 159, 28, 0.35);
}
.logo span { color: #d97f0d; }

.slogan { margin: 18px 0 26px; color: var(--ink-soft); font-size: 15px; line-height: 1.9; }

.tip { margin-top: 16px; color: rgba(74, 56, 38, 0.55); font-size: 12px; }

/* ---------- 选关页 ---------- */
.level-list {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.level-card {
  font: inherit;
  color: var(--ink);
  text-align: left;
  background: var(--cream);
  border: 2px solid transparent;
  border-radius: 20px;
  padding: 12px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .15s ease, border-color .15s ease;
}
.level-card:hover:not(.locked) { transform: translateY(-3px); border-color: var(--orange); }
.level-card.locked { opacity: .62; cursor: not-allowed; filter: grayscale(.7); }

.thumb {
  position: relative;
  aspect-ratio: 1.35 / 1;
  border-radius: 14px;
  overflow: hidden;
  background: var(--cream-2);
  display: flex;
  align-items: center;
  justify-content: center;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .num {
  position: absolute;
  top: 8px;
  left: 8px;
  background: var(--orange);
  color: #fff;
  font-weight: 700;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 8px rgba(0,0,0,.25);
}
.thumb .lock {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  background: rgba(74, 56, 38, 0.28);
  backdrop-filter: blur(1px);
}

.lname { margin-top: 10px; font-weight: 700; font-size: 16px; }
.ldesc { margin-top: 4px; color: var(--ink-soft); font-size: 12px; line-height: 1.55; }

/* ---------- 游戏页 ---------- */
#hud-progress-wrap {
  width: min(92%, 540px);
  height: 12px;
  border-radius: 999px;
  background: rgba(74, 56, 38, 0.16);
  overflow: hidden;
  margin-bottom: 10px;
}
#hud-progress {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffd166, var(--orange-2));
  transition: width .3s ease;
}

#hud-lives {
  min-height: 28px;
  font-size: 15px;
  color: var(--ink-soft);
  margin-bottom: 10px;
  letter-spacing: 2px;
}
#hud-lives .heart { display: inline-block; font-size: 20px; transition: transform .2s ease, opacity .2s ease; }
#hud-lives .heart.lost { opacity: .28; filter: grayscale(1); transform: scale(.85); }

#arena-wrap { width: 100%; display: flex; justify-content: center; }

#arena {
  position: relative;
  width: min(92vw, 540px);
  height: min(66vh, 600px);
  min-height: 430px;
  border-radius: 26px;
  overflow: hidden;
  background: #241a12;
  box-shadow: 0 16px 40px rgba(74, 56, 38, 0.35);
  touch-action: none;
  user-select: none;
}

#arena-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  opacity: .55;
  filter: blur(2px) brightness(.82);
  transform: scale(1.03);
}
#arena-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(20,12,6,.1), rgba(20,12,6,.55));
}

#arena-items {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}

#dog-wrap {
  position: absolute;
  bottom: 12px;
  left: 0;
  width: clamp(76px, 19vw, 108px);
  z-index: 4;
  pointer-events: none;
  transform-origin: 50% 90%;
  will-change: transform;
}
#dog-wrap.moving { animation: wobble .16s linear infinite alternate; }
@keyframes wobble { from { transform: translateX(var(--dx, 0)) rotate(-5deg); } to { transform: translateX(var(--dx, 0)) rotate(5deg); } }

#dog { width: 100%; height: auto; display: block; filter: drop-shadow(0 6px 10px rgba(0,0,0,.35)); }

.item {
  position: absolute;
  top: 0;
  left: 0;
  font-size: clamp(30px, 7vw, 42px);
  line-height: 1;
  will-change: transform;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,.35));
}

#arena-fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
}

.pop {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 26px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0,0,0,.5);
  animation: popUp .6s ease forwards;
  white-space: nowrap;
}
@keyframes popUp {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(.6); }
  25% { opacity: 1; transform: translate(-50%, -60%) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -130%) scale(.9); }
}

.flash-msg {
  position: absolute;
  top: 14%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 12, 6, 0.72);
  color: #ffe9c2;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: 999px;
  animation: popUp 1.2s ease forwards;
  white-space: nowrap;
}

#arena.shaking { animation: shake .45s ease; }
@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-10px, 4px) rotate(-1deg); }
  40% { transform: translate(10px, -4px) rotate(1deg); }
  60% { transform: translate(-7px, 3px); }
  80% { transform: translate(7px, -3px); }
}

#arena-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  background: rgba(25, 16, 8, 0.6);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#overlay-box {
  background: var(--cream);
  border-radius: 24px;
  padding: 26px 22px;
  width: min(88%, 340px);
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,.35);
  animation: fadeIn .3s ease;
}
#overlay-title { font-size: 24px; margin-bottom: 10px; }
#overlay-msg { color: var(--ink-soft); font-size: 14px; margin-bottom: 18px; line-height: 1.7; }
#overlay-btns { display: flex; flex-direction: column; gap: 10px; }

/* ---------- 翻牌 ---------- */
.memory-arena #arena-bg { opacity: .4; }
.memory-arena #arena-items { pointer-events: auto; }
.memory-grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: clamp(6px, 1.8vw, 12px);
  padding: clamp(10px, 2.5vw, 18px);
}

.card {
  font: inherit;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  perspective: 900px;
}
.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform .38s ease;
}
.card.flipped .card-inner { transform: rotateY(180deg); }

.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.card-back {
  background: linear-gradient(145deg, #ffd166, var(--orange));
  border: 3px solid #e08a12;
  font-size: clamp(24px, 7vw, 40px);
  box-shadow: inset 0 0 0 4px rgba(255,255,255,.35);
}
.card-front {
  background: var(--cream);
  border: 3px solid var(--soft);
  transform: rotateY(180deg);
}
.card-front img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card.matched .card-front { border-color: var(--green); box-shadow: 0 0 0 3px rgba(46,196,160,.55); }
.card.matched .card-inner { animation: matchedPop .4s ease; }
@keyframes matchedPop {
  0% { transform: rotateY(180deg) scale(1); }
  40% { transform: rotateY(180deg) scale(1.12); }
  100% { transform: rotateY(180deg) scale(1); }
}
.card.wrong .card-front { border-color: var(--red); box-shadow: 0 0 0 3px rgba(239,71,111,.55); }

/* ---------- 胜利页 ---------- */
#screen-victory { text-align: center; padding-top: 3vh; }
.victory-title { font-size: clamp(28px, 7vw, 42px); letter-spacing: 3px; margin-bottom: 20px; }
.collage {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  width: min(90%, 480px);
  margin-bottom: 22px;
}
.collage img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 20px;
  box-shadow: var(--shadow);
  background: var(--cream);
  animation: floaty 3.4s ease-in-out infinite;
}
.collage img:nth-child(2) { animation-delay: .5s; }
.collage img:nth-child(3) { animation-delay: 1s; }
.collage img:nth-child(4) { animation-delay: 1.5s; }

#victory-stats { color: var(--ink-soft); margin-bottom: 24px; font-size: 15px; }
.btn-row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

/* ---------- 加载 ---------- */
#loading {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(255, 243, 217, 0.94);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--ink-soft);
}
.spinner {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 5px solid var(--soft);
  border-top-color: var(--orange-2);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 彩带 ---------- */
.confetti {
  position: fixed;
  top: -18px;
  width: 9px;
  height: 15px;
  border-radius: 3px;
  z-index: 99;
  animation: confettiFall linear forwards;
  pointer-events: none;
}
@keyframes confettiFall {
  to { transform: translateY(115vh) rotate(720deg); opacity: .2; }
}

/* ---------- 响应式 ---------- */
@media (max-width: 480px) {
  .level-list { grid-template-columns: 1fr; }
  .lname { font-size: 17px; }
  #arena { min-height: 62vh; }
  #screen-title { padding-top: 2vh; }
}
