:root {
  --night: #0d0b1d;
  --night-soft: #191532;
  --glass: rgba(20, 17, 41, 0.72);
  --glass-deep: rgba(13, 11, 30, 0.86);
  --cream: #fff3da;
  --cream-dim: #d8c7b0;
  --gold: #f2c86b;
  --gold-light: #ffe6a5;
  --rose: #e9968e;
  --jade: #a9cfb3;
  --ink: #3c2d2c;
  --line-gold: rgba(242, 200, 107, 0.26);
  --font-body: "Nunito", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-display: "STKaiti", "KaiTi", "Kaiti SC", "Songti SC", "Noto Serif SC", "SimSun", serif;
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--font-body);
  color: var(--cream);
  background: var(--night);
  user-select: none;
  -webkit-user-select: none;
}

button {
  font-family: inherit;
  border: 0;
  cursor: pointer;
}

.app {
  position: fixed;
  inset: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

#scene {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

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

.hud {
  position: absolute;
  z-index: 5;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 12px;
  padding:
    max(16px, env(safe-area-inset-top))
    max(clamp(14px, 3.4vw, 38px), env(safe-area-inset-right))
    0
    max(clamp(14px, 3.4vw, 38px), env(safe-area-inset-left));
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: opacity 0.4s ease, transform 0.4s ease, visibility 0.4s ease;
}

.hud.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.score-card {
  display: inline-flex;
  flex-direction: column;
  grid-column: 1;
  align-items: flex-start;
  justify-self: start;
  min-width: 118px;
  padding: 8px 17px 9px;
  border-radius: 18px;
  color: var(--cream);
  background:
    linear-gradient(135deg, rgba(255, 240, 200, 0.07), transparent 55%),
    var(--glass);
  border: 1px solid var(--line-gold);
  box-shadow:
    0 12px 32px rgba(3, 2, 12, 0.32),
    inset 0 1px 0 rgba(255, 244, 214, 0.09);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.hud-label {
  color: rgba(255, 236, 195, 0.55);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.2em;
}

.score-card strong {
  margin: 1px 0 2px;
  font-size: clamp(28px, 4.2vw, 36px);
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
  color: #fff5dd;
  text-shadow: 0 2px 12px rgba(255, 210, 125, 0.18);
  transition: transform 0.16s ease, color 0.16s ease;
}

.score-card strong.is-popping {
  animation: scorePop 0.3s ease;
}

.best-inline {
  color: rgba(232, 216, 190, 0.48);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.best-inline b {
  color: rgba(242, 200, 107, 0.85);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.brand-mark {
  display: flex;
  grid-column: 2;
  flex-direction: column;
  align-items: center;
  padding-top: 7px;
  color: rgba(255, 238, 204, 0.58);
  pointer-events: none;
}

.brand-mark span {
  font-family: var(--font-display);
  font-size: 16px;
  letter-spacing: 0.28em;
  padding-left: 0.28em;
}

.brand-mark small {
  margin-top: 1px;
  color: rgba(242, 200, 107, 0.38);
  font-size: 7px;
  font-weight: 800;
  letter-spacing: 0.36em;
  padding-left: 0.36em;
}

.hud-tools {
  display: flex;
  grid-column: 3;
  justify-content: flex-end;
  align-items: flex-start;
  justify-self: end;
  gap: 9px;
}

.next-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 72px;
  padding: 5px 6px 3px;
  border-radius: 16px;
  background:
    linear-gradient(135deg, rgba(255, 239, 199, 0.06), transparent 55%),
    var(--glass);
  border: 1px solid var(--line-gold);
  box-shadow: 0 12px 28px rgba(3, 2, 12, 0.26);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s ease;
}

.next-card.is-hidden {
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  pointer-events: none;
}

.next-label {
  color: rgba(242, 200, 107, 0.6);
  font-size: 7px;
  font-weight: 900;
  letter-spacing: 0.24em;
  padding-left: 0.24em;
  line-height: 1.2;
}

#nextMochi {
  display: block;
  width: 50px;
  height: 50px;
  margin: -2px 0 -1px;
}

.icon-btn,
.card-sound {
  pointer-events: auto;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  color: var(--gold);
  background: var(--glass);
  border: 1px solid var(--line-gold);
  box-shadow: 0 10px 26px rgba(3, 2, 12, 0.26), inset 0 1px 0 rgba(255, 244, 214, 0.08);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: transform 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.icon-btn:hover,
.card-sound:hover {
  transform: translateY(-2px);
  background: rgba(42, 35, 70, 0.88);
  color: var(--gold-light);
}

.icon-btn:active,
.card-sound:active {
  transform: scale(0.94);
}

.icon-btn svg,
.card-sound svg {
  width: 20px;
  height: 20px;
}

.icon-off {
  display: none;
}

.is-muted .icon-on {
  display: none;
}

.is-muted .icon-off {
  display: block;
}

/* ---------- Combo ---------- */

.combo-tag {
  position: absolute;
  z-index: 6;
  top: calc(max(16px, env(safe-area-inset-top)) + 80px);
  left: 50%;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px 7px;
  border-radius: 999px;
  color: #5a3d1e;
  background:
    linear-gradient(135deg, #fff5cb, #f0c566 78%);
  border: 1px solid rgba(255, 250, 222, 0.75);
  box-shadow:
    0 5px 0 rgba(107, 72, 23, 0.18),
    0 12px 28px rgba(17, 8, 24, 0.34);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.04em;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -6px) scale(0.92);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

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

.combo-star {
  color: #b47c24;
  font-size: 11px;
  animation: starSpin 2.4s linear infinite;
}

.combo-tag strong {
  font-size: 14px;
  line-height: 1;
}

.combo-track {
  width: 34px;
  height: 3px;
  margin-left: 2px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(92, 61, 30, 0.18);
}

.combo-track i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: #8f6321;
  transform-origin: left center;
}

/* ---------- Moment toast ---------- */

.moment {
  position: absolute;
  z-index: 7;
  top: 29%;
  left: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 12px) scale(0.94);
  text-align: center;
}

.moment.is-visible {
  animation: momentReveal 2.1s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.moment span {
  font-family: var(--font-display);
  color: #fff0bf;
  font-size: clamp(34px, 6vw, 54px);
  letter-spacing: 0.16em;
  padding-left: 0.16em;
  text-shadow:
    0 2px 0 rgba(112, 69, 24, 0.4),
    0 0 34px rgba(255, 218, 128, 0.52);
}

.moment small {
  color: rgba(255, 229, 172, 0.7);
  font-size: 8px;
  font-weight: 900;
  letter-spacing: 0.42em;
  padding-left: 0.42em;
}

/* ---------- Hint ---------- */

.hint {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  max-width: min(78vw, 360px);
  padding: 9px 17px;
  border-radius: 999px;
  color: rgba(255, 245, 222, 0.72);
  background: rgba(18, 14, 34, 0.64);
  border: 1px solid rgba(255, 236, 195, 0.12);
  box-shadow: 0 8px 24px rgba(2, 1, 10, 0.24);
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s ease;
}

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

/* ---------- Flash ---------- */

.flash {
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  opacity: 0;
  background:
    radial-gradient(circle at 50% 54%, rgba(255, 248, 213, 0.96), rgba(255, 220, 142, 0.5) 28%, rgba(255, 196, 99, 0) 64%);
}

.flash.is-active {
  animation: moonFlash 0.85s ease-out;
}

/* ---------- Misc ---------- */

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

.noscript {
  position: fixed;
  inset: auto 0 0;
  z-index: 30;
  margin: 0;
  padding: 14px;
  color: #fff;
  background: #7a3b42;
  text-align: center;
  font-weight: 700;
}

/* ---------- Animations ---------- */

@keyframes scorePop {
  0% { transform: scale(1); color: #fff5dd; }
  42% { transform: scale(1.14); color: var(--gold-light); }
  100% { transform: scale(1); color: #fff5dd; }
}

@keyframes starSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes momentReveal {
  0% { opacity: 0; transform: translate(-50%, 16px) scale(0.9); }
  14% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  72% { opacity: 1; transform: translate(-50%, -6px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -26px) scale(1.02); }
}

@keyframes moonFlash {
  0% { opacity: 0; }
  12% { opacity: 1; }
  100% { opacity: 0; }
}

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

@media (max-width: 720px) {
  .hud {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    gap: 6px;
  }

  .brand-mark {
    display: none;
  }

  .score-card {
    min-width: 98px;
    padding: 7px 13px 8px;
    border-radius: 15px;
  }

  .score-card strong {
    font-size: clamp(25px, 8vw, 32px);
  }

  .hud-label {
    font-size: 8px;
  }

  .next-card {
    width: 62px;
    border-radius: 14px;
    padding: 4px 5px 2px;
  }

  .next-label {
    font-size: 6px;
  }

  #nextMochi {
    width: 43px;
    height: 43px;
  }

  .icon-btn {
    width: 38px;
    height: 38px;
  }

  .icon-btn svg {
    width: 18px;
    height: 18px;
  }

  .hud-tools {
    gap: 6px;
  }

  .combo-tag {
    top: calc(max(16px, env(safe-area-inset-top)) + 72px);
  }

  .hint {
    bottom: max(18px, env(safe-area-inset-bottom));
    font-size: 10px;
    padding: 8px 14px;
  }
}

@media (max-width: 380px) {
  .score-card {
    min-width: 90px;
    padding: 6px 11px 7px;
  }

  .score-card strong {
    font-size: 24px;
  }

  .next-card {
    width: 56px;
  }

  #nextMochi {
    width: 38px;
    height: 38px;
  }

  .icon-btn {
    width: 35px;
    height: 35px;
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  .hud {
    padding-top: max(10px, env(safe-area-inset-top));
    padding-right: max(12px, env(safe-area-inset-right));
    padding-left: max(12px, env(safe-area-inset-left));
  }

  .score-card {
    padding: 5px 12px 6px;
    border-radius: 14px;
  }

  .score-card strong {
    font-size: 24px;
  }

  .brand-mark {
    display: none;
  }

  .next-card {
    width: 56px;
  }

  #nextMochi {
    width: 38px;
    height: 38px;
  }

  .combo-tag {
    top: calc(max(10px, env(safe-area-inset-top)) + 62px);
  }

  .hint {
    display: none;
  }

  .moment span {
    font-size: 32px;
  }
}

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

  .moment.is-visible {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
    animation: none !important;
  }
}
