/* ============ 主题变量 ============ */
:root {
  --bg1: #6d5dfc;
  --bg2: #a855f7;
  --bg3: #ec4899;
  --card: #ffffff;
  --text: #2b2350;
  --text-light: #7a73a8;
  --primary: #ff5d8f;
  --primary-dark: #e84a7a;
  --secondary: #ffd166;
  --green: #2ec27e;
  --red: #ff6b6b;
  --gold: #ffb300;
  --shadow: 0 8px 24px rgba(60, 40, 120, 0.18);
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", -apple-system, sans-serif;
  color: var(--text);
  background: linear-gradient(160deg, var(--bg1), var(--bg2) 55%, var(--bg3));
  background-attachment: fixed;
  -webkit-user-select: none;
  user-select: none;
  overflow-x: hidden;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ============ 顶部栏 ============ */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  color: #fff;
}
#topbar-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 1px;
}
.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { background: rgba(255, 255, 255, 0.4); }

/* ============ 视图切换 ============ */
.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 20px 32px;
}
.hidden { display: none !important; }

.view-heading { color: #fff; font-size: 26px; margin: 16px 0 4px; }
.view-hint { color: rgba(255, 255, 255, 0.9); font-size: 14px; margin: 0 0 16px; }
.section-title { color: #fff; font-size: 16px; margin: 16px 0 8px; align-self: flex-start; }

/* ============ 首页 ============ */
.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin-top: 16px;
}
.avatar {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  border: 4px solid rgba(255, 255, 255, 0.7);
  overflow: hidden;
  flex-shrink: 0;
}
.avatar-lg { width: 110px; height: 110px; }
.avatar-md { width: 84px; height: 84px; }
.avatar-sm { width: 56px; height: 56px; }
.avatar-emoji { font-size: 2.2em; }
.avatar-sm .avatar-emoji { font-size: 1.6em; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.speech {
  background: #fff;
  border-radius: 16px;
  padding: 12px 18px;
  font-size: 15px;
  line-height: 1.5;
  text-align: center;
  box-shadow: var(--shadow);
  max-width: 320px;
  position: relative;
}
.speech::after {
  content: '';
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-bottom-color: #fff;
  border-top: none;
}

.game-title {
  margin: 26px 0 4px;
  font-size: 42px;
  font-weight: 900;
  color: #fff;
  letter-spacing: 3px;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.12);
}
.game-title span {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  border-radius: 12px;
  padding: 2px 12px;
  margin-left: 8px;
  font-size: 26px;
  vertical-align: middle;
}
.subtitle {
  color: rgba(255, 255, 255, 0.9);
  margin: 0 0 22px;
  font-size: 15px;
}

.home-actions {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 320px;
}
.home-stars {
  margin-top: 20px;
  color: #fff;
  font-size: 18px;
  font-weight: 700;
}

/* ============ 按钮 ============ */
.btn {
  border: none;
  border-radius: 999px;
  padding: 16px 28px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.12);
  width: 100%;
}
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--secondary); color: #7a4d00; }
.btn-ghost { background: rgba(255, 255, 255, 0.28); color: #fff; box-shadow: none; }
.btn-danger { background: #e05252; color: #fff; box-shadow: 0 5px 0 rgba(120, 20, 20, 0.25); }
.btn-danger:hover { background: #c94444; }

/* ============ 闯关页 ============ */
.game-head {
  display: flex;
  justify-content: space-between;
  width: 100%;
  color: #fff;
  font-weight: 700;
  margin-bottom: 8px;
}
.level-label { font-size: 18px; }
.progress-label { font-size: 16px; opacity: 0.9; }

.progress-bar, .timer-bar {
  width: 100%;
  height: 12px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 8px;
}
.progress-fill {
  height: 100%;
  background: var(--secondary);
  border-radius: 999px;
  transition: width 0.2s ease;
}
.timer-fill {
  height: 100%;
  background: var(--green);
  border-radius: 999px;
  transition: width 0.1s linear, background 0.3s ease;
}
.timer-fill.low { background: var(--red); }

.question {
  margin: 24px 0 22px;
  font-size: 52px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.15);
  letter-spacing: 2px;
}

.options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  width: 100%;
  max-width: 400px;
}
.option {
  border: none;
  border-radius: 18px;
  padding: 20px 12px;
  font-size: 30px;
  font-weight: 800;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.08s ease, background 0.15s ease;
}
.option:active { transform: scale(0.96); }
.option.correct { background: var(--green); color: #fff; }
.option.wrong { background: var(--red); color: #fff; }

/* ============ 动态队友（闯关页下半部） ============ */
.companion {
  position: relative;
  width: 104px;
  height: 104px;
  margin: 22px auto 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.avatar-game { width: 96px; height: 96px; border-width: 4px; }

.companion .avatar {
  animation: bounce 1.7s ease-in-out infinite;
  transition: box-shadow 0.3s ease;
}
.companion.idle .avatar {
  animation-duration: 1.7s;
  box-shadow: 0 0 0 6px rgba(46, 194, 126, 0.45), var(--shadow);
}
.companion.warn .avatar {
  animation-duration: 1.0s;
  box-shadow: 0 0 0 6px rgba(255, 179, 0, 0.6), var(--shadow);
}
.companion.worry .avatar {
  animation-duration: 0.5s;
  box-shadow: 0 0 0 6px rgba(255, 107, 107, 0.65), var(--shadow);
}
.companion.celebrate .avatar {
  animation: celebrate 0.6s ease;
  box-shadow: 0 0 0 8px rgba(255, 179, 0, 0.75), var(--shadow);
}
.companion.shake .avatar {
  animation: shake 0.5s ease;
}

.companion .burst {
  position: absolute;
  top: -18px;
  right: -14px;
  font-size: 30px;
  display: none;
  pointer-events: none;
}
.companion.celebrate .burst {
  display: block;
  animation: burst-pop 0.6s ease;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
@keyframes celebrate {
  0% { transform: translateY(0) rotate(0) scale(1); }
  30% { transform: translateY(-26px) rotate(-8deg) scale(1.12); }
  60% { transform: translateY(-10px) rotate(6deg) scale(1.05); }
  100% { transform: translateY(0) rotate(0) scale(1); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}
@keyframes burst-pop {
  0% { opacity: 0; transform: scale(0.4); }
  50% { opacity: 1; transform: scale(1.3); }
  100% { opacity: 0; transform: scale(1.6); }
}

/* ============ 结果页 ============ */
.result-stars {
  font-size: 52px;
  margin-top: 22px;
  letter-spacing: 6px;
}
.result-stars .star { color: rgba(255, 255, 255, 0.3); }
.result-stars .star.on { color: var(--gold); text-shadow: 0 2px 0 rgba(0, 0, 0, 0.15); }

.result-title { color: #fff; font-size: 30px; margin: 8px 0; }

.record-badge {
  background: var(--gold);
  color: #7a4d00;
  font-weight: 800;
  padding: 6px 18px;
  border-radius: 999px;
  margin-bottom: 8px;
  font-size: 16px;
  animation: pop 0.5s ease;
}
.unlock-badge { background: #7ef0b8; color: #0b6b3f; }
@keyframes pop {
  0% { transform: scale(0.4); opacity: 0; }
  70% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

.result-stats {
  display: flex;
  gap: 12px;
  margin: 8px 0 22px;
}
.stat {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 16px;
  padding: 12px 20px;
  min-width: 86px;
  display: flex;
  flex-direction: column;
  align-items: center;
  color: #fff;
}
.stat-num { font-size: 26px; font-weight: 800; }
.stat-label { font-size: 13px; opacity: 0.9; }

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 320px;
  margin-top: 8px;
}

/* ============ 成绩页 ============ */
.scores-head { margin: 12px 0; }
.total-stars {
  color: #fff;
  font-size: 26px;
  font-weight: 800;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 400px;
  margin-bottom: 24px;
}
.score-cell {
  background: #fff;
  border-radius: 16px;
  padding: 14px 8px;
  text-align: center;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.08s ease;
}
.score-cell:active { transform: scale(0.95); }
.score-cell.locked { opacity: 0.55; cursor: default; }
.score-level { font-weight: 800; font-size: 15px; margin-bottom: 4px; }
.score-stars { font-size: 18px; }
.score-time { font-size: 12px; color: var(--text-light); margin-top: 3px; }

.roster { width: 100%; max-width: 400px; margin-bottom: 20px; }
.roster-title { color: #fff; font-size: 18px; margin: 0 0 10px; }
.roster-list { display: flex; flex-direction: column; gap: 8px; }
.roster-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff;
  border-radius: 14px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
}
.roster-item.locked { opacity: 0.5; }
.roster-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  overflow: hidden;
  flex-shrink: 0;
}
.roster-avatar img { width: 100%; height: 100%; object-fit: cover; }
.roster-name { font-weight: 800; font-size: 16px; }
.roster-ip { margin-left: auto; font-size: 12px; color: var(--text-light); }

/* ============ 选择队友 ============ */
.select-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  max-width: 400px;
  margin-bottom: 20px;
}
.select-item {
  background: #fff;
  border-radius: 16px;
  padding: 16px 10px;
  text-align: center;
  box-shadow: var(--shadow);
  cursor: pointer;
  position: relative;
  transition: transform 0.08s ease;
}
.select-item:active { transform: scale(0.95); }
.select-item.locked { opacity: 0.55; cursor: default; }
.select-item.selected { outline: 4px solid var(--secondary); }
.select-avatar {
  width: 64px; height: 64px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px;
  margin: 0 auto 8px;
  overflow: hidden;
}
.select-avatar img { width: 100%; height: 100%; object-fit: cover; }
.select-name { font-weight: 800; font-size: 16px; }
.select-ip { font-size: 11px; color: var(--text-light); margin-top: 2px; }
.select-lock-hint { font-size: 12px; color: var(--text-light); margin-top: 4px; }

/* ============ 关卡详情 ============ */
.detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 400px;
  margin-top: 8px;
  color: #fff;
}
.detail-level { font-size: 22px; font-weight: 900; }
.detail-best { font-size: 16px; }

.detail-history, .detail-questions {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border-radius: 12px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  font-size: 14px;
}
.history-date { color: var(--text-light); font-size: 12px; }
.history-stars { margin-left: auto; font-weight: 700; }
.history-empty, .questions-empty {
  color: rgba(255, 255, 255, 0.85);
  font-size: 14px;
  text-align: center;
  padding: 12px;
}

.detail-questions {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}
.q-item {
  background: #fff;
  border-radius: 10px;
  padding: 8px 4px;
  text-align: center;
  font-size: 12px;
  box-shadow: var(--shadow);
  line-height: 1.4;
}
.q-item.ok { border-bottom: 3px solid var(--green); }
.q-item.bad { border-bottom: 3px solid var(--red); }
.q-expr { font-weight: 800; }
.q-given { color: var(--red); font-size: 11px; }
.q-mark { font-weight: 800; }

.detail-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 320px;
  margin-top: 20px;
}

/* ============ 宽屏适配 ============ */
@media (min-width: 600px) {
  .options { max-width: 460px; }
  .option { font-size: 34px; }
}
