:root {
  color-scheme: light;
  --ink: #252733;
  --muted: #69717f;
  --panel: rgba(255, 255, 255, 0.82);
  --line: rgba(37, 39, 51, 0.14);
  --theme-a: #ff7aa8;
  --theme-b: #ffd35c;
  --theme-c: #59d4c1;
  --theme-d: #6ab7ff;
}

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

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

body {
  font-family: ui-rounded, "SF Pro Rounded", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  overflow: hidden;
  touch-action: none;
  background:
    radial-gradient(circle at 20% 12%, color-mix(in srgb, var(--theme-a) 34%, transparent), transparent 32%),
    radial-gradient(circle at 84% 6%, color-mix(in srgb, var(--theme-c) 26%, transparent), transparent 30%),
    linear-gradient(150deg, color-mix(in srgb, var(--theme-a) 25%, #ffffff), color-mix(in srgb, var(--theme-b) 16%, #ffffff) 44%, color-mix(in srgb, var(--theme-d) 22%, #ffffff));
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  font-weight: 950;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.9);
  outline-offset: 2px;
}

.app {
  width: 100%;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.screen {
  width: 100%;
  min-height: 100dvh;
}

.hidden {
  display: none !important;
}

.title-screen {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
  padding: 18px 14px 16px;
  overflow-y: auto;
  touch-action: pan-y;
}

.title-head {
  display: grid;
  gap: 4px;
  padding: 4px 2px 0;
}

.eyebrow {
  margin: 0;
  color: color-mix(in srgb, var(--theme-a) 76%, #263238);
  font-size: 0.74rem;
  font-weight: 950;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(2.45rem, 14vw, 4.2rem);
  line-height: 0.9;
}

.song-list {
  display: grid;
  gap: 12px;
  align-content: start;
}

.song-card {
  position: relative;
  display: grid;
  min-height: 172px;
  padding: 16px;
  border: 2px solid rgba(255, 255, 255, 0.92);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(255, 255, 255, 0.56)),
    linear-gradient(135deg, var(--card-a), var(--card-b));
  color: var(--ink);
  box-shadow: 0 8px 0 rgba(37, 39, 51, 0.14), 0 18px 44px rgba(37, 39, 51, 0.15);
  text-align: left;
  overflow: hidden;
  transform: translateY(0);
  transition: transform 90ms ease, box-shadow 90ms ease;
}

.song-card:active,
.press-button:active {
  transform: translateY(5px) scale(0.985);
  box-shadow: 0 3px 0 rgba(37, 39, 51, 0.18), 0 10px 26px rgba(37, 39, 51, 0.14);
}

.song-card img {
  position: absolute;
  right: -4px;
  bottom: -22px;
  width: min(48%, 178px);
  pointer-events: none;
  filter: drop-shadow(0 14px 16px rgba(37, 39, 51, 0.18));
}

.song-card h2 {
  position: relative;
  z-index: 1;
  max-width: 70%;
  font-size: 2rem;
  line-height: 0.95;
}

.song-card p {
  position: relative;
  z-index: 1;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 900;
}

.song-card .stars {
  position: relative;
  z-index: 1;
  margin-top: 9px;
  color: #f5a400;
  font-size: 1.04rem;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.8);
}

.song-card .badge {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 1;
  display: inline-grid;
  place-items: center;
  min-width: 74px;
  height: 34px;
  padding: 0 12px;
  border: 2px solid rgba(255, 255, 255, 0.92);
  border-radius: 999px;
  background: color-mix(in srgb, var(--card-a) 82%, #ffffff);
  color: #ffffff;
  font-size: 0.84rem;
  font-weight: 950;
  text-shadow: 0 2px 0 rgba(37, 39, 51, 0.18);
}

.song-card.locked {
  filter: grayscale(0.72);
  opacity: 0.64;
}

.song-card.previewing {
  transform: translateY(-2px);
  box-shadow: 0 10px 0 rgba(37, 39, 51, 0.12), 0 0 0 5px color-mix(in srgb, var(--card-a) 34%, transparent);
}

.song-card .meta-small {
  position: relative;
  z-index: 1;
  max-width: 68%;
  margin-top: 5px;
  color: var(--ink);
  font-size: 0.78rem;
  opacity: 0.76;
}

.settings-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 30px rgba(37, 39, 51, 0.1);
}

.setting-row {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) 64px;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 950;
}

.setting-row strong {
  color: var(--ink);
  text-align: right;
}

.setting-action {
  min-height: 42px;
}

.stats-line {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-align: center;
}

.idle-character {
  display: grid;
  place-items: center;
  height: 58px;
  pointer-events: none;
}

.idle-character img {
  width: 68px;
  animation: idleBob 1.2s ease-in-out infinite;
  filter: drop-shadow(0 8px 12px rgba(37, 39, 51, 0.18));
}

input[type="range"] {
  width: 100%;
  accent-color: var(--theme-a);
}

.play-screen {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100dvh;
  padding: 8px 8px 0;
  overflow: hidden;
}

.hud {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 92px;
  align-items: center;
  gap: 8px;
  padding: 0 0 8px;
}

.icon-button {
  width: 42px;
  height: 42px;
  padding: 0;
}

.press-button {
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, color-mix(in srgb, var(--theme-d) 22%, #ffffff));
  color: var(--ink);
  box-shadow: 0 6px 0 rgba(37, 39, 51, 0.18), 0 10px 24px rgba(37, 39, 51, 0.14);
  transition: transform 90ms ease, box-shadow 90ms ease;
}

.press-button.alt {
  background: linear-gradient(180deg, #ffffff, color-mix(in srgb, var(--theme-b) 28%, #ffffff));
}

.hud-song,
.hud-stat {
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 8px 18px rgba(37, 39, 51, 0.08);
}

.hud-song {
  display: grid;
  gap: 1px;
}

.hud-song strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-song span,
.hud-stat span {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 900;
}

.hud-stat {
  display: grid;
  justify-items: end;
}

.hp-wrap {
  grid-column: 1 / -1;
  height: 10px;
  border: 1px solid rgba(255, 255, 255, 0.92);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.5);
  overflow: hidden;
}

.hp-bar {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #58d7bc, #ffd35c, #ff6797);
  transition: width 140ms ease;
}

.stage-wrap {
  position: relative;
  min-height: 0;
  border-radius: 8px 8px 0 0;
  overflow: hidden;
  box-shadow: 0 -1px 0 rgba(255, 255, 255, 0.58), 0 18px 50px rgba(37, 39, 51, 0.18);
  touch-action: none;
}

.combo-pop {
  position: absolute;
  top: 9%;
  left: 50%;
  z-index: 2;
  display: grid;
  justify-items: center;
  min-width: 110px;
  transform: translateX(-50%);
  color: #ffffff;
  pointer-events: none;
  text-shadow: 0 4px 0 rgba(37, 39, 51, 0.2), 0 0 22px rgba(255, 255, 255, 0.72);
  opacity: 0;
  transition: opacity 180ms ease;
}

.combo-pop.visible {
  opacity: 1;
}

.combo-pop.tier-50 {
  color: #ffe45e;
}

.combo-pop.tier-100 strong {
  background: linear-gradient(90deg, #ff4f8f, #ffd35c, #5fe0c5, #55a9ff, #b56cff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.combo-pop strong {
  font-size: clamp(2.8rem, 20vw, 5.4rem);
  font-weight: 950;
  line-height: 0.8;
}

.combo-pop span {
  font-size: 0.72rem;
  font-weight: 950;
  letter-spacing: 0;
  text-transform: uppercase;
}

.combo-pop strong.punch {
  animation: comboPunch 170ms ease-out;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  touch-action: none;
}

.touch-zones {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  touch-action: none;
}

.touch-zone {
  position: relative;
  border-radius: 0;
  background: transparent;
}

.touch-zone::after {
  content: "";
  position: absolute;
  left: 7px;
  right: 7px;
  bottom: max(12px, env(safe-area-inset-bottom));
  height: 19%;
  border: 2px solid rgba(255, 255, 255, 0.68);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.04));
  box-shadow: inset 0 0 22px rgba(255, 255, 255, 0.18);
  opacity: 0.72;
  transition: opacity 80ms ease, transform 80ms ease, box-shadow 80ms ease;
}

.touch-zone.active::after {
  opacity: 1;
  transform: scale(0.97);
  box-shadow: 0 0 26px var(--lane-color), inset 0 0 34px var(--lane-color);
}

.countdown {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  color: #ffffff;
  font-size: clamp(5rem, 30vw, 9rem);
  font-weight: 950;
  pointer-events: none;
  text-shadow: 0 7px 0 rgba(37, 39, 51, 0.22), 0 0 30px var(--theme-a);
}

.pause-overlay {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(8px);
}

.pause-overlay strong {
  font-size: 3.4rem;
  line-height: 0.9;
}

.pause-overlay button,
.result-actions button {
  min-width: 168px;
  min-height: 48px;
  padding: 12px 18px;
}

.result-screen {
  display: grid;
  place-items: center;
  padding: 18px 14px;
}

.result-panel {
  width: min(100%, 430px);
  padding: 20px 16px;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.84);
  box-shadow: 0 8px 0 rgba(37, 39, 51, 0.12), 0 22px 60px rgba(37, 39, 51, 0.18);
}

.result-panel h2 {
  font-size: 2.35rem;
  line-height: 0.95;
}

.rank {
  width: fit-content;
  margin: 18px auto 20px;
  color: #ff416d;
  font-size: 6rem;
  font-weight: 950;
  line-height: 0.78;
  text-shadow: 0 5px 0 rgba(255, 255, 255, 0.96);
}

.stamp {
  animation: stampIn 520ms cubic-bezier(.18, 1.55, .34, 1);
}

.combo-stamp {
  width: fit-content;
  margin: -8px auto 16px;
  padding: 7px 12px;
  border: 3px solid #ffffff;
  border-radius: 8px;
  background: linear-gradient(90deg, #ff4f8f, #ffd35c, #5fe0c5, #55a9ff, #b56cff);
  color: #ffffff;
  font-size: 0.92rem;
  font-weight: 950;
  text-shadow: 0 2px 0 rgba(37, 39, 51, 0.22);
  box-shadow: 0 0 24px rgba(255, 255, 255, 0.78);
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.result-grid div {
  display: grid;
  gap: 3px;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.result-grid span,
.judge-row {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 900;
}

.result-grid strong {
  overflow-wrap: anywhere;
}

.judge-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 16px 0 18px;
}

.judge-row span {
  display: grid;
  gap: 2px;
  padding: 10px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
  text-align: center;
}

.judge-row strong {
  color: var(--ink);
  font-size: 1.18rem;
}

.histogram {
  display: grid;
  grid-template-columns: repeat(20, minmax(0, 1fr));
  align-items: end;
  gap: 2px;
  height: 54px;
  margin: -4px 0 18px;
  padding: 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.55);
}

.histogram span {
  min-height: 2px;
  border-radius: 3px 3px 0 0;
  background: color-mix(in srgb, var(--theme-a) 72%, var(--theme-d));
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  justify-items: center;
}

@keyframes comboPunch {
  0% { transform: scale(1); }
  45% { transform: scale(1.4); }
  100% { transform: scale(1); }
}

@keyframes stampIn {
  0% { opacity: 0; transform: scale(2.2) rotate(-14deg); }
  58% { opacity: 1; transform: scale(0.88) rotate(-6deg); }
  100% { opacity: 1; transform: scale(1) rotate(-8deg); }
}

@keyframes idleBob {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-8px) rotate(2deg); }
}
