* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  /* Safari's toolbar collapses mid-scroll; dvh keeps the layout from jumping. */
  height: 100dvh;
  overflow: hidden;
  background: #14081f;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: #f3e8ff;
  touch-action: none;
  user-select: none;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

#hud {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 2;
}

.hud-top {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  position: relative;
  padding: 16px 62px;
  gap: 12px;
}

.hud-cluster {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 8px;
  min-width: 0;
}

.hud-center {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  min-width: 120px;
}

.hud-stats {
  background: url("../assets/speed_back.png") center / 100% 100% no-repeat;
  color: #3b1a6e;
  border-radius: 0;
  padding: 10px 22px 10px 18px;
  gap: 2px;
  box-shadow: none;
  min-width: 148px;
}

.hud-stat {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
  font-style: italic;
}

.hud-stat b {
  font-variant-numeric: tabular-nums;
  font-style: italic;
}

.hud-speed {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

body.heat-hot .hud-speed {
  text-shadow: 0 0 10px rgba(255, 220, 120, 0.85);
}

body.heat-hot .hud-core-ico {
  box-shadow: 0 0 10px rgba(255, 200, 80, 0.95);
}

.hud-core-ico {
  width: 12px;
  height: 12px;
  background: linear-gradient(135deg, #ffe56a, #c44dff 70%, #5a1a90);
  box-shadow: 0 0 6px rgba(196, 77, 255, 0.7);
  transform: rotate(45deg);
  display: inline-block;
}

.hud-box {
  background: rgba(214, 186, 255, 0.9);
  border: none;
  border-radius: 14px;
  padding: 8px 14px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #3b1a6e;
  text-shadow: none;
  backdrop-filter: blur(4px);
  font-size: 12px;
  min-width: 88px;
  text-align: center;
  box-shadow: 0 4px 16px rgba(40, 10, 70, 0.3);
}

.hearts-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 92px;
  padding: 10px 14px;
  background: url("../assets/heart-back.png") center / 100% 100% no-repeat;
  border-radius: 0;
  box-shadow: none;
  backdrop-filter: none;
}

.heart {
  width: 18px;
  height: 15px;
  display: inline-block;
  background: url("../assets/empty-heart.svg") center / contain no-repeat;
}

.heart.filled {
  background-image: url("../assets/full-heart.png");
}

.heart.empty {
  background-image: url("../assets/empty-heart.svg");
}

.pause-btn {
  pointer-events: auto;
  position: absolute;
  right: 18px;
  top: 16px;
  width: 44px;
  height: 44px;
  border: none;
  padding: 0;
  background: url("../assets/pause-button.png") center / contain no-repeat;
  background-color: transparent;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.pause-btn[hidden] {
  display: none;
}

.pause-btn:active {
  transform: scale(0.96);
}

#pause-overlay {
  pointer-events: auto;
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(12, 4, 24, 0.62);
  backdrop-filter: blur(4px);
}

#pause-overlay[hidden] {
  display: none;
}

.pause-panel {
  min-width: 240px;
  padding: 22px 28px;
  border-radius: 14px;
  background: rgba(30, 12, 56, 0.94);
  border: 1px solid rgba(232, 180, 255, 0.28);
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.pause-title {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.12em;
  margin-bottom: 16px;
  color: #ffe56a;
}

#resume-btn {
  padding: 12px 28px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(180deg, #ffe56a, #ffc93a);
  color: #4a1a86;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow: 0 4px 0 #c49a10;
}

#resume-btn:hover {
  background: linear-gradient(180deg, #fff08a, #ffd45a);
}

#rating-overlay {
  pointer-events: auto;
  position: absolute;
  inset: 0;
  z-index: 9;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(12, 4, 24, 0.72);
  backdrop-filter: blur(4px);
}

#rating-overlay[hidden] {
  display: none;
}

.rating-panel {
  width: min(360px, 92vw);
  max-height: min(80vh, 560px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 22px 22px 20px;
  border-radius: 14px;
  background: rgba(30, 12, 56, 0.96);
  border: 1px solid rgba(232, 180, 255, 0.28);
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.rating-title {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.12em;
  margin-bottom: 12px;
  color: #ffe56a;
  text-transform: uppercase;
}

.rating-you {
  margin-bottom: 14px;
}

#rating-name {
  font-size: 15px;
  font-weight: 700;
}

#rating-score {
  margin-top: 4px;
  font-size: 12px;
  opacity: 0.75;
}

.rating-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0 0 12px;
  text-align: left;
}

.rating-list li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 13px;
}

.rating-list li.is-you {
  background: rgba(255, 229, 106, 0.16);
  border: 1px solid rgba(255, 229, 106, 0.4);
}

.rating-rank {
  font-weight: 800;
  opacity: 0.55;
}

.rating-score {
  font-weight: 800;
  color: #ffe56a;
}

.rating-place {
  font-size: 12px;
  margin-bottom: 12px;
  opacity: 0.8;
}

.rating-error {
  font-size: 12px;
  margin-bottom: 12px;
  color: rgba(255, 160, 160, 0.9);
}

#rating-restart {
  padding: 12px 28px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(180deg, #ffe56a, #ffc93a);
  color: #4a1a86;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow: 0 4px 0 #c49a10;
}

#rating-restart:hover {
  background: linear-gradient(180deg, #fff08a, #ffd45a);
}

.hud-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 18px 14px;
  background: linear-gradient(transparent 0%, rgba(30, 8, 50, 0.45) 28%, rgba(20, 6, 40, 0.92) 70%);
}

.controls-hint {
  display: flex;
  justify-content: center;
  gap: 28px;
  flex-wrap: wrap;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  opacity: 0.8;
  transition: opacity 0.25s ease;
}

/* Fly-in / goal / stall cinematics — keep the frame clean. */
body.cinema .controls-hint,
body.cinema #touch-controls,
body.cinema #tutor-hide,
body.cinema #brace-flash,
body.cinema #pause-btn {
  opacity: 0 !important;
  pointer-events: none !important;
}

body.cinema #touch-controls {
  visibility: hidden;
}

body.paused #touch-controls,
body.paused .controls-hint {
  pointer-events: none;
  opacity: 0.35;
}

/* Hidden on wide desktops; shown on narrow / phone layouts (incl. DevTools). */
#touch-controls {
  display: none;
  pointer-events: auto;
  grid-template-columns: 1fr 1.1fr 1fr;
  gap: 10px;
  max-width: 420px;
  margin: 8px auto 0;
  width: 100%;
}

.touch-btn {
  appearance: none;
  border: none;
  border-radius: 0;
  background-color: transparent;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  color: #4a1a86;
  min-height: 72px;
  padding: 0;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  box-shadow: none;
}

.touch-btn-left {
  background-image: url("../assets/left-button.png");
}

.touch-btn-center {
  background-image: url("../assets/up-button.png");
}

.touch-btn-right {
  background-image: url("../assets/right-button.png");
}

.touch-btn:active,
.touch-btn.is-down {
  transform: translateY(2px) scale(0.98);
  filter: brightness(0.95);
}

@media (max-width: 900px) {
  #touch-controls {
    display: grid;
  }

  .controls-hint {
    display: none;
  }

  .hud-bottom {
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }

  /* Back link sits top-left here — clear the HUD row out from under it. */
  .hud-top {
    padding-top: 48px;
  }

  .pause-btn {
    top: 48px;
  }

  #tutor-hide {
    top: 116px;
  }
}

#brace-flash {
  position: absolute;
  left: 50%;
  top: 52%;
  transform: translate(-50%, -50%);
  padding: 10px 22px;
  border-radius: 10px;
  background: rgba(255, 80, 40, 0.55);
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.12em;
  animation: pulse 0.35s ease-in-out infinite alternate;
}

#brace-flash.grade-perfect {
  background: rgba(46, 204, 113, 0.62);
}

#brace-flash.grade-good {
  background: rgba(52, 152, 219, 0.62);
}

#brace-flash.grade-late {
  background: rgba(230, 150, 40, 0.64);
}

#brace-flash.grade-miss {
  background: rgba(231, 76, 60, 0.62);
}

#brace-flash.grade-whiff {
  background: rgba(120, 120, 140, 0.55);
}

#status {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  min-width: 200px;
  padding: 18px 26px;
  border-radius: 14px;
  background: rgba(6, 14, 28, 0.94);
  border: 1px solid rgba(232, 244, 255, 0.25);
  text-align: center;
  line-height: 1.3;
}

#status.report-good { border-color: rgba(46, 204, 113, 0.6); }
#status.report-bad { border-color: rgba(231, 76, 60, 0.6); }

.report-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.report-line {
  margin-top: 8px;
  font-size: 11px;
  line-height: 1.4;
  color: rgba(232, 244, 255, 0.62);
}

#restart-btn {
  pointer-events: auto;
  position: absolute;
  left: 50%;
  top: 56%;
  transform: translate(-50%, -50%);
  padding: 10px 22px;
  border: none;
  border-radius: 8px;
  background: #e8f4ff;
  color: #0a1628;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

#report-alt {
  position: absolute;
  left: 50%;
  top: 64%;
  transform: translate(-50%, -50%);
  font-size: 11px;
  white-space: nowrap;
}

#restart-btn:hover {
  background: #fff;
}

#tutor-hide {
  position: absolute;
  left: 50%;
  top: 76px;
  transform: translateX(-50%);
  font-size: 10.5px;
  white-space: nowrap;
  z-index: 6;
}

#tutor {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

#tutor[hidden] {
  display: none;
}

.tutor-card {
  max-width: min(420px, 92vw);
  padding: 18px 22px 16px;
  border-radius: 14px;
  background: rgba(6, 14, 28, 0.92);
  border: 1px solid rgba(232, 244, 255, 0.22);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  text-align: center;
  backdrop-filter: blur(6px);
}

.tutor-card--top {
  align-self: flex-start;
  margin-top: max(96px, 14vh);
}

.tutor-title {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
  color: #ffb380;
}

.tutor-body {
  font-size: 13px;
  line-height: 1.45;
  opacity: 0.92;
  margin-bottom: 12px;
}

.tutor-hint {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  opacity: 0.65;
  animation: tutor-hint-pulse 1.1s ease-in-out infinite;
}

@keyframes tutor-hint-pulse {
  0%,
  100% {
    opacity: 0.45;
  }
  50% {
    opacity: 0.9;
  }
}

.ghost-btn {
  pointer-events: auto;
  padding: 8px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: rgba(232, 244, 255, 0.55);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}

.ghost-btn:hover {
  color: #e8f4ff;
}

.ghost-btn[hidden] {
  display: none;
}

#intro[hidden] {
  display: none;
}

/* Opaque so the HUD never shows through, and scrollable when the rules do not
   fit a phone screen. margin:auto on the panel centres it and still scrolls. */
#intro {
  pointer-events: auto;
  position: absolute;
  inset: 0;
  display: flex;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  background: #14081f;
}

.intro-panel {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

/* Nothing behind the rules should compete with them for the screen. */
body.intro-open .hud-top,
body.intro-open .hud-bottom,
body.intro-open #pause-btn,
body.intro-open #pause-overlay,
body.intro-open #rating-overlay {
  display: none;
}

#intro h1 {
  font-size: clamp(1.5rem, 5vw, 2.1rem);
  font-weight: 800;
  letter-spacing: 0.04em;
}

/* Phones in landscape or with a tall browser chrome: shrink instead of scroll. */
@media (max-height: 760px) {
  #intro h1 {
    font-size: clamp(1.2rem, 4.5vw, 1.6rem);
  }

  .intro-panel {
    gap: 10px;
  }

  .intro-sub {
    font-size: 12px;
  }

  .intro-keys {
    font-size: 11px;
  }

  #start-btn {
    padding: 11px 28px;
  }
}

.intro-sub {
  max-width: 420px;
  font-size: 14px;
  opacity: 0.85;
  line-height: 1.5;
}

.intro-keys {
  display: flex;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
  font-size: 12px;
  letter-spacing: 0.06em;
  opacity: 0.7;
}

#start-btn {
  margin-top: 6px;
  padding: 12px 32px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(180deg, #ffe56a, #ffc93a);
  color: #4a1a86;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow: 0 4px 0 #c49a10;
}

#start-btn:hover {
  background: linear-gradient(180deg, #fff08a, #ffd45a);
}

.back-link {
  position: fixed;
  left: 14px;
  bottom: 14px;
  z-index: 3;
  color: rgba(232, 244, 255, 0.7);
  text-decoration: none;
  font-size: 11.5px;
  background: rgba(6, 14, 28, 0.55);
  padding: 6px 10px;
  border-radius: 6px;
}

.back-link:hover {
  color: #fff;
}

@media (max-width: 900px) {
  .back-link {
    top: 12px;
    bottom: auto;
    left: 12px;
  }
}

@keyframes pulse {
  from { transform: translate(-50%, -50%) scale(1); }
  to { transform: translate(-50%, -50%) scale(1.06); }
}

@media (max-width: 640px) {
  .hud-box { font-size: 10px; min-width: 80px; padding: 6px 10px; }
  .hearts-box { min-width: 78px; padding: 8px 10px; gap: 4px; }
  .heart { width: 15px; height: 13px; }
  .hud-stats { min-width: 120px; padding: 8px 16px 8px 14px; }
  .hud-stat { font-size: 10px; }
  .pause-btn { width: 38px; height: 38px; }
  .controls-hint { gap: 14px; font-size: 9.5px; }
  #brace-flash { font-size: 16px; }
}
