* { box-sizing: border-box; }

.after-dark body.heartbeat-page {
  min-height: 100vh;
  margin: 0;
  color: var(--cream);
  background: #170e13;
  font-family: "DM Sans", sans-serif;
}

.heartbeat-game {
  --serif: "Noto Serif SC", "Songti SC", Georgia, serif;
  --rule: #794452;
  width: min(100% - 36px, 460px);
  margin-inline: auto;
  padding-block: clamp(22px, 3.4vh, 38px) 38px;
  text-align: center;
}

.heartbeat-back {
  display: flex;
  align-items: center;
  width: fit-content;
  gap: 10px;
  min-height: 24px;
  padding-inline: 3px;
  color: var(--cream);
  font: 600 .95rem/1.4 var(--serif);
  text-decoration: none;
}
.heartbeat-back span {
  width: 7px;
  height: 7px;
  border: solid currentColor;
  border-width: 0 0 1.5px 1.5px;
  transform: rotate(45deg);
}
.heartbeat-back:hover { color: var(--rose); }

.heartbeat-header { margin-block: clamp(20px, 3.6vh, 38px) 25px; }
.heartbeat-header h1 {
  margin: 0;
  font: 700 clamp(2.3rem, 9vw, 3.4rem)/1.25 var(--serif);
  letter-spacing: .035em;
}
.heartbeat-header p {
  margin: 14px 0 0;
  color: var(--rose);
  font-size: clamp(.9rem, 4vw, 1.15rem);
  line-height: 1.45;
  letter-spacing: .04em;
}

.heartbeat-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 0;
  padding-block: 6px;
  border-block: 1px solid var(--rule);
  font-family: var(--serif);
}
.heartbeat-stats > div { padding-block: 2px 5px; }
.heartbeat-stats > div + div { border-inline-start: 1px solid var(--rule); }
.heartbeat-stats dt { font-size: .9rem; }
.heartbeat-stats dd {
  margin: 2px 0 0;
  font-size: 1.5rem;
  font-variant-numeric: tabular-nums;
}

.heartbeat-field {
  --ring-scale: 1;
  position: relative;
  isolation: isolate;
  display: grid;
  place-items: center;
  width: min(78%, 300px);
  aspect-ratio: 1;
  margin: clamp(32px, 7vh, 64px) auto clamp(28px, 5vh, 48px);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
}
.heartbeat-field::before {
  position: absolute;
  z-index: -1;
  inset: -14%;
  content: "";
  border-radius: 50%;
  background: radial-gradient(circle, #54232e72, #3c172358 44%, transparent 72%);
  pointer-events: none;
}
.heartbeat-field[aria-disabled="true"] { cursor: default; }
.heartbeat-field img { width: 57%; height: auto; user-select: none; }
.heartbeat-ring,
.heartbeat-shrinking {
  position: absolute;
  z-index: -1;
  aspect-ratio: 1;
  border-radius: 50%;
  pointer-events: none;
}
.heartbeat-ring {
  inset: 22%;
  border: 4px solid #984c63;
}
.heartbeat-shrinking {
  inset: 0;
  border: 2px solid #9e5169;
  border-top-color: #fac5d2;
  transform: rotate(45deg) scale(var(--ring-scale));
  box-shadow: 0 0 18px #bc557239;
}
.heartbeat-field[data-hit="perfect"] .heartbeat-ring { border-color: #ffd8e3; box-shadow: 0 0 20px #efaebf99; }
.heartbeat-field[data-hit="near"] .heartbeat-ring { border-color: #efaebf; }

@media (prefers-reduced-motion: no-preference) {
  .heartbeat-field[data-hit="perfect"] { --perfect-beat-duration: 760ms; }
  .heartbeat-field[data-hit="perfect"] img {
    animation: perfect-heartbeat var(--perfect-beat-duration) ease-in-out both;
  }
  .heartbeat-field[data-hit="perfect"]::after {
    position: absolute;
    z-index: -1;
    inset: 9%;
    content: "";
    border-radius: 50%;
    background: radial-gradient(circle, #ffd8e3 0%, #ee90adab 26%, #c14f7466 47%, transparent 69%);
    pointer-events: none;
    animation: perfect-heartbeat-glow var(--perfect-beat-duration) ease-in-out both;
  }
}

@keyframes perfect-heartbeat {
  0%, 100% { transform: scale(1); }
  18% { transform: scale(1.22); }
  31% { transform: scale(1.03); }
  49% { transform: scale(1.16); }
  72% { transform: scale(1); }
}

@keyframes perfect-heartbeat-glow {
  0%, 100% { opacity: 0; transform: scale(.78); }
  18% { opacity: .9; transform: scale(1.12); }
  31% { opacity: .28; transform: scale(.9); }
  49% { opacity: .68; transform: scale(1.08); }
  83% { opacity: 0; transform: scale(1.17); }
}

.heartbeat-status {
  min-height: 1.5em;
  margin: 0 0 24px;
  font: 600 clamp(.95rem, 4.4vw, 1.32rem)/1.5 var(--serif);
}
.heartbeat-action {
  width: min(82%, 280px);
  min-height: 52px;
  border: 1px solid #f6b8c6;
  border-radius: 11px;
  background: #efa6b7;
  color: #230e17;
  font: 700 1.3rem/1.3 var(--serif);
  cursor: pointer;
  touch-action: manipulation;
}
.heartbeat-action:hover:not([aria-disabled="true"]) { background: #ffc2d0; }
.heartbeat-action[aria-disabled="true"] { opacity: .7; cursor: default; }

.heartbeat-leaderboard {
  margin-top: 36px;
  padding: 18px 0 0;
  border-top: 1px solid var(--rule);
  text-align: start;
}
.heartbeat-leaderboard header,
.heartbeat-player {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.heartbeat-leaderboard h2,
.heartbeat-dialog h2 { margin: 0; font: 700 1.35rem/1.4 "Noto Serif SC", "Songti SC", serif; }
.heartbeat-leaderboard header > span,
.heartbeat-leaderboard p,
.heartbeat-dialog p { color: var(--soft); font-size: .875rem; line-height: 1.55; }
.heartbeat-player { margin-top: 12px; color: var(--soft); font-size: .9rem; }
.heartbeat-player > span { overflow-wrap: anywhere; }
.heartbeat-player button,
.heartbeat-dialog button {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--cream);
  background: var(--plum);
  font: 600 .875rem/1.4 "DM Sans", sans-serif;
  cursor: pointer;
}
.heartbeat-player button { flex: none; }
.heartbeat-player button:disabled { opacity: .55; cursor: default; }
.heartbeat-leaderboard ol { margin: 12px 0 0; padding: 0; list-style: none; }
.heartbeat-leaderboard li {
  display: grid;
  grid-template-columns: 2rem minmax(0, 1fr) max-content;
  align-items: baseline;
  gap: 8px;
  padding: 10px 3px;
  border-bottom: 1px solid #68445080;
}
.heartbeat-leaderboard li > :first-child { color: var(--rose); font-variant-numeric: tabular-nums; }
.heartbeat-leaderboard li > :nth-child(2) { overflow-wrap: anywhere; }
.heartbeat-leaderboard li > strong { font-variant-numeric: tabular-nums; }

.heartbeat-dialog {
  width: min(100% - 32px, 370px);
  padding: 24px;
  border: 1px solid #976175;
  border-radius: 18px;
  color: var(--cream);
  background: #281a21;
  box-shadow: 0 24px 70px #070408a6;
}
.heartbeat-dialog::backdrop { background: #140b10ba; backdrop-filter: blur(5px); }
.heartbeat-dialog p { margin: 8px 0 20px; }
.heartbeat-dialog label { display: block; margin-bottom: 6px; color: var(--soft); font-size: .875rem; }
.heartbeat-dialog input {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--cream);
  background: #171013;
  font: inherit;
}
.heartbeat-dialog-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; margin-top: 18px; }
.heartbeat-dialog button { min-height: 44px; }
.heartbeat-dialog button[type="submit"],
.heartbeat-dialog .heartbeat-replay {
  border-color: #f6b8c6;
  color: #230e17;
  background: #efa6b7;
}

.heartbeat-result {
  text-align: center;
  background: radial-gradient(ellipse at top, #482936, #281a21 72%);
}
.heartbeat-result img {
  display: block;
  width: 132px;
  height: auto;
  margin: -5px auto 4px;
}
.heartbeat-result h2 { font-size: 1.65rem; }
.heartbeat-result #heartbeat-result-message { margin-bottom: 10px; }
.heartbeat-result p.heartbeat-result-score {
  margin: 0;
  color: var(--rose);
  font-size: 1rem;
}
.heartbeat-result-score strong {
  color: var(--cream);
  font-size: 2.25rem;
  font-variant-numeric: tabular-nums;
}
.heartbeat-result .heartbeat-dialog-actions { grid-template-columns: 1fr 1fr; }
