:root {
  --cream: #FFF7F2;
  --pink: #F7B7C4;
  --pink-soft: #FCE7EC;
  --blue: #A7D8F0;
  --blue-soft: #E6F3FB;
  --green: #A8D5A2;
  --green-soft: #EAF7E6;
  --yellow: #FCE3A0;
  --gold: #E8A33D;      /* 统一的五星/排名金色 */
  --purple: #C9B6E4;
  --ink: #5A5168;
  --ink-soft: #9A91A8;
  --line: #EAD9E0;
  --danger: #E8909A;
  --danger-soft: #FCEBED;
  --card: #FFFFFF;
  --shadow: 0 6px 18px rgba(180, 150, 170, 0.18);
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: linear-gradient(180deg, #FFF7F2 0%, #FCEFF5 100%);
  color: var(--ink);
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
}

.screen { flex: 1; display: flex; flex-direction: column; padding: 20px 18px 28px; }
.hidden { display: none !important; }

/* ---------- 菜单 ---------- */
.brand { text-align: center; margin: 36px 0 24px; }
.logo {
  font-size: 56px;
  line-height: 1;
  filter: drop-shadow(0 4px 6px rgba(180,150,170,.25));
}
.brand h1 {
  font-size: 32px;
  margin: 10px 0 6px;
  letter-spacing: 4px;
  color: var(--ink);
}
.tagline { color: var(--ink-soft); font-size: 14px; margin: 0; }

.btn-primary {
  background: var(--pink);
  color: #fff;
  border: none;
  border-radius: 16px;
  padding: 14px 20px;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 2px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .12s ease;
}
.btn-primary:active { transform: scale(.96); }

.level-grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.level-chip {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 12px 6px;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(180,150,170,.12);
  transition: transform .12s ease;
  min-height: 0;
}
.level-chip:active { transform: scale(.95); }
.level-chip .num { font-size: 20px; font-weight: 700; color: var(--ink); line-height: 1.2; }
.level-chip .nm { font-size: 12px; color: var(--ink-soft); margin-top: 4px; line-height: 1.3; }
.level-chip .st { font-size: 12px; margin-top: 4px; letter-spacing: 1px; min-height: 0; line-height: 1.2; color: var(--gold); }
.level-chip.locked { opacity: .45; }
.chapter-head {
  grid-column: 1 / -1; text-align: left; font-weight: 700;
  color: var(--ink); font-size: 15px; margin: 14px 0 4px;
  letter-spacing: 1px;
}
/* 品牌区 */
.brand { margin: 20px 0 14px; }
.brand .logo { font-size: 52px; }
.brand h1 { font-size: 30px; margin: 6px 0 4px; }
.brand .tagline { font-size: 14px; }

/* 首页顶部：音效开关 */
.menu-top {
  display: flex; justify-content: flex-end;
  padding: 6px 2px 0;
}
.sound-btn { font-size: 14px; color: var(--ink-soft); }
.sound-btn.muted { opacity: .5; }
.chapter-head::before { content: "▍"; color: var(--pink); margin-right: 4px; }

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

/* ---------- 顶部栏 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 14px;
}
.btn-ghost {
  background: transparent; border: none; color: var(--ink-soft);
  font-size: 15px; cursor: pointer; padding: 6px 2px;
  white-space: nowrap;
}
.topbar .btn-ghost:first-child { flex: 1; text-align: left; }
.topbar .btn-ghost:last-child { flex: 1; text-align: right; }
.level-meta { text-align: center; flex: 2; }
#level-title { font-size: 18px; font-weight: 700; display: block; }
.level-meta .sub { font-size: 12px; color: var(--ink-soft); }

/* ---------- 座位区 ---------- */
.scene {
  background: var(--card);
  border-radius: 22px;
  padding: 18px 14px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.train-label { text-align: center; font-size: 13px; color: var(--ink-soft); margin-bottom: 12px; }
.seats {
  display: flex; flex-wrap: wrap; gap: 10px; justify-content: center;
}
/* 圆桌：座位区加圆角描边 + 提示首尾相邻 */
.seats.round {
  border: 2px dashed var(--pink);
  border-radius: 999px;
  padding: 12px 14px;
}
.seats.round::after {
  content: "↺ 首尾相邻";
  flex-basis: 100%; text-align: center; font-size: 11px;
  color: var(--ink-soft); margin-top: 4px;
}
.seat {
  width: 64px; height: 78px;
  border-radius: 14px;
  border: 2px dashed var(--line);
  background: #FBF6F9;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  transition: border-color .15s, background .15s, transform .1s;
}
.seat.filled { border-style: solid; border-color: var(--line); background: #fff; }
.seat.ok { border-color: var(--green); background: var(--green-soft); }
.seat.bad { border-color: var(--danger); background: var(--danger-soft); }
.seat.drop-hover { transform: scale(1.06); border-color: var(--pink); }
/* 障碍位（被行李箱占用，不能坐） */
.seat.blocked {
  border-style: solid; border-color: #DED4DC; background: #EFE9EE;
  cursor: not-allowed;
}
.seat.blocked .blocked-icon { font-size: 26px; opacity: .9; margin-bottom: 2px; }
.seat.blocked .marker { color: #B6ABC0; }
.seat.blocked.drop-hover { transform: none; border-color: #DED4DC; }
.seat .marker {
  position: absolute; top: 4px; left: 0; right: 0;
  text-align: center; font-size: 10px; color: var(--ink-soft);
}

/* ---------- 乘客卡片 ---------- */
.tray-wrap { background: var(--card); border-radius: 22px; padding: 14px; box-shadow: var(--shadow); margin-bottom: 14px; }
.tray-label, .train-label { font-weight: 600; }
.tray-label { font-size: 13px; color: var(--ink-soft); margin-bottom: 10px; text-align: center; }
.tray { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; min-height: 76px; }

.person {
  width: 64px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  cursor: grab; user-select: none; touch-action: none;
  transition: transform .1s;
}
.person:active { cursor: grabbing; }
.person.selected { transform: translateY(-4px); }
.person .avatar { width: 52px; height: 52px; }
.person .pname { font-size: 11px; color: var(--ink); }
.person.dragging { opacity: .35; }

.ghost {
  position: fixed; pointer-events: none; z-index: 999;
  width: 52px; height: 52px; transform: translate(-50%, -50%) scale(1.1);
}

/* 需求气泡 */
.needs { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; align-items: center; }
.need { font-size: 10px; padding: 2px 7px; border-radius: 10px; background: #F3EEF3; color: var(--ink-soft); }
.need.ok { background: var(--green-soft); color: #4E8B43; }
.need.bad { background: var(--danger-soft); color: #C25C68; }

/* ---------- 控制区 ---------- */
.controls { display: flex; align-items: center; gap: 12px; margin-top: auto; }
.timer {
  font-size: 15px; font-weight: 700; color: var(--ink);
  background: var(--card); border: 1.5px solid var(--line);
  border-radius: 12px; padding: 6px 10px; white-space: nowrap;
}
.timer.low { color: var(--danger); border-color: var(--danger); }
.btn-soft {
  background: var(--blue-soft); color: #3E7CA0; border: none;
  border-radius: 14px; padding: 10px 16px; font-size: 14px; cursor: pointer; font-weight: 600;
}
.status { flex: 1; text-align: right; font-size: 13px; color: var(--ink-soft); }

/* 提示按钮角标 */
.badge {
  display: inline-block; min-width: 18px; padding: 1px 6px;
  margin-left: 2px; border-radius: 10px;
  background: #fff; color: #3E7CA0; font-size: 12px; font-weight: 700;
}
.btn-soft.empty { background: var(--yellow); color: #9A6B12; }

/* 广告弹窗 */
.ad-card {
  background: #fff; border-radius: 22px; width: 84%; max-width: 320px;
  overflow: hidden; box-shadow: var(--shadow); animation: pop .25s ease;
}
.ad-head {
  background: var(--blue); color: #fff; font-size: 13px; font-weight: 600;
  padding: 8px 14px; letter-spacing: 1px;
}
.ad-body {
  padding: 34px 18px; text-align: center; font-size: 14px;
  color: var(--ink); min-height: 60px; display: flex; align-items: center; justify-content: center;
}
.ad-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--ink-soft);
}

/* ---------- 过关弹窗 ---------- */
.overlay {
  /* 相对「视口」居中：inset:0 + margin:auto 比 transform 更稳（不受滚动条宽度影响） */
  position: fixed;
  inset: 0;
  margin: 0 auto;
  max-width: 480px;
  background: rgba(90,81,104,.4);
  display: flex; align-items: center; justify-content: center; z-index: 50;
  backdrop-filter: blur(2px);
  padding: 16px;
}
.win-card {
  background: #fff; border-radius: 24px; padding: 28px 26px; width: 80%;
  max-width: 320px; text-align: center; box-shadow: var(--shadow);
  animation: pop .25s ease;
}
@keyframes pop { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.win-emoji { font-size: 48px; }
.win-card h2 { margin: 6px 0 10px; color: var(--ink); }
.stars { font-size: 30px; letter-spacing: 4px; margin-bottom: 8px; color: var(--gold); }
.win-tip { font-size: 12px; color: var(--ink-soft); margin: 0 0 18px; }
.win-actions { display: flex; gap: 12px; }
.win-actions .btn-primary { flex: 1; letter-spacing: 1px; }
.win-actions .btn-soft { flex: 1; }

/* ---------- 音乐按钮状态 ---------- */
#btn-music { font-size: 14px; color: var(--ink-soft); padding: 6px 8px; }
#btn-music.muted { opacity: .45; text-decoration: line-through; }

/* ---------- 小人：待座呼吸 / 满意轻晃 ---------- */
.person .avatar { animation: breathe 3.4s ease-in-out infinite; transform-origin: center; }
.seat.ok .avatar { animation: bob 1.5s ease-in-out infinite; }
.seat.bad .avatar { animation: worry 1.7s ease-in-out infinite; }
@keyframes breathe { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-2.5px); } }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-4px) rotate(-2deg); } }
@keyframes worry { 0%,100% { transform: translateY(0) rotate(0); } 25% { transform: translateY(-1px) rotate(-3deg); } 75% { transform: translateY(-1px) rotate(3deg); } }

/* ---------- 过关动效 ---------- */
.confetti {
  position: absolute; top: -16px; border-radius: 2px; z-index: 60; pointer-events: none;
  animation: confetti-fall 1.7s cubic-bezier(.3,.7,.4,1) forwards;
}
@keyframes confetti-fall {
  0% { transform: translate(0, -10px) rotate(0); opacity: 1; }
  100% { transform: translate(var(--drift), 115vh) rotate(var(--rot)); opacity: .85; }
}
.win-emoji { animation: emojiPop .6s ease; }
@keyframes emojiPop {
  0% { transform: scale(.3) rotate(-12deg); }
  60% { transform: scale(1.2) rotate(6deg); }
  100% { transform: scale(1); }
}
.stars { animation: starPop .5s ease .1s both; }
@keyframes starPop {
  0% { transform: scale(.4); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* ---------- 总进度条 ---------- */
.progress-wrap { margin: 4px 0 14px; }
.progress-top { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-soft); margin-bottom: 6px; }
#star-text { color: var(--gold); font-weight: 700; }
.progress-bar {
  height: 12px; border-radius: 999px; background: #F0E6EE; overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(150,120,150,.18);
}
.progress-fill {
  height: 100%; width: 0%; border-radius: 999px;
  background: linear-gradient(90deg, #F7B7C4, #FCE3A0, #A8D5A2);
  transition: width .55s cubic-bezier(.3,.8,.4,1);
}

/* ---------- 成就入口 ---------- */
.ach-entry { margin-top: 10px; width: 100%; display: flex; align-items: center; justify-content: center; gap: 6px; }
.ach-entry .badge { background: #fff; color: #3E7CA0; }

/* ---------- 成就弹窗 ---------- */
.ach-card {
  background: #fff; border-radius: 22px; width: 88%; max-width: 380px; max-height: 80vh;
  display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow);
  animation: pop .25s ease;
}
.ach-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; font-weight: 700; color: var(--ink);
  border-bottom: 1px solid var(--line); background: linear-gradient(180deg, #FFF3F7, #fff);
}
.ach-list { padding: 10px 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.ach-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 14px; background: #F7F2F6; opacity: .6;
}
.ach-item.got { background: linear-gradient(90deg, var(--green-soft), var(--blue-soft)); opacity: 1; }
.ach-icon { font-size: 24px; width: 32px; text-align: center; }
.ach-name { font-size: 14px; font-weight: 700; color: var(--ink); }
.ach-desc { font-size: 11px; color: var(--ink-soft); }

/* ---------- 成就解锁浮层 ---------- */
.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%);
  background: rgba(90, 81, 104, .94); color: #fff; font-size: 13px;
  padding: 10px 16px; border-radius: 999px; z-index: 200; max-width: 84%;
  box-shadow: 0 8px 22px rgba(90, 81, 104, .35); animation: toastIn .3s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 14px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- 美术打磨 ---------- */
.seat {
  background: linear-gradient(180deg, #FFFFFF, #FBF3F8);
  box-shadow: inset 0 -3px 0 rgba(180,150,170,.10), 0 2px 4px rgba(180,150,170,.10);
}
.seat.filled { background: linear-gradient(180deg, #FFFFFF, #FDF7FB); }
.seat.ok { background: linear-gradient(180deg, #F3FBEF, #E4F4DE); }
.seat.bad { background: linear-gradient(180deg, #FDF1F3, #FBE4E8); }
.seat.ok::after {
  content: "✓"; position: absolute; top: -6px; right: -6px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--green); color: #fff; font-size: 13px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 5px rgba(120,160,110,.5); animation: badgePop .3s ease;
}
@keyframes badgePop { from { transform: scale(0); } 70% { transform: scale(1.25); } to { transform: scale(1); } }

.logo { animation: floaty 3.6s ease-in-out infinite; }
@keyframes floaty { 0%,100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-6px) rotate(2deg); } }

#scene-label {
  font-weight: 700; letter-spacing: 1px;
  background: linear-gradient(90deg, #E58AA0, #C9A24B, #6FA96A);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.btn-primary { background: linear-gradient(180deg, #F9C2CE, #F2A7B8); }

/* ---------- 菜单按钮行 ---------- */
.menu-btns { display: flex; gap: 10px; margin-top: 10px; }
.menu-btns .btn-soft { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; }
.menu-btns .badge { background: #fff; color: #3E7CA0; }

/* ---------- 分享弹窗 ---------- */
.share-card {
  background: #fff; border-radius: 22px; width: 92%; max-width: 400px; max-height: 88vh;
  display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow);
  animation: pop .25s ease;
}
.share-body { padding: 12px; overflow-y: auto; background: #F7F2F6; }
#share-canvas {
  width: 100%; height: auto; display: block; border-radius: 14px;
  box-shadow: 0 4px 14px rgba(180,150,170,.2);
}
.share-img {
  width: 100%; height: auto; display: block; border-radius: 14px;
  box-shadow: 0 4px 14px rgba(180,150,170,.2);
  -webkit-user-select: none; user-select: none;
}
.share-actions { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.share-actions .btn-soft, .share-actions .btn-primary { flex: 1; font-size: 13px; padding: 10px 8px; }

/* 过关弹窗多按钮排布 */
.win-actions { gap: 8px; }
.win-actions .btn-soft, .win-actions .btn-primary { font-size: 13px; padding: 12px 6px; }

/* ---------- 登录 / 用户栏 ---------- */
.login-bar { margin: 10px 0 0; }
.login-btn { width: 100%; }
.user-bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 8px 12px;
  box-shadow: 0 2px 6px rgba(180,150,170,.08);
}
.user-avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: #F0E6EE; flex-shrink: 0; }
.user-meta { flex: 1; min-width: 0; }
.user-nickname { font-size: 14px; font-weight: 700; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-region { font-size: 11px; color: var(--ink-soft); }
.hidden { display: none !important; }

/* ---------- 地区排名页 ---------- */
.rank-card {
  background: #fff; border-radius: 22px; width: 92%; max-width: 420px; max-height: 86vh;
  display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow);
  animation: pop .25s ease;
}
.rank-tabs {
  display: flex; gap: 6px; padding: 10px 12px 0; flex-wrap: wrap;
}
.rank-tab {
  flex: 1; min-width: 0; padding: 8px 4px; border: 1px solid var(--line);
  background: #F7F2F6; border-radius: 10px; color: var(--ink-soft);
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.rank-tab.active { background: var(--pink); color: #fff; border-color: transparent; }
.rank-pick {
  flex: 1; min-width: 0; padding: 8px 10px; border: 1px solid var(--line);
  background: #fff; border-radius: 10px; font-size: 13px;
}
.rank-type-row {
  display: flex; align-items: center; gap: 6px; padding: 10px 14px 0;
  font-size: 12px; color: var(--ink-soft);
}
.rank-type-label { color: var(--ink-soft); }
.rank-type-btn {
  padding: 5px 10px; border: 1px solid var(--line); background: #fff;
  border-radius: 999px; font-size: 12px; color: var(--ink-soft); cursor: pointer;
}
.rank-type-btn.active { background: var(--blue-soft); color: #3E7CA0; border-color: transparent; font-weight: 700; }
.rank-period-row {
  display: flex; align-items: center; gap: 6px; padding: 10px 14px 0;
  font-size: 12px; color: var(--ink-soft);
}
.rank-period-btn {
  padding: 5px 12px; border: 1px solid var(--line); background: #fff;
  border-radius: 999px; font-size: 12px; color: var(--ink-soft); cursor: pointer;
}
.rank-period-btn.active { background: var(--pink-soft); color: #C25C68; border-color: transparent; font-weight: 700; }
.rank-region-label { padding: 8px 16px 4px; font-size: 12px; color: var(--ink-soft); }
.rank-list {
  flex: 1; overflow-y: auto; padding: 4px 8px 12px;
  min-height: 200px;
}
.rank-list-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border-radius: 10px; background: #FAFAFA; margin-bottom: 4px;
}
.rank-list-item.me { background: linear-gradient(90deg, var(--pink-soft), var(--blue-soft)); font-weight: 700; }
.rank-rank { width: 28px; text-align: center; font-weight: 700; color: var(--ink-soft); font-size: 14px; }
.rank-rank.top { color: var(--gold); font-size: 16px; }
.rank-value .gold { color: var(--gold); }
.rank-avatar { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; background: #F0E6EE; flex-shrink: 0; }
.rank-info { flex: 1; min-width: 0; }
.rank-nickname { font-size: 13px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-region-mini { font-size: 10px; color: var(--ink-soft); }
.rank-value { font-size: 14px; font-weight: 700; color: var(--ink); }
.rank-you {
  padding: 10px 16px; border-top: 1px solid var(--line);
  background: #FAFAFA; font-size: 13px; color: var(--ink);
}
.rank-you .you-rank { color: var(--pink); font-weight: 700; }

/* 地区选择 */
.user-name-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.region-chip {
  border: none; background: var(--blue-soft); color: #3E7CA0;
  font-size: 12px; padding: 3px 8px; border-radius: 999px;
  cursor: pointer; white-space: nowrap; flex-shrink: 0;
}
.region-card {
  background: #fff; border-radius: 22px; width: 88%; max-width: 340px;
  overflow: hidden; box-shadow: var(--shadow); animation: pop .25s ease;
}
.region-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.region-tip { margin: 0; font-size: 12px; color: var(--ink-soft); }
.region-field { display: flex; align-items: center; gap: 10px; }
.region-field span { width: 44px; font-size: 14px; color: var(--ink); flex-shrink: 0; }
.region-field select, .region-field input {
  flex: 1; padding: 9px 10px; border: 1px solid var(--line);
  border-radius: 10px; font-size: 14px; color: var(--ink); background: #fff;
}
.region-body .btn-primary { margin-top: 4px; letter-spacing: 1px; }
