:root {
  --ink: #2c1646;
  --paper: #fff9ee;
  --pink: #ff90d4;
  --yellow: #fff180;
  --lavender: #e8d2ff;
  --scene: url("collage.jpg");
  --line: 3px solid var(--ink);
  font-family: "Lato", "Arial Rounded MT Bold", system-ui, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }

body {
  overflow: hidden auto;
  background: linear-gradient(#24103c59, #45126930), var(--scene) center / cover fixed;
}

button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; font: inherit; }
:focus-visible { outline: 3px solid #5523a6; outline-offset: 3px; }
h1, h2, p { margin: 0; }

.page {
  width: min(1120px, 100%);
  margin-inline: auto;
  padding: max(22px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.masthead {
  display: flex;
  position: relative;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 100px;
  padding: 12px 22px;
  margin-bottom: 16px;
  border: var(--line);
  border-radius: 24px;
  background: var(--ink);
  box-shadow: 0 4px 0 #ffffffcb;
}

h1 {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0 .19em;
  color: var(--pink);
  font-size: clamp(2rem, 6vw, 4.85rem);
  font-weight: 1000;
  font-style: italic;
  letter-spacing: -.07em;
  line-height: .99;
  text-shadow: 2px 3px 0 #831c75;
}

h1 span:first-child {
  color: var(--yellow);
  text-shadow: 2px 3px 0 #ab5326;
}

.bead-strand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  flex: 1;
  transform: rotate(-7deg);
}

.bead-strand i {
  width: clamp(10px, 2vw, 23px);
  aspect-ratio: 1;
  border-radius: 40%;
  background: var(--bead, var(--pink));
  box-shadow: inset 3px 3px 0 #ffffff9c, inset -2px -3px 0 #2c164638;
}

.bead-strand i:nth-child(2n) { --bead: #a0f9d5; }
.bead-strand i:nth-child(3n) { --bead: var(--yellow); }
.bead-strand i:nth-child(4n) { --bead: #c6a3ff; }
.bead-strand i:nth-child(2n + 1) { transform: translateY(4px) rotate(13deg); }

.arcade-link {
  display: grid;
  place-items: center;
  min-width: 88px;
  min-height: 52px;
  padding: 5px 12px;
  border: 2px solid var(--paper);
  border-radius: 999px;
  color: var(--paper);
  font-weight: 900;
  text-decoration: none;
}

.arcade-link:focus-visible { outline-color: var(--yellow); }

.player-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  max-width: 18rem;
  color: var(--paper);
  font-weight: 900;
}

.player-bar[hidden] { display: none; }
#player-greeting { overflow-wrap: anywhere; }

.player-bar .action {
  min-height: 48px;
  padding-inline: 12px;
  font-size: .9rem;
  white-space: nowrap;
}

.player-bar .action:focus-visible { outline-color: var(--yellow); }

.studio {
  display: grid;
  grid-template-columns: minmax(0, 1.06fr) minmax(0, 1fr);
  gap: 15px;
}

.stage, .closet {
  border: var(--line);
  border-radius: 24px;
  box-shadow: 0 5px 0 var(--ink);
}

.stage {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  min-height: 540px;
  isolation: isolate;
  background: #d0acff var(--scene) center / cover;
}

.spotlight {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(ellipse 38% 51% at 50% 50%, #fffdf7 18%, #ffedfad9 69%, #f4d1ff00 100%);
}

#doll {
  position: absolute;
  top: 56px;
  display: block;
  width: 94%;
  height: calc(100% - 68px);
  object-fit: contain;
  filter: drop-shadow(0 2px 3px #51236a5e);
}

.stage-trim {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 12px;
  border-top: 2px solid var(--ink);
  background-color: var(--yellow);
  background-image: conic-gradient(var(--ink) 25%, transparent 0 50%, var(--ink) 0 75%, transparent 0);
  background-size: 10px 10px;
}

.closet {
  display: flex;
  flex-direction: column;
  container-type: inline-size;
  gap: 16px;
  min-width: 0;
  padding: 19px;
  background: var(--paper);
}

.closet-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 2px 8px;
}

.closet-head h2, .studio-dialog h2 {
  font-size: clamp(1.55rem, 3.2vw, 2.25rem);
  font-weight: 1000;
  letter-spacing: -.04em;
}

#hint {
  font-size: .9rem;
  font-weight: 750;
  color: #654677;
}

.categories, .choices {
  display: grid;
  gap: 8px;
}

.categories { grid-template-columns: repeat(6, minmax(0, 1fr)); }

@container (max-width: 375px) {
  .categories { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.category, .choice, .action {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  border: 2px solid var(--ink);
  box-shadow: 0 3px 0 var(--ink);
  font-weight: 900;
  text-align: center;
  transition: transform 100ms, box-shadow 100ms, background 140ms;
}

.category:active, .choice:active, .action:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--ink);
}

.category {
  flex-direction: column;
  gap: 2px;
  min-height: 65px;
  padding: 4px 1px 6px;
  border-radius: 13px;
  background: var(--lavender);
  font-size: .86rem;
}

.category canvas { width: 43px; max-width: 100%; height: auto; }
.category[aria-pressed="true"] { background: var(--yellow); }

.choices {
  flex: 1;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: 1fr;
}

.choices.scrollable {
  flex: none;
  grid-auto-rows: max-content;
  max-block-size: min(269px, 45svh);
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-color: #873fa9 #ecd9fb;
  padding: 6px;
}

.choice {
  position: relative;
  flex-direction: column;
  gap: 2px;
  min-height: 112px;
  padding: 8px 3px;
  border-radius: 15px;
  background: var(--swatch);
  font-size: .91rem;
  line-height: 1.12;
}

.choice canvas { width: min(100%, 113px); height: auto; }

.choice[aria-pressed="true"] {
  border-color: #631a81;
  box-shadow: inset 0 0 0 2px #fff, 0 3px 0 #631a81;
}

.choice[aria-pressed="true"]::after {
  content: "✓";
  position: absolute;
  top: 5px;
  right: 5px;
  display: grid;
  place-items: center;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: #631a81;
  color: white;
  font-size: .75rem;
}

.actions {
  display: grid;
  grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr);
  gap: 10px;
}

.action {
  gap: 6px;
  min-height: 60px;
  padding: 6px 8px;
  border-radius: 15px;
  color: var(--ink);
  font-size: 1rem;
  text-decoration: none;
  cursor: pointer;
}

.action span { font-size: 1.25rem; }
.shuffle { background: var(--yellow); }
.photo-button { background: var(--pink); }
.backdrop-button { background: #b9f9e0; }

.stage .action {
  position: absolute;
  z-index: 1;
  top: 12px;
  min-height: 48px;
  padding-inline: 10px;
  font-size: .9rem;
}

.stage .backdrop-button { right: 12px; }
.stage-gender { left: 12px; flex-direction: column; gap: 1px; }
.stage-gender .gender-value { font-size: .78rem; }

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

.studio-dialog {
  width: min(435px, calc(100vw - 28px));
  max-height: calc(100dvh - 30px);
  padding: 12px;
  border: var(--line);
  border-radius: 22px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 5px 0 var(--ink);
  text-align: center;
}

.studio-dialog::backdrop { background: #27113ec2; }

.name-dialog { padding: 18px; }

#name-form {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

#name-form [hidden] { display: none; }
#name-form label { text-align: start; font-weight: 900; }

#nickname {
  width: 100%;
  min-height: 52px;
  border: 2px solid var(--ink);
  border-radius: 13px;
  padding: 9px 12px;
  background: white;
  color: var(--ink);
  font: inherit;
  font-size: 1.125rem;
}

.back-to-arcade {
  display: grid;
  place-items: center;
  min-height: 44px;
  color: inherit;
  font-weight: 800;
}

.gender-choices, .background-choices {
  display: grid;
  gap: 9px;
  margin: 10px 0 13px;
}

.gender-choices { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.gender-choice { min-height: 68px; background: var(--lavender); cursor: pointer; }
.gender-choice[aria-pressed="true"] { background: var(--yellow); }

.background-choices { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.background-choice {
  justify-content: flex-start;
  overflow: hidden;
  gap: 0;
  padding: 0;
  background: var(--lavender);
  cursor: pointer;
}

.background-choice img {
  display: block;
  width: 100%;
  height: clamp(62px, 20vw, 88px);
  object-fit: cover;
  border-bottom: 2px solid var(--ink);
}

.background-choice span { padding: 6px 4px; }
.background-choice[aria-pressed="true"] { background: var(--yellow); }
.studio-dialog .backdrop-button { width: 100%; }
#save-photo:not([href]) { opacity: .6; cursor: default; }

#portrait {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: min(530px, calc(100dvh - 170px));
  margin: 8px auto 12px;
  border: var(--line);
  border-radius: 14px;
}

@media (max-width: 760px) {
  .page { padding: max(9px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); }
  .masthead { flex-wrap: wrap; gap: 8px; min-height: 67px; margin-bottom: 11px; padding: 5px 10px; border-radius: 18px; }
  h1 { font-size: clamp(1.7rem, 8.6vw, 3.5rem); }
  .bead-strand { display: none; }
  .arcade-link { min-width: 62px; min-height: 48px; font-size: .84rem; padding-inline: 7px; }
  .player-bar { order: 1; flex-basis: 100%; max-width: none; padding-bottom: 4px; }
  .studio { grid-template-columns: minmax(0, 1fr); gap: 9px; }
  .stage { min-height: clamp(247px, 35svh, 390px); border-radius: 18px; }
  #doll { top: 51px; height: calc(100% - 60px); }
  .closet { gap: 9px; padding: 9px; border-radius: 18px; }
  .categories, .choices { gap: 6px; }
  .choices.scrollable { max-block-size: min(197px, 41svh); }
  .category { font-size: clamp(.75rem, 3.4vw, .9rem); }
  .choice { min-height: 76px; padding: 4px 2px; font-size: .83rem; }
  .choice canvas { width: min(100%, 77px); }
  .actions { gap: 7px; }
  .action { min-height: 55px; }
  .stage .action { top: 6px; }
  .stage .backdrop-button { right: 6px; }
  .stage-gender { left: 6px; }
  .background-choice { padding: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .category, .choice, .action { transition: none; }
}
