:root {
  --qp-teal: #35c3c8;
  --qp-teal-dark: #259ba0;
  --qp-red: #e8564f;
  --qp-ink: #27383a;
  --qp-strip: 100px;
  font-family: "Avenir Next", "Nunito", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

/* screen-reader-only content (the aria-live announcer) */
.qp-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* visible keyboard focus everywhere */
.qp-top__btn:focus-visible,
.qp-grid__tile:focus-visible,
.qp-about__close:focus-visible {
  outline: 3px solid var(--qp-teal);
  outline-offset: -3px;
}

html, body { height: 100%; }

body {
  margin: 0;
  background: #fff;
  color: var(--qp-ink);
}

/* ---------- app frame: top strip + body ---------- */
.qp-app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- top strip (100px, per layout reference) ---------- */
.qp-top {
  position: relative;
  flex: none;
  height: var(--qp-strip);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 22px;
  background: #fff;
}

/* original app wordmark — wide in landscape, stacked variant in portrait */
.qp-top__logo {
  position: relative;
  height: 38px;
}

.qp-top__logo--stacked { height: 64px; }

@media (orientation: landscape) {
  .qp-top__logo--stacked { display: none; }
}

@media (orientation: portrait) {
  .qp-top__logo--wide { display: none; }
}

@media (max-width: 640px) {
  .qp-top__logo--wide { height: 28px; }
  .qp-top__logo--stacked { height: 56px; }
}

/* icon-only buttons using the original app's option-panel glyphs —
   one uniform size everywhere */
.qp-top__btn {
  border: 0;
  padding: 0;
  width: 40px;
  height: 40px;
  background: none;
  cursor: pointer;
  transition: transform 0.1s ease;
}

.qp-top__btn:hover { transform: scale(1.1); }
.qp-top__btn:active { transform: scale(0.94); }

.qp-top__btn-icon {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ---------- about overlay ---------- */
.qp-about {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(39, 56, 58, 0.55);
  animation: qp-fade 0.25s ease;
}

/* display:flex above would otherwise override the hidden attribute */
.qp-about[hidden] { display: none; }

.qp-about__panel {
  background: #fff;
  border-radius: 18px;
  padding: 30px 34px;
  max-width: 380px;
  margin: 20px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  animation: qp-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* the three makers' avatars, bouncing in one after another */
.qp-about__team {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin: 4px 0 18px;
}

.qp-about__face {
  width: 84px;
  height: 84px;
  border-radius: 18px;
  animation: qp-face-in 0.5s calc(0.15s + var(--i) * 0.13s) cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes qp-fade {
  from { opacity: 0; }
}

@keyframes qp-pop {
  from { transform: scale(0.5); opacity: 0; }
}

@keyframes qp-face-in {
  from { transform: scale(0) rotate(-12deg); opacity: 0; }
}

/* ---------- juice: reactions, spins and confetti ---------- */
@media (prefers-reduced-motion: no-preference) {
  /* whole-avatar squash & stretch when something changes */
  .qp-stage__svg { transform-origin: 50% 100%; }
  .qp-stage__svg.qp-bounce { animation: qp-squash 0.32s ease; }

  /* changed feature layer pops */
  .qp-stage__svg g[id^="L_"] {
    transform-box: fill-box;
    transform-origin: 50% 50%;
  }
  .qp-stage__svg g.qp-pop { animation: qp-layer-pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1); }

  /* idle blink: the eyes layer squashes flat and springs back */
  .qp-stage__svg g#L_eyes.qp-blink { animation: qp-blink 0.16s ease-in-out; }

  /* dice spins while the slot machine runs */
  .qp-top__btn.qp-spin .qp-top__btn-icon { animation: qp-rot 0.5s linear infinite; }
}

@keyframes qp-squash {
  30% { transform: scale(1.02, 0.94); }
  65% { transform: scale(0.985, 1.02); }
}

@keyframes qp-layer-pop {
  0% { transform: scale(0.7); }
}

@keyframes qp-rot {
  to { transform: rotate(360deg); }
}

@keyframes qp-blink {
  50% { transform: scaleY(0.08); }
}

/* first-visit nudge: the active tile pulses a few times */
@media (prefers-reduced-motion: no-preference) {
  .qp-grid__tile.qp-hint { animation: qp-hint-pulse 1.1s ease-in-out 3; }
}

@keyframes qp-hint-pulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.25); }
}

/* confetti burst on download / share */
.qp-confetti {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  width: 0;
  height: 0;
}

.qp-confetti__bit {
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  animation: qp-confetti-fly 0.8s cubic-bezier(0.16, 0.8, 0.4, 1) forwards;
}

@keyframes qp-confetti-fly {
  from { transform: translate(0, 0) rotate(0deg); opacity: 1; }
  to { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); opacity: 0; }
}

.qp-about__text {
  margin: 0 0 20px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--qp-ink);
}

.qp-about__text a { color: var(--qp-teal-dark); font-weight: 700; }

.qp-about__close {
  border: 0;
  border-radius: 12px;
  padding: 12px 22px;
  font-size: 15px;
  font-weight: 800;
  font-family: inherit;
  color: #fff;
  background: var(--qp-teal);
  cursor: pointer;
}

.qp-about__close:hover { background: var(--qp-teal-dark); }

/* ---------- body: avatar + options grid ---------- */
.qp-body {
  flex: 1;
  min-height: 0;
  display: flex;
}

.qp-stage { flex: none; }

.qp-stage__svg {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.qp-rail {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: grid;
}

.qp-grid__tile {
  position: relative;
  border: 0;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: filter 0.1s ease;
}

.qp-grid__tile:hover { filter: brightness(1.08); }
.qp-grid__tile:active { filter: brightness(0.92); }

/* active ring drawn on an overlay so the full-bleed colour swatch on the
   skin / hair-colour tiles can't paint over it */
.qp-grid__tile--active::after {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 4px #ffffff;
  pointer-events: none;
}

/* live colour swatch behind the icon on the skin / hair colour tiles */
.qp-grid__swatch {
  position: absolute;
  inset: 0;
}

.qp-grid__swatch svg {
  display: block;
  width: 100%;
  height: 100%;
}

.qp-grid__icon {
  position: relative;
  height: 34%;
  max-width: 62%;
  pointer-events: none;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.12));
  transition: transform 0.15s ease;
}

.qp-grid__tile:hover .qp-grid__icon { transform: scale(1.18) rotate(-4deg); }
.qp-grid__tile:active .qp-grid__icon { transform: scale(0.9); }

/* ---------- landscape: avatar centred, rails stacked left/right ---------- */
@media (orientation: landscape) {
  .qp-body { flex-direction: row; }
  .qp-stage { height: 100%; aspect-ratio: 1 / 1; order: 1; }
  .qp-rail {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(5, 1fr);
  }
  #gridLeft { order: 0; }
  #gridRight { order: 2; }
}

/* ---------- portrait: avatar top (full width), rails as rows below ---------- */
@media (orientation: portrait) {
  .qp-body { flex-direction: column; }
  .qp-stage { width: 100%; aspect-ratio: 1 / 1; order: 0; }
  .qp-rail {
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: 1fr;
    min-height: 55px;
  }
  #gridLeft { order: 1; }
  #gridRight { order: 2; }
}
