:root {
  --ink: #241a52;
  --royal: #4a3fd1;
  --peri: #8f9cf5;
  --pink: #ff3d9a;
  --cream: #fff7e8;
  --gold: #f5c542;
  /* The space above the puzzle frame, where the clock and the corner buttons sit. */
  --band: calc((100vh - min(129vw, 74vh)) / 2);
  --icon: min(11vw, 5.5vh);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  font-family: "Quicksand", system-ui, sans-serif;
  font-weight: 500;
  color: var(--cream);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

button { font: inherit; cursor: pointer; }

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4vh;
  text-align: center;
  padding: 6vw;
  z-index: 20;
}

#start-screen {
  background: radial-gradient(ellipse at center, rgba(36, 26, 82, 0.35), rgba(36, 26, 82, 0.7));
}

#end-screen {
  justify-content: flex-end;
  padding-bottom: 14vh;
  pointer-events: none;
}
#end-screen > * { pointer-events: auto; }

.overlay[hidden], #hud[hidden] { display: none; }

h1 {
  font-family: "Grandstander", sans-serif;
  font-weight: 800;
  font-size: min(13vw, 7vh);
  margin: 0;
  color: var(--cream);
  text-shadow: 0 3px 0 var(--ink), 0 0 24px rgba(36, 26, 82, 0.6);
}

h1.start-title { font-size: min(13vw, 7vh); line-height: 1.05; max-width: min(86vw, 49vh); }

/* Short names get big and long ones still fit across the frame. */
#end-title {
  -webkit-text-stroke: 0.16em var(--ink);
  paint-order: stroke fill;
  font-size: min(22vw, 11vh, calc(min(86vw, 49vh) * 1.4 / var(--letters, 8)));
  animation: pop-in 0.6s cubic-bezier(0.3, 1.6, 0.5, 1) both;
}

.big-btn {
  width: min(48vw, 28vh);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 0.8vh solid var(--cream);
  background: radial-gradient(circle at 35% 30%, #ff7cbd, var(--pink) 55%, #c8237a);
  color: white;
  font-family: "Grandstander", sans-serif;
  font-weight: 800;
  font-size: min(10vw, 5.5vh);
  box-shadow: 0 1vh 0 #9c1a5f, 0 0 4vh rgba(255, 61, 154, 0.6);
  animation: breathe 2.4s ease-in-out infinite;
}
.big-btn:active { transform: translateY(0.6vh); box-shadow: 0 0.4vh 0 #9c1a5f; }

.replay-btn {
  width: min(24vw, 12vh);
  height: min(24vw, 12vh);
  border-radius: 50%;
  border: 0;
  padding: 0;
  display: grid;
  place-items: center;
  background: var(--cream);
  box-shadow: 0 0.6vh 0 rgba(36, 26, 82, 0.5);
  animation: pop-in 0.5s 1.2s both;
}
.replay-btn:active { transform: translateY(0.4vh); box-shadow: 0 0.2vh 0 rgba(36, 26, 82, 0.5); }
.replay-btn svg {
  width: 58%;
  height: 58%;
  fill: none;
  stroke: var(--royal);
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hint {
  margin: 0;
  font-family: "Grandstander", sans-serif;
  font-weight: 700;
  font-size: min(6.4vw, 3.4vh);
  text-shadow: 0 1px 6px var(--ink);
}

.icon-btn {
  width: var(--icon);
  height: var(--icon);
  border-radius: 50%;
  border: 0;
  background: rgba(36, 26, 82, 0.55);
  display: grid;
  place-items: center;
  padding: 0;
}
.icon-btn svg {
  width: 60%;
  height: 60%;
  fill: none;
  stroke: var(--cream);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#sound {
  position: fixed;
  top: calc(env(safe-area-inset-top) + (var(--band) - env(safe-area-inset-top) - var(--icon)) / 2);
  right: 3vw;
  z-index: 30;
}
#sound .on { display: none; }
#sound[aria-pressed="true"] .on { display: block; }
#sound[aria-pressed="true"] .off { display: none; }

/* The header fills the space above the puzzle frame, so the clock can be as big as that space allows. */
#hud {
  position: fixed;
  top: 0;
  left: 3vw;
  right: 3vw;
  height: var(--band);
  padding-top: env(safe-area-inset-top);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 25;
}
.hud-spacer { width: var(--icon); }
body.done #stop { visibility: hidden; }
.hud-mid {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
#clock {
  font-family: "Grandstander", sans-serif;
  font-weight: 800;
  font-size: min(22vw, calc(var(--band) * 0.72));
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-align: center;
  text-shadow: 0 0.5vh 0 var(--ink), 0 0 3vh rgba(36, 26, 82, 0.6);
}

#confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 21;
}

#footer {
  position: fixed;
  bottom: max(1.5vh, env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  text-align: center;
  font-size: min(3.6vw, 1.8vh);
  z-index: 30;
  text-shadow: 0 1px 4px var(--ink);
  transition: opacity 0.4s;
}
#footer a { color: inherit; font-weight: 600; }
body.running #footer { opacity: 0; pointer-events: none; }

@keyframes breathe { 50% { transform: scale(1.05); } }
@keyframes pop-in {
  from { transform: scale(0.3); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
