/* ===========================================================================
   RHYTHM TAP — a perspective highway that breathes with the beat
   =========================================================================== */

.rh-stage {
  --pulse: 0;
  --track: var(--game-accent);
  --head: 22px;
  --pads: 0px;
  position: absolute;
  inset: 0;
  overflow: hidden;
}

@media (pointer: coarse) {
  .rh-stage { --pads: clamp(72px, 15%, 104px); }
}

body.force-touch .rh-stage { --pads: clamp(72px, 15%, 104px); }

/* --- Beat-reactive backdrop --- */
.rh-glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(60% 50% at 50% 92%, color-mix(in srgb, var(--track) 55%, transparent), transparent 70%),
    radial-gradient(40% 30% at 50% 20%, color-mix(in srgb, var(--track) 14%, transparent), transparent 70%);
  transition: background 0.4s var(--ease);
  opacity: calc(0.35 + var(--pulse) * 0.55);
}

.rh-stage.fever .rh-glow {
  background:
    radial-gradient(70% 60% at 50% 90%, rgba(255, 79, 216, 0.7), transparent 70%),
    radial-gradient(60% 50% at 50% 10%, rgba(255, 212, 71, 0.35), transparent 70%);
}

.rh-eq {
  position: absolute;
  bottom: calc(var(--pads) + 8%);
  width: 12%;
  height: 46%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 5px;
  pointer-events: none;
  opacity: 0.6;
}

.rh-eq--left { left: 3%; align-items: flex-start; }
.rh-eq--right { right: 3%; align-items: flex-end; }

.rh-eq i {
  display: block;
  height: 4px;
  width: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--track), transparent);
  transform-origin: left;
  transform: scaleX(calc(0.15 + var(--pulse) * var(--k)));
  transition: transform 0.06s linear;
}

.rh-eq--right i {
  background: linear-gradient(270deg, var(--track), transparent);
  transform-origin: right;
}

/* --- Progress + labels --- */
.rh-progress {
  position: absolute;
  left: 16px;
  right: 16px;
  top: 2px;
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
  z-index: 4;
}

.rh-progress__fill {
  display: block;
  height: 100%;
  transform-origin: left;
  transform: scaleX(0);
  background: linear-gradient(90deg, #FF4FD8, #2ED8FF, #FFD447, #A66BFF);
}

.rh-section {
  position: absolute;
  left: 0;
  right: 0;
  top: 12%;
  z-index: 4;
  text-align: center;
  font-family: var(--font-display);
  font-size: clamp(1.1rem, 4vw, 1.6rem);
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #fff;
  text-shadow: 0 0 24px var(--track);
  opacity: 0;
  pointer-events: none;
}

.rh-section.show {
  animation: rh-section 1.8s var(--ease) forwards;
}

@keyframes rh-section {
  0% { opacity: 0; letter-spacing: 0.6em; }
  20% { opacity: 1; letter-spacing: 0.22em; }
  75% { opacity: 1; }
  100% { opacity: 0; letter-spacing: 0.3em; }
}

.rh-combo {
  position: absolute;
  left: 0;
  right: 0;
  top: 26%;
  z-index: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s var(--ease);
}

.rh-combo.on { opacity: 1; }

.rh-combo b {
  font-family: var(--font-display);
  font-size: clamp(4rem, 16vw, 7.5rem);
  font-weight: 700;
  line-height: 1;
  color: rgba(255, 255, 255, 0.09);
  -webkit-text-stroke: 1px rgba(255, 255, 255, 0.16);
}

.rh-combo small {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.25);
}

.rh-combo.bump b {
  animation: rh-combo-bump 0.18s var(--ease);
}

@keyframes rh-combo-bump {
  0% { transform: scale(1.12); color: rgba(255, 255, 255, 0.2); }
  100% { transform: scale(1); }
}

/* --- Highway --- */
.rh-highway {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: var(--pads);
  width: min(460px, 72%);
  translate: -50% 0;
  perspective: 720px;
  perspective-origin: 50% 100%;
  z-index: 2;
}

.rh-road {
  position: absolute;
  inset: 0;
  display: flex;
  transform: rotateX(30deg);
  transform-origin: 50% 100%;
  background: linear-gradient(180deg, transparent, rgba(10, 12, 28, 0.85) 28%, rgba(14, 16, 36, 0.92));
  border-left: 1px solid rgba(255, 255, 255, 0.12);
  border-right: 1px solid rgba(255, 255, 255, 0.12);
  mask-image: linear-gradient(180deg, transparent 0%, #000 16%);
  -webkit-mask-image: linear-gradient(180deg, transparent 0%, #000 16%);
}

.rh-stage.fever .rh-road {
  border-color: rgba(255, 79, 216, 0.6);
  box-shadow: 0 0 60px rgba(255, 79, 216, 0.35);
}

.rh-lane {
  --lane: #FF4FD8;
  position: relative;
  flex: 1;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  cursor: pointer;
}

.rh-lane:last-child { border-right: none; }
.rh-lane[data-lane="1"] { --lane: #2ED8FF; }
.rh-lane[data-lane="2"] { --lane: #FFD447; }
.rh-lane[data-lane="3"] { --lane: #A66BFF; }

.rh-lane::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(0deg, color-mix(in srgb, var(--lane) 30%, transparent), transparent 70%);
  opacity: 0;
  transition: opacity 0.18s var(--ease);
}

.rh-lane.down::before {
  opacity: 1;
  transition-duration: 0.02s;
}

.rh-lane__notes {
  position: absolute;
  inset: 0;
}

/* Notes: the node's top is the tail's tip, its bottom the head's centre + half. */
.rh-note {
  position: absolute;
  top: 0;
  left: 9%;
  right: 9%;
  height: calc(var(--tail, 0px) + var(--head));
  margin-top: calc(var(--head) / -2);
  will-change: transform;
}

.rh-note__head {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--head);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.85), rgba(255, 255, 255, 0) 55%),
    var(--lane);
  box-shadow: 0 0 16px var(--lane), 0 0 2px #fff inset;
}

.rh-note__tail {
  position: absolute;
  top: 0;
  bottom: calc(var(--head) / 2);
  left: 28%;
  right: 28%;
  border-radius: 6px 6px 0 0;
  background: linear-gradient(0deg, var(--lane), color-mix(in srgb, var(--lane) 30%, transparent));
  box-shadow: 0 0 12px color-mix(in srgb, var(--lane) 60%, transparent);
  opacity: 0.85;
}

.rh-note.holding .rh-note__head {
  box-shadow: 0 0 26px var(--lane), 0 0 50px var(--lane);
}

.rh-note.holding .rh-note__tail {
  opacity: 1;
  animation: rh-hold 0.2s linear infinite alternate;
}

@keyframes rh-hold {
  to { filter: brightness(1.5); }
}

.rh-note.missed {
  opacity: 0.25;
  filter: grayscale(1);
}

/* --- Judge line + receptors --- */
.rh-judge {
  position: absolute;
  left: -2px;
  right: -2px;
  top: 86%;
  height: 3px;
  margin-top: -1.5px;
  background: #fff;
  box-shadow: 0 0 14px var(--track), 0 0 30px var(--track);
  opacity: calc(0.6 + var(--pulse) * 0.4);
  pointer-events: none;
}

.rh-receptors {
  position: absolute;
  left: 0;
  right: 0;
  top: 86%;
  display: flex;
  pointer-events: none;
  translate: 0 -50%;
}

.rh-receptor {
  --lane: #FF4FD8;
  flex: 1;
  display: flex;
  justify-content: center;
}

.rh-receptor[data-lane="1"] { --lane: #2ED8FF; }
.rh-receptor[data-lane="2"] { --lane: #FFD447; }
.rh-receptor[data-lane="3"] { --lane: #A66BFF; }

.rh-receptor span {
  width: min(52px, 80%);
  aspect-ratio: 1.6;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
  color: color-mix(in srgb, var(--lane) 80%, #fff);
  border: 2px solid color-mix(in srgb, var(--lane) 70%, transparent);
  background: rgba(5, 6, 13, 0.6);
  transition: transform 0.08s var(--ease), background 0.1s, box-shadow 0.1s;
}

.rh-receptor.down span {
  transform: scale(0.9);
  background: color-mix(in srgb, var(--lane) 35%, transparent);
  box-shadow: 0 0 20px var(--lane);
}

.rh-receptor.hit span {
  animation: rh-receptor-hit 0.22s var(--ease);
}

.rh-receptor.holding span {
  background: var(--lane);
  color: #05060D;
  box-shadow: 0 0 30px var(--lane);
}

@keyframes rh-receptor-hit {
  0% { box-shadow: 0 0 0 0 var(--lane); background: var(--lane); color: #05060D; }
  100% { box-shadow: 0 0 0 14px transparent; }
}

@media (pointer: coarse) {
  .rh-receptor span { font-size: 0; }
}

/* --- Fever gauge --- */
.rh-fever {
  position: absolute;
  right: max(14px, calc(50% - min(230px, 36%) - 46px));
  bottom: calc(var(--pads) + 14%);
  width: 12px;
  height: 34%;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--arena-line);
  overflow: hidden;
  z-index: 3;
}

.rh-fever__fill {
  position: absolute;
  inset: 0;
  transform-origin: bottom;
  transform: scaleY(0);
  background: linear-gradient(0deg, #A66BFF, #FF4FD8, #FFD447);
  box-shadow: 0 0 16px #FF4FD8;
  transition: transform 0.2s var(--ease);
}

.rh-fever small {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  translate: -50% 0;
  font-family: var(--font-mono);
  font-size: 0.55rem;
  letter-spacing: 0.2em;
  color: var(--arena-ink-3);
  writing-mode: vertical-rl;
  display: none;
}

.rh-stage.fever .rh-fever {
  box-shadow: 0 0 20px #FF4FD8;
  animation: rh-fever 0.25s steps(2) infinite;
}

@keyframes rh-fever {
  50% { opacity: 0.6; }
}

/* --- Touch pads --- */
.rh-pads {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--pads);
  display: none;
  gap: 6px;
  padding: 6px 8px calc(8px + var(--safe-bottom));
  z-index: 5;
}

@media (pointer: coarse) {
  .rh-pads { display: flex; }
}

body.force-touch .rh-pads { display: flex; }

.rh-pad {
  --lane: #FF4FD8;
  flex: 1;
  border-radius: 14px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--lane) 22%, transparent), color-mix(in srgb, var(--lane) 8%, transparent));
  border: 1px solid color-mix(in srgb, var(--lane) 50%, transparent);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: background 0.08s, transform 0.08s;
}

.rh-pad[data-lane="1"] { --lane: #2ED8FF; }
.rh-pad[data-lane="2"] { --lane: #FFD447; }
.rh-pad[data-lane="3"] { --lane: #A66BFF; }

.rh-pad.down {
  background: color-mix(in srgb, var(--lane) 55%, transparent);
  box-shadow: 0 0 24px var(--lane);
  transform: scale(0.97);
}

@media (max-width: 760px) {
  .rh-highway { width: 94%; top: -6%; perspective: 760px; }
  .rh-road { transform: rotateX(24deg); }
  .rh-stage { --head: 20px; }
  .rh-eq { display: none; }
  .rh-fever { right: 6px; width: 8px; }
}

/* --- Song + difficulty picker (in the setup panel) --- */
.rh-picks {
  display: grid;
  gap: 8px;
  justify-items: center;
}

.rh-picks .seg { width: 100%; max-width: 440px; flex-wrap: nowrap; }
.rh-picks .seg button { flex: 1; padding: 6px 8px; line-height: 1.2; }

@media (max-width: 420px) {
  .rh-picks .seg button { font-size: 0.78rem; padding: 6px 4px; }
  .rh-picks .seg button small { font-size: 0.6rem; }
}
