:root {
  --ink: #140816;
  --ice: #d7f6ff;
  --gold: #ffe14a;
  --pink: #ff4fa3;
  --cyan: #3de1ff;
  --night: #070b16;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--night);
  font-family: Nunito, "Trebuchet MS", system-ui, sans-serif;
  color: var(--ice);
  touch-action: none;
}

button {
  font: inherit;
  touch-action: manipulation;
}

[hidden] { display: none !important; }

#app {
  height: 100%;
  height: 100dvh;
  height: 100svh;
  display: flex;
  flex-direction: column;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

#hud {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 6px 10px 0;
}

#btn-pause {
  flex: none;
  width: 44px;
  height: 44px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--gold);
  color: var(--ink);
  font-weight: 800;
  letter-spacing: -0.08em;
}

#health {
  flex: 1;
  height: 16px;
  border-radius: 999px;
  border: 3px solid var(--ink);
  background: #241433;
  overflow: hidden;
}

#health-fill {
  width: 100%;
  height: 100%;
  background: #5dff9a;
}

#score {
  min-width: 72px;
  text-align: right;
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--gold);
  text-shadow: 0 2px 0 var(--ink);
}

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  margin: 6px 8px 0;
  border-radius: 18px;
  overflow: hidden;
  background: #10182c;
  box-shadow: inset 0 0 0 3px #241433;
}

#stage.shake { animation: shake 0.18s linear; }

#game {
  display: block;
  width: 100%;
  height: 100%;
}

#combo {
  position: absolute;
  top: 8px;
  left: 0;
  right: 0;
  text-align: center;
  font-weight: 800;
  color: var(--gold);
  text-shadow: 0 2px 0 var(--ink);
  pointer-events: none;
}

#judge {
  position: absolute;
  left: 0;
  right: 0;
  top: 22%;
  text-align: center;
  font-family: Bangers, Impact, sans-serif;
  font-size: clamp(2rem, 11vw, 3.3rem);
  letter-spacing: 0.04em;
  pointer-events: none;
  text-shadow: 3px 3px 0 var(--ink);
  animation: pop 0.4s ease;
}

#judge.perfect { color: var(--gold); }
#judge.good { color: #5dff9a; }
#judge.ok { color: #8ad8ff; }
#judge.miss { color: #ff5b7a; }

#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(7, 11, 22, 0.28);
}

.panel {
  width: min(100%, 420px);
  max-height: 100%;
  overflow: auto;
  padding: 16px 14px 14px;
  border: 3px solid var(--gold);
  border-radius: 22px;
  background: rgba(12, 8, 24, 0.9);
  box-shadow: 6px 6px 0 var(--pink);
}

.kicker {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--cyan);
}

h1, h2, #end-rank, #end-name {
  font-family: Bangers, Impact, sans-serif;
  font-weight: 400;
}

h1 {
  margin: 2px 0 8px;
  font-size: clamp(2.15rem, 11vw, 3.15rem);
  line-height: 0.9;
  color: var(--gold);
  text-shadow: 3px 3px 0 var(--ink);
}

h2 {
  margin: 0;
  font-size: 2.4rem;
  color: var(--gold);
  text-shadow: 3px 3px 0 var(--ink);
}

.lead, #end-stats, #end-extra, #end-name {
  margin: 6px 0 0;
  font-weight: 800;
  line-height: 1.3;
}

#end-rank {
  margin: 4px 0 0;
  font-size: clamp(3.2rem, 18vw, 5rem);
  line-height: 0.85;
  color: var(--gold);
  text-shadow: 4px 4px 0 var(--ink);
}

#end-rank.wipe {
  font-size: clamp(2.4rem, 12vw, 3.6rem);
  color: #ff5b7a;
}

#end-name { color: white; font-size: 1.7rem; }
#end-extra { color: var(--cyan); min-height: 1.2em; }

.song, .wide {
  width: 100%;
  min-height: 58px;
  margin-top: 10px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  font-weight: 800;
}

.song {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  text-align: left;
}

.song span:first-child { display: block; }

.song .diff, .song .best {
  display: block;
  font-size: 0.78rem;
  font-weight: 800;
}

.song.easy { background: #5dff9a; color: var(--ink); }
.song.mid { background: var(--gold); color: var(--ink); }
.song.hard { background: #ff8a3d; color: var(--ink); }
.song .best:empty { display: none; }

.wide {
  background: var(--gold);
  color: var(--ink);
}

.wide.ghost {
  background: transparent;
  color: var(--ice);
  border-color: var(--ice);
}

.song:active, .wide:active, #btn-pause:active, .hit:active {
  transform: translateY(2px);
}

#controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 8px 10px 10px;
}

.hit {
  min-height: 76px;
  border-radius: 16px;
  border: 3px solid var(--ink);
  display: grid;
  place-items: center;
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
  color: var(--ink);
}

.hit[data-lane="0"] { background: var(--cyan); }
.hit[data-lane="1"] { background: #3d8cff; color: #fff; }
.hit[data-lane="2"] { background: #3dff6a; }
.hit[data-lane="3"] { background: #ff8a3d; }

.hit.held {
  transform: translateY(3px) scale(0.97);
  filter: brightness(1.15);
}

@keyframes pop {
  0% { transform: scale(0.55); opacity: 0; }
  35% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

@media (prefers-reduced-motion: reduce) {
  #judge, #stage.shake { animation: none; }
}

@media (max-height: 640px) {
  .hit { min-height: 64px; }
  h1 { font-size: 2rem; }
  .lead { font-size: 0.92rem; }
}
