:root {
  color-scheme: light;
  --ink: #231942;
  --muted: #665e7a;
  --panel: rgba(255, 255, 255, 0.88);
  --surface: #ffffff;
  --line: rgba(35, 25, 66, 0.1);
  --pink: #ff5c8a;
  --mint: #2ed3a2;
  --sun: #ffd166;
  --blue: #5ba7ff;
  --danger: #6e4b8f;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(135deg, #e9fbff 0%, #fff8dc 48%, #ffe9f2 100%);
}

button,
input {
  font: inherit;
}

.hidden {
  display: none !important;
}

.shell {
  width: min(1180px, calc(100vw - 28px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 0;
  display: grid;
  grid-template-columns: minmax(320px, 660px) minmax(300px, 360px);
  align-items: center;
  justify-content: center;
  gap: 18px;
}

.game-wrap {
  position: relative;
  width: min(100%, 62vh);
  max-width: 660px;
  min-width: 300px;
  aspect-ratio: 2 / 3;
  justify-self: end;
  border: 4px solid #ffffff;
  border-radius: 8px;
  box-shadow: 0 18px 48px rgba(35, 25, 66, 0.2);
  overflow: hidden;
  background: #a8e6ff;
  touch-action: none;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.hud {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  color: #ffffff;
  font-weight: 800;
  text-shadow: 0 2px 0 rgba(35, 25, 66, 0.18);
  pointer-events: none;
}

.hud span {
  min-height: 32px;
  padding: 5px 9px;
  border-radius: 8px;
  background: rgba(35, 25, 66, 0.18);
  backdrop-filter: blur(8px);
}

#lives {
  color: #ffeff5;
  letter-spacing: 1px;
}

#status {
  text-align: right;
}

.sound-toggle {
  position: absolute;
  top: 54px;
  right: 10px;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 2px solid rgba(255, 255, 255, 0.86);
  border-radius: 8px;
  color: #ffffff;
  background: rgba(35, 25, 66, 0.2);
  box-shadow: 0 8px 18px rgba(35, 25, 66, 0.12);
  font-size: 1rem;
  font-weight: 950;
  text-shadow: 0 1px 0 rgba(35, 25, 66, 0.24);
  backdrop-filter: blur(8px);
  cursor: pointer;
}

.sound-toggle:focus-visible {
  outline: 3px solid rgba(255, 209, 102, 0.95);
  outline-offset: 2px;
}

.sound-toggle.muted {
  color: rgba(255, 255, 255, 0.72);
  background: rgba(35, 25, 66, 0.38);
}

.combo-hud {
  --combo-scale: 1;
  position: absolute;
  top: 54px;
  left: 50%;
  min-width: 128px;
  padding: 7px 13px 9px;
  border: 2px solid rgba(255, 255, 255, 0.86);
  border-radius: 8px;
  overflow: hidden;
  color: #ffffff;
  background: rgba(255, 92, 138, 0.82);
  box-shadow: 0 8px 18px rgba(35, 25, 66, 0.16);
  font-size: 0.86rem;
  font-weight: 950;
  text-align: center;
  text-shadow: 0 2px 0 rgba(35, 25, 66, 0.2);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -8px) scale(0.94);
  transition: opacity 160ms ease, transform 160ms ease;
}

.combo-hud::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 5px;
  height: 3px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--sun), #ffffff);
  transform: scaleX(var(--combo-scale));
  transform-origin: left center;
}

.combo-hud.active {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.combo-hud.flash {
  background: rgba(255, 209, 102, 0.92);
  color: var(--ink);
}

.target-meter {
  position: absolute;
  left: 10px;
  right: 10px;
  top: 96px;
  height: 24px;
  border: 2px solid rgba(255, 255, 255, 0.82);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(35, 25, 66, 0.18);
  color: #ffffff;
  font-size: 0.74rem;
  font-weight: 900;
  text-align: center;
  line-height: 20px;
  text-shadow: 0 1px 0 rgba(35, 25, 66, 0.25);
  pointer-events: none;
}

.target-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: linear-gradient(90deg, var(--mint), var(--sun));
  transition: width 140ms ease;
}

.target-meter span {
  position: relative;
  z-index: 1;
}

.mission-chip {
  position: absolute;
  left: 10px;
  right: 10px;
  top: 126px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border: 2px solid rgba(255, 255, 255, 0.74);
  border-radius: 8px;
  background: rgba(35, 25, 66, 0.2);
  color: #ffffff;
  font-size: 0.7rem;
  font-weight: 900;
  text-shadow: 0 1px 0 rgba(35, 25, 66, 0.28);
  backdrop-filter: blur(8px);
  pointer-events: none;
}

.mission-chip span {
  color: #ffd166;
}

.mission-chip strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.luck-meter {
  position: absolute;
  left: 10px;
  right: 10px;
  top: 160px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(35, 25, 66, 0.16);
  color: #ffffff;
  font-size: 0.62rem;
  font-weight: 950;
  line-height: 16px;
  text-align: center;
  text-shadow: 0 1px 0 rgba(35, 25, 66, 0.25);
  pointer-events: none;
}

.luck-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: linear-gradient(90deg, #5ba7ff, #ffd166, #ff5c8a);
  transition: width 140ms ease;
}

.luck-meter span {
  position: relative;
  z-index: 1;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.24));
}

.overlay.hidden {
  display: none;
}

.panel {
  width: min(92%, 430px);
  padding: 22px;
  border: 2px solid rgba(255, 255, 255, 0.96);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 14px 34px rgba(35, 25, 66, 0.18);
  text-align: center;
  backdrop-filter: blur(10px);
}

.kicker {
  margin: 0 0 8px;
  color: var(--pink);
  font-weight: 800;
  text-transform: uppercase;
  font-size: 0.8rem;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: clamp(2rem, 8vw, 4rem);
  line-height: 1;
}

h2 {
  margin-bottom: 12px;
  font-size: 1.15rem;
  letter-spacing: 0;
}

.copy {
  color: var(--muted);
  line-height: 1.6;
}

.challenge-card {
  display: grid;
  gap: 4px;
  margin: 10px 0 12px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid rgba(35, 25, 66, 0.08);
  background: linear-gradient(135deg, #fff8dc, #eafff7);
  box-shadow: inset 0 -2px 0 rgba(35, 25, 66, 0.06);
}

.challenge-card span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.challenge-card strong {
  font-size: 1rem;
}

.primary,
.submit-row button,
.refresh-board,
.board-tabs button,
.share-button {
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  background: var(--pink);
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 6px 0 #cc3763;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

button:disabled {
  cursor: default;
  opacity: 0.68;
  transform: none;
  box-shadow: none;
}

.primary {
  min-width: 160px;
  min-height: 48px;
  padding: 12px 24px;
}

.result-content h1 {
  margin-bottom: 8px;
  font-size: clamp(1.8rem, 7vw, 3.4rem);
}

.result-score {
  font-size: clamp(2.2rem, 10vw, 5rem);
  line-height: 1;
  font-weight: 950;
  color: var(--pink);
}

.result-grade {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  margin: 12px auto;
  border-radius: 50%;
  background: var(--sun);
  box-shadow: inset 0 -5px 0 rgba(35, 25, 66, 0.12);
  font-size: 1.7rem;
  font-weight: 950;
}

.result-title {
  display: grid;
  gap: 3px;
  margin: 10px 0 12px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 209, 102, 0.55);
  background: linear-gradient(135deg, #fff8dc, #ffffff);
}

.result-title strong {
  color: var(--ink);
  font-size: 1.04rem;
  font-weight: 950;
}

.result-title span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.35;
}

.result-ranks {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 12px 0;
}

.result-ranks div {
  min-width: 0;
  padding: 10px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.result-ranks span {
  display: block;
  font-size: 1.25rem;
  font-weight: 950;
}

.result-ranks small {
  color: var(--muted);
  font-weight: 800;
}

button:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #cc3763;
}

.side {
  display: grid;
  gap: 12px;
  align-content: center;
}

.mini-links {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 8px;
}

.mini-links a {
  min-height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 900;
  text-decoration: none;
  box-shadow: 0 8px 18px rgba(35, 25, 66, 0.07);
}

.score-card,
.leaderboard {
  border: 1px solid rgba(255, 255, 255, 0.86);
  border-radius: 8px;
  padding: 16px;
  background: var(--panel);
  box-shadow: 0 12px 28px rgba(35, 25, 66, 0.12);
  backdrop-filter: blur(10px);
}

.score-card h2,
.board-head h2 {
  margin: 0 0 12px;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--line);
  font-size: 1rem;
  font-weight: 900;
}

dl {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin: 0 0 14px;
}

dl div {
  padding: 9px 7px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  text-align: center;
}

dt {
  color: var(--muted);
  font-size: 0.78rem;
}

dd {
  margin: 2px 0 0;
  font-weight: 900;
  font-size: 1.04rem;
}

.score-form label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.86rem;
}

.submit-row {
  display: grid;
  grid-template-columns: 1fr 78px;
  gap: 8px;
}

input {
  min-width: 0;
  height: 44px;
  border: 1px solid #ddd6ef;
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #ffffff;
  outline: none;
}

input:focus {
  border-color: var(--blue);
}

.submit-row button,
.refresh-board {
  min-height: 44px;
  padding: 0 12px;
}

.share-button {
  width: 100%;
  min-height: 42px;
  margin-top: 10px;
  background: var(--mint);
  box-shadow: 0 6px 0 #20a87f;
}

.share-text {
  width: 100%;
  min-height: 74px;
  margin-top: 10px;
  border: 2px solid #e5dff5;
  border-radius: 8px;
  padding: 10px;
  resize: none;
  color: var(--ink);
}

.message {
  min-height: 18px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.board-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  list-style: none;
  cursor: pointer;
}

.board-head::-webkit-details-marker {
  display: none;
}

.board-body {
  margin-top: 0;
}

.board-tools {
  display: grid;
  grid-template-columns: 1fr 42px;
  gap: 8px;
  align-items: stretch;
  margin-bottom: 12px;
}

.refresh-board {
  width: 42px;
  font-size: 1.2rem;
  background: var(--blue);
  box-shadow: 0 6px 0 #3779c5;
}

.board-tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.board-tabs button {
  min-height: 38px;
  background: #ece7f8;
  color: var(--ink);
  box-shadow: 0 4px 0 #cfc5e5;
}

.board-tabs button.active {
  background: var(--pink);
  color: #ffffff;
  box-shadow: 0 5px 0 #cc3763;
}

ol {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 9px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
}

li .rank {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: #fff0f5;
  color: var(--pink);
  font-weight: 900;
}

li .name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

li .meta {
  color: var(--muted);
  font-size: 0.78rem;
}

li .points {
  font-weight: 900;
}

li.highlight {
  border-color: rgba(255, 209, 102, 0.95);
  outline: 2px solid rgba(255, 209, 102, 0.5);
  background: #fffaf0;
}

@media (max-width: 860px) {
  .shell {
    width: min(100vw - 16px, 520px);
    min-height: 100dvh;
    grid-template-columns: 1fr;
    align-items: start;
    gap: 10px;
    padding: max(8px, env(safe-area-inset-top)) 0 max(14px, env(safe-area-inset-bottom));
  }

  .game-wrap {
    width: min(100%, calc((100dvh - 26px) * 0.62));
    justify-self: center;
    max-height: calc(100dvh - 26px);
    min-width: 0;
    border-width: 4px;
  }

  .side {
    align-content: start;
    gap: 10px;
  }

  .score-card,
  .leaderboard {
    padding: 14px;
  }

  .leaderboard:not([open]) {
    padding-bottom: 10px;
  }

  .board-head {
    min-height: 44px;
  }

  .board-head h2 {
    margin: 0;
  }

  .leaderboard .board-head::after {
    content: "收起";
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 800;
  }

  .leaderboard:not([open]) .board-head::after {
    content: "展开";
  }
}

@media (max-width: 420px) {
  body {
    background: linear-gradient(180deg, #e9fbff 0%, #fff8dc 54%, #fdf4ff 100%);
  }

  .hud {
    top: 8px;
    left: 8px;
    right: 8px;
    gap: 5px;
    font-size: 0.74rem;
  }

  .hud span {
    min-height: 29px;
    padding: 5px 6px;
  }

  .sound-toggle {
    top: 46px;
    right: 8px;
    width: 34px;
    height: 34px;
    font-size: 0.9rem;
  }

  .combo-hud {
    top: 46px;
    min-width: 112px;
    padding: 6px 10px 8px;
    font-size: 0.76rem;
  }

  .target-meter {
    left: 8px;
    right: 8px;
    top: 88px;
    height: 21px;
    font-size: 0.62rem;
    line-height: 17px;
  }

  .mission-chip {
    left: 8px;
    right: 8px;
    top: 114px;
    min-height: 25px;
    gap: 6px;
    padding: 3px 7px;
    font-size: 0.6rem;
  }

  .luck-meter {
    left: 8px;
    right: 8px;
    top: 144px;
    height: 16px;
    font-size: 0.56rem;
    line-height: 12px;
  }

  .overlay {
    padding: 14px;
    align-items: center;
  }

  .panel {
    width: min(96%, 350px);
    max-height: calc(100dvh - 58px);
    overflow: auto;
    padding: 14px;
  }

  h1 {
    font-size: clamp(1.9rem, 10vw, 2.7rem);
  }

  .kicker {
    margin-bottom: 5px;
    font-size: 0.72rem;
  }

  .copy {
    margin-bottom: 12px;
    font-size: 0.84rem;
    line-height: 1.45;
  }

  .challenge-card {
    margin: 8px 0 10px;
    padding: 8px;
  }

  .primary {
    width: 100%;
    min-height: 50px;
  }

  .result-content h1 {
    font-size: 1.65rem;
  }

  .result-score {
    font-size: 2.5rem;
  }

  .result-grade {
    width: 52px;
    height: 52px;
    margin: 8px auto;
    font-size: 1.35rem;
  }

  .result-title {
    margin: 8px 0;
    padding: 8px;
  }

  .result-title strong {
    font-size: 0.98rem;
  }

  .result-title span {
    font-size: 0.76rem;
  }

  dl {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  dl div {
    padding: 8px 6px;
  }

  dd {
    font-size: 1rem;
  }

  .result-ranks {
    grid-template-columns: repeat(2, 1fr);
    margin: 8px 0;
  }

  .submit-row {
    grid-template-columns: 1fr 72px;
  }

  input,
  .submit-row button,
  .share-button,
  .board-tabs button,
  .refresh-board {
    min-height: 46px;
  }

  li {
    grid-template-columns: 26px minmax(0, 1fr) auto;
    gap: 6px;
    padding: 7px;
  }

  li .points {
    font-size: 0.92rem;
  }
}

@media (max-width: 360px) {
  .shell {
    width: calc(100vw - 10px);
  }

  .score-card,
  .leaderboard {
    padding: 10px;
  }

  .result-ranks {
    grid-template-columns: 1fr;
  }
}
