@font-face {
  font-family: "Noto Serif Tibetan";
  src: url("assets/noto-serif-tibetan.woff2") format("woff2-variations");
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --ink: #f8f3e9;
  --muted: rgba(238, 239, 232, 0.62);
  --gold: #ffd166;
  --glass: rgba(9, 18, 40, 0.46);
  --line: rgba(255, 244, 210, 0.18);
  --safe-top: max(18px, env(safe-area-inset-top));
  --safe-bottom: max(18px, env(safe-area-inset-bottom));
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #071125;
}

body {
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button {
  color: inherit;
  font: inherit;
}

button:focus-visible {
  outline: 2px solid #fff4bb;
  outline-offset: 5px;
}

.stage {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  isolation: isolate;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.backdrop {
  position: absolute;
  inset: 0;
  z-index: -2;
  overflow: hidden;
  background:
    radial-gradient(circle at 52% 37%, rgba(87, 76, 155, 0.28), transparent 35%),
    linear-gradient(155deg, #061127 0%, #0a1732 46%, #071225 100%);
}

.backdrop::after {
  position: absolute;
  inset: 0;
  content: "";
  opacity: 0.16;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.36'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
}

.aurora {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.24;
  will-change: transform;
}

.aurora-one {
  top: -22vmax;
  left: -14vmax;
  width: 55vmax;
  height: 55vmax;
  background: #9858c7;
  animation: aurora-a 18s ease-in-out infinite alternate;
}

.aurora-two {
  right: -20vmax;
  bottom: -25vmax;
  width: 59vmax;
  height: 59vmax;
  background: #2aa795;
  animation: aurora-b 22s ease-in-out infinite alternate;
}

.aurora-three {
  top: 32%;
  left: 42%;
  width: 35vmax;
  height: 34vmax;
  background: #dc6a6f;
  opacity: 0.11;
  animation: aurora-c 15s ease-in-out infinite alternate;
}

.halo {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(74vmin, 720px);
  aspect-ratio: 1;
  border: 1px solid rgba(255, 221, 151, 0.12);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow:
    0 0 0 8vmin rgba(255, 217, 134, 0.018),
    0 0 0 16vmin rgba(255, 217, 134, 0.012);
}

.halo::before,
.halo::after {
  position: absolute;
  border-radius: 50%;
  content: "";
}

.halo::before {
  inset: 8%;
  border: 1px dashed rgba(141, 221, 229, 0.1);
  animation: slow-spin 55s linear infinite;
}

.halo::after {
  inset: 31%;
  border: 1px solid rgba(255, 238, 186, 0.11);
}

.stars {
  position: absolute;
  inset: 0;
}

.star {
  position: absolute;
  width: var(--s);
  height: var(--s);
  border-radius: 50%;
  background: #fff6d5;
  box-shadow: 0 0 9px rgba(255, 240, 183, 0.8);
  opacity: var(--o);
  animation: twinkle var(--t) ease-in-out infinite alternate;
}

.horizon {
  position: absolute;
  right: -15%;
  bottom: -38%;
  left: -15%;
  height: 62%;
  border-radius: 50% 50% 0 0;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(111, 197, 188, 0.13), transparent 52%),
    linear-gradient(to bottom, transparent, rgba(3, 10, 23, 0.38));
}

.world {
  position: absolute;
  inset: 0;
}

.words {
  position: absolute;
  inset: 0;
}

.word {
  --glow: rgba(255, 255, 255, 0.4);
  position: absolute;
  top: var(--y);
  left: var(--x);
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  margin: 0;
  padding: 4px 7px;
  border: 0;
  background: none;
  color: var(--color);
  font-family: "Noto Serif Tibetan", "Microsoft Himalaya", serif;
  font-size: var(--size);
  font-weight: var(--weight);
  font-variant-ligatures: normal;
  line-height: 1.55;
  white-space: nowrap;
  text-shadow:
    0 0 1px rgba(255, 255, 255, 0.35),
    0 0 14px var(--glow),
    0 0 34px var(--glow);
  cursor: pointer;
  transform: translate(-50%, -50%);
  transform-origin: 50% 50%;
  animation: drift var(--duration) ease-in-out var(--delay) infinite alternate;
  will-change: transform;
}

.word::before {
  position: absolute;
  inset: 10% -7%;
  z-index: -1;
  border-radius: 999px;
  background: radial-gradient(ellipse, var(--glow), transparent 70%);
  content: "";
  opacity: 0.15;
  filter: blur(8px);
}

.word:active {
  animation-play-state: paused;
}

.word.is-popping {
  pointer-events: none;
  animation: word-pop 240ms cubic-bezier(0.18, 0.88, 0.32, 1.2) forwards;
}

.word.rare {
  text-shadow:
    0 0 2px rgba(255, 255, 255, 0.9),
    0 0 10px rgba(255, 233, 151, 0.8),
    0 0 28px rgba(255, 205, 91, 0.72),
    0 0 52px rgba(255, 181, 76, 0.4);
}

.word.rare::after {
  position: absolute;
  top: -10px;
  right: -8px;
  color: #fff5c7;
  font-family: sans-serif;
  font-size: 12px;
  line-height: 1;
  text-shadow: 0 0 12px #ffd166;
  content: "✦";
  animation: sparkle 1.8s ease-in-out infinite;
}

.word[data-color="gold"] {
  --color: #ffd166;
  --glow: rgba(255, 195, 85, 0.36);
}

.word[data-color="coral"] {
  --color: #ff8c9e;
  --glow: rgba(255, 94, 128, 0.32);
}

.word[data-color="mint"] {
  --color: #81edc4;
  --glow: rgba(50, 231, 163, 0.27);
}

.word[data-color="sky"] {
  --color: #7edcff;
  --glow: rgba(72, 181, 255, 0.3);
}

.word[data-color="lilac"] {
  --color: #cbb1ff;
  --glow: rgba(167, 122, 255, 0.3);
}

.word[data-color="peach"] {
  --color: #ffb56f;
  --glow: rgba(255, 140, 62, 0.3);
}

.hud {
  position: absolute;
  top: var(--safe-top);
  right: max(18px, env(safe-area-inset-right));
  left: max(18px, env(safe-area-inset-left));
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  pointer-events: none;
}

.score-panel,
.clock,
.sound-button {
  pointer-events: auto;
}

.score-panel {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-self: start;
  min-width: 118px;
  padding: 12px 16px 11px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(16, 29, 55, 0.72), rgba(10, 20, 42, 0.42));
  box-shadow: 0 12px 45px rgba(0, 0, 0, 0.17);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.eyebrow {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.24em;
}

.score-line {
  display: flex;
  align-items: baseline;
  min-height: 42px;
  gap: 8px;
}

#score {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(35px, 5vw, 48px);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  line-height: 1.05;
  letter-spacing: -0.04em;
  text-shadow: 0 0 22px rgba(255, 235, 170, 0.18);
}

.multiplier {
  padding: 3px 7px;
  border: 1px solid rgba(255, 219, 116, 0.25);
  border-radius: 999px;
  background: rgba(255, 200, 78, 0.12);
  color: #ffe08f;
  font-size: 12px;
  font-weight: 700;
}

.best {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.1em;
}

.best b {
  color: rgba(248, 243, 233, 0.8);
  font-weight: 500;
}

.clock {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-self: center;
  margin-top: 1px;
  color: var(--muted);
  transition: color 250ms ease;
}

.clock-ring {
  position: relative;
  display: grid;
  width: clamp(58px, 8vw, 70px);
  aspect-ratio: 1;
  place-items: center;
  border: 1px solid rgba(255, 243, 210, 0.24);
  border-radius: 50%;
  background: rgba(8, 17, 38, 0.42);
  box-shadow:
    inset 0 0 24px rgba(255, 255, 255, 0.025),
    0 8px 38px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.clock-ring::after {
  position: absolute;
  inset: -4px;
  border: 2px solid transparent;
  border-top-color: rgba(255, 217, 126, 0.72);
  border-radius: 50%;
  content: "";
  transform: rotate(-35deg);
}

#timer {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(24px, 3.8vw, 32px);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  line-height: 1;
}

.clock-label {
  margin-top: 4px;
  font-size: 9px;
  letter-spacing: 0.26em;
}

.clock.urgent {
  color: #ffc4b7;
}

.clock.urgent .clock-ring {
  border-color: rgba(255, 139, 131, 0.4);
  animation: urgent-beat 850ms ease-in-out infinite;
}

.clock.urgent .clock-ring::after {
  border-top-color: #ff8e86;
}

.sound-button {
  display: grid;
  width: 45px;
  height: 45px;
  place-items: center;
  justify-self: end;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(10, 21, 43, 0.45);
  color: rgba(248, 243, 233, 0.78);
  cursor: pointer;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.sound-button svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.sound-button svg path:first-child {
  fill: currentColor;
  stroke: none;
}

.sound-off,
.sound-button.is-muted .sound-on {
  display: none;
}

.sound-button.is-muted .sound-off {
  display: block;
}

.sound-button.is-muted {
  color: rgba(248, 243, 233, 0.45);
}

.combo {
  position: absolute;
  top: 22%;
  left: 50%;
  z-index: 15;
  padding: 7px 13px;
  border: 1px solid rgba(255, 220, 125, 0.22);
  border-radius: 999px;
  background: rgba(255, 208, 104, 0.1);
  color: #ffe59e;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.08em;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 160ms ease, transform 160ms ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

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

.combo.is-bumping {
  animation: combo-bump 240ms ease;
}

.start-hint {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 36px);
  left: 50%;
  z-index: 18;
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: calc(100vw - 36px);
  padding: 12px 18px;
  border: 1px solid rgba(255, 232, 171, 0.24);
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(16, 30, 58, 0.74), rgba(9, 19, 41, 0.62));
  box-shadow: 0 12px 38px rgba(0, 0, 0, 0.22);
  color: rgba(255, 247, 224, 0.92);
  font-size: 12px;
  letter-spacing: 0.04em;
  white-space: nowrap;
  cursor: pointer;
  transform: translateX(-50%);
  transition: opacity 350ms ease, transform 350ms ease;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  animation: hint-breathe 2.4s ease-in-out infinite;
}

.start-hint.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
}

.hint-mark {
  color: #ffe28c;
  font-size: 14px;
  text-shadow: 0 0 15px #ffc64a;
}

.game-note {
  position: absolute;
  bottom: var(--safe-bottom);
  left: 50%;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  color: rgba(247, 243, 231, 0.34);
  font-size: 9px;
  letter-spacing: 0.18em;
  white-space: nowrap;
  transform: translateX(-50%);
  transition: opacity 300ms ease;
}

.game-note i {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: rgba(255, 221, 139, 0.62);
}

.stage.is-playing .game-note {
  opacity: 0.55;
}

.result {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(3, 9, 22, 0.43);
  animation: fade-in 260ms ease both;
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}

.result[hidden] {
  display: none;
}

.result-glow {
  position: absolute;
  width: min(86vw, 520px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 196, 93, 0.2), transparent 65%);
  pointer-events: none;
}

.result-card {
  position: relative;
  width: min(90vw, 380px);
  padding: 32px 30px 28px;
  overflow: hidden;
  border: 1px solid rgba(255, 234, 180, 0.23);
  border-radius: 30px;
  background:
    radial-gradient(circle at 50% -10%, rgba(255, 213, 116, 0.17), transparent 47%),
    linear-gradient(145deg, rgba(19, 33, 63, 0.96), rgba(8, 17, 38, 0.97));
  box-shadow:
    0 36px 100px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  text-align: center;
  animation: card-enter 480ms cubic-bezier(0.17, 0.84, 0.32, 1.12) both;
}

.result-card::before {
  position: absolute;
  top: 17px;
  right: 20px;
  color: rgba(255, 227, 154, 0.48);
  font-size: 13px;
  content: "✦";
}

.result-kicker {
  color: rgba(240, 236, 222, 0.5);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3em;
}

.result h1 {
  margin: 10px 0 8px;
  color: #fff0c5;
  font-family: "Noto Serif Tibetan", "Songti SC", "SimSun", serif;
  font-size: clamp(26px, 7vw, 34px);
  font-weight: 550;
  letter-spacing: 0.08em;
}

.result-score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  margin: 4px 0 0;
}

.result-score strong {
  color: var(--gold);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(68px, 18vw, 88px);
  font-variant-numeric: tabular-nums;
  font-weight: 400;
  line-height: 1;
  letter-spacing: -0.06em;
  text-shadow: 0 0 45px rgba(255, 197, 83, 0.2);
}

.result-score span {
  color: rgba(247, 241, 225, 0.56);
  font-size: 12px;
}

.result p {
  margin: 13px 0 24px;
  color: rgba(247, 241, 225, 0.6);
  font-size: 12px;
  letter-spacing: 0.04em;
}

.replay-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 50px;
  gap: 10px;
  border: 0;
  border-radius: 15px;
  background: linear-gradient(135deg, #ffe29a, #efb55e);
  box-shadow: 0 12px 30px rgba(237, 171, 75, 0.18);
  color: #33200d;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.replay-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

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

.float-score {
  position: fixed;
  z-index: 30;
  color: #fff1b1;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(22px, 4vw, 34px);
  font-weight: 700;
  pointer-events: none;
  text-shadow: 0 0 14px rgba(255, 197, 77, 0.75);
  animation: score-rise 780ms cubic-bezier(0.12, 0.72, 0.24, 1) forwards;
}

.particle {
  position: fixed;
  z-index: 29;
  width: var(--particle-size);
  height: var(--particle-size);
  border-radius: var(--particle-radius);
  background: var(--particle-color);
  box-shadow: 0 0 10px var(--particle-color);
  pointer-events: none;
  animation: particle-burst 620ms cubic-bezier(0.14, 0.66, 0.2, 1) forwards;
}

.live-region,
.noscript {
  position: fixed;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.stage.celebrate .backdrop {
  animation: backdrop-flash 700ms ease;
}

@keyframes drift {
  0% {
    transform: translate(-50%, -50%) translate3d(var(--dx-a), var(--dy-a), 0) rotate(var(--r-a));
  }
  100% {
    transform: translate(-50%, -50%) translate3d(var(--dx-b), var(--dy-b), 0) rotate(var(--r-b));
  }
}

@keyframes word-pop {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  55% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.32);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.38);
  }
}

@keyframes score-rise {
  0% {
    opacity: 0;
    transform: translate(-50%, -15%) scale(0.7);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, -55%) scale(1.12);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -170%) scale(0.92);
  }
}

@keyframes particle-burst {
  0% {
    opacity: 0.95;
    transform: translate(-50%, -50%) scale(0.3) rotate(0deg);
  }
  35% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--burst-x)), calc(-50% + var(--burst-y))) scale(0.05) rotate(180deg);
  }
}

@keyframes combo-bump {
  0%,
  100% {
    transform: translate(-50%, 0) scale(1);
  }
  50% {
    transform: translate(-50%, 0) scale(1.14);
  }
}

@keyframes hint-breathe {
  0%,
  100% {
    box-shadow: 0 12px 38px rgba(0, 0, 0, 0.22);
  }
  50% {
    box-shadow: 0 12px 44px rgba(255, 202, 95, 0.11);
  }
}

@keyframes urgent-beat {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.07);
  }
}

@keyframes card-enter {
  0% {
    opacity: 0;
    transform: translateY(20px) scale(0.94);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

@keyframes twinkle {
  from {
    opacity: calc(var(--o) * 0.45);
    transform: scale(0.75);
  }
  to {
    opacity: var(--o);
    transform: scale(1);
  }
}

@keyframes aurora-a {
  from {
    transform: translate3d(-3%, 0, 0) scale(0.95);
  }
  to {
    transform: translate3d(12%, 9%, 0) scale(1.08);
  }
}

@keyframes aurora-b {
  from {
    transform: translate3d(3%, 4%, 0) scale(1);
  }
  to {
    transform: translate3d(-10%, -8%, 0) scale(1.12);
  }
}

@keyframes aurora-c {
  from {
    transform: translate3d(-4%, -2%, 0) scale(0.9);
  }
  to {
    transform: translate3d(8%, 5%, 0) scale(1.16);
  }
}

@keyframes slow-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes sparkle {
  0%,
  100% {
    opacity: 0.35;
    transform: scale(0.7) rotate(0);
  }
  50% {
    opacity: 1;
    transform: scale(1.1) rotate(28deg);
  }
}

@keyframes backdrop-flash {
  0%,
  100% {
    filter: brightness(1);
  }
  38% {
    filter: brightness(1.22);
  }
}

@media (max-width: 620px) {
  .hud {
    left: max(13px, env(safe-area-inset-left));
    right: max(13px, env(safe-area-inset-right));
  }

  .score-panel {
    min-width: 103px;
    padding: 10px 13px 9px;
    border-radius: 16px;
  }

  #score {
    font-size: 36px;
  }

  .clock-ring {
    width: 58px;
  }

  .sound-button {
    width: 42px;
    height: 42px;
  }

  .start-hint {
    bottom: calc(var(--safe-bottom) + 30px);
    padding: 11px 15px;
    font-size: 11px;
  }

  .game-note {
    font-size: 8px;
  }
}

@media (max-width: 380px) {
  .score-panel {
    min-width: 92px;
  }

  .best {
    font-size: 9px;
  }

  .clock-ring {
    width: 52px;
  }

  #timer {
    font-size: 23px;
  }

  .sound-button {
    width: 39px;
    height: 39px;
  }

  .start-hint {
    max-width: calc(100vw - 24px);
    padding-inline: 12px;
    font-size: 10px;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .hud {
    top: 12px;
  }

  .score-panel {
    flex-direction: row;
    align-items: center;
    gap: 9px;
    padding: 7px 12px;
  }

  .eyebrow,
  .best {
    display: none;
  }

  .score-line {
    min-height: 0;
  }

  #score {
    font-size: 28px;
  }

  .clock-ring {
    width: 46px;
  }

  #timer {
    font-size: 20px;
  }

  .clock-label {
    display: none;
  }

  .start-hint {
    bottom: calc(var(--safe-bottom) + 4px);
  }

  .game-note {
    display: none;
  }
}

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

  .word {
    transform: translate(-50%, -50%);
  }
}
