:root {
  --orange: #FF8A3D;
  --orange-2: #FFC46B;
  --orange-deep: #D9540E;
  --pink: #FF4FD8;
  --cyan: #2DE2FF;
  --violet: #A77BFF;
  --gold: #FFD166;
  --ink: #F8F4FF;
  --muted: #A99ACA;
  --bg: #080416;
  --panel: rgba(21, 11, 46, 0.74);
  --line: rgba(174, 140, 255, 0.24);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: "PingFang SC", "HarmonyOS Sans SC", "Noto Sans SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button {
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(120% 70% at 50% -10%, #2a1060 0%, #100628 45%, #080416 100%),
    var(--bg);
}

#game {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

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

.hud {
  position: absolute;
  z-index: 20;
  top: calc(var(--safe-top) + 8px);
  left: 50%;
  width: calc(100% - 20px);
  max-width: 540px;
  transform: translateX(-50%);
  display: flex;
  align-items: stretch;
  gap: 7px;
  pointer-events: none;
  filter: drop-shadow(0 8px 20px rgba(0, 0, 0, 0.38));
}

.hud-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 15px;
  background:
    linear-gradient(165deg, rgba(71, 39, 136, 0.56), rgba(17, 8, 40, 0.82));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.13),
    inset 0 -8px 16px rgba(9, 3, 24, 0.28);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  overflow: hidden;
}

.hud-card::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(110deg, rgba(255, 255, 255, 0.1), transparent 38%);
  opacity: 0.7;
}

.hud-song {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px 7px 7px;
}

.hud-note {
  flex: none;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(145deg, #ff7ae6 0%, #b33cff 46%, #5b2bd4 100%);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.34) inset,
    0 0 16px rgba(255, 79, 216, 0.5),
    0 3px 10px rgba(0, 0, 0, 0.35);
}

.hud-note .mp-icon {
  width: 19px;
  height: 19px;
}

.hud-song-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  line-height: 1.1;
}

.hud-song-copy b {
  overflow: hidden;
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: 0.03em;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: #f4eeff;
  text-shadow: 0 0 10px rgba(190, 150, 255, 0.45);
}

.hud-song-copy small {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 4px;
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: #b8a6df;
}

.bpm-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 7px var(--cyan);
  animation: beatDot 1s ease-in-out infinite;
}

.hud-score {
  flex: none;
  min-width: 78px;
  padding: 6px 10px 5px;
  text-align: center;
  border-color: rgba(193, 154, 255, 0.42);
  background:
    linear-gradient(180deg, rgba(119, 65, 210, 0.55), rgba(22, 10, 52, 0.88));
}

.hud-label {
  display: block;
  margin-bottom: 3px;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.2em;
  color: #c0adeb;
}

.hud-score b {
  display: block;
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
  color: #fff;
  text-shadow: 0 0 16px rgba(174, 116, 255, 0.8);
}

.hud-combo {
  flex: none;
  min-width: 58px;
  padding: 6px 8px 5px;
  text-align: center;
}

.hud-combo b {
  display: block;
  font-size: 17px;
  font-weight: 900;
  line-height: 1.18;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
  text-shadow: 0 0 13px rgba(255, 197, 92, 0.7);
}

.hud-score b.pop,
.hud-combo b.pop {
  animation: statPop 0.28s cubic-bezier(0.2, 1.5, 0.5, 1);
}

.round-btn {
  flex: none;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(179, 145, 255, 0.38);
  border-radius: 50%;
  color: #ede3ff;
  background: linear-gradient(155deg, rgba(75, 42, 144, 0.8), rgba(16, 7, 38, 0.9));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    0 4px 14px rgba(0, 0, 0, 0.3),
    0 0 16px rgba(124, 74, 220, 0.24);
  pointer-events: auto;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: transform 0.12s ease, opacity 0.2s ease;
}

.round-btn .mp-icon {
  width: 21px;
  height: 21px;
}

.round-btn:active {
  transform: scale(0.9);
}

.pause-btn {
  align-self: center;
}

.app.is-menu .pause-btn {
  opacity: 0.35;
  pointer-events: none;
}

.sound-btn {
  position: absolute;
  z-index: 22;
  right: max(13px, calc((100vw - 540px) / 2 + 7px));
  bottom: calc(var(--safe-bottom) + 13px);
  width: 40px;
  height: 40px;
  color: #dcd0ff;
  opacity: 0.86;
}

.app.is-menu .sound-btn,
.app.is-paused .sound-btn {
  opacity: 0;
  pointer-events: none;
}

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

.sound-btn.is-muted .sound-on {
  display: none;
}

.sound-btn.is-muted .sound-off {
  display: inline-block;
  color: #ff9bb8;
}

/* ---------------- start panel ---------------- */

.start-layer {
  position: absolute;
  z-index: 30;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 16px calc(var(--safe-bottom) + 16px);
  background: linear-gradient(180deg, rgba(8, 4, 22, 0) 30%, rgba(8, 4, 22, 0.45) 62%, rgba(8, 4, 22, 0.9) 100%);
  pointer-events: none;
  transition: opacity 0.34s ease, visibility 0.34s;
}

.start-layer.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.start-panel {
  position: relative;
  width: min(380px, 100%);
  padding: 14px 14px 12px;
  border: 1px solid rgba(186, 150, 255, 0.42);
  border-radius: 25px;
  background:
    radial-gradient(130% 100% at 15% 0%, rgba(255, 122, 230, 0.15), transparent 46%),
    linear-gradient(160deg, rgba(47, 26, 96, 0.94), rgba(13, 6, 31, 0.97));
  box-shadow:
    0 22px 60px rgba(0, 0, 0, 0.62),
    0 0 0 1px rgba(255, 255, 255, 0.045) inset,
    0 0 46px rgba(124, 58, 237, 0.22);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  pointer-events: auto;
  animation: panelRise 0.6s cubic-bezier(0.2, 0.9, 0.3, 1.05) both;
}

.start-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.cover {
  position: relative;
  flex: none;
  width: 78px;
  height: 78px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 17px;
  box-shadow:
    0 0 22px rgba(255, 79, 216, 0.3),
    0 5px 16px rgba(0, 0, 0, 0.35);
}

.cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 42%;
  filter: saturate(1.18) contrast(1.04);
}

.cover::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 42%, rgba(10, 4, 26, 0.55) 100%);
}

.cover-shine {
  position: absolute;
  top: -30%;
  left: -55%;
  width: 45%;
  height: 160%;
  transform: rotate(18deg);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.42), transparent);
  animation: coverShine 4.6s ease-in-out infinite;
}

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

.eyebrow {
  margin: 0 0 4px;
  font-size: 8.5px;
  font-weight: 800;
  letter-spacing: 0.26em;
  color: var(--orange-2);
  text-shadow: 0 0 10px rgba(255, 138, 61, 0.38);
}

.start-copy h1 {
  margin: 0;
  overflow: hidden;
  font-size: 21px;
  font-weight: 900;
  line-height: 1.16;
  letter-spacing: 0.015em;
  white-space: nowrap;
  color: #fff;
  text-shadow:
    0 0 18px rgba(184, 140, 255, 0.55),
    0 2px 0 rgba(76, 31, 150, 0.65);
}

.start-sub {
  margin: 6px 0 0;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.05em;
  color: #b9a9df;
}

.primary-btn {
  position: relative;
  width: 100%;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  overflow: hidden;
  padding: 0 16px;
  border: 0;
  border-radius: 16px;
  color: #2b0e00;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.12em;
  background: linear-gradient(180deg, #ffd08a 0%, #ffab55 30%, #ff8a3d 58%, #ee5a12 100%);
  box-shadow:
    0 9px 24px rgba(255, 108, 36, 0.38),
    0 1px 0 rgba(255, 255, 255, 0.65) inset,
    0 -3px 0 rgba(143, 48, 0, 0.3) inset;
  transition: transform 0.1s ease, filter 0.16s ease;
}

.primary-btn .mp-icon {
  width: 23px;
  height: 23px;
}

.primary-btn > * {
  position: relative;
  z-index: 2;
}

.primary-btn::after {
  content: "";
  position: absolute;
  z-index: 1;
  top: -20%;
  left: -50%;
  width: 34%;
  height: 140%;
  transform: skewX(-18deg);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.6), transparent);
  animation: buttonShine 3s ease-in-out infinite;
}

.primary-btn:active {
  transform: scale(0.972);
  filter: brightness(0.97);
}

.start-hint {
  margin: 9px 0 0;
  text-align: center;
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: #a899cc;
}

.start-best {
  margin: 5px 0 0;
  text-align: center;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: #8f81b5;
}

.start-best b {
  margin-left: 3px;
  font-size: 12px;
  color: var(--gold);
  letter-spacing: 0.02em;
  text-shadow: 0 0 10px rgba(255, 209, 102, 0.35);
}

/* ---------------- sheets ---------------- */

.sheet-layer {
  position: absolute;
  z-index: 40;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 18px calc(var(--safe-bottom) + 20px);
  background: rgba(5, 2, 14, 0.68);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  -webkit-backdrop-filter: blur(9px);
  backdrop-filter: blur(9px);
  transition: opacity 0.22s ease, visibility 0.22s;
}

.sheet-layer.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.sheet {
  width: min(340px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 14px 20px 18px;
  border: 1px solid rgba(185, 149, 255, 0.36);
  border-radius: 26px;
  text-align: center;
  background:
    radial-gradient(120% 60% at 50% 0%, rgba(255, 122, 230, 0.12), transparent 55%),
    linear-gradient(165deg, rgba(47, 26, 96, 0.97), rgba(11, 5, 28, 0.99));
  box-shadow:
    0 26px 70px rgba(0, 0, 0, 0.7),
    0 0 0 1px rgba(255, 255, 255, 0.045) inset,
    0 0 60px rgba(124, 58, 237, 0.18);
  transform: translateY(14px) scale(0.97);
  transition: transform 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}

.sheet-layer.is-open .sheet {
  transform: translateY(0) scale(1);
}

.sheet-cover {
  height: 92px;
  margin: 0 0 15px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  background-image:
    linear-gradient(180deg, rgba(10, 4, 26, 0) 30%, rgba(16, 7, 36, 0.82) 100%),
    url("images/gen/gptimg_1795177426_look.png");
  background-size: cover, cover;
  background-position: center, 50% 46%;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
}

.sheet .eyebrow {
  margin-bottom: 5px;
}

.sheet h2 {
  margin: 0;
  font-size: 25px;
  font-weight: 900;
  letter-spacing: 0.03em;
  color: #fff;
  text-shadow: 0 0 22px rgba(174, 116, 255, 0.5);
}

.sheet-sub {
  margin: 7px 0 0;
  font-size: 11.5px;
  line-height: 1.5;
  color: #ad9dd3;
}

.sheet-actions {
  display: grid;
  gap: 9px;
  margin-top: 16px;
}

.sheet-actions .primary-btn {
  height: 50px;
  font-size: 15px;
}

.ghost-btn {
  width: 100%;
  height: 45px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid rgba(170, 135, 255, 0.26);
  border-radius: 14px;
  color: #d9ccff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  background: rgba(255, 255, 255, 0.05);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transition: transform 0.1s ease, background 0.16s ease;
}

.ghost-btn .mp-icon {
  width: 19px;
  height: 19px;
}

.ghost-btn:active {
  transform: scale(0.975);
  background: rgba(255, 255, 255, 0.09);
}

.final-score {
  margin: 11px 0 14px;
  font-size: 46px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
  color: #fff;
  text-shadow:
    0 0 28px rgba(255, 138, 61, 0.55),
    0 0 60px rgba(255, 79, 216, 0.3);
}

.stats {
  display: flex;
  gap: 9px;
}

.stats div {
  flex: 1;
  padding: 9px 6px;
  border: 1px solid rgba(171, 137, 255, 0.2);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.045);
}

.stats span {
  display: block;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.09em;
  color: #9e8ec6;
}

.stats b {
  display: block;
  margin-top: 4px;
  font-size: 17px;
  font-weight: 800;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.best-line {
  margin: 12px 0 0;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: #8f81b5;
}

.best-line b {
  margin-left: 4px;
  font-size: 12px;
  color: #e8dcff;
}

.over-sheet .sheet-cover {
  height: 76px;
  opacity: 0.85;
}

/* ---------------- misc ---------------- */

.toast {
  position: absolute;
  z-index: 25;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 78px);
  max-width: calc(100% - 48px);
  padding: 9px 15px;
  border: 1px solid rgba(180, 145, 255, 0.28);
  border-radius: 999px;
  background: rgba(20, 10, 44, 0.8);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  white-space: nowrap;
  color: #e4d8ff;
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: opacity 0.24s ease, transform 0.24s ease;
}

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

.safe-probe {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 1px;
  height: var(--safe-bottom);
  opacity: 0;
  pointer-events: none;
}

/* ---------------- animations ---------------- */

@keyframes beatDot {
  0%, 100% { transform: scale(1); opacity: 0.75; }
  18% { transform: scale(1.7); opacity: 1; }
  46% { transform: scale(1); opacity: 0.85; }
}

@keyframes statPop {
  0% { transform: scale(1); }
  35% { transform: scale(1.28); }
  100% { transform: scale(1); }
}

@keyframes panelRise {
  from { opacity: 0; transform: translateY(26px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes buttonShine {
  0%, 54% { left: -55%; }
  82%, 100% { left: 125%; }
}

@keyframes coverShine {
  0%, 62% { left: -60%; }
  88%, 100% { left: 130%; }
}

@media (max-height: 700px) {
  .start-panel {
    padding: 11px 13px 9px;
  }
  .cover {
    width: 64px;
    height: 64px;
  }
  .start-copy h1 {
    font-size: 18.5px;
  }
  .primary-btn {
    height: 48px;
    font-size: 15px;
  }
  .start-hint,
  .start-best {
    margin-top: 5px;
  }
  .sheet-cover {
    height: 68px;
    margin-bottom: 11px;
  }
  .sheet {
    padding: 12px 18px 15px;
  }
  .sheet h2 {
    font-size: 22px;
  }
  .final-score {
    font-size: 38px;
    margin: 8px 0 11px;
  }
  .sheet-actions {
    margin-top: 12px;
  }
}

@media (max-width: 350px) {
  .hud {
    gap: 5px;
    width: calc(100% - 14px);
  }
  .hud-score {
    min-width: 68px;
    padding-left: 7px;
    padding-right: 7px;
  }
  .hud-combo {
    min-width: 50px;
    padding-left: 6px;
    padding-right: 6px;
  }
  .round-btn {
    width: 38px;
    height: 38px;
  }
  .start-copy h1 {
    font-size: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
