/* =====================================================================
   avatar.css — avatar stage + wardrobe picker
   Mobile-first (designed at 390px), system fonts only, no assets,
   no @import, no network. Theme by overriding the custom properties
   below on :root or on any ancestor of .av-stage / .av-wardrobe.
   ===================================================================== */

:root {
  /* palette ------------------------------------------------------- */
  --av-bg: #f4f6fb;
  --av-surface: #ffffff;
  --av-surface-2: #eef1f8;
  --av-surface-3: #e3e8f3;
  --av-ink: #22203a;
  --av-ink-soft: #5c5a74;
  --av-muted: #8b89a3;
  --av-line: #d8ddea;
  --av-accent: #ff8a3d;
  --av-accent-ink: #ffffff;
  --av-accent-soft: #fff0e4;
  --av-ok: #2bb673;
  --av-locked: #a7a5bb;
  --av-coin: #ffc53d;
  --av-coin-ink: #6b4a05;
  --av-shadow: 0 2px 10px rgba(34, 32, 58, 0.08);
  --av-shadow-lift: 0 6px 18px rgba(34, 32, 58, 0.16);

  /* shape + rhythm ----------------------------------------------- */
  --av-radius: 18px;
  --av-radius-sm: 12px;
  --av-radius-pill: 999px;
  --av-gap: 10px;
  --av-pad: 14px;
  --av-tap: 44px; /* minimum touch target */
  --av-stage-max: 390px;
  --av-thumb: 96px;

  /* motion ------------------------------------------------------- */
  --av-bob-duration: 3.4s;
  --av-blink-duration: 6s;
  --av-ease: cubic-bezier(0.34, 1.4, 0.64, 1);

  --av-font: ui-rounded, system-ui, -apple-system, "Segoe UI Variable Text",
    "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}

/* ---------------------------------------------------------------- *
   avatar stage
 * ---------------------------------------------------------------- */

.av-stage {
  display: block;
  width: 100%;
  max-width: var(--av-stage-max);
  margin-inline: auto;
  position: relative;
  line-height: 0;
  -webkit-tap-highlight-color: transparent;
}

.av-stage.av-stage--sm {
  max-width: 132px;
}

.av-root {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  font-family: var(--av-font);
  user-select: none;
  -webkit-user-select: none;
}

/* keep crisp edges on the tiny thumbnails */
.av-thumb-svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  font-family: var(--av-font);
}

/* ---------------------------------------------------------------- *
   motion: idle bob, blink, per-mood pose
 * ---------------------------------------------------------------- */

.av-bob {
  transform-box: view-box;
  transform-origin: 80px 180px;
  animation: av-bob var(--av-bob-duration) ease-in-out infinite;
  will-change: transform;
}

@keyframes av-bob {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }
  50% {
    transform: translateY(-3.2px) rotate(-0.5deg);
  }
}

.av-lid {
  transform-box: view-box;
  animation: av-blink var(--av-blink-duration) steps(1, end) infinite;
  transform: scaleY(0);
}
.av-lid-l {
  transform-origin: 65px 74px;
}
.av-lid-r {
  transform-origin: 95px 74px;
  animation-delay: 40ms;
}

@keyframes av-blink {
  0%,
  92%,
  100% {
    transform: scaleY(0);
  }
  93.5%,
  95.5% {
    transform: scaleY(1);
  }
  96.5% {
    transform: scaleY(0.4);
  }
}

/* arms swing per mood */
.av-arm {
  transform-box: view-box;
  transition: transform 0.4s var(--av-ease);
}
.av-arm-l {
  transform-origin: 47px 114px;
}
.av-arm-r {
  transform-origin: 113px 114px;
}

.av-mood-happy .av-arm-l {
  transform: rotate(14deg);
}
.av-mood-happy .av-arm-r {
  transform: rotate(-14deg);
}
.av-mood-happy .av-bob {
  animation-duration: 2.2s;
}

.av-mood-celebrating .av-arm-l {
  transform: rotate(142deg);
}
.av-mood-celebrating .av-arm-r {
  transform: rotate(-142deg);
}
.av-mood-celebrating .av-bob {
  animation: av-jump 0.72s var(--av-ease) infinite;
}

@keyframes av-jump {
  0%,
  100% {
    transform: translateY(0) scale(1, 1);
  }
  28% {
    transform: translateY(-9px) scale(0.985, 1.025);
  }
  60% {
    transform: translateY(0) scale(1.03, 0.965);
  }
}

.av-mood-sleepy .av-bob {
  animation-duration: 5.6s;
  transform-origin: 80px 184px;
}
.av-mood-sleepy .av-arm-l {
  transform: rotate(-7deg);
}
.av-mood-sleepy .av-arm-r {
  transform: rotate(7deg);
}

.av-mood-determined .av-arm-l {
  transform: rotate(-24deg);
}
.av-mood-determined .av-arm-r {
  transform: rotate(24deg);
}
.av-mood-determined .av-bob {
  animation-duration: 1.5s;
}

/* sleepy "zzz" drift + celebration sparkle twinkle */
.av-zzz {
  animation: av-drift 2.8s ease-in-out infinite;
}
@keyframes av-drift {
  0%,
  100% {
    opacity: 0.25;
    transform: translate(0, 0);
  }
  50% {
    opacity: 0.85;
    transform: translate(-3px, -5px);
  }
}

.av-cheer,
.av-sparkle {
  transform-box: view-box;
  transform-origin: 80px 70px;
  animation: av-twinkle 1.1s ease-in-out infinite alternate;
}
@keyframes av-twinkle {
  from {
    opacity: 0.35;
    transform: scale(0.86) rotate(-6deg);
  }
  to {
    opacity: 1;
    transform: scale(1.1) rotate(8deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .av-bob,
  .av-lid,
  .av-zzz,
  .av-cheer,
  .av-sparkle,
  .av-arm,
  .av-item,
  .av-cat {
    animation: none !important;
    transition: none !important;
  }
  .av-lid {
    transform: scaleY(0) !important;
  }
}

/* ---------------------------------------------------------------- *
   coin bar
 * ---------------------------------------------------------------- */

.av-coinbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--av-gap);
  max-width: var(--av-stage-max);
  margin: 0 auto;
  padding: 8px var(--av-pad);
  font-family: var(--av-font);
  color: var(--av-ink);
}

.av-coins {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 4px 12px 4px 6px;
  border-radius: var(--av-radius-pill);
  background: var(--av-surface);
  box-shadow: var(--av-shadow);
  font-weight: 700;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.av-coins::before {
  content: "";
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe9a8, var(--av-coin) 70%);
  box-shadow: inset 0 0 0 2px rgba(107, 74, 5, 0.25);
}

/* ---------------------------------------------------------------- *
   wardrobe: horizontally scrolling category picker
 * ---------------------------------------------------------------- */

.av-wardrobe {
  font-family: var(--av-font);
  color: var(--av-ink);
  max-width: var(--av-stage-max);
  margin-inline: auto;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.av-cats {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  padding: 10px var(--av-pad);
  margin: 0;
  list-style: none;
  scrollbar-width: none;
}
.av-cats::-webkit-scrollbar {
  display: none;
}

.av-cat {
  flex: 0 0 auto;
  scroll-snap-align: center;
  min-height: var(--av-tap);
  min-width: var(--av-tap);
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1.5px solid var(--av-line);
  border-radius: var(--av-radius-pill);
  background: var(--av-surface);
  color: var(--av-ink-soft);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.16s var(--av-ease), background-color 0.16s ease,
    color 0.16s ease, border-color 0.16s ease;
}

.av-cat:active {
  transform: scale(0.96);
}

.av-cat.is-active,
.av-cat[aria-selected="true"] {
  background: var(--av-accent);
  border-color: var(--av-accent);
  color: var(--av-accent-ink);
  box-shadow: var(--av-shadow);
}

.av-cat-count {
  font-size: 12px;
  font-weight: 700;
  opacity: 0.65;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- *
   wardrobe: item grid
 * ---------------------------------------------------------------- */

.av-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--av-thumb), 1fr));
  gap: var(--av-gap);
  padding: 4px var(--av-pad) var(--av-pad);
  margin: 0;
  list-style: none;
}

.av-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  min-height: calc(var(--av-tap) * 2.4);
  padding: 8px 6px 10px;
  border: 2px solid var(--av-line);
  border-radius: var(--av-radius);
  background: var(--av-surface);
  color: var(--av-ink);
  font: inherit;
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.16s var(--av-ease), border-color 0.16s ease,
    box-shadow 0.16s ease;
}

.av-item:active {
  transform: scale(0.97);
}

.av-item-thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  width: 100%;
  border-radius: var(--av-radius-sm);
  background: var(--av-surface-2);
  overflow: hidden;
  line-height: 0;
}

.av-item-name {
  font-size: 12px;
  font-weight: 650;
  line-height: 1.2;
  color: var(--av-ink);
  word-break: normal;
  overflow-wrap: break-word;
  hyphens: auto;
}

/* price / state chip */
.av-item-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 20px;
  padding: 1px 8px;
  margin-inline: auto;
  border-radius: var(--av-radius-pill);
  background: var(--av-surface-3);
  color: var(--av-ink-soft);
  font-size: 11.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.av-item-tag--price::before {
  content: "";
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe9a8, var(--av-coin) 70%);
}

.av-item-tag--free {
  background: #e6f7ee;
  color: #157a4c;
}

/* unlocked + owned but not worn */
.av-item.is-owned {
  border-color: var(--av-surface-3);
}

/* currently worn */
.av-item.is-equipped {
  border-color: var(--av-accent);
  background: var(--av-accent-soft);
  box-shadow: var(--av-shadow-lift);
}

/* badge + tick are drawn in CSS so no icon font or emoji is ever needed */
.av-item.is-equipped::after {
  content: "";
  position: absolute;
  top: -7px;
  right: -7px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--av-accent);
  box-shadow: var(--av-shadow);
}

.av-item.is-equipped::before {
  content: "";
  position: absolute;
  top: -1px;
  right: 2px;
  z-index: 1;
  width: 6px;
  height: 11px;
  border: solid var(--av-accent-ink);
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(42deg);
}

/* locked */
.av-item.is-locked {
  border-color: var(--av-line);
  background: var(--av-surface-2);
  cursor: not-allowed;
}

.av-item.is-locked .av-item-thumb {
  background: var(--av-surface-3);
}

.av-item.is-locked .av-item-thumb > * {
  filter: grayscale(0.85) contrast(0.85);
  opacity: 0.55;
}

.av-item.is-locked .av-item-name {
  color: var(--av-locked);
}

/* CSS padlock: shackle (::before) + body (::after) */
.av-item.is-locked .av-item-thumb::before,
.av-item.is-locked .av-item-thumb::after {
  content: "";
  position: absolute;
  left: 50%;
  filter: none;
  opacity: 1;
}

.av-item.is-locked .av-item-thumb::before {
  bottom: 15px;
  width: 10px;
  height: 8px;
  margin-left: -5px;
  border: 2.5px solid var(--av-locked);
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
}

.av-item.is-locked .av-item-thumb::after {
  bottom: 6px;
  width: 18px;
  height: 13px;
  margin-left: -9px;
  border-radius: 3px;
  background: var(--av-locked);
  box-shadow: 0 0 0 2px var(--av-surface-3);
}

/* affordable-but-locked gets a nudge of accent */
.av-item.is-locked.is-affordable {
  border-color: var(--av-accent);
  border-style: dashed;
}
.av-item.is-locked.is-affordable .av-item-tag--price {
  background: var(--av-accent);
  color: var(--av-accent-ink);
}

/* "none / take it off" tile for optional slots */
.av-item--none .av-item-thumb {
  display: grid;
  place-items: center;
  background: repeating-linear-gradient(
    45deg,
    var(--av-surface-2),
    var(--av-surface-2) 7px,
    var(--av-surface-3) 7px,
    var(--av-surface-3) 14px
  );
}
/* CSS cross for the "take it off" tile */
.av-item--none .av-item-thumb::before,
.av-item--none .av-item-thumb::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 22px;
  height: 3px;
  margin: -1.5px 0 0 -11px;
  border-radius: 2px;
  background: var(--av-muted);
}
.av-item--none .av-item-thumb::before {
  transform: rotate(45deg);
}
.av-item--none .av-item-thumb::after {
  transform: rotate(-45deg);
}

/* keyboard focus (visible, never on touch taps) */
.av-item:focus-visible,
.av-cat:focus-visible,
.av-btn:focus-visible {
  outline: 3px solid var(--av-accent);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------- *
   small shared button (randomise, save, buy…)
 * ---------------------------------------------------------------- */

.av-actions {
  display: flex;
  gap: var(--av-gap);
  padding: 0 var(--av-pad) var(--av-pad);
}

.av-btn {
  flex: 1 1 auto;
  min-height: var(--av-tap);
  padding: 0 18px;
  border: 1.5px solid var(--av-line);
  border-radius: var(--av-radius-pill);
  background: var(--av-surface);
  color: var(--av-ink);
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.16s var(--av-ease), background-color 0.16s ease;
}
.av-btn:active {
  transform: scale(0.97);
}
.av-btn--primary {
  background: var(--av-accent);
  border-color: var(--av-accent);
  color: var(--av-accent-ink);
}
.av-btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------------------------------------------------------------- *
   layout helpers for taller phones / landscape
 * ---------------------------------------------------------------- */

@media (min-width: 480px) {
  :root {
    --av-stage-max: 420px;
    --av-thumb: 104px;
  }
}

@media (max-height: 700px) and (orientation: portrait) {
  .av-stage {
    max-width: 300px;
  }
}

/* optional dark theme — same variables, different values */
@media (prefers-color-scheme: dark) {
  :root {
    --av-bg: #14131f;
    --av-surface: #1e1d2d;
    --av-surface-2: #272637;
    --av-surface-3: #343349;
    --av-ink: #f2f1f8;
    --av-ink-soft: #c3c1d6;
    --av-muted: #8e8ca5;
    --av-line: #3a3850;
    --av-accent-soft: #3a2a1c;
    --av-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
    --av-shadow-lift: 0 6px 18px rgba(0, 0, 0, 0.55);
  }
  .av-item-tag--free {
    background: #17382a;
    color: #7fe3b0;
  }
}
