:root {
  --bg1: #2a2150;
  --bg2: #4a2f6e;
  --panel: rgba(255, 255, 255, 0.08);
  --ink: #f4f1ff;
  --accent: #ffd23f;
  --accent-d: #e6a700;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

/* Paint the root element too, so iOS Safari's overscroll/safe-area and the
   address/tool bars don't flash white above and below the purple game area.
   Uses the lighter gradient-top tone so the top status bar blends with it. */
html {
  background: var(--bg2);
}

body {
  color: var(--ink);
  background: radial-gradient(circle at 30% 0%, var(--bg2), var(--bg1) 70%) fixed;
  background-color: var(--bg1);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.app {
  width: 100%;
  max-width: 720px;
  padding: 12px 14px 32px;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.title {
  flex: 1;
  text-align: center;
  margin: 6px 0;
  font-size: clamp(26px, 7vw, 40px);
  letter-spacing: 0.5px;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
  color: var(--accent);
}

.back {
  text-decoration: none;
  color: var(--ink);
  font-size: 30px;
  line-height: 1;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--panel);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
  font-size: 20px;
  cursor: pointer;
}

.hud {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin: 4px 0 6px;
}

.hud-item {
  background: var(--panel);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 15px;
}
.hud-item strong { color: var(--accent); }

.hint {
  text-align: center;
  font-size: 13px;
  opacity: 0.8;
  margin: 4px auto 12px;
  max-width: 460px;
  line-height: 1.45;
}

/* ---- Board -------------------------------------------------------------- */
.board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(86px, 1fr));
  gap: 8px 6px;
  justify-items: center;
  align-items: end;
  flex: 1;
}

.wig {
  border: none;
  background: transparent;
  padding: 4px 2px 2px;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease;
  width: 100%;
  max-width: 110px;
}

.wig:hover { background: rgba(255, 255, 255, 0.05); }

.wig.selected {
  background: rgba(255, 210, 63, 0.16);
  transform: translateY(-4px);
}

.wig.complete {
  animation: pulse 1.4s ease-in-out infinite;
}

.wig.screaming {
  animation: shake 0.16s linear 0s 4;
}

.wig-svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

/* hair bands transition position so lift/drop animate smoothly */
.wig-svg .hair-band rect { transition: y 0.18s ease; }

@keyframes pulse {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(255, 210, 63, 0)); }
  50% { filter: drop-shadow(0 0 10px rgba(255, 210, 63, 0.6)); }
}

@keyframes shake {
  0% { transform: translate(0, 0) rotate(0deg); }
  25% { transform: translate(-3px, -1px) rotate(-2deg); }
  50% { transform: translate(3px, 0) rotate(2deg); }
  75% { transform: translate(-2px, 1px) rotate(-1deg); }
  100% { transform: translate(0, 0) rotate(0deg); }
}

/* ---- Controls ----------------------------------------------------------- */
.controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 18px;
}

.ctrl-btn {
  border: none;
  border-radius: 12px;
  padding: 12px 22px;
  font-size: 16px;
  font-weight: 600;
  color: #2a2150;
  background: linear-gradient(#fff, #e4ddf3);
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
  transition: transform 0.08s ease;
}
.ctrl-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25); }
.ctrl-btn:disabled { opacity: 0.4; cursor: default; box-shadow: none; }

.ctrl-btn.primary {
  color: #5a3a00;
  background: linear-gradient(var(--accent), var(--accent-d));
}

/* ---- Win overlay -------------------------------------------------------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 14, 40, 0.7);
  display: none;
  place-items: center;
  padding: 20px;
}
.overlay.show { display: grid; animation: fade 0.25s ease; }

.win-card {
  background: linear-gradient(#3a2c63, #2a2150);
  border: 2px solid rgba(255, 210, 63, 0.5);
  border-radius: 20px;
  padding: 28px 32px;
  text-align: center;
  max-width: 320px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  animation: pop 0.3s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.win-card h2 { margin: 6px 0 8px; color: var(--accent); font-size: 30px; }
.win-card p { margin: 0 0 18px; opacity: 0.9; }
.win-emoji { font-size: 44px; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { transform: scale(0.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
