.game {
  --game-bg: #0B0714;
  --game-panel: #1B1030;
  --game-line: rgba(255, 255, 255, .08);
  --deck-a: #33E1FF;
  --deck-b: #FF3DAE;
  --hit-perfect: #FFD84A;
  --hit-good: #7CFFB2;
  --hit-miss: #FF4D4D;
  --hud-text: #F5F0FF;
  --hud-dim: rgba(245, 240, 255, .55);
  --g-display: 'Unbounded', 'Arial Rounded MT Bold', sans-serif;
  --g-body: 'Rubik', -apple-system, 'Segoe UI', Roboto, sans-serif;
  --g-mono: 'JetBrains Mono', 'Consolas', monospace;

  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--game-bg);
  color: var(--hud-text);
  font-family: var(--g-body);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.game[hidden] { display: none !important; }

html.game-open, html.game-open body { overflow: hidden; }

.game__canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: 1fr minmax(0, 1.4fr) 1fr;
  align-items: center;
  gap: 12px;
  padding: 12px 20px 14px;
  background: linear-gradient(180deg, rgba(11, 7, 20, .92), rgba(11, 7, 20, .55) 70%, rgba(11, 7, 20, 0));
  pointer-events: none;
}

.hud__block { display: flex; align-items: center; gap: 16px; min-width: 0; }
.hud__block--center { flex-direction: column; gap: 2px; text-align: center; }
.hud__block--right { justify-content: flex-end; gap: 10px; }

.hud__stat { display: flex; flex-direction: column; line-height: 1.1; }
.hud__label {
  font-size: 10px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--hud-dim);
}
.hud__value {
  font-family: var(--g-mono);
  font-weight: 700;
  font-size: clamp(16px, 1.6vw, 24px);
  font-variant-numeric: tabular-nums;
}

.hud__mult {
  font-family: var(--g-display);
  font-weight: 900;
  font-size: 16px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(124, 255, 178, .15);
  color: var(--hit-good);
  border: 1px solid currentColor;
  transition: color .2s, background .2s;
}
.hud__mult[data-level="3"] { color: var(--deck-a); background: rgba(51, 225, 255, .15); }
.hud__mult[data-level="4"] { color: var(--hit-perfect); background: rgba(255, 216, 74, .15); box-shadow: 0 0 16px rgba(255, 216, 74, .35); }

.hud__now, .hud__next {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hud__now { font-family: var(--g-display); font-weight: 700; font-size: clamp(12px, 1.1vw, 16px); }
.hud__now[data-deck="0"] { color: var(--deck-a); }
.hud__now[data-deck="1"] { color: var(--deck-b); }
.hud__next { font-size: 12px; color: var(--hud-dim); }

.hype {
  width: clamp(90px, 18vw, 260px);
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .1);
  overflow: hidden;
}
.hype__fill {
  height: 100%;
  width: 50%;
  border-radius: inherit;
  background: linear-gradient(90deg, #FF3DAE, #FFD84A);
  transition: width .15s linear;
}
.hype--low .hype__fill { background: var(--hit-miss); animation: hype-blink .5s steps(2) infinite; }
@keyframes hype-blink { 50% { opacity: .35; } }

.hud__pause {
  pointer-events: auto;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .25);
  background: rgba(255, 255, 255, .08);
  color: var(--hud-text);
  cursor: pointer;
}
.hud__pause:hover { background: rgba(255, 255, 255, .18); }

.hud__progress {
  grid-column: 1 / -1;
  position: relative;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .1);
  overflow: hidden;
}
.hud__progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--deck-a), var(--deck-b)); }
.hud__marks { position: absolute; inset: 0; }
.hud__mark { position: absolute; top: 0; bottom: 0; background: rgba(255, 216, 74, .7); }

.touch {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 16vh;
  display: none;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: rgba(11, 7, 20, .85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid var(--game-line);
}
.touch__btn {
  border: 1px solid rgba(255, 255, 255, .15);
  border-radius: 14px;
  background: rgba(255, 255, 255, .06);
  color: var(--hud-text);
  font-size: 26px;
  font-weight: 700;
  touch-action: none;
  transition: transform .06s, background .06s;
}
.touch__btn--a { box-shadow: inset 0 -3px 0 var(--deck-a); }
.touch__btn--b { box-shadow: inset 0 -3px 0 var(--deck-b); }
.touch__btn--swap {
  grid-column: 1 / -1;
  font-family: var(--g-display);
  font-size: 13px;
  letter-spacing: .1em;
  padding: 8px;
  color: #1a0b2e;
  background: linear-gradient(90deg, var(--deck-a), var(--hit-perfect), var(--deck-b));
}
.touch__btn:active { transform: scale(.92); background: rgba(255, 255, 255, .2); }

@media (pointer: coarse), (max-width: 760px) {
  .touch { display: grid; }
}

.game-screen {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(11, 7, 20, .82);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.game-screen[hidden] { display: none; }
.game-screen[data-screen="loading"] { background: var(--game-bg); }

.game-card {
  width: min(480px, 100%);
  padding: 32px 28px;
  border-radius: 24px;
  background: var(--game-panel);
  border: 1px solid rgba(255, 255, 255, .08);
  box-shadow: 0 16px 60px rgba(0, 0, 0, .5);
  text-align: center;
}
.game-card__title { font-family: var(--g-display); font-weight: 900; font-size: 28px; margin-bottom: 12px; }
.game-card__sub { color: var(--hud-dim); font-size: 15px; line-height: 1.5; }
.game-card__hint {
  margin-top: 20px;
  font-family: var(--g-mono);
  font-size: 12px;
  color: var(--hud-dim);
  line-height: 1.6;
}
.game-card__actions { display: flex; flex-direction: column; gap: 10px; margin-top: 24px; }

.gbtn {
  font-family: var(--g-display);
  font-weight: 700;
  font-size: 15px;
  padding: 14px 24px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .2);
  background: rgba(255, 255, 255, .08);
  color: var(--hud-text);
  cursor: pointer;
  transition: transform .15s, background .15s;
}
.gbtn:hover { transform: translateY(-2px); background: rgba(255, 255, 255, .16); }
.gbtn--primary { background: #E4392E; border-color: #E4392E; color: #fff; }
.gbtn--primary:hover { background: #C92E24; }
.gbtn--ghost { background: transparent; }

.loader { display: grid; place-items: center; margin: 12px 0 16px; }
.loader__vinyl {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background:
    radial-gradient(circle, var(--deck-b) 0 16%, #0c0a10 17% 19%, transparent 20%),
    repeating-radial-gradient(circle, #111 0 3px, #1c1a22 3px 5px);
  box-shadow: 0 0 0 3px rgba(51, 225, 255, .4), 0 0 30px rgba(51, 225, 255, .3);
  position: relative;
  animation: spin 1.8s linear infinite;
}
.loader__vinyl::after {
  content: "";
  position: absolute;
  top: 8px;
  left: 50%;
  width: 2px;
  height: 30px;
  background: rgba(255, 255, 255, .8);
}
@keyframes spin { to { transform: rotate(360deg); } }

.grade {
  font-family: var(--g-display);
  font-weight: 900;
  font-size: 96px;
  line-height: 1;
  margin-bottom: 8px;
}
.grade[data-grade="S"] { color: var(--hit-perfect); text-shadow: 0 0 30px rgba(255, 216, 74, .6); }
.grade[data-grade="A"] { color: var(--deck-a); text-shadow: 0 0 24px rgba(51, 225, 255, .5); }
.grade[data-grade="B"] { color: var(--hit-good); }
.grade[data-grade="C"] { color: var(--hit-miss); opacity: .85; }

.stats { margin: 20px 0 0; text-align: left; }
.stats__row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--game-line);
  font-size: 14px;
}
.stats__row dt { color: var(--hud-dim); }
.stats__row dd { margin: 0; font-family: var(--g-mono); font-weight: 700; text-align: right; }

@media (max-width: 760px) {
  .hud { grid-template-columns: auto 1fr; padding: 8px 12px 10px; gap: 8px; }
  .hud__block--center { display: none; }
  .hud__block--left { gap: 10px; }
  .hud__mult { font-size: 12px; padding: 2px 8px; }
  .hype { width: 90px; }
  .game-card { padding: 24px 18px; }
  .grade { font-size: 72px; }
}

.slideshow {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: #000;
  overflow: hidden;
  opacity: 0;
  transition: opacity .6s ease;
}
.slideshow.is-open { opacity: 1; }
.slideshow[hidden] { display: none; }
.slideshow__bg {
  position: absolute;
  inset: -40px;
  background: center / cover no-repeat;
  filter: blur(34px) brightness(.45) saturate(1.3);
  transition: background-image .2s;
}
.slideshow__stage { position: absolute; inset: 0; }
.slideshow__media {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transform: scale(1);
  transition: opacity .16s linear;
}
.slideshow__media.is-active {
  opacity: 1;
  animation: kenburns var(--kb, 1s) linear forwards;
}
.slideshow.is-paused .slideshow__media.is-active { animation-play-state: paused; }
@keyframes kenburns { from { transform: scale(1); } to { transform: scale(1.07); } }
.slideshow__age {
  position: absolute;
  top: max(24px, 4vh);
  left: max(20px, 4vw);
  font-family: var(--g-display);
  font-weight: 900;
  font-size: clamp(40px, 9vw, 120px);
  line-height: 1;
  color: var(--hit-perfect);
  text-shadow: 0 0 30px rgba(255, 216, 74, .55), 0 6px 0 rgba(0, 0, 0, .55);
}
.slideshow__age.is-pop { animation: age-pop .35s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes age-pop { from { transform: scale(1.35); opacity: .3; } to { transform: scale(1); opacity: 1; } }
.slideshow__caption {
  position: absolute;
  left: 50%;
  bottom: max(28px, 6vh);
  transform: translateX(-50%);
  width: min(900px, calc(100% - 32px));
  padding: 12px 20px;
  border-radius: 16px;
  background: rgba(11, 7, 20, .72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-family: var(--g-display);
  font-weight: 700;
  font-size: clamp(16px, 2.6vw, 30px);
  text-align: center;
  color: #fff;
}
.slideshow__final {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  background: radial-gradient(circle at 50% 45%, rgba(255, 61, 174, .55), rgba(11, 7, 20, .96) 65%);
  animation: final-in .5s ease;
}
.slideshow__final[hidden] { display: none; }
.slideshow__final-title { font-family: var(--g-display); font-weight: 900; font-size: clamp(28px, 6vw, 72px); color: #fff; }
.slideshow__final-age {
  font-family: var(--g-display);
  font-weight: 900;
  font-size: clamp(90px, 22vw, 260px);
  line-height: .9;
  color: var(--hit-perfect);
  text-shadow: 0 0 60px rgba(255, 216, 74, .7);
}
.slideshow__final-sub { font-family: var(--g-mono); font-size: clamp(14px, 2vw, 20px); color: var(--hud-dim); }
@keyframes final-in { from { opacity: 0; transform: scale(1.08); } to { opacity: 1; transform: none; } }
.game.is-finale .hud, .game.is-finale .touch { opacity: 0; pointer-events: none; transition: opacity .6s; }

.game-screen { z-index: 10; }
