:root {
  --accent: #4aa3e0;
  --accent-2: #6fb6ea;
  --text: #34404a;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

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

html, body {
  margin: 0; min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: linear-gradient(160deg, #d8f0ff 0%, #e8e3ff 55%, #ffe9f2 100%);
  background-attachment: fixed;
  -webkit-user-select: none; user-select: none;
}

.wrap {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 16px);
  gap: 12px;
}

.topbar { width: 100%; max-width: 720px; display: flex; align-items: center; justify-content: space-between; }
.brand { font-size: 22px; font-weight: 800; margin: 0; color: var(--accent); text-shadow: 0 2px 0 #fff; }
.back-btn, .sound-toggle {
  flex: none; width: 40px; height: 40px; border-radius: 50%; border: none;
  background: #fff; color: var(--accent); box-shadow: var(--shadow);
  font-size: 20px; font-weight: 800; text-decoration: none;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.back-btn:active, .sound-toggle:active { transform: scale(0.92); }
.sound-toggle.off { opacity: 0.5; }
.topbar-right { display: flex; gap: 8px; }

.hud { width: 100%; max-width: 720px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.hud-item { background: #fff; border-radius: 999px; padding: 8px 16px; font-size: 15px; font-weight: 700; box-shadow: var(--shadow); color: #6a7a86; }
.hud-item b { color: var(--accent); font-size: 17px; }
.mini-btn { border: none; background: var(--accent); color: #fff; font-weight: 800; border-radius: 999px; padding: 9px 18px; font-size: 14px; cursor: pointer; box-shadow: var(--shadow); }
.mini-btn:first-of-type { margin-left: auto; }
.mini-btn:active { transform: scale(0.95); }

.play {
  flex: 1; width: 100%; max-width: 720px;
  display: flex; align-items: flex-start; justify-content: center; gap: 16px;
}

.board {
  position: relative;
  width: min(92vw, 78vh, 520px);
  aspect-ratio: 1 / 1;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 18px;
  box-shadow: var(--shadow), inset 0 0 0 2px rgba(255, 255, 255, 0.7);
  touch-action: none;
  overflow: hidden;
}

.tile {
  position: absolute;
  background-repeat: no-repeat;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.55);
  cursor: grab;
  touch-action: none;
  transition: left 0.18s ease, top 0.18s ease, box-shadow 0.18s ease;
  will-change: left, top, transform;
}
.tile.dragging {
  cursor: grabbing; z-index: 50;
  transition: none;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.35);
  filter: brightness(1.04);
}
.tile.correct {
  box-shadow: inset 0 0 0 2.5px rgba(120, 210, 90, 0.95);
}

.ref { flex: none; text-align: center; }
.ref-label { font-size: 12px; color: #7a8a96; font-weight: 700; margin-bottom: 6px; }
.ref img {
  width: clamp(72px, 22vw, 130px); aspect-ratio: 1 / 1; object-fit: cover;
  border-radius: 14px; background: #fff; box-shadow: var(--shadow); border: 3px solid #fff;
}
@media (max-width: 520px) {
  .play { flex-direction: column-reverse; align-items: center; }
  .ref img { width: 92px; }
}

/* 浮层 */
.overlay { position: fixed; inset: 0; background: rgba(30, 40, 50, 0.45); backdrop-filter: blur(5px); display: flex; align-items: center; justify-content: center; z-index: 60; padding: 20px; }
.overlay[hidden] { display: none; }
.card-panel { background: #fff; border-radius: 26px; padding: 24px 22px; width: 100%; max-width: 400px; box-shadow: var(--shadow); text-align: center; max-height: 90vh; overflow-y: auto; }
.card-panel h2 { margin: 0 0 18px; font-size: 24px; color: var(--accent); }
.card-panel p { margin: 4px 0 18px; color: #7a8a96; font-weight: 600; }
.win-emoji { font-size: 64px; animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-8px) rotate(4deg); } }

.field { text-align: left; margin-bottom: 18px; }
.field > label { display: block; font-size: 14px; color: #7a8a96; font-weight: 700; margin-bottom: 8px; }

.scene-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.scene-opt {
  aspect-ratio: 1 / 1; border-radius: 14px; border: 3px solid transparent; background-size: cover;
  background-position: center; cursor: pointer; box-shadow: var(--shadow);
}
.scene-opt.active { border-color: var(--accent); transform: scale(1.03); }

.upload-btn {
  display: block; text-align: center; border: 2px dashed #b9c6d2; border-radius: 14px;
  padding: 12px; font-size: 15px; font-weight: 700; color: var(--accent); cursor: pointer;
}
.upload-btn.has-img { border-color: var(--accent); background: #eef6fd; }

.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg-btn { flex: 1; min-width: 84px; border: 2px solid #cfe2f1; background: #f4faff; color: var(--text); padding: 12px 8px; border-radius: 14px; font-size: 15px; font-weight: 700; cursor: pointer; }
.seg-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.big-btn { width: 100%; border: none; border-radius: 16px; padding: 16px; margin-top: 6px; background: var(--accent); color: #fff; font-size: 18px; font-weight: 800; cursor: pointer; box-shadow: var(--shadow); }
.big-btn:active { transform: scale(0.97); background: var(--accent-2); }
.big-btn.ghost { background: #fff; color: var(--accent); border: 2px solid #cfe2f1; box-shadow: none; margin-top: 10px; }
