:root {
  color-scheme: light;
  --bg-1: #fffdeb;
  --bg-2: #eccfee;
  --ink: #5f5b58;
  --ink-soft: #8a8580;
  --line: #d3cdc5;
  --accent: #ff8f3f;
  --accent-dark: #f05a28;
  --panel: #ffffff;
  --panel-strong: rgba(255, 255, 255, 0.92);
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.12);
  --soft-shadow: 0 10px 18px rgba(0, 0, 0, 0.12);
  --font-base: "Alibaba PuHuiTi", "PingFang SC", "Noto Sans SC", sans-serif;
  --ui-scale: 1.5;
  --hero-title-size: 28px;
  --hero-subtitle-size: 12px;
  --hero-gap: 6px;
  --score-label-size: 14px;
  --score-value-size: 16px;
  --score-scale: 0.8;
  --score-top-offset: 6px;
  --stage-label-size: 15px;
  --footer-text-size: 13px;
  --logo-size-min: 14px;
  --logo-size-fluid: 4vw;
  --logo-size-max: 20px;
  --logo-radius: 6px;
  --hud-side: clamp(16px, 6vw, 100px);
  --hud-top: clamp(20px, 6vw, 80px);
  --hud-bottom: clamp(24px, 6vh, 90px);
  --next-gap: clamp(4px, 1.2vh, 12px);
  --next-label-size: clamp(14px, 3.2vw, 40px);
  --footer-gap: clamp(12px, 3vh, 28px);
  --audio-size: clamp(34px, 8vw, 52px);
}

* {
  box-sizing: border-box;
}

[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;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: var(--app-height, 100vh);
  height: var(--app-height, 100vh);
  font-family: var(--font-base);
  color: var(--ink);
  background: linear-gradient(180deg, #ffffff 0%, #ead9eb 100%);
  overflow: hidden;
}

.app {
  width: 100%;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  align-items: stretch;
  min-height: 100%;
  height: 100%;
  position: relative;
  animation: fadeIn 0.6s ease-out;
}

.hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: clamp(12px, 4vw, 40px);
  position: absolute;
  top: var(--hud-top);
  left: var(--hud-side);
  right: var(--hud-side);
  z-index: 2;
  pointer-events: none;
}

.hero-left {
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 2vw, 18px);
}

.hero-left h1 {
  margin: 0;
  font-size: clamp(32px, 8vw, 96px);
  letter-spacing: 1px;
  color: #5a5a5a;
  font-weight: 700;
  line-height: 1.05;
}

.subtitle {
  margin: 0;
  font-size: clamp(12px, 2.8vw, 32px);
  color: #5a5a5a;
  line-height: 1.2;
  display: none;
}

.score-block {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  text-align: right;
  font-size: inherit;
  color: #000;
  min-width: 0;
  line-height: 1.1;
  gap: clamp(8px, 2vw, 20px);
  pointer-events: auto;
}

.audio-toggle {
  align-self: flex-end;
  margin-top: clamp(6px, 1.6vw, 16px);
  width: var(--audio-size);
  height: var(--audio-size);
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: #ffffff;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.12);
  text-decoration: none;
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.5;
  --audio-icon: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='%235a5a5a'%20stroke-width='2'%20stroke-linecap='round'%20stroke-linejoin='round'%3E%3Cpath%20d='M11%205L6%209H3v6h3l5%204z'/%3E%3Cpath%20d='M15.54%208.46a5%205%200%200%201%200%207.07'/%3E%3Cpath%20d='M18.07%205.93a9%209%200%200%201%200%2012.14'/%3E%3C/svg%3E");
}

.audio-toggle::before {
  content: "";
  width: 58%;
  height: 58%;
  background: var(--audio-icon) center/contain no-repeat;
  display: block;
}

.audio-toggle[aria-pressed="false"] {
  box-shadow: none;
  --audio-icon: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='%235a5a5a'%20stroke-width='2'%20stroke-linecap='round'%20stroke-linejoin='round'%3E%3Cpath%20d='M11%205L6%209H3v6h3l5%204z'/%3E%3Cline%20x1='16'%20y1='9'%20x2='21'%20y2='14'/%3E%3Cline%20x1='21'%20y1='9'%20x2='16'%20y2='14'/%3E%3C/svg%3E");
}

.audio-toggle:hover,
.audio-toggle:active {
  transform: none;
}

.audio-toggle:hover {
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.12);
}

.audio-toggle[aria-pressed="false"],
.audio-toggle[aria-pressed="false"]:hover,
.audio-toggle[aria-pressed="false"]:active {
  box-shadow: none;
}

.score-current {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: clamp(4px, 1vw, 12px);
}

.score-label {
  font-size: clamp(16px, 4vw, 50px);
  font-weight: 600;
  color: #5a5a5a;
}

#score {
  font-weight: 600;
  font-size: clamp(44px, 8.5vw, 100px);
  line-height: 1;
  background-image: linear-gradient(90deg, #f775ba 15%, #fbcb47 110%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
}

.score-best {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: clamp(6px, 1vw, 12px);
  font-size: clamp(16px, 4vw, 50px);
  font-weight: 600;
  color: #5a5a5a;
}

.score-best strong {
  font-weight: 600;
  background-image: linear-gradient(-86deg, #ffcc89 2%, #ff2abf 118%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
}

.next-ball {
  --next-max-size: 28px;
  --next-size: 18px;
  --next-color: #ffd166;
  --next-stroke: #f4a261;
  width: var(--next-max-size);
  height: var(--next-max-size);
  display: grid;
  place-items: center;
}

.next-ball-inner {
  width: var(--next-size);
  height: var(--next-size);
  border-radius: 50%;
  background: var(--next-color);
  border: 1px solid var(--next-stroke);
}

button,
.button-link {
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 10px 20px rgba(242, 84, 28, 0.3);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button:hover,
.button-link:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 24px rgba(242, 84, 28, 0.35);
}

button:active,
.button-link:active {
  transform: translateY(1px);
}

button.ready {
  background: linear-gradient(135deg, #ffe58f, #ffb347);
  color: #3b2a12;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.7), 0 14px 26px rgba(255, 176, 71, 0.45);
  animation: readyPulse 1.6s ease-in-out infinite;
}

button.ready:disabled {
  animation: none;
}

.stage {
  display: flex;
  flex-direction: column;
  gap: 0;
  align-items: stretch;
  justify-content: stretch;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  position: relative;
}

.canvas-wrap {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  padding: 0;
  min-height: 0;
  border-radius: 0;
  overflow: hidden;
  background: transparent;
  border: none;
  box-shadow: none;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.stage-body {
  width: 100%;
  height: 100%;
  position: relative;
}

.stage-header {
  width: auto;
  display: flex;
  align-items: center;
  gap: clamp(5px, 1.8vw, 14px);
  font-size: var(--next-label-size);
  color: #000;
  padding: 0;
  line-height: 1;
  border-bottom: none;
  position: absolute;
  top: var(--danger-line-y, 200px);
  left: var(--hud-side);
  z-index: 2;
  pointer-events: none;
  transform: translateY(calc(-80% - var(--next-gap)));
}

.game-viewport {
  width: 100%;
  position: relative;
  height: 100%;
  flex: 1 1 auto;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

canvas {
  display: block;
  touch-action: none;
  width: 100%;
  height: 100%;
}

.stage-footer {
  width: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 1.5vw, 14px);
  text-align: center;
  font-size: clamp(12px, 3vw, 36px);
  color: #aca3a3;
  position: absolute;
  left: 50%;
  top: calc(var(--bucket-floor-y, 80%) + var(--footer-gap));
  bottom: auto;
  transform: translateX(-50%);
  z-index: 2;
  pointer-events: none;
}

.footer-logo {
  width: clamp(24px, 6.5vw, 79px);
  height: clamp(24px, 6.5vw, 79px);
  border-radius: clamp(4px, 1vw, 10px);
  object-fit: cover;
}

.tips {
  background: var(--panel-strong);
  padding: 22px;
  border-radius: 22px;
  box-shadow: var(--soft-shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: fadeIn 0.5s ease-out;
}

.tips h2 {
  margin: 0;
  font-size: 18px;
  text-align: center;
}

.tips ul {
  margin: 0;
  padding-left: 0;
  list-style: none;
  display: grid;
  gap: 10px;
  line-height: 1.5;
  font-size: 14px;
}

.legend {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: rgba(59, 47, 47, 0.7);
  justify-content: center;
}

.legend-line {
  width: 48px;
  height: 0;
  border-top: 1px dashed rgba(90, 90, 90, 0.7);
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(39, 24, 12, 0.48);
  display: grid;
  place-items: center;
  backdrop-filter: blur(6px);
  z-index: 2;
}

.modal-overlay {
  position: fixed;
  inset: 0;
}

.overlay.intro {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 3;
  animation: none;
  opacity: 1;
}

.overlay.share-overlay {
  position: fixed;
  inset: 0;
  z-index: 5;
}

.overlay-card {
  background: #fffdf7;
  padding: 24px 28px;
  border-radius: 18px;
  text-align: center;
  box-shadow: var(--shadow);
  width: min(92%, 360px);
  box-sizing: border-box;
}

.overlay-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.overlay-actions button {
  font-size: 16px;
}

.share-preview {
  position: relative;
  width: min(88vw, 360px);
  padding: 14px;
  border-radius: 18px;
  background: #ffffff;
  display: grid;
  gap: 10px;
  text-align: center;
  box-shadow: var(--shadow);
}

.share-preview img {
  width: 100%;
  max-height: 72vh;
  border-radius: 12px;
  object-fit: contain;
  display: block;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.share-hint {
  margin: 0;
  font-size: 12px;
  color: rgba(59, 47, 47, 0.65);
}

.share-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  font-size: 18px;
  box-shadow: var(--soft-shadow);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.intro-shell {
  width: min(92%, 420px);
  position: relative;
  display: grid;
  place-items: center;
}

.intro-card {
  width: 100%;
  position: relative;
  text-align: center;
  align-items: center;
  gap: 12px;
  padding: 64px 28px 26px;
  background: #ffffff;
  border-radius: clamp(28px, 8vw, 48px);
  box-shadow: 0 4px 40px rgba(0, 0, 0, 0.25);
  z-index: 2;
}

.intro-mascots {
  position: absolute;
  left: 50%;
  top: -30px;
  transform: translate(-50%, -55%);
  display: flex;
  align-items: flex-end;
  gap: clamp(8px, 2vw, 16px);
  pointer-events: none;
  z-index: 1;
}

.intro-mascot {
  display: block;
  height: auto;
  max-width: 100%;
  object-fit: contain;
  flex: 0 0 auto;
}

.intro-mascot-left {
  width: clamp(90px, 30vw, 150px);
  transform: translateY(10px);
}

.intro-mascot-right {
  width: clamp(70px, 22vw, 120px);
  margin-bottom: clamp(2px, 1vw, 8px);
}

.intro-card .intro-title {
  margin: 0;
  font-size: clamp(30px, 8vw, 46px);
  font-weight: 800;
  letter-spacing: 1px;
  background-image: linear-gradient(-86deg, #ffcc89 2%, #ff2abf 118%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  white-space: nowrap;
}

.intro-desc {
  margin: 0;
  margin-top: clamp(8px, 2.5vw, 14px);
  color: #585858;
  font-size: clamp(12px, 3vw, 16px);
  line-height: 1.5;
  display: grid;
  gap: 4px;
}

.intro-desc span {
  display: block;
}

.intro-card .legend {
  margin-top: 6px;
}

.intro-card .legend-line {
  display: none;
}

.intro-actions {
  margin-top: 6px;
  display: flex;
  justify-content: center;
}

.intro-actions button {
  font-size: clamp(16px, 4.2vw, 20px);
  font-weight: 800;
  padding: 12px 32px;
  background: linear-gradient(90deg, #ff5baf, #ffc88b);
  box-shadow: 0 12px 24px rgba(255, 133, 171, 0.35);
  border-radius: 999px;
}

.intro-brand {
  margin-top: 6px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #c1c1c1;
}

.intro-audio {
  margin-top: 4px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: #5a5a5a;
}

.intro-audio input {
  width: 18px;
  height: 18px;
  accent-color: #ff8f3f;
}

.intro-brand-logo {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  object-fit: cover;
}

.overlay-card h2 {
  margin: 0 0 10px;
  font-size: 22px;
}

.overlay-card p {
  margin: 0 0 18px;
  font-size: 16px;
}

.rank-overlay {
  z-index: 6;
}

.rank-card {
  text-align: left;
  padding: 22px 22px 18px;
  display: grid;
  gap: 12px;
  position: relative;
}

.rank-heading {
  margin: 0;
  font-size: 20px;
  text-align: center;
}

.rank-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: #4b4b4b;
}

.rank-meta strong {
  font-size: 18px;
  font-weight: 600;
  color: #1f1f1f;
}

.rank-name {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
  font-size: 13px;
  color: #4b4b4b;
}

.rank-input {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.rank-name input {
  flex: 1;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: #fff;
  font-size: 13px;
  color: #2f2f2f;
  min-width: 0;
  width: 100%;
}

.rank-name-text {
  flex: 1;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.05);
  color: #2f2f2f;
  font-size: 13px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-name input:focus {
  outline: 2px solid rgba(255, 143, 63, 0.35);
  border-color: rgba(255, 143, 63, 0.5);
}

.rank-input button {
  padding: 6px 12px;
  font-size: 13px;
  white-space: nowrap;
  width: auto;
  flex: 0 0 auto;
}

.rank-input button.is-submitted {
  background: #d9d9d9;
  color: #6b6b6b;
  box-shadow: none;
}

.rank-edit {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  color: #4b4b4b;
  box-shadow: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  --stroke-0: #4b4b4b;
}

.rank-edit-icon {
  width: 20px;
  height: 20px;
  display: block;
}

.rank-edit:hover {
  transform: none;
  box-shadow: none;
  background: transparent;
  opacity: 0.8;
}

.rank-edit:active {
  transform: none;
}

.rank-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  font-size: 18px;
  box-shadow: var(--soft-shadow);
  display: grid;
  place-items: center;
}

.rank-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
  max-height: 160px;
  overflow-y: auto;
}

.rank-item {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.88);
  font-size: 13px;
  color: #2f2f2f;
}

.rank-item.is-me {
  background: #ffe9c2;
}

.rank-pos {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #fff1da;
  font-weight: 600;
  font-size: 12px;
  color: #d2751a;
}

.rank-score {
  font-weight: 600;
  color: #1f1f1f;
}

.rank-status {
  margin: 0;
  min-height: 16px;
  font-size: 12px;
  color: rgba(59, 47, 47, 0.65);
  text-align: center;
}

.ad-block {
  margin: 6px auto 18px;
  padding: 0;
  display: grid;
  gap: 12px;
  justify-items: center;
  width: 100%;
  text-align: center;
}

.ad-block img {
  width: 100%;
  border-radius: 12px;
  box-shadow: var(--soft-shadow);
}

.ad-media {
  position: relative;
  width: 100%;
  max-width: 320px;
}

.ad-timer {
  position: absolute;
  top: 0;
  right: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  color: #5a5a5a;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 600;
  box-shadow: var(--soft-shadow);
  pointer-events: none;
}

.ad-timer span {
  position: relative;
  z-index: 1;
}

.ad-timer-ring {
  position: absolute;
  inset: 0;
  transform: rotate(-90deg);
}

.ad-timer-bg {
  fill: none;
  stroke: rgba(90, 90, 90, 0.2);
  stroke-width: 2.4;
}

.ad-timer-progress {
  fill: none;
  stroke: rgba(90, 90, 90, 0.85);
  stroke-width: 2.4;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.2s linear;
}

button[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.ad-block .button-link {
  width: 100%;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes floatIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes readyPulse {
  0% {
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.7), 0 12px 20px rgba(255, 176, 71, 0.3);
  }
  70% {
    box-shadow: 0 0 0 6px rgba(255, 229, 143, 0.2), 0 16px 28px rgba(255, 176, 71, 0.45);
  }
  100% {
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.7), 0 12px 20px rgba(255, 176, 71, 0.3);
  }
}

@media (max-width: 600px) {
  :root {
    --hero-title-size: 26px;
    --score-value-size: 15px;
    --stage-label-size: 14px;
    --footer-text-size: 12px;
  }

  .app {
    width: 100%;
    padding: 0;
    gap: 0;
  }

  button {
    width: 100%;
  }

}

@media (max-width: 360px) {
  :root {
    --hero-title-size: 24px;
    --hero-subtitle-size: 11px;
    --hero-gap: 4px;
    --score-label-size: 12px;
    --score-value-size: 14px;
    --stage-label-size: 13px;
    --footer-text-size: 12px;
    --logo-size-min: 12px;
    --logo-size-fluid: 4.5vw;
    --logo-size-max: 18px;
    --logo-radius: 5px;
  }

  .app {
    width: 100%;
    padding: 0;
    gap: 0;
  }

  .stage-header {
    padding: 0;
    margin-top: 0;
  }

  .game-viewport {
    height: 100%;
  }

  button,
  .button-link {
    padding: 8px 14px;
    font-size: 14px;
  }

  .overlay-card {
    padding: 20px;
    border-radius: 16px;
  }

  .overlay-card h2 {
    font-size: 20px;
  }

  .overlay-card p {
    font-size: 14px;
  }

  .overlay-actions button {
    font-size: 14px;
  }

  .intro-actions button {
    font-size: 16px;
  }

  .rank-heading {
    font-size: 18px;
  }

  .rank-meta strong {
    font-size: 16px;
  }

  .rank-name,
  .rank-name input,
  .rank-name-text,
  .rank-input button,
  .rank-item {
    font-size: 12px;
  }

  .rank-item {
    grid-template-columns: 24px 1fr auto;
  }

  .rank-pos {
    width: 20px;
    height: 20px;
    font-size: 11px;
  }

  .rank-list {
    max-height: 140px;
  }

  .share-preview {
    width: min(92vw, 320px);
  }

  .share-hint {
    font-size: 11px;
  }
}
