:root {
  --bg: #FBF7EF;
  --slot-outline: #C7BDA8;
  --slot-fill: rgba(255, 255, 255, 0.55);
  --hint: rgba(180, 200, 220, 0.35);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Nunito", "SF Pro Rounded", system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#stage {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#mute {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top));
  right: calc(16px + env(safe-area-inset-right));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.7);
  color: #6B7280;
  display: grid;
  place-items: center;
  cursor: pointer;
  z-index: 10;
  transition: transform 120ms ease-out, background 200ms;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
#mute:active { transform: scale(0.94); }
#mute.muted { background: rgba(230, 220, 200, 0.7); }

#level-chip {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top));
  left: calc(16px + env(safe-area-inset-left));
  min-width: 44px;
  height: 32px;
  padding: 0 10px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.7);
  color: #6B7280;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.5px;
  display: grid;
  place-items: center;
  z-index: 10;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  user-select: none;
  cursor: pointer;
}
#level-chip.trophy {
  background: rgba(255, 220, 140, 0.85);
  color: #7A5A0A;
}
#level-chip.pressing {
  transform: scale(0.94);
  transition: transform 120ms ease-out;
}

#milestone-save-btn {
  position: fixed;
  left: 50%;
  bottom: calc(32px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  border: none;
  background: rgba(255, 220, 140, 0.95);
  color: #7A5A0A;
  padding: 14px 22px;
  border-radius: 26px;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 20;
  animation: milestone-btn-in 400ms ease-out;
}
#milestone-save-btn:active { transform: translateX(-50%) scale(0.96); }
#milestone-save-btn:disabled { opacity: 0.6; }

@keyframes milestone-btn-in {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

#finish-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background: rgba(251, 247, 239, 0.92);
  z-index: 50;
  animation: finish-fade 400ms ease-out;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
#finish-trophy {
  font-size: 40vmin;
  line-height: 1;
  filter: drop-shadow(0 8px 20px rgba(0, 0, 0, 0.18));
  animation: finish-pop 700ms cubic-bezier(0.2, 1.4, 0.4, 1);
}
#finish-sub {
  font-size: 22px;
  font-weight: 800;
  color: #7A5A0A;
}
#finish-cert {
  color: #B98A1A;
  font-weight: 700;
  font-size: 16px;
  text-decoration: none;
  border-bottom: 2px solid rgba(185, 138, 26, 0.4);
  padding-bottom: 2px;
}
#finish-again {
  border: none;
  background: rgba(255, 220, 140, 0.95);
  color: #7A5A0A;
  padding: 14px 28px;
  border-radius: 26px;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
#finish-again:active { transform: scale(0.96); }

@keyframes finish-pop {
  0%   { transform: scale(0); }
  70%  { transform: scale(1.15); }
  100% { transform: scale(1); }
}
@keyframes finish-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

#home {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top));
  right: calc(84px + env(safe-area-inset-right));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.7);
  color: #6B7280;
  display: grid;
  place-items: center;
  cursor: pointer;
  z-index: 10;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
#home:active { transform: scale(0.94); }

#menu {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  gap: 5vmin;
  padding: 24px 16px;
  background: var(--bg);
  overflow-y: auto;
  touch-action: pan-y;
}
#menu[hidden] { display: none; }
#menu h1 {
  margin: 0;
  font-size: clamp(32px, 8vmin, 64px);
  font-weight: 900;
  color: #5A4A2A;
}
.menu-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4vmin;
}
.menu-card {
  width: clamp(100px, 27vmin, 220px);
  aspect-ratio: 1;
  border: none;
  border-radius: 32px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 120ms ease-out;
}
.menu-card:active { transform: scale(0.95); }
.menu-card svg { width: 58%; height: 58%; }
.menu-level {
  font-style: normal;
  font-size: 12px;
  letter-spacing: 3px;
  color: #E8B84A;
}
.menu-card span {
  font-size: clamp(13px, 3.6vmin, 24px);
  font-weight: 800;
  color: #6B7280;
}

#finish-menu {
  border: none;
  background: none;
  color: #B98A1A;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

#grownups {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top));
  right: calc(16px + env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: rgba(255, 255, 255, 0.8);
  color: #6B7280;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  padding: 8px 12px;
  border-radius: 18px;
  cursor: pointer;
}

#gate {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(90, 74, 42, 0.35);
}
#gate[hidden] { display: none; }
.gate-card {
  width: min(340px, 100%);
  background: #fff;
  border-radius: 24px;
  padding: 24px;
  text-align: center;
  color: #5A4A2A;
  font-size: 18px;
  user-select: text;
  -webkit-user-select: text;
}
.gate-card input {
  width: 100px;
  font-family: inherit;
  font-size: 28px;
  font-weight: 800;
  text-align: center;
  padding: 8px;
  border: 2px solid #E5DCC8;
  border-radius: 14px;
  margin: 8px 0 16px;
}
.gate-buttons { display: flex; gap: 12px; justify-content: center; }
.gate-buttons button {
  border: none;
  border-radius: 18px;
  padding: 12px 20px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  background: #F3F0E8;
  color: #5A4A2A;
}
.gate-buttons button[type="submit"] { background: #E8B84A; color: #fff; }
