:root {
  --ink: #30223d;
  --purple: #8c4fd8;
  --purple-deep: #58317c;
  --pink: #f36faa;
  --yellow: #ffd95f;
  --mint: #9af0d9;
  --paper: #fffaf5;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100dvh;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 20%, rgba(255,255,255,.86) 0 3px, transparent 4px),
    radial-gradient(circle at 86% 14%, rgba(255,255,255,.72) 0 4px, transparent 5px),
    linear-gradient(135deg, #ffe3ef 0%, #f3e4ff 48%, #dff8ff 100%);
  background-size: 52px 52px, 67px 67px, auto;
  font-family: var(--ui, "Arial Rounded MT Bold", sans-serif);
}

button, a { -webkit-tap-highlight-color: transparent; }

.game-header {
  min-height: 64px;
  padding: max(8px, env(safe-area-inset-top)) 14px 8px;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 108px;
  align-items: center;
  gap: 8px;
}

.home-button, .icon-button {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  color: var(--ink);
  background: rgba(255,255,255,.92);
  border: 3px solid var(--ink);
  border-radius: 18px;
  box-shadow: 0 4px 0 rgba(48,34,61,.2);
  font-size: 27px;
  font-weight: 900;
  text-decoration: none;
  cursor: pointer;
}

.icon-button { color: #d74083; }

.header-actions { display: flex; justify-content: flex-end; gap: 8px; }
.sound-button { color: var(--purple-deep); font-size: 23px; }
.sound-button[aria-pressed="false"] { color: #9b8ca3; }

.game-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(5px, 2vw, 14px);
  min-width: 0;
}

.game-title h1 {
  margin: 0;
  color: var(--purple-deep);
  font-size: clamp(21px, 4vw, 38px);
  line-height: 1;
  text-align: center;
  text-shadow: 0 3px 0 #fff;
}

.title-spark { color: #f1b91f; font-size: clamp(17px, 3vw, 29px); }

.game-shell {
  width: min(1440px, 100%);
  min-height: calc(100dvh - 68px);
  margin: 0 auto;
  padding: 0 12px max(16px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: minmax(480px, 1.45fr) minmax(360px, .78fr);
  gap: clamp(14px, 2vw, 26px);
}

.stage-panel, .closet-panel {
  min-width: 0;
  border: 3px solid var(--ink);
  box-shadow: 0 7px 0 rgba(48,34,61,.18);
}

.stage-panel {
  position: relative;
  min-height: 750px;
  padding: 14px 16px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  border-radius: 34px 22px 30px 20px;
  background:
    linear-gradient(90deg, transparent 48%, rgba(255,255,255,.42) 49% 51%, transparent 52%),
    linear-gradient(#fac8de 0 9%, #f6d8e8 9% 74%, #d6a875 74% 76%, #f1c88f 76%);
}

.stage-panel::before, .stage-panel::after {
  content: "";
  position: absolute;
  top: 12%;
  bottom: 21%;
  width: 18%;
  background: repeating-linear-gradient(90deg, #b16edf 0 18%, #ce8ef1 18% 36%);
  border: 3px solid var(--ink);
  z-index: 0;
}

.stage-panel::before { left: -8%; border-radius: 0 30px 30px 0; }
.stage-panel::after { right: -8%; border-radius: 30px 0 0 30px; }

.mirror-lights {
  position: absolute;
  z-index: 1;
  width: min(76%, 620px);
  height: calc(100% - 148px);
  top: 12px;
  border: 13px dotted #ffd95f;
  border-radius: 48% 48% 42% 42% / 36% 36% 58% 58%;
  filter: drop-shadow(0 0 5px rgba(255,255,255,.9));
  pointer-events: none;
}

.mirror {
  position: relative;
  z-index: 2;
  width: min(74%, 600px);
  flex: 1;
  min-height: 590px;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  overflow: hidden;
  border: 5px solid var(--ink);
  border-radius: 48% 48% 42% 42% / 36% 36% 58% 58%;
  background: radial-gradient(ellipse at 50% 30%, #fff 0%, #fdeaf4 55%, #eadff8 100%);
  box-shadow: inset 0 0 34px rgba(140,79,216,.14), 0 0 0 6px #f0bcdb;
}

.mirror-shine {
  position: absolute;
  inset: 0;
  z-index: 11;
  pointer-events: none;
  opacity: .25;
  background: linear-gradient(115deg, rgba(255,255,255,.9) 0 8%, transparent 10% 54%, rgba(255,255,255,.6) 56% 62%, transparent 64%);
}

.avatar-stack {
  position: relative;
  z-index: 4;
  height: min(96%, 820px);
  aspect-ratio: 1024 / 1792;
  transform-origin: 50% 94%;
  animation: breathe 3.6s ease-in-out infinite;
}

.avatar-stack.pop { animation: outfit-pop .52s cubic-bezier(.34,1.56,.64,1), breathe 3.6s .52s ease-in-out infinite; }

.avatar { position: absolute; inset: 0; }

.avatar-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  filter: drop-shadow(0 5px 4px rgba(48,34,61,.22));
}

.sparkles { position: absolute; inset: 0; z-index: 12; pointer-events: none; }
.sparkles i {
  position: absolute;
  left: var(--sx);
  top: var(--sy);
  color: #ffd32f;
  font-style: normal;
  font-size: clamp(15px, 4vh, 31px);
  text-shadow: 0 2px 0 #fff, 0 0 8px #fff;
  animation: sparkle-burst .82s var(--sd) ease-out both;
}

.floor-glow {
  position: absolute;
  z-index: 1;
  left: 17%;
  right: 17%;
  bottom: 1.5%;
  height: 8%;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(140,79,216,.28), transparent);
}

.look-status {
  position: relative;
  z-index: 3;
  min-height: 28px;
  margin: 8px 0 4px;
  color: var(--purple-deep);
  font-family: var(--hand, cursive);
  font-size: clamp(17px, 2vw, 21px);
  font-weight: 800;
  text-align: center;
}

.quick-actions { position: relative; z-index: 3; display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }

.action-button {
  min-height: 50px;
  padding: 9px 18px;
  color: var(--ink);
  background: var(--yellow);
  border: 3px solid var(--ink);
  border-radius: 16px 20px 14px 18px;
  box-shadow: 0 4px 0 rgba(48,34,61,.2);
  font: 900 16px/1 var(--ui, sans-serif);
  cursor: pointer;
}

.action-button span { margin-right: 5px; }
.action-button.reset { background: #fff; }

.closet-panel {
  align-self: stretch;
  max-height: calc(100dvh - 84px);
  padding: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 22px 34px 20px 28px;
  background: rgba(255,250,245,.94);
}

.category-tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(52px, 1fr));
  gap: 7px;
}

.category-tab {
  min-height: 64px;
  padding: 6px 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--ink);
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 16px;
  box-shadow: 0 3px 0 rgba(48,34,61,.16);
  cursor: pointer;
}

.category-tab span { font-size: 24px; line-height: 1; }
.category-tab b { font-size: 11px; }
.category-tab[aria-selected="true"] { color: #fff; background: var(--purple); transform: translateY(-2px); }

.closet-topline { margin: 15px 3px 8px; display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.closet-topline h2 { margin: 0; color: var(--purple-deep); font-size: 23px; }
.closet-topline span { color: #75657d; font-size: 13px; font-weight: 800; }

.item-grid {
  min-height: 0;
  padding: 3px 6px 8px 3px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 11px;
  align-content: start;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

.item-card {
  min-height: 160px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
  justify-content: space-between;
  color: var(--ink);
  background: linear-gradient(145deg, #fff, #fcebf5);
  border: 3px solid var(--ink);
  border-radius: 20px 14px 18px 16px;
  box-shadow: 0 4px 0 rgba(48,34,61,.16);
  cursor: pointer;
}

.item-card[aria-pressed="true"] {
  background: linear-gradient(145deg, #efe2ff, #ffd9ec);
  border-color: var(--purple);
  box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--purple);
}

.item-card:disabled {
  opacity: .46;
  filter: saturate(.45);
  cursor: not-allowed;
}

.item-grid-message {
  grid-column: 1 / -1;
  margin: 0 0 2px;
  padding: 10px 12px;
  color: var(--purple-deep);
  background: #f3e7ff;
  border: 2px solid var(--purple);
  border-radius: 14px;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.25;
  text-align: center;
}

.item-card b { min-height: 28px; display: grid; place-items: center; font-size: 13px; line-height: 1.05; }

.item-art {
  width: 100%;
  flex: 0 0 108px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 14px;
  background: radial-gradient(circle, #fff 0 44%, #f6deef 70%, #e8dcf7 100%);
}

.item-art img { display: block; width: 100%; height: 100%; object-fit: contain; object-position: center; pointer-events: none; }
.item-card--none { justify-content: center; gap: 9px; background: #fff; }
.none-mark { width: 66px; height: 66px; display: grid; place-items: center; color: #a48bab; border: 4px dashed #cbb8d0; border-radius: 50%; font-size: 43px; line-height: 1; }

.toast {
  position: fixed;
  z-index: 90;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  padding: 12px 20px;
  opacity: 0;
  color: #fff;
  background: var(--purple-deep);
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 5px 0 rgba(48,34,61,.22);
  font-weight: 900;
  transform: translate(-50%, 18px) scale(.9);
  transition: opacity .18s, transform .18s;
  pointer-events: none;
}

.toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }

@keyframes breathe {
  0%, 100% { transform: translateY(0) scaleY(1); }
  50% { transform: translateY(-.45%) scaleY(1.006); }
}

@keyframes outfit-pop {
  0% { transform: scale(.96); }
  42% { transform: translateY(-1.3%) scale(1.035); }
  72% { transform: scale(.99); }
  100% { transform: scale(1); }
}

@keyframes sparkle-burst {
  0% { opacity: 0; transform: scale(.1) rotate(-20deg); }
  22% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-42px) scale(1.35) rotate(35deg); }
}

@media (max-width: 900px) {
  body { overflow: auto; }
  .game-header { min-height: 58px; grid-template-columns: 46px minmax(0,1fr) 98px; }
  .home-button, .icon-button { width: 44px; height: 44px; border-radius: 15px; }
  .game-shell { min-height: 0; grid-template-columns: 1fr; padding: 0 8px max(12px, env(safe-area-inset-bottom)); gap: 10px; }
  .stage-panel { min-height: min(66dvh, 650px); padding: 9px 8px 12px; }
  .mirror-lights { width: min(79%, 470px); height: calc(100% - 112px); }
  .mirror { width: min(77%, 450px); min-height: 430px; }
  .avatar-stack { height: min(96%, 650px); }
  .look-status { margin: 5px 0 2px; }
  .action-button { min-height: 46px; padding: 8px 13px; font-size: 14px; }
  .closet-panel { max-height: none; padding: 10px; }
  .item-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); overflow: visible; }
  .item-card { min-height: 146px; }
  .item-art { flex-basis: 94px; }
}

@media (max-width: 560px) {
  .game-header { padding-inline: 8px; grid-template-columns: 44px minmax(0,1fr) 88px; gap: 4px; }
  .header-actions { gap: 4px; }
  .home-button, .icon-button { width: 42px; height: 42px; }
  .game-title h1 { font-size: clamp(19px, 5.7vw, 27px); }
  .title-spark:last-child { display: none; }
  .stage-panel { min-height: min(63dvh, 590px); border-radius: 24px 17px 22px 16px; }
  .mirror-lights { width: min(92%, 430px); height: calc(100% - 108px); }
  .mirror { width: min(89%, 410px); min-height: 395px; }
  .avatar-stack { height: min(97%, 590px); }
  .category-tabs { gap: 5px; grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .category-tab { min-height: 58px; }
  .category-tab span { font-size: 21px; }
  .category-tab b { font-size: 10px; }
  .closet-topline { margin-top: 11px; }
  .item-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .item-card { min-height: 150px; }
  .item-art { flex-basis: 98px; }
}

@media (max-height: 740px) and (min-width: 901px) {
  .stage-panel { min-height: 600px; }
  .mirror { min-height: 470px; }
  .avatar-stack { max-height: 610px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
