html, body { height: 100%; overflow: hidden; }

body {
  background: radial-gradient(120% 90% at 50% 30%, var(--plum) 0%, var(--plum-deep) 70%);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
body.pointer-idle, body.pointer-idle * { cursor: none !important; }

#cam {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}
.veil {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(110% 85% at 50% 42%, rgba(63, 43, 46, 0.5), rgba(36, 23, 26, 0.84));
  transition: opacity 0.6s ease;
}
body[data-state='playing'] .veil { opacity: 0.32; }
body[data-state='countdown'] .veil { opacity: 0.6; }

#stage, #fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
#fx { z-index: 40; }

/* Screens */
.panel {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 1.8vh, 22px);
  padding: 4vh 4vw 9vh;
  text-align: center;
}
body[data-state='menu'] #menu,
body[data-state='end'] #end,
body[data-state='problem'] #problem { display: flex; }

.title {
  margin: 0;
  font: 400 clamp(64px, 15vh, 190px) / 1 var(--font-display);
  filter: drop-shadow(0 8px 30px rgba(20, 10, 12, 0.45));
}
.tagline {
  margin: 0 0 1.5vh;
  font: 700 clamp(20px, 3.6vh, 42px) / 1.3 var(--font-body);
  text-shadow: 0 2px 16px rgba(20, 10, 12, 0.6);
}
.hint {
  margin: 1.4vh 0 0;
  font: 700 clamp(16px, 2.6vh, 30px) / 1.3 var(--font-body);
  color: var(--foam-dim);
}
.status {
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  margin: 0;
  padding: 0.35em 1em;
  border-radius: 999px;
  background: var(--plum-glass);
  font: 700 clamp(15px, 2.3vh, 26px) / 1.3 var(--font-body);
}
.status::before {
  content: '';
  width: 0.6em;
  height: 0.6em;
  border-radius: 50%;
  background: var(--film-gold);
  box-shadow: 0 0 10px var(--film-gold);
}
.status[data-kind='ok']::before { background: var(--film-cyan); box-shadow: 0 0 12px var(--film-cyan); }
.status[data-kind='wait']::before { animation: blink 1.2s ease-in-out infinite; }
.sound-hint {
  margin: 0;
  font: 500 clamp(13px, 1.8vh, 19px) / 1.3 var(--font-body);
  color: var(--film-gold);
}
body.audio-on .sound-hint { display: none; }
.menu-tools {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 0.8vh;
}
.privacy {
  position: absolute;
  bottom: 2.6vh;
  inset-inline: 0;
  margin: 0;
  font: 500 clamp(12px, 1.6vh, 17px) / 1.4 var(--font-body);
  color: var(--foam-dim);
}
body.mouse-mode #mouse-mode { display: none; }

/* HUD */
.hud {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 10;
  display: none;
  justify-content: space-between;
  align-items: flex-start;
  padding: 3vh 3vw;
  pointer-events: none;
}
body[data-state='playing'] .hud,
body[data-state='countdown'] .hud { display: flex; }
.score {
  display: flex;
  align-items: baseline;
  gap: 0.35em;
  padding: 0.12em 0.7em 0.08em;
  border-radius: 999px;
  background: var(--plum-glass);
  -webkit-backdrop-filter: blur(6px);
          backdrop-filter: blur(6px);
  box-shadow: inset 0 0 0 2px rgba(255, 246, 241, 0.12);
  font: 400 clamp(40px, 8.5vh, 104px) / 1.05 var(--font-display);
}
.score small { font: 800 clamp(15px, 2.4vh, 28px) / 1 var(--font-body); color: var(--foam-dim); }
.score.bump span { display: inline-block; animation: bump 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.4); }
.timer { position: relative; width: clamp(84px, 14vh, 160px); aspect-ratio: 1; }
.timer svg { width: 100%; height: 100%; transform: rotate(-90deg); overflow: visible; }
.timer .track { fill: var(--plum-glass); stroke: rgba(255, 246, 241, 0.16); stroke-width: 7; }
.timer .ring {
  fill: none;
  stroke: url(#film-grad);
  stroke-width: 7;
  stroke-linecap: round;
  stroke-dasharray: 276.46;
  stroke-dashoffset: 0;
}
.timer span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding-top: 0.08em;
  font: 400 clamp(32px, 6vh, 70px) / 1 var(--font-display);
}
.timer.is-low .ring { stroke: var(--film-gold); }
.timer.is-low span { color: var(--film-gold); animation: pulse 1s ease-in-out infinite; }

.combo {
  position: fixed;
  top: 17vh;
  inset-inline: 0;
  z-index: 15;
  text-align: center;
  pointer-events: none;
  font: 400 clamp(48px, 10vh, 120px) / 1 var(--font-display);
  color: var(--film-gold);
  text-shadow: 0 6px 30px rgba(20, 10, 12, 0.5);
  opacity: 0;
}
.combo.show { animation: combo 1.1s cubic-bezier(0.2, 0.9, 0.3, 1.2) both; }

.countdown {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: none;
  place-items: center;
  pointer-events: none;
  font: 400 clamp(140px, 36vh, 400px) / 1 var(--font-display);
  text-shadow: 0 10px 60px rgba(20, 10, 12, 0.55);
}
body[data-state='countdown'] .countdown { display: grid; }
.countdown span { animation: count-in 0.8s cubic-bezier(0.2, 0.9, 0.3, 1.3) both; }
.countdown span.go { color: var(--film-gold); font-size: 0.6em; }

/* End screen */
.result {
  display: flex;
  align-items: baseline;
  gap: 0.25em;
  margin: 0;
  font: 400 clamp(90px, 20vh, 240px) / 1 var(--font-display);
}
.result small { font: 800 clamp(20px, 3.6vh, 42px) / 1 var(--font-body); color: var(--foam-dim); }
.stars { display: flex; gap: clamp(8px, 1.5vh, 18px); }
.stars svg {
  width: clamp(44px, 8vh, 96px);
  height: auto;
  fill: rgba(255, 246, 241, 0.14);
  transition: fill 0.2s;
}
.stars svg.on { fill: var(--film-gold); filter: drop-shadow(0 0 14px rgba(255, 201, 77, 0.7)); animation: star-in 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.5); }
.best { margin: 0; font: 700 clamp(16px, 2.6vh, 30px) / 1.3 var(--font-body); color: var(--foam-dim); }
.best.is-new { color: var(--film-gold); }
.end-actions { display: flex; align-items: center; gap: clamp(28px, 6vw, 90px); margin-top: 2vh; }

/* Problem screen */
.problem-title { margin: 0; font: 400 clamp(40px, 8vh, 96px) / 1.1 var(--font-display); color: var(--film-gold); }
.problem-text { max-width: 34ch; margin: 0 0 1vh; font: 700 clamp(18px, 3vh, 34px) / 1.5 var(--font-body); }
.chip-btn.is-primary { background: var(--foam); color: var(--plum); border-color: var(--foam); }
.chip-btn.is-primary:hover { background: #fff; }

/* Corner tools stay available on every screen; quieter while playing. */
.corner-tools {
  position: fixed;
  bottom: 2.4vh;
  inset-inline-end: 2.4vw;
  z-index: 30;
  display: flex;
  gap: 8px;
  transition: opacity 0.3s;
}
body[data-state='playing'] .corner-tools { opacity: 0.45; }
body[data-state='playing'] .corner-tools:hover { opacity: 1; }
#sound[aria-pressed='false'] { text-decoration: line-through; color: var(--foam-dim); }

/* Exit: chip (top) with the X-gesture meter, and the confirmation dialog */
.top-tools {
  position: fixed;
  z-index: 30;
  top: 2.4vh;
  left: 2.4vw;
  display: flex;
  align-items: center;
  gap: 12px;
}
body[data-state='problem'] .top-tools { display: none; }
body[data-state='playing'] .top-tools { top: auto; bottom: 2.4vh; left: auto; right: 2.4vw; opacity: 0.6; }
.exit-chip { padding-inline-start: 0.5em; }
.x-meter { display: inline-grid; width: 1.7em; height: 1.7em; }
.x-meter svg { width: 100%; height: 100%; overflow: visible; transform: rotate(-90deg); }
.x-meter .track { fill: rgba(255, 246, 241, 0.1); stroke: rgba(255, 246, 241, 0.2); stroke-width: 3; }
.x-meter .ring { fill: none; stroke: var(--film-gold); stroke-width: 3.5; stroke-linecap: round; stroke-dasharray: 94.25; stroke-dashoffset: 94.25; }
.x-meter path { fill: none; stroke: var(--foam); stroke-width: 3; stroke-linecap: round; transform: rotate(90deg); transform-origin: 18px 18px; }
.x-hint { font: 700 clamp(13px, 1.8vh, 19px) / 1.3 var(--font-body); color: var(--foam-dim); }
.x-hint b { color: var(--film-gold); }
body.mouse-mode .x-hint, body[data-state='playing'] .x-hint { display: none; }
.overlay {
  position: fixed;
  inset: 0;
  z-index: 35;
  display: grid;
  place-items: center;
  background: rgba(20, 10, 12, 0.76);
}
.overlay[hidden] { display: none; }
.dialog {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3vh;
  padding: 4vh 5vw;
  border-radius: 40px;
  background: rgba(63, 43, 46, 0.92);
  box-shadow: inset 0 0 0 2px rgba(255, 246, 241, 0.12), 0 30px 80px rgba(0, 0, 0, 0.5);
  text-align: center;
}
.dialog h2 { margin: 0; font: 400 clamp(34px, 7vh, 84px) / 1.15 var(--font-display); }
.dialog-actions { display: flex; gap: clamp(30px, 6vw, 110px); }

.debug {
  position: fixed;
  bottom: 8px;
  right: 8px;
  z-index: 50;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.6);
  font: 12px/1.4 ui-monospace, monospace;
  direction: ltr;
  white-space: pre;
}

@keyframes blink { 50% { opacity: 0.35; } }
@keyframes bump { 0% { transform: scale(1); } 45% { transform: scale(1.25); } 100% { transform: scale(1); } }
@keyframes pulse { 50% { transform: scale(1.12); } }
@keyframes count-in {
  0% { transform: scale(0.4); opacity: 0; }
  30% { transform: scale(1.08); opacity: 1; }
  80% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.3); opacity: 0; }
}
@keyframes combo {
  0% { transform: scale(0.5); opacity: 0; }
  20% { transform: scale(1.1); opacity: 1; }
  75% { transform: scale(1); opacity: 1; }
  100% { transform: translateY(-4vh); opacity: 0; }
}
@keyframes star-in { 0% { transform: scale(0.3) rotate(-30deg); } 100% { transform: scale(1) rotate(0); } }

@media (prefers-reduced-motion: reduce) {
  .status[data-kind='wait']::before, .timer.is-low span { animation: none; }
}
