:root {
  --orange: #FF8A3D;
  --orange-light: #FFB572;
  --orange-deep: #A6430D;
  --cream: #FFF2DF;
  --gold: #FFC53D;
  --ink: #2A1430;
  --bg-deep: #120A24;
  --panel: #241442;
  --panel-2: #2E1B52;
  --line: #4B3574;
  --line-soft: #3B2A5C;
  --text: #F7EDE1;
  --muted: #AD9ACB;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Courier New", monospace;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  height: 100%;
  background: #0B0617;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
}

body {
  display: flex;
  justify-content: center;
  align-items: stretch;
  overflow: hidden;
  background:
    radial-gradient(70% 45% at 50% 0%, #2A1249 0%, rgba(11, 6, 23, 0) 70%),
    #0B0617;
}

.stage {
  position: relative;
  width: 100vw;
  max-width: 480px;
  width: min(100vw, 480px, 56vh);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #160D2B;
  isolation: isolate;
}

@media (min-width: 540px) {
  .stage {
    box-shadow: 0 0 0 1px #2A1B46, 0 0 90px rgba(255, 138, 61, 0.1);
  }
}

#game {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  cursor: crosshair;
}

.vignette {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    radial-gradient(130% 75% at 50% 10%, rgba(0, 0, 0, 0) 52%, rgba(8, 3, 18, 0.5) 100%);
}

.scanlines {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0.2;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.4) 0,
    rgba(0, 0, 0, 0.4) 1px,
    rgba(0, 0, 0, 0) 1px,
    rgba(0, 0, 0, 0) 3px
  );
  mix-blend-mode: multiply;
}

/* ---------------- HUD ---------------- */

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 6;
  display: flex;
  align-items: flex-start;
  gap: 7px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 12px 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.hud.is-hidden {
  opacity: 0;
  transform: translateY(-12px);
  pointer-events: none !important;
}

.hud.is-hidden > * {
  pointer-events: none !important;
}

.hud > * {
  pointer-events: auto;
}

.hud-btn,
.hud-card,
.hud-lives {
  background: rgba(27, 15, 49, 0.8);
  border: 2px solid var(--line-soft);
  border-radius: 10px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.hud-btn {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  background: linear-gradient(180deg, #FFB572 0%, #FF8A3D 55%, #F5792B 100%);
  border: 2px solid #A6430D;
  box-shadow: 0 3px 0 #7C2F08, inset 0 2px 0 rgba(255, 255, 255, 0.45);
  transition: transform 0.08s ease, filter 0.15s ease;
}

.hud-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #7C2F08, inset 0 2px 0 rgba(255, 255, 255, 0.35);
}

.px-pause {
  display: flex;
  gap: 4px;
}

.px-pause i {
  display: block;
  width: 4px;
  height: 14px;
  background: #3B1704;
  border-radius: 1px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.24);
}

.hud-card {
  flex: 1 1 auto;
  min-width: 0;
  padding: 6px 9px 7px;
}

.hud-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.hud-line-bottom {
  margin-top: 5px;
}

.hud-level {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 1.4px;
  color: var(--cream);
  white-space: nowrap;
}

.hud-score {
  min-width: 0;
  overflow: hidden;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.5px;
  color: var(--orange-light);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-score::before {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: 4px;
  vertical-align: 1px;
  background: var(--gold);
  border-radius: 1px;
  box-shadow: 0 0 4px rgba(255, 197, 61, 0.45);
}

.hud-bar {
  flex: 1 1 auto;
  height: 5px;
  overflow: hidden;
  background: #3A2758;
  border-radius: 3px;
}

.hud-bar i {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--orange));
  border-radius: 3px;
  box-shadow: 0 0 6px rgba(255, 138, 61, 0.6);
  transition: width 0.18s ease;
}

.hud-stars {
  flex: 0 0 auto;
  display: flex;
  gap: 2px;
}

.star {
  display: block;
  width: 9px;
  height: 9px;
  background: #4A3768;
  clip-path: polygon(50% 0%, 61% 34%, 97% 35%, 68% 57%, 79% 92%, 50% 71%, 21% 92%, 32% 57%, 3% 35%, 39% 34%);
}

.star.on {
  background: var(--gold);
  filter: drop-shadow(0 0 3px rgba(255, 197, 61, 0.55));
}

.hud-lives {
  flex: 0 0 auto;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 8px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--cream);
}

.life-ball {
  display: block;
  width: 9px;
  height: 9px;
  background: #EAF9FF;
  border-radius: 2px;
  box-shadow: 0 0 6px rgba(170, 225, 255, 0.85), inset 0 0 0 1px #B7E6FF;
}

/* ---------------- Overlays ---------------- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: calc(env(safe-area-inset-top, 0px) + 18px) 18px calc(env(safe-area-inset-bottom, 0px) + 18px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: rgba(10, 5, 22, 0.58);
}

.overlay.show {
  display: flex;
  animation: fade-in 0.2s ease both;
}

#screenHome {
  background:
    linear-gradient(180deg, rgba(12, 6, 26, 0.08) 0%, rgba(12, 6, 26, 0.52) 56%, rgba(12, 6, 26, 0.92) 100%),
    radial-gradient(95% 42% at 50% 0%, rgba(255, 138, 61, 0.16), rgba(255, 138, 61, 0) 72%);
}

/* ---------------- 首页 ---------------- */

.home {
  position: relative;
  width: 100%;
  max-width: 360px;
  margin: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.home-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

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

.avatar {
  position: relative;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  overflow: hidden;
  background: #2A1747;
  border: 2px solid #6B4A9C;
  border-radius: 12px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.32);
}

.avatar svg {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.player-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.player-kicker {
  font-family: var(--mono);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--muted);
}

.player-meta strong {
  max-width: 180px;
  overflow: hidden;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--cream);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sound-btn {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--orange-light);
  cursor: pointer;
  background: rgba(27, 15, 49, 0.8);
  border: 2px solid var(--line-soft);
  border-radius: 10px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  transition: transform 0.08s ease;
}

.sound-btn:active {
  transform: translateY(2px);
}

.sound-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.sound-btn .ico-mute {
  display: none;
}

.sound-btn.is-off {
  color: #806D9E;
}

.sound-btn.is-off .ico-sound {
  display: none;
}

.sound-btn.is-off .ico-mute {
  display: block;
}

.logo {
  margin: 4px 0 2px;
  text-align: center;
}

.brick-logo {
  display: flex;
  justify-content: center;
  gap: 3px;
  margin-bottom: 14px;
}

.brick-logo i {
  width: clamp(22px, 7vw, 28px);
  height: 11px;
  background: var(--c);
  border-radius: 2px;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.46),
    inset 0 -3px 0 rgba(0, 0, 0, 0.26),
    0 3px 0 rgba(0, 0, 0, 0.34);
  animation: brick-bob 2.6s ease-in-out infinite;
}

.brick-logo i:nth-child(2n) {
  margin-top: 3px;
  animation-delay: -0.8s;
}

.brick-logo i:nth-child(3n) {
  animation-delay: -1.6s;
}

.logo h1 {
  margin: 0;
  font-size: clamp(32px, 9.6vw, 41px);
  font-weight: 900;
  line-height: 1.08;
  letter-spacing: 3px;
  color: #FFF7EA;
  text-shadow:
    3px 3px 0 #8F3A0C,
    6px 6px 0 rgba(0, 0, 0, 0.36),
    0 0 28px rgba(255, 138, 61, 0.34);
}

.logo-en {
  margin: 9px 0 0;
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 5px;
  color: var(--orange);
  text-shadow: 0 0 12px rgba(255, 138, 61, 0.45);
}

.best-chip {
  align-self: center;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(28, 15, 52, 0.82);
  border: 2px solid var(--line-soft);
  border-radius: 9px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
}

.best-kicker {
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--muted);
}

.best-chip strong {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  color: var(--orange-light);
}

.best-tag {
  padding: 3px 5px;
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #1B1033;
  background: var(--gold);
  border-radius: 4px;
}

.home-actions {
  display: flex;
  gap: 10px;
}

.home-actions .btn {
  flex: 1 1 0;
  min-width: 0;
}

.home-hint {
  margin: 2px 0 0;
  font-size: 11px;
  letter-spacing: 0.4px;
  color: var(--muted);
  text-align: center;
}

.home-foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  color: #7E6A9E;
}

.foot-dot {
  width: 3px;
  height: 3px;
  background: #5B477C;
}

/* ---------------- 按钮 ---------------- */

.btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 1px;
  border: 0;
  border-radius: 13px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.15s ease;
}

.btn-primary {
  color: #3C1B06;
  background: linear-gradient(180deg, #FFC078 0%, #FF8A3D 55%, #F5792B 100%);
  box-shadow:
    0 6px 0 var(--orange-deep),
    0 12px 22px rgba(0, 0, 0, 0.38),
    inset 0 2px 0 rgba(255, 255, 255, 0.55);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.28);
}

.btn-primary:active {
  transform: translateY(5px);
  box-shadow:
    0 2px 0 var(--orange-deep),
    0 6px 12px rgba(0, 0, 0, 0.35),
    inset 0 2px 0 rgba(255, 255, 255, 0.4);
}

@media (hover: hover) {
  .btn-primary:hover {
    filter: brightness(1.04);
  }

  .btn-ghost:hover {
    background: rgba(255, 255, 255, 0.09);
  }
}

.btn-ghost {
  min-height: 46px;
  font-size: 14px;
  color: #EADDF6;
  background: rgba(255, 255, 255, 0.055);
  border: 2px solid #503A78;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.btn-ghost:active {
  transform: translateY(3px);
  box-shadow: 0 0 0 rgba(0, 0, 0, 0), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

/* 激励视频复活按钮：金色 + AD 标，和普通橙色主按钮区分 */
.btn-ad {
  color: #3A2205;
  font-size: 15px;
  background: linear-gradient(180deg, #FFE59A 0%, #FFC53D 55%, #F2AC1F 100%);
  box-shadow:
    0 6px 0 #9A6206,
    0 12px 22px rgba(0, 0, 0, 0.34),
    inset 0 2px 0 rgba(255, 255, 255, 0.6);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
}

.btn-ad:active {
  transform: translateY(5px);
  box-shadow:
    0 2px 0 #9A6206,
    0 6px 12px rgba(0, 0, 0, 0.32),
    inset 0 2px 0 rgba(255, 255, 255, 0.45);
}

.btn-ad:disabled {
  cursor: default;
  filter: saturate(0.65) brightness(0.9);
  transform: none;
}

.btn-ad.is-loading {
  animation: ad-breathe 1.2s ease-in-out infinite;
}

.ad-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 5px;
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 1px;
  color: var(--gold);
  background: #2A1430;
  border-radius: 4px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.ad-plus {
  padding: 3px 5px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  color: #6B3A02;
  background: rgba(255, 255, 255, 0.38);
  border-radius: 4px;
}

.btn-ad.is-loading .ad-plus {
  display: none;
}

.revive-box {
  margin-top: 16px;
}

.revive-box + .panel-actions {
  margin-top: 12px;
}

.ad-hint {
  margin: 8px 0 0;
  font-size: 11px;
  line-height: 1.4;
  color: var(--muted);
  text-align: center;
}

.px-play {
  width: 15px;
  height: 15px;
  fill: currentColor;
  filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.25));
}

.btn:focus-visible,
.hud-btn:focus-visible,
.sound-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* ---------------- 弹层 ---------------- */

.panel {
  width: 100%;
  max-width: 340px;
  margin: auto;
  padding: 22px 18px 18px;
  text-align: center;
  background: linear-gradient(180deg, #2C194E 0%, #21113E 100%);
  border: 2px solid #543D80;
  border-radius: 18px;
  box-shadow:
    0 8px 0 rgba(0, 0, 0, 0.32),
    0 24px 60px rgba(0, 0, 0, 0.5),
    inset 0 2px 0 rgba(255, 255, 255, 0.08);
  animation: pop 0.24s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}

.panel-left {
  text-align: left;
}

.kicker {
  margin: 0 0 8px;
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--orange);
}

.panel h2 {
  margin: 0;
  font-size: 23px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: 1px;
  color: var(--cream);
}

.panel-sub {
  margin: 8px 0 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}

.result-stars {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 26px;
  margin-top: 14px;
}

.result-stars .star {
  width: 24px;
  height: 24px;
}

.result-stars .star.on {
  filter: drop-shadow(0 0 7px rgba(255, 197, 61, 0.5));
}

.score-box {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin: 14px 0 4px;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.24);
  border: 2px solid var(--line-soft);
  border-radius: 10px;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.25);
}

.score-box span {
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--muted);
}

.score-box strong {
  font-family: var(--mono);
  font-size: 30px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  color: var(--orange-light);
  text-shadow: 0 3px 0 #6E2A08;
}

.meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 12px 0 0;
  padding: 0 2px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.5px;
  color: var(--muted);
}

.panel-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

.rules {
  margin: 14px 0 0;
  padding-left: 20px;
  font-size: 13px;
  line-height: 1.65;
  color: #D9CCEA;
}

.rules li {
  margin-bottom: 9px;
}

.rules li:last-child {
  margin-bottom: 0;
}

.rules b {
  color: var(--orange-light);
}

/* ---------------- Toast ---------------- */

.toast {
  position: absolute;
  top: 62%;
  left: 50%;
  z-index: 30;
  max-width: 88%;
  overflow: hidden;
  padding: 9px 14px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--cream);
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
  background: rgba(22, 11, 40, 0.94);
  border: 2px solid var(--orange);
  border-radius: 9px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  opacity: 0;
  transform: translate(-50%, -6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

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

/* ---------------- 小屏适配 ---------------- */

@media (max-height: 700px) {
  .home {
    gap: 10px;
  }

  .logo {
    margin: 0;
  }

  .logo h1 {
    font-size: clamp(29px, 8.6vw, 34px);
  }

  .brick-logo {
    margin-bottom: 10px;
  }

  .brick-logo i {
    height: 9px;
  }

  .home-hint {
    display: none;
  }

  .panel {
    padding: 18px 16px 15px;
  }

  .panel-actions {
    margin-top: 13px;
  }
}

@media (max-height: 590px) {
  .home-foot,
  .logo-en {
    display: none;
  }

  .logo h1 {
    font-size: 26px;
  }

  .brick-logo {
    display: none;
  }

  .btn {
    min-height: 46px;
    font-size: 15px;
  }

  .btn-ghost {
    min-height: 40px;
    font-size: 13px;
  }

  .meta-row {
    display: none;
  }

  .ad-hint {
    display: none;
  }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes pop {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes brick-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}

@keyframes ad-breathe {
  0%, 100% { filter: brightness(0.92); }
  50% { filter: brightness(1.06); }
}

@media (prefers-reduced-motion: reduce) {
  .overlay.show,
  .panel {
    animation: none;
  }

  .brick-logo i {
    animation: none;
  }

  .btn-ad.is-loading {
    animation: none;
  }
}
