:root {
  --pink: #ff5da2;
  --pink2: #ff8ad6;
  --purple: #8a4dff;
  --cyan: #6be5ff;
  --gold: #ffd166;
  --ink: #1a0726;
  --font: "Baloo 2", system-ui, -apple-system, sans-serif;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  color: #fff;
  background:
    radial-gradient(1200px 800px at 20% -10%, #ff8ad6 0%, transparent 55%),
    radial-gradient(1000px 700px at 100% 0%, #6be5ff 0%, transparent 50%),
    radial-gradient(1200px 900px at 50% 120%, #8a4dff 0%, transparent 55%),
    linear-gradient(160deg, #2a0b3f, #120420 60%, #0a0214);
  overflow: hidden;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: grid;
  place-items: center;
}

/* ---- stage (camera + canvas) ---- */
#stage {
  position: relative;
  width: min(100vw, 177.7vh);
  aspect-ratio: 16 / 9;
  z-index: 0;
}
/* keep the source video decoding (not display:none) but visually hidden */
#cam {
  position: absolute;
  width: 2px; height: 2px;
  opacity: 0; pointer-events: none; z-index: -1;
}
#view {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 18px;
  background: #0a0214;
  box-shadow: 0 0 0 3px rgba(255,93,162,.5), 0 24px 80px rgba(0,0,0,.6);
}

/* ---- screens ---- */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  z-index: 10;
}
.screen.active { display: grid; }

/* opaque screens get a dimmed sparkly backdrop */
#screen-title.active,
#screen-result.active,
#screen-loading.active,
#screen-error.active {
  background:
    radial-gradient(700px 500px at 50% 0%, rgba(255,138,214,.25), transparent 60%),
    rgba(10, 2, 20, .72);
  backdrop-filter: blur(6px);
}

/* card */
.card {
  text-align: center;
  padding: 40px 46px;
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(255,255,255,.10), rgba(255,255,255,.03));
  border: 2px solid rgba(255,255,255,.18);
  box-shadow: 0 0 60px rgba(255,93,162,.35), inset 0 0 40px rgba(138,77,255,.15);
  max-width: 560px;
}

/* logo */
.logo {
  font-size: clamp(48px, 9vw, 104px);
  font-weight: 900;
  letter-spacing: 2px;
  line-height: .95;
  background: linear-gradient(180deg, #fff, var(--pink2) 60%, var(--pink));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 0 30px rgba(255,93,162,.6);
  filter: drop-shadow(0 4px 0 rgba(138,77,255,.5));
}
.logo span { color: var(--cyan); -webkit-text-fill-color: var(--cyan); margin: 0 .1em; }
.tag { margin: 12px 0 26px; color: #ffd1ec; font-weight: 700; }

/* buttons */
.btn {
  font-family: var(--font);
  font-weight: 900;
  font-size: 20px;
  color: #2a0420;
  border: none;
  border-radius: 999px;
  padding: 14px 34px;
  cursor: pointer;
  background: linear-gradient(180deg, #fff, var(--pink2));
  box-shadow: 0 8px 0 #c23b86, 0 14px 30px rgba(255,93,162,.5);
  transition: transform .08s ease, box-shadow .08s ease;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(4px); box-shadow: 0 4px 0 #c23b86; }
.btn.big { font-size: 26px; padding: 18px 52px; }
.btn.ghost {
  background: transparent; color: #fff;
  border: 2px solid rgba(255,255,255,.5); box-shadow: none;
}

/* hints list */
.hints { list-style: none; margin: 26px auto 0; text-align: left; max-width: 440px; }
.hints li { padding: 7px 0; color: #ffe7f5; font-weight: 600; font-size: 15px; }
.hints b { color: var(--cyan); }

/* title layout: card + ad slot stacked */
.title-wrap { display: flex; flex-direction: column; align-items: center; gap: 18px; }

/* Google AdSense slot — shows a neutral placeholder until configured / on localhost */
.ad-slot {
  min-width: 300px; min-height: 100px;
  background: rgba(0, 0, 0, .28);
  border: 1px dashed rgba(255, 255, 255, .22);
  border-radius: 12px; position: relative; overflow: hidden;
}
.ad-slot:empty::after {
  content: "Advertisement";
  position: absolute; inset: 0; display: grid; place-items: center;
  color: rgba(255, 255, 255, .32); font-size: 12px; letter-spacing: 1px; font-weight: 700;
}

/* privacy / legal footer link */
.legal { margin: 2px 0 0; font-size: 12px; }
.legal a { color: rgba(255, 255, 255, .55); text-decoration: none; }
.legal a:hover { color: #fff; text-decoration: underline; }

/* select top bar */
#screen-select { align-content: start; pointer-events: none; }
.topbar {
  margin-top: 2.2vh;
  text-align: center;
  background: rgba(10,2,20,.55);
  padding: 12px 26px;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,.2);
}
.topbar h2 { font-size: clamp(20px, 3vw, 30px); color: #fff; }
.topbar p { margin-top: 4px; color: #ffd1ec; font-weight: 600; }
.kbd {
  display: inline-block; margin-left: 8px; padding: 2px 10px;
  border-radius: 8px; background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.3); font-size: 13px;
}

/* game */
#screen-game { pointer-events: none; align-content: start; justify-content: end; }
.esc-hint {
  margin: 14px 18px; padding: 6px 14px; border-radius: 10px;
  background: rgba(10,2,20,.5); border: 1px solid rgba(255,255,255,.2);
  font-weight: 700; font-size: 13px; color: #ffd1ec;
}

/* result */
.result .stats {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px 28px;
  margin: 18px 0 16px;
}
.stat { display: flex; flex-direction: column; }
.stat label { font-size: 13px; color: #ffb8e2; font-weight: 700; letter-spacing: 1px; }
.stat b { font-size: 30px; font-weight: 900; }
.counts {
  display: flex; flex-wrap: wrap; gap: 10px; justify-content: center;
  margin-bottom: 22px; font-weight: 800; font-size: 14px;
}
.counts span { padding: 5px 12px; border-radius: 999px; background: rgba(255,255,255,.08); }
.counts .perfect { color: var(--pink); }
.counts .great { color: var(--gold); }
.counts .good { color: var(--cyan); }
.counts .miss { color: #9aa0b5; }
.row { display: flex; gap: 14px; justify-content: center; }

/* ---- result rank presentation (DJMAX / EZ2ON style) ---- */
.result-title {
  font-weight: 900; letter-spacing: 6px; font-size: 18px;
  color: #ffb8e2; margin-bottom: 6px;
}
.rank-wrap { line-height: 1; }
.rank {
  display: inline-block;
  font-size: 132px; font-weight: 900; line-height: 1;
  text-shadow: 0 0 42px currentColor;
}
.rank-sub { margin-top: 4px; font-weight: 800; font-size: 20px; color: #ffe7f5; }
.rank-S   { color: #ffd166; }
.rank-A   { color: #6be5ff; }
.rank-B   { color: #7cffcb; }
.rank-C   { color: #b388ff; }
.rank-D   { color: #cfd3e6; }
.rank-F   { color: #ff6b6b; }
.rank-SSS {
  background: linear-gradient(90deg, #ff5da2, #ffd166, #6be5ff, #7cffcb, #ff5da2);
  background-size: 220% auto;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: none; filter: drop-shadow(0 0 26px #ff8ad6);
}

@keyframes rankSlam {
  0%   { transform: scale(2.7); opacity: 0; filter: blur(8px); }
  55%  { transform: scale(0.88); opacity: 1; filter: blur(0); }
  75%  { transform: scale(1.06); }
  100% { transform: scale(1); }
}
@keyframes shimmer { to { background-position: 220% center; } }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: none; }
}

.card.reveal .result-title { animation: fadeUp .4s both; }
.card.reveal .rank        { animation: rankSlam .7s cubic-bezier(.2,1.5,.4,1) both; }
.card.reveal .rank-SSS    { animation: rankSlam .7s cubic-bezier(.2,1.5,.4,1) both,
                                        shimmer 2.4s linear .7s infinite; }
.card.reveal .rank-sub    { animation: fadeUp .5s .55s both; }
.card.reveal .stat        { animation: fadeUp .5s both; }
.card.reveal .stat:nth-child(1) { animation-delay: .60s; }
.card.reveal .stat:nth-child(2) { animation-delay: .70s; }
.card.reveal .stat:nth-child(3) { animation-delay: .80s; }
.card.reveal .stat:nth-child(4) { animation-delay: .90s; }
.card.reveal .counts      { animation: fadeUp .5s 1.0s both; }
.card.reveal .row         { animation: fadeUp .5s 1.15s both; }

/* loading / error */
.spinner { font-size: 56px; animation: spin 1.4s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#screen-loading p { margin-top: 14px; font-weight: 800; font-size: 20px; }
#screen-loading small, #screen-error small { display: block; margin-top: 10px; color: #ffd1ec; }
.err { color: #ffb8e2; margin: 12px 0; font-weight: 700; word-break: break-word; }
