:root {
  --bg-0: #140b26;
  --bg-1: #241236;
  --accent: #b070ff;
  --accent-2: #ff7ac6;
  --accent-3: #ffd166;
  --text: #f6f2ff;
  --muted: #b8aed6;
  --card: rgba(255, 255, 255, 0.06);
  --card-border: rgba(255, 255, 255, 0.14);
  --gold: #ffd166;
  --good: #4fe3bd;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 700px at 10% -10%, #3a1f5c 0%, transparent 55%),
    radial-gradient(900px 650px at 100% 0%, #5c1f4d 0%, transparent 50%),
    linear-gradient(160deg, var(--bg-0), var(--bg-1));
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 760px;
  margin: 0 auto;
  padding: 20px 16px 56px;
  position: relative;
}

.app-header {
  text-align: center;
  padding: 4px 0 12px;
  position: relative;
}

.back-home {
  position: absolute;
  left: 0;
  top: 4px;
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
}

.back-home:hover { color: var(--text); }

.logo {
  font-size: 32px;
  letter-spacing: 1px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2), var(--accent-3));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.wallet {
  margin: 12px auto 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--card);
  border: 1px solid var(--card-border);
  padding: 6px 16px;
  border-radius: 999px;
  font-weight: 800;
  color: var(--gold);
}

.wallet.inline { margin: 0; padding: 5px 12px; font-size: 13px; }
.wallet-icon { font-size: 15px; }

.wallet.bump { animation: bump 0.4s ease; }
@keyframes bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.view.hidden { display: none !important; }

.section-hint {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin: 6px 0 16px;
}

/* ===== 大厅传送门 ===== */
.lobby-pet {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 64px;
  height: 64px;
  font-size: 46px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
  animation: bob 2.4s ease-in-out infinite;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.45));
  z-index: 5;
}
.lobby-pet img {
  max-width: 64px;
  max-height: 64px;
  image-rendering: auto;
}

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

.portal-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
@media (min-width: 620px) {
  .portal-grid { grid-template-columns: repeat(3, 1fr); }
}

.portal {
  position: relative;
  cursor: pointer;
  border: 1px solid var(--card-border);
  background: var(--card);
  border-radius: 20px;
  padding: 18px 14px 16px;
  color: var(--text);
  text-align: center;
  backdrop-filter: blur(8px);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  overflow: hidden;
}
.portal:hover {
  transform: translateY(-5px);
  border-color: var(--p1, var(--accent));
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.4);
}

.portal-ring {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  margin-bottom: 6px;
  background:
    radial-gradient(circle at 50% 50%, rgba(255,255,255,0.14), transparent 70%),
    conic-gradient(from 0deg, var(--p1), var(--p2), var(--p1));
  box-shadow: 0 0 22px -4px var(--p1), inset 0 0 14px rgba(0,0,0,0.35);
  animation: swirl 6s linear infinite;
}
@keyframes swirl { to { transform: rotate(360deg); } }

.portal-icon {
  font-size: 34px;
  display: block;
  animation: swirl-rev 6s linear infinite;
}
@keyframes swirl-rev { to { transform: rotate(-360deg); } }

.portal h2 { font-size: 16px; }
.portal p { color: var(--muted); font-size: 12px; line-height: 1.45; }

.portal-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: #ff5c7a;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 10px rgba(255, 92, 122, 0.5);
}
.portal-badge.hidden { display: none; }

/* ===== 通用舞台条 ===== */
.stage-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.stage-title { font-size: 17px; font-weight: 700; }

.play-hud {
  display: flex;
  gap: 12px;
  font-size: 14px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--card-border);
  padding: 5px 12px;
  border-radius: 999px;
}
.play-hud b { color: var(--accent-3); }

.prompt-banner {
  text-align: center;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 10px;
  margin-bottom: 12px;
  font-size: 14px;
  color: var(--muted);
}
.prompt-banner strong { color: var(--accent-3); font-size: 16px; }

/* ===== 画布 ===== */
.canvas-wrap {
  position: relative;
  display: flex;
  justify-content: center;
}

#drawCanvas {
  width: 100%;
  max-width: 480px;
  aspect-ratio: 1 / 1;
  border-radius: 18px;
  background: #ffffff;
  border: 1px solid var(--card-border);
  touch-action: none;
  display: block;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

.guide-canvas {
  position: absolute;
  inset: 0;
  margin: 0 auto;
  width: 100%;
  max-width: 480px;
  aspect-ratio: 1 / 1;
  pointer-events: none;
}
.guide-canvas.hidden { display: none; }

.canvas-pet {
  position: absolute;
  right: 10px;
  bottom: 10px;
  font-size: 34px;
  pointer-events: none;
  animation: bob 2.4s ease-in-out infinite;
}
.canvas-pet img { max-width: 42px; max-height: 42px; }

/* ===== 工具栏 ===== */
.toolbar {
  margin-top: 14px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 12px;
}
.tool-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.tool-row + .tool-row { margin-top: 10px; }

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.swatch:hover { transform: scale(1.1); }
.swatch.active { border-color: var(--text); transform: scale(1.15); }
.swatch.rainbow { background: conic-gradient(red, orange, yellow, green, blue, violet, red); }

.controls { justify-content: space-between; }
.size-control {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.size-control input { accent-color: var(--accent); }

.tool-btn {
  cursor: pointer;
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 16px;
  color: var(--text);
}
.tool-btn.active { border-color: var(--accent); background: rgba(176, 112, 255, 0.25); }
.finish-btn { margin-left: auto; }

/* ===== 小游戏舞台 ===== */
.play-wrap {
  display: flex;
  justify-content: center;
}
.play-wrap canvas {
  width: 100%;
  max-width: 480px;
  border-radius: 18px;
  border: 1px solid var(--card-border);
  display: block;
  touch-action: manipulation;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}
#advCanvas { aspect-ratio: 8 / 5; }
#battleCanvas { aspect-ratio: 8 / 5; }
#petCanvas { aspect-ratio: 4 / 3; }

.play-actions {
  margin-top: 14px;
  display: flex;
  gap: 12px;
  justify-content: center;
}
.big-btn { padding: 13px 28px; font-size: 15px; }

.mood-bar {
  margin: 12px auto 0;
  max-width: 480px;
  height: 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--card-border);
  overflow: hidden;
}
#moodFill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff6fb5, #ffd166);
  transition: width 0.25s ease;
}

.battle-log {
  margin: 12px auto 0;
  max-width: 480px;
  min-height: 62px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
}
.battle-log b { color: var(--accent-3); }

/* ===== 任务 ===== */
.mission-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.mission {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 14px 16px;
}
.mission-icon { font-size: 30px; flex-shrink: 0; }
.mission-info { flex: 1; min-width: 0; }
.mission-info h3 { font-size: 15px; }
.mission-track {
  margin-top: 8px;
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}
.mission-track span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.3s ease;
}
.mission-meta {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
}
.mission-meta .reward { color: var(--gold); font-weight: 700; }
.mission-claim {
  flex-shrink: 0;
  border: none;
  cursor: pointer;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #fff;
}
.mission-claim:disabled {
  background: rgba(255, 255, 255, 0.1);
  color: var(--muted);
  cursor: not-allowed;
}
.mission-claim.claimed {
  background: rgba(79, 227, 189, 0.16);
  color: var(--good);
}

/* ===== 结果弹窗 ===== */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 8, 20, 0.62);
  backdrop-filter: blur(4px);
  z-index: 40;
  padding: 20px;
}
.overlay.hidden { display: none; }
.overlay-card {
  text-align: center;
  padding: 28px 24px;
  background: rgba(36, 18, 54, 0.96);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  width: min(340px, 90%);
  animation: pop 0.25s ease;
}
@keyframes pop {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.result-emoji { font-size: 46px; margin-bottom: 6px; }
.overlay-card h2 { font-size: 22px; margin-bottom: 8px; }
.overlay-card p { color: var(--muted); margin-bottom: 18px; font-size: 14px; line-height: 1.6; }
.overlay-card p b { color: var(--gold); }
.overlay-actions { display: flex; flex-direction: column; gap: 10px; }

/* ===== 按钮 ===== */
.btn {
  cursor: pointer;
  border: none;
  border-radius: 12px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  transition: transform 0.12s ease, opacity 0.12s ease;
  color: var(--text);
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: linear-gradient(90deg, var(--accent), var(--accent-2)); color: #fff; }
.btn.ghost { background: rgba(255, 255, 255, 0.08); border: 1px solid var(--card-border); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== 商店 ===== */
.shop-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-top: 6px;
}
.shop-tab {
  flex-shrink: 0;
  cursor: pointer;
  border: 1px solid var(--card-border);
  background: var(--card);
  color: var(--muted);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}
.shop-tab.active {
  color: #fff;
  border-color: var(--accent);
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.shop-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 14px;
}
@media (min-width: 560px) {
  .shop-grid { grid-template-columns: repeat(2, 1fr); }
}

.shop-item {
  border: 1px solid var(--card-border);
  background: var(--card);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.shop-item-icon { font-size: 32px; flex-shrink: 0; }
.shop-item-info { flex: 1; min-width: 0; }
.shop-item-info h3 { font-size: 15px; }
.shop-item-info p { color: var(--muted); font-size: 12px; margin-top: 2px; }
.shop-item-price { color: var(--gold); font-size: 12px; font-weight: 700; margin-top: 4px; }
.shop-item-action { flex-shrink: 0; }

.shop-buy-btn {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #fff;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  border: none;
  cursor: pointer;
  font-weight: 600;
}
.shop-buy-btn:disabled { background: rgba(255, 255, 255, 0.1); color: var(--muted); cursor: not-allowed; }

.shop-equip-btn {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--card-border);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 600;
}
.shop-equip-btn.equipped { border-color: var(--good); color: var(--good); }

/* ===== 魔法世界 ===== */
.world-wrap {
  position: relative;
  display: flex;
  justify-content: center;
}
#worldCanvas {
  width: 100%;
  max-width: 720px;
  aspect-ratio: 3 / 2;
  border-radius: 18px;
  border: 1px solid var(--card-border);
  display: block;
  touch-action: none;
  cursor: pointer;
  background: #1a1430;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

.world-banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 11, 38, 0.9);
  border: 1px solid var(--card-border);
  color: var(--text);
  padding: 7px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  pointer-events: none;
}
.world-banner.hidden { display: none; }
.world-banner.place { border-color: var(--good); color: var(--good); }
.world-banner.remove { border-color: #ff6b6b; color: #ff9a9a; }

.world-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 12px;
}
.world-tools .btn { padding: 9px 14px; font-size: 13px; }
.world-tools .btn.active {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #fff;
  border-color: transparent;
}

.world-inv {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 12px 2px 4px;
  margin-top: 10px;
  min-height: 64px;
}
.world-inv:empty::after {
  content: "还没有道具，点「画新道具」创造一个吧 ✏️";
  color: var(--muted);
  font-size: 13px;
  align-self: center;
  margin: 0 auto;
}
.inv-item {
  flex-shrink: 0;
  width: 60px;
  height: 60px;
  border-radius: 14px;
  border: 2px solid var(--card-border);
  background: rgba(255, 255, 255, 0.9);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 4px;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.inv-item img { max-width: 100%; max-height: 100%; }
.inv-item:hover { transform: translateY(-3px); }
.inv-item.selected { border-color: var(--good); box-shadow: 0 0 0 2px rgba(79, 227, 189, 0.4); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: rgba(20, 11, 38, 0.95);
  border: 1px solid var(--card-border);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 60;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-6px); }
