:root {
  color-scheme: light;
  --ink: #34405f;
  --muted: #71809f;
  --white: #fffdf8;
  --sky: #7eddf6;
  --blue: #4db4ed;
  --purple: #7059d8;
  --pink: #ff7698;
  --orange: #ff9f42;
  --yellow: #ffd85a;
  --green: #73c96b;
  --shadow: 0 8px 0 rgba(69, 83, 126, .12), 0 18px 36px rgba(71, 100, 145, .16);
  --round: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #8fe4f5;
  color: var(--ink);
  font-family: var(--round);
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

button,
a { font: inherit; }

button {
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

#scene {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#scene.holding { cursor: grabbing; }

.mobile-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(100%, 560px);
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 14px 8px;
  pointer-events: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px 7px 8px;
  border: 3px solid rgba(255, 255, 255, .82);
  border-radius: 20px;
  background: rgba(255, 253, 248, .9);
  box-shadow: 0 5px 0 rgba(71, 120, 162, .14);
}

.brand-mascot {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 13px;
  background: #e6f8d7;
  font-size: 22px;
}

.brand h1 {
  margin: 0;
  color: #42527b;
  font-size: 19px;
  line-height: 1.05;
  letter-spacing: .1em;
}

.brand p {
  margin: 3px 0 0;
  color: var(--pink);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .08em;
}

.header-actions {
  display: flex;
  gap: 7px;
  pointer-events: auto;
}

.bubble-btn {
  display: grid;
  place-items: center;
  width: 43px;
  height: 43px;
  padding: 0;
  border: 3px solid rgba(255, 255, 255, .9);
  border-radius: 16px;
  background: rgba(255, 253, 248, .92);
  box-shadow: 0 5px 0 rgba(71, 120, 162, .16);
  font-size: 20px;
  font-weight: 900;
  cursor: pointer;
}

.bubble-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(71, 120, 162, .16); }

.player-strip {
  position: fixed;
  top: calc(73px + env(safe-area-inset-top));
  left: 50%;
  z-index: 3;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  width: min(calc(100% - 24px), 536px);
  transform: translateX(-50%);
  pointer-events: none;
}

.player-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 144px;
  padding: 6px 11px 6px 7px;
  border: 2px solid rgba(255, 255, 255, .75);
  border-radius: 16px;
  background: rgba(255, 253, 248, .82);
  box-shadow: 0 4px 0 rgba(71, 120, 162, .12);
  pointer-events: auto;
  cursor: pointer;
}

.player-chip > span:first-child {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 11px;
  background: #fff0b5;
  font-size: 19px;
}

.player-chip > span:last-child { display: flex; flex-direction: column; align-items: flex-start; }
.player-chip small { color: var(--muted); font-size: 8px; }
.player-chip b { max-width: 88px; overflow: hidden; color: var(--purple); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }

.mini-stats {
  display: flex;
  align-items: center;
  padding: 5px 7px;
  border: 2px solid rgba(255, 255, 255, .75);
  border-radius: 16px;
  background: rgba(255, 253, 248, .82);
  box-shadow: 0 4px 0 rgba(71, 120, 162, .12);
}

.mini-stats span {
  padding: 0 8px;
  color: var(--muted);
  font-size: 9px;
  text-align: center;
}

.mini-stats span + span { border-left: 1px dashed rgba(112, 89, 216, .25); }
.mini-stats b { display: block; color: var(--orange); font-size: 14px; line-height: 1.2; }

.challenge-hud {
  position: fixed;
  top: calc(126px + env(safe-area-inset-top));
  left: 50%;
  z-index: 5;
  width: min(calc(100% - 28px), 420px);
  padding: 11px 14px 12px;
  transform: translateX(-50%);
  border: 3px solid white;
  border-radius: 20px;
  background: rgba(255, 253, 248, .94);
  box-shadow: var(--shadow);
}

.challenge-topline { display: flex; align-items: center; justify-content: space-between; }
.challenge-topline > span { color: var(--pink); font-size: 12px; font-weight: 900; }
.challenge-topline > b { color: var(--purple); font-size: 10px; }
.challenge-topline em { font-size: 18px; font-style: normal; }
.target-line { margin-top: 2px; color: var(--muted); font-size: 10px; }
.target-line strong { color: var(--orange); font-size: 12px; }
.progress { height: 8px; margin-top: 8px; overflow: hidden; border-radius: 999px; background: #e8eef5; }
.progress i { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--yellow), var(--pink)); }

.speed-badge {
  position: fixed;
  top: 31%;
  right: max(13px, calc((100% - 540px) / 2 + 13px));
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 61px;
  padding: 8px 10px;
  border: 3px solid rgba(255, 255, 255, .84);
  border-radius: 18px;
  background: rgba(255, 253, 248, .84);
  box-shadow: 0 5px 0 rgba(71, 120, 162, .12);
}

.speed-badge b { color: var(--purple); font-size: 23px; line-height: 1; font-variant-numeric: tabular-nums; }
.speed-badge span { margin-top: 3px; color: var(--muted); font-size: 8px; }

.guide {
  position: fixed;
  left: 50%;
  bottom: calc(158px + env(safe-area-inset-bottom));
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 9px;
  width: max-content;
  max-width: calc(100% - 28px);
  padding: 10px 15px 10px 10px;
  transform: translateX(-50%);
  border: 3px solid rgba(255, 255, 255, .86);
  border-radius: 22px;
  background: rgba(255, 253, 248, .88);
  box-shadow: 0 5px 0 rgba(71, 120, 162, .12);
  pointer-events: none;
  transition: opacity .5s ease, transform .5s ease;
}

.guide.gone { opacity: 0; transform: translate(-50%, 8px); }
.guide .finger { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 14px; background: #fff1a9; font-size: 21px; animation: finger-orbit 2.4s ease-in-out infinite; }
.guide > span:last-child { display: flex; flex-direction: column; }
.guide strong { color: var(--purple); font-size: 12px; }
.guide small { margin-top: 2px; color: var(--muted); font-size: 9px; }

.wah-layer { position: fixed; inset: 0; z-index: 3; overflow: hidden; pointer-events: none; }
.wah-word { position: absolute; font-size: clamp(26px, 8vw, 48px); font-weight: 900; text-shadow: 0 3px 0 white, 0 9px 20px rgba(80, 90, 130, .22); animation: wah-float 1.15s ease-out forwards; }

.controls {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 4;
  width: min(100%, 560px);
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0), rgba(255, 253, 248, .35) 35%, rgba(255, 253, 248, .75));
}

.challenge-btn {
  width: 100%;
  min-height: 56px;
  padding: 9px 18px;
  border: 3px solid #fff;
  border-radius: 21px;
  background: linear-gradient(135deg, #ff8d67, var(--pink));
  box-shadow: 0 7px 0 #db5378, 0 15px 30px rgba(210, 84, 121, .22);
  color: white;
  font-weight: 900;
  cursor: pointer;
}

.challenge-btn:active { transform: translateY(4px); box-shadow: 0 3px 0 #db5378, 0 9px 20px rgba(210, 84, 121, .18); }
.challenge-btn span { display: block; font-size: 15px; letter-spacing: .05em; }
.challenge-btn small { display: block; margin-top: 2px; font-size: 9px; opacity: .85; }
.challenge-btn.running { background: linear-gradient(135deg, #6d5fe0, #9b7eea); box-shadow: 0 7px 0 #5342bd, 0 15px 30px rgba(83, 66, 189, .22); }

.control-row { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 11px; }
.control-row.motion-ready { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.soft-btn { min-width: 0; height: 43px; padding: 0 6px; border: 3px solid white; border-radius: 17px; background: rgba(255, 253, 248, .94); box-shadow: 0 5px 0 rgba(76, 95, 143, .15); color: var(--purple); font-size: 12px; font-weight: 800; cursor: pointer; }
.soft-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(76, 95, 143, .15); }
.soft-btn[aria-pressed="true"] { background: #efeafe; }
.motion-btn[aria-pressed="true"] { background: #e7f8ff; color: #2584bd; }
.sound-btn[aria-pressed="true"] { color: var(--muted); }
.soft-btn:disabled { opacity: .5; cursor: not-allowed; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(78, 94, 138, .36);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.modal[hidden] { display: none; }

.modal-card {
  position: relative;
  width: min(100%, 440px);
  max-height: min(760px, calc(100vh - 36px));
  overflow-y: auto;
  padding: 30px 22px 24px;
  border: 5px solid white;
  border-radius: 30px;
  background: var(--white);
  box-shadow: 0 11px 0 rgba(86, 104, 151, .18), 0 30px 80px rgba(63, 82, 126, .28);
  text-align: center;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  display: grid;
  place-items: center;
  width: 35px;
  height: 35px;
  padding: 0;
  border: 0;
  border-radius: 13px;
  background: #edf1f8;
  color: var(--muted);
  font-size: 22px;
  font-weight: 900;
  cursor: pointer;
}

.eyebrow,
.welcome-kicker { color: var(--pink); font-size: 10px; font-weight: 900; letter-spacing: .1em; }
.modal-card h2 { margin: 7px 0 10px; color: var(--purple); font-size: 24px; }
.modal-card h3 { margin: 18px 0 8px; color: var(--purple); font-size: 14px; }
.modal-card p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.8; }
.card-emoji { display: block; margin-bottom: 8px; font-size: 40px; }

.welcome-card { overflow: hidden; padding-top: 34px; }
.welcome-avatar { display: grid; place-items: center; width: 88px; height: 88px; margin: 18px auto 12px; border: 5px solid white; border-radius: 30px; background: linear-gradient(145deg, #fff1a8, #ffc6d5); box-shadow: 0 7px 0 rgba(232, 139, 112, .18); font-size: 48px; animation: welcome-bounce 1.3s ease-in-out infinite; }
.welcome-card h2 { font-size: 27px; }
.welcome-card > p { max-width: 280px; margin: 0 auto; }
.countdown { width: 72%; height: 8px; margin: 20px auto 7px; overflow: hidden; border-radius: 999px; background: #e8edf6; }
.countdown i { display: block; width: 100%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--yellow), var(--pink)); animation: countdown 3s linear forwards; }
.profile-modal:not(.ready) .countdown i { animation: none; }
.welcome-card > small { color: var(--purple); font-size: 10px; font-weight: 800; }
.welcome-card .privacy-note { margin-top: 17px; color: #9aa5b9; font-size: 8px; }
.party-dots i { position: absolute; width: 9px; height: 9px; border-radius: 3px; background: var(--pink); transform: rotate(22deg); }
.party-dots i:nth-child(1) { top: 34px; left: 30px; }
.party-dots i:nth-child(2) { top: 70px; right: 25px; background: var(--yellow); }
.party-dots i:nth-child(3) { bottom: 75px; left: 35px; background: var(--blue); }
.party-dots i:nth-child(4) { bottom: 32px; right: 40px; background: var(--green); }
.party-dots i:nth-child(5) { top: 22px; right: 95px; background: var(--purple); }

.principle { display: flex; align-items: center; justify-content: center; gap: 4px; margin: 17px 0; }
.principle span { padding: 7px 8px; border-radius: 12px; background: #eef8ff; color: var(--blue); font-size: 10px; font-weight: 900; }
.principle span:nth-of-type(2) { background: #fff6ce; color: #d89916; }
.principle span:nth-of-type(3) { background: #eaf8e6; color: var(--green); }
.principle span:nth-of-type(4) { background: #ffe5ec; color: var(--pink); }
.principle i { color: #a8b2c5; font-style: normal; }

.board-note { margin-bottom: 15px !important; font-size: 9px !important; }
.leaderboard-list { display: flex; flex-direction: column; gap: 7px; margin: 13px 0 0; padding: 0; list-style: none; text-align: left; }
.leaderboard-list li { display: grid; grid-template-columns: 28px 36px 1fr auto; align-items: center; gap: 8px; min-height: 49px; padding: 6px 10px; border-radius: 16px; background: #f2f6fb; }
.leaderboard-list li.me { outline: 2px solid #ffb1c2; background: #fff0f4; }
.rank-number { display: grid; place-items: center; width: 27px; height: 27px; border-radius: 10px; background: #dfe7f2; color: var(--muted); font-size: 11px; font-weight: 900; }
.leaderboard-list li:nth-child(1) .rank-number { background: #ffe483; color: #a66b00; }
.leaderboard-list li:nth-child(2) .rank-number { background: #e4e9f0; color: #66748a; }
.leaderboard-list li:nth-child(3) .rank-number { background: #ffd1aa; color: #ad6124; }
.rank-avatar { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 12px; background: white; font-size: 19px; }
.rank-person { min-width: 0; }
.rank-person b { display: block; overflow: hidden; color: var(--ink); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.rank-person small { color: #98a3b6; font-size: 8px; }
.rank-score { color: var(--pink); font-size: 15px; font-weight: 900; }
.rank-score small { margin-left: 2px; color: #9aa5b9; font-size: 8px; }
.empty-board { padding: 28px 10px 10px; }

.result-head { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 12px; text-align: left; }
.result-head h2 { margin: 0 0 4px; font-size: 20px; }
.result-head p { max-width: 190px; font-size: 10px; }
.result-seal { display: grid; flex: none; place-items: center; width: 64px; height: 64px; border: 4px solid var(--pink); border-radius: 22px; background: #ffe8ef; color: var(--pink); font-size: 32px; font-weight: 900; transform: rotate(-5deg); }
.result-score { display: flex; align-items: center; justify-content: center; gap: 22px; margin: 17px 0; padding: 13px; border-radius: 20px; background: #f5f1ff; }
.result-score span { display: flex; flex-direction: column; min-width: 72px; }
.result-score b { color: var(--purple); font-size: 32px; line-height: 1; }
.result-score small { margin-top: 4px; color: var(--muted); font-size: 9px; }
.result-score i { width: 1px; height: 38px; background: #d9d2ef; }
.compact-board { max-height: 196px; overflow-y: auto; }
.compact-board li { min-height: 42px; padding: 4px 8px; }
.challenge-btn.compact { min-height: 48px; margin-top: 16px; font-size: 12px; }

@keyframes finger-orbit {
  0%, 100% { transform: translateX(-2px) rotate(-10deg); }
  50% { transform: translateX(5px) rotate(12deg); }
}

@keyframes welcome-bounce {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-7px) rotate(2deg); }
}

@keyframes countdown { to { width: 0; } }

@keyframes wah-float {
  0% { opacity: 0; transform: translate(-50%, -35%) scale(.5) rotate(-6deg); }
  20% { opacity: 1; transform: translate(-50%, -65%) scale(1.08) rotate(2deg); }
  100% { opacity: 0; transform: translate(-50%, -155%) scale(.92) rotate(8deg); }
}

@media (min-width: 720px) {
  .mobile-header { padding-top: 18px; }
  .player-strip { top: 82px; }
  .challenge-hud { top: 138px; }
  .controls { padding-bottom: 18px; }
  .guide { bottom: 172px; }
}

@media (max-height: 690px) {
  .player-strip { top: calc(67px + env(safe-area-inset-top)); }
  .challenge-hud { top: calc(114px + env(safe-area-inset-top)); }
  .guide { bottom: calc(143px + env(safe-area-inset-bottom)); }
  .controls { padding-top: 6px; }
  .challenge-btn { min-height: 49px; }
  .soft-btn { height: 38px; }
  .control-row { margin-top: 7px; }
}

@media (max-width: 360px) {
  .brand { padding-right: 9px; }
  .brand h1 { font-size: 17px; }
  .brand p { font-size: 8px; }
  .player-chip { min-width: 132px; }
  .mini-stats span { padding: 0 6px; }
  .guide { padding-right: 11px; }
  .guide strong { font-size: 11px; }
  .control-row.motion-ready { gap: 6px; }
  .control-row.motion-ready .soft-btn { padding: 0 3px; font-size: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .guide .finger,
  .welcome-avatar,
  .countdown i { animation: none; }
}
