:root {
  color-scheme: light;
  --ink: #252235;
  --panel: rgba(255, 255, 255, 0.9);
  --shadow: 0 18px 42px rgba(47, 40, 90, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", "Comic Sans MS", system-ui, sans-serif;
  background:
    radial-gradient(circle at 13% 15%, rgba(255, 211, 61, 0.78) 0 9%, transparent 9.5%),
    radial-gradient(circle at 88% 13%, rgba(32, 184, 255, 0.62) 0 11%, transparent 11.5%),
    radial-gradient(circle at 86% 88%, rgba(53, 200, 115, 0.52) 0 10%, transparent 10.5%),
    linear-gradient(135deg, #ffec72 0%, #ff8fc3 34%, #88e7ff 68%, #a2ef9f 100%);
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.game-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 196px;
  gap: 16px;
  width: min(1188px, calc(100vw - 28px));
  height: min(820px, calc(100vh - 28px));
  margin: 14px auto;
}

.stage {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-width: 0;
  overflow: hidden;
  border: 4px solid rgba(255, 255, 255, 0.88);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.84), rgba(255, 255, 255, 0.36)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.32) 0 22px, rgba(255, 255, 255, 0.08) 22px 44px);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.66);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  color: white;
  background: #ff5fa2;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.12);
  font-size: 1.9rem;
}

h1 {
  margin: 0;
  font-size: clamp(1.42rem, 2.7vw, 2.25rem);
  line-height: 1;
  letter-spacing: 0;
}

p {
  min-height: 1.3em;
  margin: 4px 0 0;
  color: #6f3b8e;
  font-size: 1rem;
  font-weight: 850;
}

.meter {
  display: grid;
  grid-template-columns: auto 124px auto;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  font-weight: 950;
  white-space: nowrap;
}

.meter-track {
  width: 124px;
  height: 16px;
  overflow: hidden;
  border-radius: 999px;
  background: #d8e7f1;
  box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.12);
}

.meter-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #20b8ff, #35c873, #ffd33d, #ff5fa2);
  transition: width 180ms ease;
}

.profile-picker {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 52px;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 10px;
  background: rgba(255, 255, 255, 0.5);
}

.profile-arrow {
  display: grid;
  place-items: center;
  height: 44px;
  border-radius: 8px;
  color: white;
  background: #1b8fc9;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.16), 0 4px 0 rgba(45, 44, 70, 0.14);
  font-size: 2rem;
  font-weight: 950;
  line-height: 1;
}

.profile-card {
  display: grid;
  justify-items: center;
  min-width: 0;
  padding: 7px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: inset 0 -3px 0 rgba(45, 44, 70, 0.08);
}

.profile-card strong,
.profile-card span {
  overflow: hidden;
  max-width: 100%;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-card strong {
  font-size: 1.05rem;
  font-weight: 950;
}

.profile-card span {
  margin-top: 1px;
  color: #6f3b8e;
  font-size: 0.82rem;
  font-weight: 850;
}

.play-area {
  position: relative;
  min-height: 0;
}

#dressCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.sparkle-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.sparkle {
  position: absolute;
  width: 18px;
  height: 18px;
  background: var(--sparkle-color);
  clip-path: polygon(50% 0, 62% 34%, 98% 35%, 68% 56%, 79% 91%, 50% 70%, 21% 91%, 32% 56%, 2% 35%, 38% 34%);
  animation: sparkle-pop 820ms ease-out forwards;
}

@keyframes sparkle-pop {
  to {
    opacity: 0;
    transform: translate(var(--sparkle-x), var(--sparkle-y)) rotate(210deg) scale(0.35);
  }
}

.controls {
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 12px;
  min-width: 0;
}

.closet-grid,
.swatches,
.pattern-pad,
.actions {
  padding: 10px;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.closet-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.clothes-button {
  display: grid;
  place-items: center;
  min-height: 68px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.1), 0 4px 0 rgba(45, 44, 70, 0.16);
  font-weight: 950;
  transition: transform 140ms ease, background 140ms ease;
}

.clothes-button span {
  font-size: 1.9rem;
  line-height: 1;
}

.clothes-button strong {
  font-size: 0.84rem;
}

.clothes-button.active {
  color: white;
  background: #6b5cff;
  transform: translateY(2px);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18), 0 2px 0 rgba(45, 44, 70, 0.16);
}

.swatches {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.swatch {
  aspect-ratio: 1;
  min-width: 0;
  border: 4px solid rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  background: var(--swatch);
  box-shadow: 0 4px 0 rgba(45, 44, 70, 0.16);
}

.swatch.active {
  outline: 4px solid #252235;
  outline-offset: 2px;
}

.pattern-pad,
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.pattern-pad button,
.actions button {
  min-height: 44px;
  border-radius: 8px;
  color: white;
  background: #ff5fa2;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.16), 0 4px 0 rgba(45, 44, 70, 0.14);
  font-weight: 950;
}

.pattern-pad button:nth-child(2) {
  background: #1b8fc9;
}

.pattern-pad button:nth-child(3) {
  background: #35c873;
}

.pattern-pad button:nth-child(4) {
  background: #6b5cff;
}

.pattern-button.active {
  outline: 4px solid #252235;
  outline-offset: 2px;
}

.actions {
  align-content: end;
}

.actions button {
  background: #ff7a3d;
}

.actions button:nth-child(2) {
  background: #364156;
}

@media (max-width: 760px) {
  body {
    overflow: auto;
  }

  .game-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(470px, 1fr) auto;
    width: calc(100vw - 16px);
    height: auto;
    min-height: calc(100vh - 16px);
    margin: 8px auto;
  }

  .stage {
    min-height: 470px;
  }

  .topbar {
    padding: 9px 10px;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
  }

  .meter {
    grid-template-columns: auto 84px auto;
  }

  .meter-track {
    width: 84px;
  }

  .profile-picker {
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    gap: 7px;
    padding: 7px 8px;
  }

  .profile-arrow {
    height: 40px;
  }

  .profile-card {
    padding: 6px 8px;
  }

  .controls {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }

  .closet-grid,
  .swatches,
  .pattern-pad,
  .actions {
    grid-auto-flow: column;
    grid-auto-columns: minmax(76px, 1fr);
    grid-template-columns: none;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .clothes-button {
    min-width: 76px;
    min-height: 62px;
  }

  .swatch {
    min-height: 46px;
  }
}
