:root {
  --ink: #fff7e6;
  --shadow: #1a0f2e;
  --accent: #57e8ff;
  --accent2: #ff5ce1;
  --gold: #ffd23a;
  --danger: #ff3355;
  --panel: rgba(24, 14, 52, 0.86);
  --font: 'Press Start 2P', 'Courier New', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #120a24;
  color: var(--ink);
  font-family: var(--font);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  touch-action: none;
}
body.playing #game { cursor: none; }

.hidden { display: none !important; }

/* ------------------------------------------------------------ HUD */

#hud {
  position: fixed;
  inset: 0 0 auto 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  padding: 16px 20px;
  pointer-events: none;
  text-shadow: 3px 3px 0 var(--shadow);
}
.label { font-size: 10px; letter-spacing: 1px; opacity: 0.85; }
#score { font-size: 22px; margin-top: 6px; color: var(--gold); }
#combo { font-size: 11px; margin-top: 8px; color: var(--accent2); min-height: 1em; }
.hud-center { text-align: center; }
#timer {
  font-size: 30px;
  padding: 10px 16px;
  background: var(--panel);
  border: 3px solid #8b6cd8;
  box-shadow: inset 0 0 0 3px #2b1a55, 0 4px 0 #0c0619;
  border-radius: 6px;
}
#timer.low { color: var(--danger); animation: pulse 0.5s steps(2) infinite; }
.hud-right { justify-self: end; text-align: right; }
#hearts { display: flex; gap: 6px; justify-content: flex-end; margin-bottom: 8px; }
.heart { width: 30px; height: 26px; filter: drop-shadow(3px 3px 0 var(--shadow)); }
.heart.full { fill: var(--danger); }
.heart.empty { fill: #3b2d52; }
#kills { color: var(--gold); }

@keyframes pulse { 50% { opacity: 0.45; } }

#crosshair {
  position: fixed;
  left: 0;
  top: 0;
  pointer-events: none;
  display: none;
  --charge: 0;
}
#crosshair .ring, #crosshair .dot {
  position: absolute;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}
#crosshair .ring {
  width: calc(34px - 16px * var(--charge));
  height: calc(34px - 16px * var(--charge));
  border: 2px solid rgba(255, 247, 230, 0.9);
  box-shadow: 0 0 0 2px rgba(26, 15, 46, 0.7);
}
#crosshair .dot { width: 4px; height: 4px; background: var(--gold); }

#floaters { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.floater {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 14px;
  color: var(--gold);
  text-shadow: 2px 2px 0 var(--shadow);
  animation: floatUp 0.9s ease-out forwards;
  white-space: nowrap;
}
.floater.big { font-size: 18px; }
.floater.combo { font-size: 11px; color: var(--accent2); }
.floater.crystal { color: var(--accent); font-size: 12px; }
@keyframes floatUp {
  0% { opacity: 0; margin-top: 10px; }
  15% { opacity: 1; }
  100% { opacity: 0; margin-top: -50px; }
}

#center-text {
  position: fixed;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  font-size: 64px;
  pointer-events: none;
  opacity: 0;
  color: var(--ink);
  text-shadow: 5px 5px 0 var(--shadow), 0 0 24px rgba(87, 232, 255, 0.7);
}
#center-text.show { animation: pop 0.9s ease-out forwards; }
#center-text.go { color: var(--gold); }
@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(2.2); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
}

#hurt-flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(255, 30, 60, 0.65));
  opacity: 0;
}
#hurt-flash.on { animation: flash 0.5s ease-out; }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }

#mute {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 40px;
  height: 40px;
  border: 3px solid #8b6cd8;
  border-radius: 6px;
  background: var(--panel) no-repeat center / 22px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8' shape-rendering='crispEdges' fill='%23fff7e6'%3E%3Cpath d='M0 3h2v2H0zM2 2h1v4H2zM3 1h1v6H3zM5 2h1v1H5zM6 1h1v1H6zM5 5h1v1H5zM6 6h1v1H6zM6 3h1v2H6z'/%3E%3C/svg%3E");
  cursor: pointer;
  z-index: 5;
}
#mute.muted {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8' shape-rendering='crispEdges' fill='%23ff3355'%3E%3Cpath d='M0 3h2v2H0zM2 2h1v4H2zM3 1h1v6H3zM5 2h1v1H5zM7 2h1v1H7zM6 3h1v2H6zM5 5h1v1H5zM7 5h1v1H7z'/%3E%3C/svg%3E");
}
body.playing #mute { opacity: 0.6; }

/* ------------------------------------------------------------ screens */

.screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(18, 10, 36, 0.35), rgba(18, 10, 36, 0.8));
  z-index: 4;
}
.panel {
  width: min(560px, 100%);
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 28px 28px 24px;
  text-align: center;
  background: linear-gradient(180deg, rgba(58, 34, 110, 0.92), rgba(20, 12, 44, 0.94));
  border: 3px solid #a58cf0;
  border-radius: 10px;
  box-shadow: inset 0 0 0 4px #2b1a55, inset 0 0 40px rgba(87, 232, 255, 0.15), 0 8px 0 #0c0619, 0 0 60px rgba(255, 92, 225, 0.25);
}
.panel.small { width: min(340px, 100%); }

h1 {
  margin: 0 0 12px;
  font-size: clamp(30px, 8vw, 54px);
  line-height: 1.15;
  display: flex;
  flex-direction: column;
  letter-spacing: 2px;
}
h1 span:first-child {
  color: var(--accent);
  text-shadow: 4px 4px 0 #1b5a73, 8px 8px 0 var(--shadow), 0 0 30px rgba(87, 232, 255, 0.6);
}
h1 span:last-child {
  color: var(--accent2);
  text-shadow: 4px 4px 0 #6d1a60, 8px 8px 0 var(--shadow), 0 0 30px rgba(255, 92, 225, 0.6);
}
h2 { margin: 0 0 12px; font-size: 28px; color: var(--gold); text-shadow: 4px 4px 0 var(--shadow); }
.tag { margin: 0 0 20px; font-size: 11px; color: #d8c8ff; line-height: 1.6; }

.rules {
  list-style: none;
  padding: 0;
  margin: 0 0 18px;
  font-size: 11px;
  line-height: 2;
  text-align: left;
  display: inline-block;
}
.rules li::before { content: '\25B6  '; color: var(--gold); }
.rules b { color: var(--accent); font-weight: normal; }

.controls {
  font-size: 9px;
  line-height: 2.2;
  color: #cbbcf0;
  margin-bottom: 22px;
}
kbd {
  display: inline-block;
  min-width: 20px;
  padding: 3px 5px;
  margin: 0 2px;
  font-family: inherit;
  font-size: 8px;
  color: var(--ink);
  background: #2b1a55;
  border: 2px solid #8b6cd8;
  border-radius: 3px;
  box-shadow: 0 2px 0 #0c0619;
}
.touch-only { display: none; }
body.touch .touch-only { display: block; }
body.touch .desktop-only { display: none; }

.btn {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 16px;
  font-family: inherit;
  font-size: 16px;
  color: #1a0f2e;
  background: linear-gradient(180deg, #fff1a0, var(--gold) 50%, #e0a520);
  border: 3px solid #fff7e6;
  border-radius: 6px;
  box-shadow: 0 5px 0 #7a4a10, 0 0 24px rgba(255, 210, 58, 0.45);
  cursor: pointer;
  animation: glowBtn 1.4s ease-in-out infinite;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #7a4a10; }
.btn.alt {
  color: var(--ink);
  background: linear-gradient(180deg, #5b3fa8, #3a2472);
  border-color: #a58cf0;
  box-shadow: 0 5px 0 #0c0619;
  animation: none;
}
@keyframes glowBtn { 50% { box-shadow: 0 5px 0 #7a4a10, 0 0 36px rgba(255, 210, 58, 0.8); } }

#new-best { color: var(--accent); margin-bottom: 14px; animation: pulse 0.6s steps(2) infinite; }

.stats {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  margin-bottom: 18px;
}
.stats td { padding: 8px 4px; border-bottom: 2px dashed rgba(165, 140, 240, 0.35); }
.stats td:first-child { text-align: left; color: #cbbcf0; }
.stats td:last-child { text-align: right; }
.stats tr.total td { color: var(--gold); font-size: 15px; }

/* ------------------------------------------------------------ touch */

#touch { display: none; }
body.touch.playing #touch {
  display: flex;
  position: fixed;
  left: 16px;
  bottom: 16px;
  gap: 12px;
  z-index: 3;
}
#touch button {
  width: 64px;
  height: 64px;
  font-size: 22px;
  color: var(--ink);
  background: var(--panel);
  border: 3px solid #8b6cd8;
  border-radius: 10px;
  touch-action: none;
  opacity: 0.8;
}
#touch button:active { background: #5b3fa8; }

.rotate-hint { display: none; font-size: 9px; color: var(--accent); line-height: 1.8; margin: -8px 0 16px; }
@media (orientation: portrait) {
  body.touch .rotate-hint { display: block; }
}

@media (max-width: 600px) {
  h1 { line-height: 1.35; }
  h1 span:first-child { text-shadow: 3px 3px 0 #1b5a73, 5px 5px 0 var(--shadow), 0 0 20px rgba(87, 232, 255, 0.6); }
  h1 span:last-child { text-shadow: 3px 3px 0 #6d1a60, 5px 5px 0 var(--shadow), 0 0 20px rgba(255, 92, 225, 0.6); }
  #hud { padding: 12px; }
  #score { font-size: 14px; }
  #timer { font-size: 18px; padding: 8px 10px; }
  .heart { width: 20px; height: 18px; }
  .label { font-size: 8px; }
  #center-text { font-size: 44px; }
  .panel { padding: 20px 16px; }
}
