:root {
  color-scheme: light;
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  color: #35405a;
  background: #fff9f5;
  font-synthesis: none;
  --ink: #35405a;
  --muted: #7c859d;
  --line: #ece5ec;
  --sky: #6f8fd3;
  --sky-deep: #526fad;
  --sky-soft: #edf4ff;
  --pink: #e9a1b3;
  --pink-soft: #fff0f4;
  --mint: #81bda9;
  --mint-soft: #edf9f4;
  --butter: #f3cf72;
  --butter-soft: #fff8e2;
  --white: #ffffff;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background-color: #fff9f5;
  background-image: radial-gradient(rgba(227, 203, 214, 0.36) 0.7px, transparent 0.7px);
  background-size: 20px 20px;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(111, 143, 211, 0.26);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-header {
  position: relative;
  z-index: 10;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid #f1e7eb;
  box-shadow: 0 4px 20px rgba(88, 83, 115, 0.04);
}

.header-inner {
  width: min(1120px, 100%);
  min-height: 72px;
  margin: 0 auto;
  padding: 10px 20px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-avatar {
  width: 50px;
  height: 50px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 2px solid #dce9ff;
  border-radius: 50%;
  background: var(--sky-soft);
  box-shadow: 0 4px 12px rgba(96, 127, 181, 0.12);
}

.brand-avatar img {
  width: 46px;
  height: 46px;
  display: block;
}

.brand-copy {
  min-width: 0;
}

.brand-kicker {
  display: block;
  margin-bottom: 1px;
  color: var(--pink);
  font-size: 9px;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  color: var(--ink);
  font-size: 20px;
  line-height: 1.25;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border: 1px solid #e8e4ee;
  border-radius: 8px;
  background: #f7f5fa;
}

.mode-switch button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 15px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.mode-switch button svg {
  width: 15px;
  height: 15px;
}

.mode-switch button.active {
  color: var(--white);
  background: var(--sky);
  box-shadow: 0 4px 10px rgba(95, 128, 194, 0.22);
}

.header-actions {
  justify-self: end;
  display: flex;
  gap: 8px;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid #ebe5ec;
  border-radius: 8px;
  background: var(--white);
  color: var(--sky-deep);
  box-shadow: 0 3px 9px rgba(75, 69, 99, 0.05);
}

.icon-button:hover:not(:disabled) {
  border-color: #cbdaf5;
  background: var(--sky-soft);
}

.icon-button:disabled {
  opacity: 0.4;
}

.icon-button svg {
  width: 19px;
  height: 19px;
}

.game-layout {
  width: min(1060px, 100%);
  margin: 0 auto;
  padding: 22px 20px 30px;
  display: grid;
  grid-template-columns: 170px minmax(320px, 480px) minmax(210px, 240px);
  grid-template-areas: "status play side";
  justify-content: center;
  align-items: start;
  gap: 24px;
}

.status-panel {
  grid-area: status;
  padding-top: 38px;
}

.status-panel section {
  padding: 17px 0;
  border-bottom: 1px solid var(--line);
}

.status-panel section:first-child {
  padding-top: 0;
}

.status-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.status-label svg {
  width: 14px;
  height: 14px;
  color: var(--pink);
}

.score-value {
  display: block;
  margin: 5px 0 2px;
  color: var(--ink);
  font-size: 36px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.best-line {
  color: var(--muted);
  font-size: 12px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.section-heading .status-label svg {
  color: #d9a51f;
}

.energy-track {
  width: 100%;
  height: 9px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 8px;
  background: #f1eaf0;
}

.energy-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--butter), var(--pink));
  transition: width 180ms ease-out;
}

.next-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.next-preview {
  position: relative;
  width: 64px;
  height: 64px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 2px solid #dce9ff;
  border-radius: 50%;
  background: var(--sky-soft);
}

.next-preview img {
  display: block;
  width: 58px;
  height: 58px;
}

.next-section strong {
  display: block;
  max-width: 82px;
  margin-top: 4px;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.next-badge {
  position: absolute;
  right: -7px;
  bottom: -3px;
  padding: 2px 5px;
  border: 1px solid #f0dfb2;
  border-radius: 6px;
  background: var(--butter-soft);
  color: #7a5e16;
  font-size: 10px;
  font-weight: 700;
}

.play-column {
  grid-area: play;
  min-width: 0;
}

.run-heading {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 2px 8px;
  font-size: 14px;
}

.run-heading > strong {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.run-heading > strong::before {
  content: "";
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--pink);
  box-shadow: 0 0 0 4px var(--pink-soft);
}

.goal-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

.goal-banner strong {
  color: var(--sky-deep);
  white-space: nowrap;
}

.canvas-shell {
  position: relative;
  width: 100%;
  max-width: 480px;
  aspect-ratio: 2 / 3;
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid #e2dce9;
  border-radius: 8px;
  background: #fff9f4;
  box-shadow:
    0 16px 38px rgba(92, 81, 121, 0.11),
    0 0 0 5px rgba(255, 255, 255, 0.62);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

body:has(.skill-button.active) #game-canvas {
  cursor: crosshair;
}

.game-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(59, 59, 86, 0.36);
  backdrop-filter: blur(3px);
}

.overlay-panel {
  width: min(100%, 322px);
  max-height: 100%;
  overflow-y: auto;
  padding: 24px;
  border: 2px solid rgba(255, 255, 255, 0.92);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 18px 46px rgba(57, 55, 87, 0.2);
  text-align: center;
}

.overlay-avatar {
  width: 76px;
  height: 76px;
  margin-bottom: 8px;
  border: 3px solid #eaf1ff;
  border-radius: 50%;
  background: var(--sky-soft);
}

.overlay-kicker {
  margin: 0 0 6px;
  color: var(--pink);
  font-size: 11px;
  font-weight: 800;
}

.overlay-panel h2 {
  margin: 0;
  font-size: 25px;
  line-height: 1.3;
}

.overlay-detail {
  margin: 10px 0 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.overlay-score {
  display: block;
  margin: -4px 0 16px;
  color: var(--sky-deep);
  font-size: 30px;
  font-variant-numeric: tabular-nums;
}

.overlay-actions {
  display: grid;
  gap: 8px;
}

.primary-button,
.secondary-button,
.small-button {
  min-height: 42px;
  padding: 9px 16px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 14px;
}

.primary-button {
  border: 1px solid var(--sky-deep);
  background: var(--sky);
  color: var(--white);
  box-shadow: 0 6px 14px rgba(88, 121, 185, 0.22);
}

.primary-button:hover {
  background: var(--sky-deep);
}

.secondary-button {
  border: 1px solid #e7e0e9;
  background: var(--white);
  color: var(--sky-deep);
}

.secondary-button:hover {
  background: var(--sky-soft);
}

.score-form {
  display: flex;
  gap: 8px;
  margin: 0 0 14px;
}

.score-form input {
  width: 100%;
  min-width: 0;
  height: 40px;
  padding: 8px 10px;
  border: 1px solid #dfe4ee;
  border-radius: 8px;
  background: var(--white);
  color: var(--ink);
  font-size: 16px;
}

.score-form input:focus {
  border-color: #a9c0e9;
  background: #fbfdff;
}

.small-button {
  min-height: 40px;
  padding: 8px 11px;
  flex: 0 0 auto;
  border: 1px solid #eed588;
  background: var(--butter-soft);
  color: #765b17;
  font-size: 12px;
}

.submission-note {
  margin: 0 0 14px;
  color: var(--mint);
  font-size: 12px;
}

.submission-note.error {
  color: #bd647b;
}

.skill-grid {
  width: 100%;
  max-width: 480px;
  margin: 11px auto 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.skill-button {
  --skill: var(--sky);
  --skill-soft: var(--sky-soft);
  min-width: 0;
  min-height: 76px;
  display: grid;
  grid-template-columns: auto auto;
  grid-template-rows: 32px 18px;
  align-items: center;
  justify-content: center;
  column-gap: 6px;
  padding: 8px 5px;
  border: 1px solid #eae4ec;
  border-radius: 8px;
  background: var(--white);
  box-shadow: 0 4px 11px rgba(74, 68, 96, 0.04);
  transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}

.skill-button[data-skill="undo"] {
  --skill: #759be0;
  --skill-soft: #eef4ff;
}

.skill-button[data-skill="bomb"] {
  --skill: #e795a9;
  --skill-soft: #fff0f4;
}

.skill-button[data-skill="wild"] {
  --skill: #d2a533;
  --skill-soft: #fff8df;
}

.skill-button[data-skill="wave"] {
  --skill: #70b19e;
  --skill-soft: #ecf9f5;
}

.skill-button:hover:not(:disabled) {
  border-color: var(--skill);
  background: var(--skill-soft);
  transform: translateY(-1px);
}

.skill-button.active {
  border-color: var(--pink);
  background: var(--pink-soft);
}

.skill-button:disabled {
  opacity: 0.43;
  box-shadow: none;
}

.skill-button > svg {
  grid-column: 1 / -1;
  justify-self: center;
  width: 19px;
  height: 19px;
  padding: 5px;
  border-radius: 50%;
  background: var(--skill-soft);
  color: var(--skill);
}

.skill-name {
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.skill-cost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-width: 27px;
  padding: 1px 4px;
  border-radius: 6px;
  background: var(--butter-soft);
  color: #8a6815;
  font-size: 10px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.skill-cost svg {
  width: 10px;
  height: 10px;
  color: #d2a533;
}

.side-panel {
  grid-area: side;
  min-width: 0;
  padding-top: 38px;
}

.side-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.side-heading h2 {
  margin: 4px 0 0;
  font-size: 17px;
  line-height: 1.4;
}

.side-heading > svg {
  width: 21px;
  height: 21px;
  color: var(--pink);
}

.local-note {
  margin: 10px 0 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.leaderboard-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.leaderboard-list li {
  min-height: 39px;
  display: grid;
  grid-template-columns: 27px minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  border-bottom: 1px solid #f2edf3;
  font-size: 12px;
}

.leaderboard-list li:first-child {
  color: #9b7420;
}

.leaderboard-list .rank {
  color: #a2a8b9;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.leaderboard-list .player-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-list strong {
  font-variant-numeric: tabular-nums;
}

.leaderboard-list .leaderboard-empty {
  display: block;
  padding: 18px 0;
  color: var(--muted);
  text-align: center;
}

.level-list {
  display: grid;
  gap: 7px;
  margin-top: 12px;
}

.level-button {
  width: 100%;
  min-height: 68px;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 18px;
  align-items: center;
  gap: 9px;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.52);
  text-align: left;
}

.level-button:hover {
  border-color: #e5ddeb;
  background: var(--white);
}

.level-button.active {
  border-color: #cfddf5;
  background: var(--sky-soft);
}

.level-icon {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--white);
  color: var(--sky);
  box-shadow: 0 3px 8px rgba(77, 80, 111, 0.06);
}

.level-icon svg {
  width: 18px;
  height: 18px;
}

.level-copy {
  min-width: 0;
}

.level-copy strong,
.level-copy small,
.level-rule {
  display: block;
  overflow-wrap: anywhere;
}

.level-copy strong {
  font-size: 12px;
}

.level-copy small {
  margin-top: 2px;
  color: var(--sky-deep);
  font-size: 10px;
  font-style: normal;
}

.level-rule {
  margin-top: 2px;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.45;
}

.level-status {
  color: var(--muted);
}

.level-status svg {
  width: 16px;
  height: 16px;
}

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: rgba(53, 64, 90, 0.94);
  color: var(--white);
  font-size: 13px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 920px) {
  .header-inner {
    grid-template-columns: 1fr auto;
    gap: 10px;
    padding: 10px 14px;
  }

  .brand-avatar {
    width: 44px;
    height: 44px;
  }

  .brand-avatar img {
    width: 40px;
    height: 40px;
  }

  .mode-switch {
    grid-column: 1 / -1;
    grid-row: 2;
    width: min(100%, 360px);
    justify-self: center;
  }

  .header-actions {
    grid-column: 2;
    grid-row: 1;
  }

  .game-layout {
    width: min(100%, 560px);
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "status" "play" "side";
    gap: 13px;
    padding: 14px 12px 26px;
  }

  .status-panel {
    display: grid;
    grid-template-columns: 0.9fr 1.25fr 1fr;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    border: 1px solid #efe7ed;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.72);
  }

  .status-panel section,
  .status-panel section:first-child {
    padding: 0;
    border: 0;
  }

  .score-value {
    font-size: 27px;
  }

  .next-section {
    gap: 8px;
    justify-content: flex-end;
  }

  .next-preview {
    width: 50px;
    height: 50px;
  }

  .next-preview img {
    width: 44px;
    height: 44px;
  }

  .next-section strong {
    max-width: 66px;
    font-size: 12px;
  }

  .side-panel {
    padding-top: 8px;
  }

  .level-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .leaderboard-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 20px;
  }
}

@media (max-width: 390px) {
  .header-inner {
    padding-inline: 10px;
  }

  .brand {
    gap: 8px;
  }

  .brand h1 {
    font-size: 18px;
  }

  .brand-avatar {
    width: 40px;
    height: 40px;
  }

  .brand-avatar img {
    width: 36px;
    height: 36px;
  }

  .icon-button {
    width: 35px;
    height: 35px;
  }

  .game-layout {
    padding: 10px;
  }

  .status-panel {
    gap: 9px;
    padding: 10px;
  }

  .status-label {
    font-size: 11px;
  }

  .section-heading {
    font-size: 10px;
  }

  .next-preview {
    width: 42px;
    height: 42px;
  }

  .next-preview img {
    width: 38px;
    height: 38px;
  }

  .run-heading {
    font-size: 13px;
  }

  .goal-banner {
    gap: 4px;
    font-size: 10px;
  }

  .skill-grid {
    gap: 6px;
  }

  .skill-button {
    min-height: 70px;
    column-gap: 3px;
    padding-inline: 3px;
  }

  .skill-name {
    font-size: 11px;
  }

  .overlay-panel {
    padding: 20px;
  }

  .overlay-avatar {
    width: 64px;
    height: 64px;
  }

  .level-list {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
