:root {
  /* Pastel purple accent system */
  --purple-100: #f3eefc;
  --purple-200: #e6dcfa;
  --purple-300: #cdbcf3;
  --purple-400: #b49ae9;
  --purple-500: #9a7ade;
  --purple-600: #7d5cc9;
  --purple-ink: #4a3a72;

  /* Desk environment neutrals */
  --desk: #ece6da;
  --desk-deep: #ddd4c2;
  --paper: #fbf9f3;
  --ink: #3d3a44;
  --coral: #f08a8a;

  --shadow: 24px 32px 60px -28px rgba(74, 58, 114, 0.55);
}

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

html, body {
  height: 100%;
  background:
    radial-gradient(circle at 20% 0%, #f5f1fb 0%, transparent 55%),
    radial-gradient(circle at 90% 100%, #efe9f9 0%, transparent 50%),
    #e8e2f1;
  font-family: "DM Sans", system-ui, sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.stage {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 18px;
}

.frame {
  position: relative;
  width: min(94vw, 46vh, 480px);
  aspect-ratio: 480 / 800;
  border-radius: 26px;
  overflow: hidden;
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.6);
  background: var(--desk);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: optimizeQuality;
}

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  inset: 0 0 auto 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 14px 0;
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.hud.is-dim { opacity: 0; transform: translateY(-8px); }

/* ---------- Sound toggle ---------- */
.sound-toggle {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 6;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  border: none;
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
  border-radius: 12px;
  background: rgba(251, 249, 243, 0.82);
  backdrop-filter: blur(6px);
  box-shadow: 0 6px 16px -10px rgba(74, 58, 114, 0.6), inset 0 0 0 1px rgba(255,255,255,0.7);
  transition: transform 0.15s ease, opacity 0.2s ease;
}
.sound-toggle:hover { transform: scale(1.08); }
.sound-toggle:active { transform: scale(0.94); }
.sound-toggle__on { display: block; }
.sound-toggle__off { display: none; }
.sound-toggle.is-muted .sound-toggle__on { display: none; }
.sound-toggle.is-muted .sound-toggle__off { display: block; }


.hud__pill {
  display: flex;
  flex-direction: column;
  line-height: 1;
  padding: 8px 13px;
  border-radius: 14px;
  background: rgba(251, 249, 243, 0.82);
  backdrop-filter: blur(6px);
  box-shadow: 0 6px 16px -10px rgba(74, 58, 114, 0.6), inset 0 0 0 1px rgba(255,255,255,0.7);
}
.hud__pill--best { text-align: right; }
.hud__label {
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--purple-600);
  font-weight: 700;
  margin-bottom: 4px;
}
.hud__value {
  font-family: "Fredoka", sans-serif;
  font-weight: 600;
  font-size: 19px;
  color: var(--purple-ink);
}
.hud__value small { font-size: 11px; opacity: 0.6; margin-left: 1px; }

.hud__center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding-top: 4px;
}
.hud__brand {
  font-family: "Fredoka", sans-serif;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--purple-500);
  opacity: 0.85;
  text-align: center;
}

/* Remaining chances, shown as little sticky-note pips. */
.hud__lives { display: flex; gap: 5px; }
.life {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--purple-400);
  box-shadow: 0 2px 5px -2px rgba(74, 58, 114, 0.7), inset 0 0 0 1px rgba(255,255,255,0.55);
  transform: rotate(-7deg);
  transition: background 0.25s ease, transform 0.25s ease, opacity 0.25s ease;
}
.life.is-lost {
  background: rgba(74, 58, 114, 0.18);
  box-shadow: inset 0 0 0 1px rgba(74, 58, 114, 0.22);
  transform: rotate(7deg) scale(0.82);
  opacity: 0.65;
}

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.45s ease, visibility 0.45s;
  z-index: 5;
  background:
    radial-gradient(circle at 50% 30%, rgba(154, 122, 222, 0.18), transparent 60%),
    rgba(236, 230, 218, 0.55);
  backdrop-filter: blur(3px);
}
.overlay.is-visible { opacity: 1; visibility: visible; }

.card {
  width: 100%;
  max-width: 340px;
  text-align: center;
  background: var(--paper);
  border-radius: 22px;
  padding: 30px 26px 26px;
  box-shadow: 0 30px 60px -30px rgba(74, 58, 114, 0.65), inset 0 0 0 1px rgba(255,255,255,0.8);
  position: relative;
  animation: pop 0.5s cubic-bezier(0.18, 1.2, 0.4, 1) both;
}
@keyframes pop {
  from { opacity: 0; transform: translateY(14px) scale(0.96); }
  to   { opacity: 1; transform: none; }
}

.card__tag, .card__stamp {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--purple-600);
  background: var(--purple-100);
  padding: 6px 12px;
  border-radius: 999px;
  margin-bottom: 16px;
}
.card__stamp {
  color: #b65b5b;
  background: #fbe7e7;
  transform: rotate(-4deg);
  border: 2px dashed #e9a3a3;
}

.card__stamp--over {
  color: #6a5aa0;
  background: var(--purple-100);
  border-color: var(--purple-300);
}

  font-family: "Fredoka", sans-serif;
  font-weight: 700;
  font-size: 38px;
  line-height: 0.95;
  letter-spacing: -0.01em;
  color: var(--purple-ink);
}
.card__title span { color: var(--purple-500); }
.card__title--win { font-size: 34px; }

.card__sub {
  margin: 14px auto 22px;
  font-size: 14px;
  line-height: 1.5;
  color: #6c6776;
  max-width: 270px;
}
.card__sub b { color: var(--purple-600); }

.btn {
  font-family: "Fredoka", sans-serif;
  font-weight: 600;
  font-size: 17px;
  color: #fff;
  border: none;
  cursor: pointer;
  padding: 14px 30px;
  border-radius: 16px;
  background: linear-gradient(180deg, var(--purple-500), var(--purple-600));
  box-shadow: 0 12px 22px -10px rgba(125, 92, 201, 0.8), inset 0 1px 0 rgba(255,255,255,0.4);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 16px 26px -10px rgba(125, 92, 201, 0.85), inset 0 1px 0 rgba(255,255,255,0.4); }
.btn:active { transform: translateY(1px) scale(0.98); }

.legend {
  list-style: none;
  display: flex;
  gap: 18px;
  justify-content: center;
  margin: 22px 0 14px;
  font-size: 12px;
  color: #847f8e;
  font-weight: 500;
}
.legend li { display: flex; align-items: center; gap: 6px; }
.key {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: 7px;
  background: #fff;
  box-shadow: 0 2px 0 var(--purple-200), inset 0 0 0 1px var(--purple-200);
  font-family: "Fredoka", sans-serif;
  font-size: 12px;
  color: var(--purple-ink);
}
.key--wide { min-width: 54px; }

.notes-legend { display: flex; gap: 10px; justify-content: center; }
.chip {
  font-size: 10.5px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 999px;
  position: relative;
  padding-left: 22px;
}
.chip::before {
  content: "";
  position: absolute;
  left: 8px; top: 50%;
  transform: translateY(-50%);
  width: 9px; height: 9px;
  border-radius: 2px;
}
.chip--stable { background: var(--purple-100); color: var(--purple-600); }
.chip--stable::before { background: var(--purple-400); }
.chip--urgent { background: #fbe7e7; color: #b65b5b; }
.chip--urgent::before { background: var(--coral); }

.stats { display: flex; gap: 14px; justify-content: center; margin: 20px 0 22px; }
.stat {
  flex: 1;
  background: var(--purple-100);
  border-radius: 14px;
  padding: 14px 8px;
}
.stat__num {
  display: block;
  font-family: "Fredoka", sans-serif;
  font-weight: 700;
  font-size: 28px;
  color: var(--purple-ink);
  line-height: 1;
}
.stat__cap {
  display: block;
  margin-top: 5px;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--purple-600);
  font-weight: 600;
}

/* ---------- Fall flash ---------- */
.flash {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(74, 58, 114, 0.28);
  opacity: 0;
  visibility: hidden;
  z-index: 4;
  pointer-events: none;
}
.flash.is-on { animation: flashfade 0.7s ease forwards; }
.flash span {
  font-family: "Fredoka", sans-serif;
  font-weight: 600;
  font-size: 18px;
  color: #fff;
  letter-spacing: 0.04em;
  text-shadow: 0 2px 8px rgba(74,58,114,0.6);
}
@keyframes flashfade {
  0%   { opacity: 0; visibility: visible; }
  25%  { opacity: 1; }
  100% { opacity: 0; visibility: hidden; }
}

.hint {
  font-size: 12px;
  color: #8b8595;
  text-align: center;
  max-width: 320px;
  opacity: 0;
}
@media (pointer: coarse) {
  .hint { opacity: 1; }
}
