:root {
  --pink: #ff6b9d;
  --pink-soft: #ffd0e0;
  --purple: #8b5cf6;
  --blue: #4dabf7;
  --dark: #1b1230;
  --dark2: #2a1c47;
  --text: #fdf7ff;
  --muted: #b9a8d4;
  --p1: #ff6b9d;
  --p2: #4dabf7;
  --ok: #43d17a;
  --warn: #ffb84d;
  --radius: 20px;
  --shadow: 0 18px 50px rgba(0, 0, 0, .45);
  --glass: rgba(255, 255, 255, .07);
  --glass-brd: rgba(255, 255, 255, .14);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background:
    radial-gradient(1200px 800px at 20% -10%, #4a2a7a 0%, transparent 55%),
    radial-gradient(1000px 700px at 110% 10%, #2b3a75 0%, transparent 50%),
    radial-gradient(900px 900px at 50% 120%, #6d2b5e 0%, transparent 55%),
    linear-gradient(160deg, #140d26 0%, #1b1230 50%, #241640 100%);
  background-attachment: fixed;
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, -apple-system, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

#app { height: 100%; display: flex; flex-direction: column; position: relative; }

/* 全局光晕装饰 */
#app::before {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(600px 400px at 15% 20%, rgba(255, 107, 157, .12), transparent 60%),
    radial-gradient(500px 400px at 85% 30%, rgba(139, 92, 246, .12), transparent 60%);
}

.hidden { display: none !important; }

/* ---------- 顶栏 ---------- */
#topbar {
  height: 54px; flex: 0 0 54px;
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px;
  background: rgba(20, 14, 38, .55);
  backdrop-filter: blur(16px) saturate(140%);
  border-bottom: 1px solid var(--glass-brd);
  z-index: 20;
}
#level-title {
  flex: 1; font-weight: 800; font-size: 15px; letter-spacing: .5px;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  background: linear-gradient(90deg, #ffd9e6, #c9b6ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tb-right { display: flex; gap: 8px; }
.tb-btn {
  border: 1px solid var(--glass-brd);
  background: rgba(255, 255, 255, .08);
  color: var(--text); border-radius: 13px;
  padding: 7px 12px; font-size: 13px; cursor: pointer;
  transition: .18s; backdrop-filter: blur(6px);
}
.tb-btn:hover { background: rgba(255, 255, 255, .18); transform: translateY(-1px); }

/* ---------- 场景 ---------- */
#scene { flex: 1; position: relative; overflow: hidden; z-index: 1; }
.screen {
  position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden;
  animation: fadeIn .3s ease;
  padding-bottom: 24px;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- 按钮 ---------- */
.btn {
  border: none; border-radius: 999px; padding: 13px 28px;
  font-size: 15px; font-weight: 800; cursor: pointer;
  transition: transform .12s, box-shadow .25s, filter .2s;
  font-family: inherit; letter-spacing: .5px;
  position: relative; overflow: hidden;
}
.btn:active { transform: scale(.94); }
.btn.primary {
  background: linear-gradient(135deg, #ff7eb3, #a06bff);
  color: #fff; box-shadow: 0 10px 26px rgba(255, 107, 157, .42), inset 0 1px 0 rgba(255, 255, 255, .35);
}
.btn.primary::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(120deg, transparent 30%, rgba(255, 255, 255, .35) 50%, transparent 70%);
  transform: translateX(-120%); transition: none;
}
.btn.primary:active::after { transform: translateX(120%); transition: transform .5s; }
.btn.primary:hover { filter: brightness(1.08); box-shadow: 0 14px 34px rgba(255, 107, 157, .55); }
.btn.ghost {
  background: rgba(255, 255, 255, .08); color: var(--text);
  border: 1px solid var(--glass-brd); backdrop-filter: blur(8px);
}
.btn.ghost:hover { background: rgba(255, 255, 255, .16); }
.btn.small { padding: 9px 18px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- 弹层 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(8, 5, 16, .66);
  backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; animation: fadeIn .2s ease;
}
.modal-card {
  width: min(460px, 100%); max-height: 86vh; overflow-y: auto;
  background: linear-gradient(160deg, rgba(60, 38, 92, .9), rgba(36, 26, 61, .92));
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 24px; padding: 28px 24px;
  box-shadow: var(--shadow); text-align: center;
  animation: pop .28s cubic-bezier(.2, .9, .3, 1.4);
}
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-card h3 { margin: 6px 0 12px; font-size: 22px;
  background: linear-gradient(90deg, #ffd9e6, #c9b6ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.modal-card p { color: var(--muted); line-height: 1.8; font-size: 14px; margin: 8px 0; }
.modal-actions { display: flex; gap: 12px; justify-content: center; margin-top: 22px; flex-wrap: wrap; }
#result-emoji { font-size: 56px; line-height: 1; filter: drop-shadow(0 6px 14px rgba(255, 107, 157, .4)); animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px); } }
.help-list { text-align: left; color: var(--muted); font-size: 14px; line-height: 1.9; }
.help-list b { color: var(--text); }
.key { display: inline-block; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.22);
  border-radius: 6px; padding: 1px 7px; font-size: 12px; margin: 0 2px; color: var(--text); font-weight: 700; }

/* ---------- 通用布局 ---------- */
.center-col { min-height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 26px 22px; gap: 18px; text-align: center; }
.pad { padding: 18px; }
.row { display: flex; gap: 10px; align-items: center; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.muted { color: var(--muted); font-size: 13px; }
.tag { display: inline-block; padding: 4px 12px; border-radius: 999px; font-size: 11px;
  background: rgba(255,255,255,.12); color: var(--muted); backdrop-filter: blur(6px); }

/* ---------- HUD ---------- */
.hud { display: flex; align-items: center; gap: 10px; justify-content: space-between;
  padding: 10px 14px; margin: 0 auto 12px; max-width: 880px;
  background: rgba(20, 14, 38, .5); border: 1px solid var(--glass-brd); border-radius: 16px;
  backdrop-filter: blur(10px); }
.hud .item { display: flex; flex-direction: column; align-items: center; min-width: 56px; }
.hud .item .k { font-size: 10px; color: var(--muted); letter-spacing: 1px; }
.hud .item .v { font-size: 19px; font-weight: 800; text-shadow: 0 2px 8px rgba(0,0,0,.4); }
.p1c { color: #ff8fb4; }
.p2c { color: #79c0ff; }

.bar { height: 10px; border-radius: 999px; background: rgba(255,255,255,.12); overflow: hidden; flex: 1;
  box-shadow: inset 0 1px 3px rgba(0,0,0,.4); }
.bar > i { display: block; height: 100%; border-radius: 999px; transition: width .25s; }

/* ---------- 画布 ---------- */
.canvas-wrap { display: flex; justify-content: center; padding: 0 10px 14px; }
canvas { max-width: 100%; border-radius: var(--radius); background: #100a20;
  border: 1px solid rgba(255,255,255,.12); box-shadow: var(--shadow); touch-action: none;
  box-shadow: 0 18px 50px rgba(0,0,0,.4), 0 0 0 1px rgba(255,255,255,.06) inset; }

/* ---------- 首页 ---------- */
.title-big {
  font-size: clamp(36px, 10vw, 66px); font-weight: 900; line-height: 1.08; letter-spacing: 1px;
  background: linear-gradient(120deg, #ff8fb1, #ffd2e0 38%, #b392ff 70%, #7dd3fc);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 8px 22px rgba(255,107,157,.4));
  animation: titleGlow 3s ease-in-out infinite;
}
@keyframes titleGlow { 50% { filter: drop-shadow(0 8px 30px rgba(139,92,246,.55)); } }
.subtitle { color: var(--muted); font-size: 14px; max-width: 380px; line-height: 1.85; }
.heart-float { position: absolute; font-size: 20px; opacity: .5; animation: rise linear infinite; pointer-events: none; filter: drop-shadow(0 0 6px rgba(255,255,255,.3)); }
@keyframes rise {
  from { transform: translateY(20px) scale(.7) rotate(0); opacity: 0; }
  20% { opacity: .6; }
  to { transform: translateY(-90vh) scale(1.15) rotate(20deg); opacity: 0; }
}
.name-inputs { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.name-inputs input {
  width: 132px; text-align: center; padding: 12px 12px; border-radius: 14px;
  border: 1px solid rgba(255,255,255,.2); background: rgba(255,255,255,.08);
  color: var(--text); font-size: 15px; font-family: inherit; outline: none; transition: .2s;
  backdrop-filter: blur(8px);
}
.name-inputs input:focus { border-color: var(--pink); box-shadow: 0 0 0 3px rgba(255,107,157,.25); }
.name-inputs input::placeholder { color: #8d7fa8; }

/* ---------- 关卡地图 ---------- */
.map-wrap { max-width: 880px; margin: 0 auto; padding: 20px 16px 40px; }
.map-head { text-align: center; margin-bottom: 20px; }
.map-head h2 { margin: 4px 0 6px; font-size: 23px;
  background: linear-gradient(90deg, #ffd9e6, #c9b6ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.progress-line { display: flex; align-items: center; gap: 10px; max-width: 440px; margin: 14px auto 0; }
.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 13px; }
.level-card {
  position: relative; text-align: left; cursor: pointer; overflow: hidden;
  background: linear-gradient(160deg, rgba(255,255,255,.11), rgba(255,255,255,.04));
  border: 1px solid var(--glass-brd); border-radius: 18px; padding: 15px 15px 13px;
  transition: transform .18s, box-shadow .25s, border-color .2s;
  backdrop-filter: blur(8px);
}
.level-card::before {
  content: ''; position: absolute; inset: 0; opacity: 0; transition: .25s; pointer-events: none;
  background: radial-gradient(120px 80px at 80% 0%, rgba(255,107,157,.25), transparent 60%);
}
.level-card:hover { transform: translateY(-4px); border-color: rgba(255,107,157,.6); box-shadow: 0 14px 32px rgba(255,107,157,.22); }
.level-card:hover::before { opacity: 1; }
.level-card .no { font-size: 11px; color: var(--muted); letter-spacing: 1.5px; }
.level-card .ico { font-size: 32px; margin: 5px 0 7px; filter: drop-shadow(0 4px 10px rgba(0,0,0,.35)); }
.level-card .nm { font-weight: 800; font-size: 15px; }
.level-card .ty { margin-top: 6px; font-size: 11px; color: var(--muted); }
.level-card.locked { opacity: .45; cursor: not-allowed; filter: grayscale(.5); }
.level-card.locked:hover { transform: none; border-color: var(--glass-brd); box-shadow: none; }
.level-card .lock { position: absolute; right: 12px; top: 12px; font-size: 15px; }
.level-card .star { position: absolute; right: 10px; top: 10px; font-size: 15px; color: #ffd86b; text-shadow: 0 0 8px rgba(255,216,107,.6); }
.level-card.done { border-color: rgba(67,209,122,.55); box-shadow: 0 0 0 1px rgba(67,209,122,.2); }
.badge-type {
  position: absolute; left: 0; top: 0; padding: 3px 10px; font-size: 10px; font-weight: 800;
  border-bottom-right-radius: 12px; backdrop-filter: blur(4px);
}
.t-quiz { background: #f472b6; }
.t-td { background: #f59e0b; color: #3b2600; }
.t-vs { background: #ef4444; }
.t-coop { background: #22c55e; color: #06280f; }
.t-brain { background: #38bdf8; color: #052b3d; }
.t-final { background: linear-gradient(90deg, #ff6b9d, #8b5cf6); }

/* ---------- 触屏控制条 ---------- */
.touch-pads { display: none; gap: 10px; padding: 8px 12px 16px; }
.touch-pads .pad-side { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.touch-pads .lbl { font-size: 11px; color: var(--muted); }
.tp-row { display: flex; gap: 6px; }
.tp {
  width: 54px; height: 48px; border-radius: 13px; border: 1px solid rgba(255,255,255,.2);
  background: rgba(255,255,255,.1); color: var(--text); font-size: 17px; font-weight: 800;
  display: flex; align-items: center; justify-content: center; transition: .12s;
}
.tp:active { background: rgba(255,255,255,.3); transform: scale(.92); }
.tp.p1 { border-color: rgba(255,107,157,.5); }
.tp.p2 { border-color: rgba(77,171,247,.5); }
body.touch .touch-pads { display: flex; }

/* ---------- 卡片/网格通用 ---------- */
.q-card {
  max-width: 620px; margin: 0 auto; background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.13); border-radius: var(--radius); padding: 20px;
  backdrop-filter: blur(8px);
}
.opt-list { display: grid; gap: 11px; margin-top: 14px; }
.opt {
  padding: 14px 17px; border-radius: 15px; cursor: pointer; text-align: left; font-size: 15px;
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.16); color: var(--text);
  transition: .18s; font-family: inherit; backdrop-filter: blur(6px); position: relative; overflow: hidden;
}
.opt:hover { background: rgba(255,255,255,.16); border-color: var(--pink); transform: translateX(3px); }
.opt.sel-p1 { border-color: var(--p1); background: rgba(255,107,157,.22); }
.opt.sel-p2 { border-color: var(--p2); background: rgba(77,171,247,.22); }
.opt.right { border-color: var(--ok); background: rgba(67,209,122,.22); box-shadow: 0 0 18px rgba(67,209,122,.3); }
.opt.wrong { border-color: #ef4444; background: rgba(239,68,68,.18); }
.opt:disabled { cursor: default; }
.opt .pick-p1, .opt .pick-p2 { font-size: 11px; margin-left: 6px; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: rgba(18, 12, 32, .96); border: 1px solid rgba(255,255,255,.22);
  padding: 11px 22px; border-radius: 999px; font-size: 14px; z-index: 200;
  animation: fadeIn .18s ease; pointer-events: none; max-width: 90vw; text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
}

/* ---------- 结局页 ---------- */
.ending {
  min-height: 100%; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 18px; padding: 30px 22px; text-align: center;
}
.cert {
  max-width: 420px; width: 100%; padding: 28px 22px; border-radius: 22px;
  background: linear-gradient(160deg, rgba(255,209,224,.16), rgba(167,139,250,.14));
  border: 1px solid rgba(255,255,255,.24); backdrop-filter: blur(10px);
  box-shadow: 0 18px 50px rgba(139,92,246,.3);
}
.cert h3 { margin: 0 0 4px; font-size: 21px;
  background: linear-gradient(90deg, #ffd9e6, #c9b6ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.cert .names { font-size: 27px; font-weight: 900; margin: 14px 0; color: #ffd9e6; text-shadow: 0 2px 14px rgba(255,107,157,.4); }
.cert .line { color: var(--muted); font-size: 13px; line-height: 1.9; }

/* ---------- 连接状态点 ---------- */
.conn-dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.conn-dot.ok { background: #43d17a; box-shadow: 0 0 10px #43d17a; }
.conn-dot.wait { background: #ffb84d; box-shadow: 0 0 10px #ffb84d; animation: blink 1s infinite; }
.conn-dot.off { background: #888; }
@keyframes blink { 50% { opacity: .3; } }

.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.18); border-top-color: var(--pink);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.copy-row { display: flex; justify-content: center; }
.tag.role { background: linear-gradient(90deg,#ff6b9d,#8b5cf6); }

/* ---------- 记忆翻牌 ---------- */
.mem-cell {
  aspect-ratio: 1; border-radius: 13px; display: flex; align-items: center; justify-content: center;
  font-size: 26px; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.18);
  cursor: pointer; transition: .15s; user-select: none; backdrop-filter: blur(6px);
}
.mem-cell:active { transform: scale(.94); }
.mem-cell.matched { background: rgba(67,209,122,.22); border-color: rgba(67,209,122,.5); box-shadow: 0 0 16px rgba(67,209,122,.25); }

.opt.sel-p1, .btn.sel-p1 { border-color: var(--p1) !important; background: rgba(255,107,157,.25) !important; }
.opt.sel-p2, .btn.sel-p2 { border-color: var(--p2) !important; background: rgba(77,171,247,.25) !important; }

/* ============ CG 过场 / 开场动画 ============ */
#cg-overlay {
  position: fixed; inset: 0; z-index: 500; pointer-events: none;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .45s ease;
  background: radial-gradient(800px 600px at 50% 40%, rgba(40,24,70,.6), rgba(8,5,16,.92));
}
#cg-overlay.show { opacity: 1; }
#cg-overlay.transition { background: rgba(8,5,16,.92); }
#cg-overlay.big { background: rgba(8,5,16,.55); }

.cg-card { text-align: center; animation: cgIn .6s cubic-bezier(.2,.9,.3,1.3); }
@keyframes cgIn { from { transform: scale(.8) translateY(14px); opacity: 0; } to { transform: scale(1) translateY(0); opacity: 1; } }
.cg-title {
  font-size: clamp(28px, 8vw, 48px); font-weight: 900; letter-spacing: 2px;
  background: linear-gradient(120deg, #ff8fb1, #c9b6ff, #7dd3fc);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 6px 18px rgba(255,107,157,.45));
}
.cg-sub { margin-top: 8px; color: var(--muted); font-size: 14px; letter-spacing: 1px; }
.cg-bar { width: 120px; height: 3px; border-radius: 999px; margin: 18px auto 0;
  background: linear-gradient(90deg, transparent, var(--pink), transparent); animation: cgBar 1.2s ease-in-out infinite; }
@keyframes cgBar { 0%,100% { opacity: .4; width: 80px; } 50% { opacity: 1; width: 160px; } }

.cg-big {
  font-size: clamp(42px, 14vw, 96px); font-weight: 900; letter-spacing: 4px;
  text-shadow: 0 10px 40px rgba(0,0,0,.5); animation: bigPop 1.1s cubic-bezier(.2,.9,.3,1.4);
}
@keyframes bigPop { from { transform: scale(.4) rotate(-6deg); opacity: 0; } to { transform: scale(1) rotate(0); opacity: 1; } }

/* 开场 CG */
#cg-overlay.intro { background: radial-gradient(900px 700px at 50% 35%, #3a2160, #0a0612 70%); }
.cg-intro { text-align: center; position: relative; z-index: 2; }
.cg-intro-title {
  font-size: clamp(40px, 12vw, 86px); font-weight: 900; letter-spacing: 3px; line-height: 1.05;
  background: linear-gradient(120deg, #ff9ec4, #ffd2e0 35%, #b392ff 65%, #7dd3fc);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 10px 30px rgba(255,107,157,.5));
  animation: introTitle 1s cubic-bezier(.2,.9,.3,1.3) both;
}
@keyframes introTitle { from { transform: translateY(40px) scale(.9); opacity: 0; filter: blur(8px); } to { transform: none; opacity: 1; filter: none; } }
.cg-intro-sub { margin-top: 14px; color: #d9c9ff; font-size: clamp(13px, 3.4vw, 17px); letter-spacing: 4px;
  animation: introSub 1s .5s ease both; opacity: 0; }
@keyframes introSub { from { opacity: 0; letter-spacing: 12px; } to { opacity: 1; letter-spacing: 4px; } }
.cg-intro-bar { width: 0; height: 3px; border-radius: 999px; margin: 22px auto 0;
  background: linear-gradient(90deg, var(--pink), var(--purple), var(--blue));
  animation: introBar 2s .3s ease-in-out forwards; }
@keyframes introBar { from { width: 0; opacity: 0; } 30% { opacity: 1; } to { width: 220px; opacity: 1; } }
.cg-star { position: absolute; width: 3px; height: 3px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 8px 2px rgba(255,255,255,.7); z-index: 1;
  animation: cgTwinkle 3s ease-in-out infinite; }
@keyframes cgTwinkle { 0%,100% { opacity: .2; transform: scale(.6); } 50% { opacity: 1; transform: scale(1.3); } }

@media (max-width: 520px) {
  .level-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .modal-card { padding: 22px 18px; }
  .hud { gap: 8px; padding: 8px 10px; }
  .hud .item .v { font-size: 16px; }
  .title-big { font-size: clamp(34px, 11vw, 52px); }
}
