:root {
  color-scheme: dark;
  font-family: "Trebuchet MS", system-ui, sans-serif;
  color: #fff7fe;
  background: #291632;
  --gold: #ffe6b3;
  --rim: #ffd7f39c;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
h1, h2 { margin: 0; }

body {
  --outer: clamp(8px, 1.7vw, 24px);
  margin: 0;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: max(var(--outer), env(safe-area-inset-top))
           max(var(--outer), env(safe-area-inset-right))
           max(var(--outer), env(safe-area-inset-bottom))
           max(var(--outer), env(safe-area-inset-left));
  background: radial-gradient(ellipse at 32% 0, #784878, #291632 72%);
}

button {
  font: inherit;
  font-weight: 750;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:disabled { cursor: default; }
button:focus-visible { outline: 2px solid #fff8db; outline-offset: 3px; }
h1:focus { outline: none; }

.studio {
  position: relative;
  isolation: isolate;
  width: min(100%, 1520px);
  height: min(850px, calc(100svh - max(var(--outer), env(safe-area-inset-top)) - max(var(--outer), env(safe-area-inset-bottom))));
  min-height: 348px;
  display: grid;
  grid-template-columns: minmax(0, 17fr) minmax(0, 39fr) minmax(0, 44fr);
  grid-template-areas: "rail scene panel";
  gap: clamp(6px, 1vw, 15px);
  padding: clamp(9px, 1.45vw, 22px);
  overflow: hidden;
  border: 1px solid #fbd2dfaa;
  border-radius: clamp(16px, 2.5vw, 34px);
  background: #794c86 url("./assets/processed/room.webp") 47% center / cover no-repeat;
  box-shadow: 0 20px 60px #18091db8, inset 0 0 78px #5124516b;
}

.studio::before {
  position: absolute;
  z-index: -1;
  inset: 0;
  content: "";
  background: linear-gradient(90deg, #34153d48, transparent 34% 52%, #3d224347);
  pointer-events: none;
}

.rail {
  grid-area: rail;
  min-width: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: space-between;
  gap: clamp(8px, 1.6svh, 16px);
  padding: clamp(5px, 1.35svh, 15px) 0 0;
}

.wordmark {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 0;
  padding: clamp(9px, 1.8svh, 20px) 4px;
  border: 1px solid #ffe1a6;
  border-radius: 44% / 28%;
  background: radial-gradient(ellipse at 50% 72%, #60316c, #3d224cf0 84%);
  box-shadow: 0 0 15px #ffbe857d, inset 0 0 11px #f9c0d382;
  text-align: center;
  text-shadow: 0 1px 7px #e879bd8a;
  font: italic 600 clamp(15px, 2.05vw, 34px)/1.05 Georgia, serif;
}

.wordmark img {
  width: clamp(22px, 4.5vw, 64px);
  height: clamp(16px, 4.5svh, 46px);
  margin-bottom: 3px;
  object-fit: contain;
}

.wordmark em { color: #fff0fa; font-size: .77em; }

#categories { display: grid; gap: clamp(5px, 1.15svh, 11px); margin: auto 0; }

.category, .round-action {
  border: 1px solid #efc0f4be;
  background: linear-gradient(174deg, #8e5c9ace 0%, #5b376dda 54%, #4d2e61f0 100%);
  box-shadow: inset 0 1px 6px #ffe3fc8c, 0 3px 9px #3c1a4b70;
}

.category {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: clamp(4px, .7vw, 12px);
  padding: 4px clamp(6px, .95vw, 16px);
  min-height: clamp(32px, 8.1svh, 75px);
  border-radius: 999px;
  text-align: left;
  font-size: clamp(.66rem, 1.45vw, 1.4rem);
  text-shadow: 0 2px 3px #2c1436;
}

.category img {
  width: clamp(18px, 3.3vw, 48px);
  height: clamp(19px, 5.2svh, 48px);
  flex: none;
  object-fit: contain;
  filter: drop-shadow(0 1px 2px #24112a);
}

.category[aria-pressed="true"] {
  border-color: #ffe1b5;
  background: linear-gradient(165deg, #dcadf3, #a463c0 53%, #9251ad);
  box-shadow: inset 0 1px 9px #ffecfdad, 0 0 10px #ffd2b999;
}

.rail-actions { display: flex; gap: clamp(6px, 1vw, 13px); }

.round-action {
  width: clamp(37px, 5.4vw, 65px);
  height: clamp(37px, 5.4vw, 65px);
  padding: 0;
  border-radius: 50%;
  font-size: clamp(1.25rem, 3vw, 2.2rem);
  line-height: 1;
  text-shadow: 0 1px 4px #34143d;
}

.round-action:hover, .category:hover { filter: brightness(1.12); }

.scene {
  --stage-bottom: 3.5%;
  --stage-height: clamp(40px, 15%, 124px);
  grid-area: scene;
  position: relative;
  min-width: 0;
  min-height: 0;
  isolation: isolate;
  container-type: inline-size;
}

.stage {
  position: absolute;
  width: 100%;
  height: var(--stage-height);
  bottom: var(--stage-bottom);
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
}

.actor {
  --character-height: min(88%, 141cqw);
  position: absolute;
  z-index: 2;
  left: 50%;
  /* Preserve the V0.2 foot anchor at y=1005 on the shared 1020px canvas. */
  bottom: calc(var(--stage-bottom) + var(--stage-height) * .57 - var(--character-height) * .014706);
  height: var(--character-height);
  max-width: 94%;
  aspect-ratio: 680 / 1020;
  transform: translateX(-50%);
  transform-origin: 50% 98.53%;
  pointer-events: none;
}

.actor img { position: absolute; inset: 0; width: 100%; height: 100%; user-select: none; }

.actor.drop-target::after {
  position: absolute;
  inset: 2% 3%;
  border: 2px solid #fff0c1b3;
  border-radius: 46%;
  box-shadow: 0 0 22px #ffdda689, inset 0 0 15px #ffe1b54d;
  content: "";
}

.panel { grid-area: panel; min-width: 0; }

.panel:not(#dress) {
  align-self: center;
  display: grid;
  place-items: center;
  padding: clamp(16px, 3vw, 42px);
}

.welcome-content {
  width: min(100%, 504px);
  display: grid;
  justify-items: center;
  gap: clamp(6px, 2svh, 20px);
  text-align: center;
  padding: clamp(18px, 4.9svh, 50px) 12px;
  border: 1px solid var(--rim);
  border-radius: 26px;
  background: radial-gradient(ellipse at 50% 0, #9d568aaa, #422650ec 72%);
  box-shadow: 0 8px 30px #31163a72, inset 0 0 13px #f0b1f067;
}

.ornament {
  width: 38%;
  display: flex;
  align-items: center;
  gap: .55rem;
  color: var(--gold);
  font-size: clamp(16px, 3svh, 30px);
  text-shadow: 0 0 14px #ffccacaa;
}

.ornament span { flex: 1; height: 1px; background: var(--rim); }

h1 {
  font: 700 clamp(25px, 4.7vw, 76px)/.99 Georgia, serif;
  letter-spacing: -.04em;
  text-wrap: balance;
}

h1 em { color: #ffcbe9; font-weight: 400; }
#welcome-title { font-size: clamp(25px, 4.1vw, 66px); }

.primary {
  min-height: clamp(43px, 8.2svh, 75px);
  min-width: 0;
  max-width: 100%;
  padding: .28em .8em;
  border: 1px solid #ffe5f2;
  border-radius: 999px;
  background: linear-gradient(#fbc4e5 0%, #e159a4 31%, #b83078 55%, #d54c92 83%, #f197cc 100%);
  box-shadow: 0 0 0 2px #d962a87d, inset 0 2px 7px #fff5fcce, 0 4px 12px #4b1a456b;
  color: #fffafd;
  text-shadow: 0 2px 4px #762452;
  font-size: clamp(.9rem, 2vw, 1.8rem);
  white-space: nowrap;
}

.primary:enabled:hover { filter: brightness(1.12); }
.primary:enabled:active { transform: translateY(1px); }
.primary:disabled { opacity: .6; }
.primary span { color: #fff6fc; }
.welcome-content .primary { min-width: min(160px,100%); margin-top: 4px; }
.quiet { min-height: 36px; border: 0; padding: .25em .75em; background: transparent; color: #ffebf8; }
.quiet:hover { text-decoration: underline; }

#dress {
  display: grid;
  grid-template-rows: minmax(0,1fr) auto;
  gap: clamp(7px, 1.45svh, 16px);
  padding: clamp(5px, 2.7svh, 25px) 0 0;
}

.options { display: grid; grid-template-rows: repeat(4,minmax(0,1fr)); gap: clamp(4px, .9svh, 9px); min-width: 0; }

.shelf {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: clamp(2px, .5svh, 6px);
  padding: clamp(4px, .9svh, 10px) clamp(6px, 1.15vw, 17px);
  border: 1px solid #f8cfedbb;
  border-bottom-color: #ffe1a3de;
  border-radius: clamp(11px, 2vw, 25px);
  background: linear-gradient(160deg, #563662ec, #62396cdd 58%, #603552eb);
  box-shadow: inset 0 0 10px #e6acd773, 0 2px 9px #3817336b;
}

.shelf[data-active="true"] {
  border-color: #ffe6bd;
  box-shadow: 0 0 10px #f9c298a0, inset 0 0 12px #eab0eb78;
}

.shelf h2 {
  font-size: clamp(.76rem, 1.55vw, 1.55rem);
  line-height: 1;
  text-shadow: 0 2px 4px #2e1737;
}

.items { display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); gap: clamp(3px, .66vw, 9px); }

.item, .empty-slot {
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 1px solid #f1c4ed54;
  border-radius: clamp(7px, 1vw, 16px);
  background: #381e4766;
}

.empty-slot { border-color: #e0b0db29; background: #44254e43; }

.item {
  position: relative;
  display: grid;
  place-items: center;
  touch-action: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.item img { position: absolute; width: 87%; height: 88%; object-fit: contain; pointer-events: none; }
.item:enabled { cursor: grab; }
.item:enabled:hover { background-color: #753d86; }
.item[data-dragging] { cursor: grabbing; }
.item:disabled img { opacity: .42; }
.item:disabled::after {
  position: absolute;
  right: 3px;
  bottom: 3px;
  font-size: clamp(.6rem, 1.25vw, .95rem);
  content: "🔒";
}
.item[aria-pressed="true"] {
  border-color: #fff0bf;
  background: radial-gradient(ellipse at 50% 80%, #ad66a8, #6d4386);
  box-shadow: 0 0 9px #ffce80d9, inset 0 0 8px #ffd995b8;
}
.item[aria-pressed="true"]::after {
  position: absolute;
  bottom: 2px;
  right: 2px;
  display: grid;
  place-items: center;
  width: clamp(13px, 1.8vw, 24px);
  aspect-ratio: 1;
  border: 1px solid #ffe7ae;
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(120deg, #ffd27c, #c38329);
  font-size: clamp(.54rem, 1.2vw, .92rem);
  content: "✓";
}

.play-action { justify-self: end; width: min(55%, 260px); }

.drag-preview {
  position: fixed;
  z-index: 10;
  pointer-events: none;
  width: clamp(56px, 11vw, 120px);
  height: clamp(56px, 11vw, 120px);
  object-fit: contain;
  filter: drop-shadow(0 4px 7px #35162c) drop-shadow(0 0 8px #ffe5b8);
  transform: translate(-50%, -50%);
}

.spotlight {
  position: absolute;
  inset: 0;
  opacity: 0;
  background: radial-gradient(ellipse at 50% 36%, #fff0cf60, transparent 49%);
  pointer-events: none;
}

.sparkles { position: absolute; z-index: 4; inset: 0; pointer-events: none; }
.sparkles i { position: absolute; opacity: 0; color: #fff2b9; text-shadow: 0 0 8px #fff, 0 0 17px #f39ade; font: 28px Georgia, serif; }
.sparkles i:nth-child(1) { top: 23%; left: 31%; }
.sparkles i:nth-child(2) { top: 43%; left: 73%; --delay: .5s; }
.sparkles i:nth-child(3) { top: 54%; left: 21%; --delay: .9s; }
.sparkles i:nth-child(4) { top: 30%; left: 64%; --delay: 1.25s; }
.sparkles i:nth-child(5) { top: 66%; left: 75%; --delay: 1.7s; }
.sparkles i:nth-child(6) { top: 71%; left: 29%; --delay: 2.25s; }
.showing .actor { animation: pose 4s ease-in-out; }
.showing .spotlight { animation: light 4s ease-in-out; }
.showing .sparkles i { animation: twinkle 1.6s var(--delay, .1s) ease-in-out; }

@keyframes pose {
  0%, 100% { transform: translateX(-50%); }
  25% { transform: translate(-52%, -1.5%) rotate(-2deg); }
  55% { transform: translate(-48%, -.8%) rotate(2deg); }
  80% { transform: translate(-51%, -1.1%) rotate(-1deg); }
}
@keyframes light { 0%, 100% { opacity: 0; } 20%, 75% { opacity: 1; } }
@keyframes twinkle {
  0%, 100% { opacity: 0; transform: scale(.65); }
  46% { opacity: 1; transform: scale(1.2); }
}

.sr-only { position: absolute; width: 1px; height: 1px; clip-path: inset(50%); overflow: hidden; }

@media (orientation: landscape) and (max-height: 500px) {
  body { --outer: 6px; }
  .studio { grid-template-columns: minmax(0,18fr) minmax(0,40fr) minmax(0,42fr); padding: 8px; gap: 7px; }
  .rail { gap: 5px; padding-top: 2px; }
  .wordmark { padding-block: 5px; }
  #categories { gap: 4px; }
  .category { min-height: 32px; }
  #dress { padding-top: 2px; gap: 6px; }
  .shelf { padding-block: 3px; }
  .welcome-content { padding-block: 16px; }
}

@media (orientation: portrait) {
  .studio { height: auto; min-height: 0; grid-template: auto auto auto / minmax(0,1fr); grid-template-areas: "rail" "scene" "panel"; padding: 11px; }
  .rail { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; padding: 0; }
  .wordmark { grid-column: 1; font-size: 19px; padding: 5px; }
  .rail-actions { grid-column: 3; grid-row: 1; }
  .done-action { grid-column: 2; grid-row: 1; }
  #categories { grid-column: 1 / -1; grid-row: 2; grid-template-columns: repeat(5,minmax(0,1fr)); }
  .category { display: grid; justify-items: center; min-height: 46px; gap: 2px; padding: 3px 0; text-align: center; font-size: clamp(.57rem, 2.35vw, .9rem); }
  .scene { height: min(58svh, 650px); min-height: 285px; }
  .stage { width: min(100%, 500px); }
  #dress { grid-template-rows: auto auto; padding: 0; }
  .options { grid-auto-rows: minmax(76px,auto); grid-template-rows: repeat(4,minmax(76px,auto)); }
  .panel:not(#dress) { padding: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .showing .actor, .showing .spotlight, .showing .sparkles i { animation: none; }
  .showing .spotlight { opacity: .7; }
  .showing .sparkles i { opacity: .8; }
}
