* { box-sizing: border-box; }
[hidden] { display: none !important; }

:root {
  color-scheme: light;
  font-family: system-ui, "PingFang SC", "Microsoft YaHei", sans-serif;
  --ink: #312321;
  --paper: #fff4dc;
  --cream: #fff9e9;
  --apricot: #ffd5a1;
  --muted: #67463b;
  --dash: #b79a82;
  background: var(--paper);
  color: var(--ink);
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 8% 12%, #ffe3b848 0, transparent 40%),
    radial-gradient(circle at 92% 88%, #f8c6b840 0, transparent 42%),
    var(--paper);
}

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

main {
  width: min(100% - 4rem, 74rem);
  margin: auto;
  padding: clamp(1.6rem, 4.8vh, 3.6rem) 0 3.5rem;
}

.intro { margin-bottom: clamp(1.2rem, 2.8vw, 1.9rem); }

.intro-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.65rem;
}

.mini-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 40px;
  padding: 0.25rem 0.78rem;
  border: 1.5px solid #9f7967;
  border-radius: 999px;
  background: var(--cream);
  font-size: 0.86rem;
  font-weight: 600;
  transition: background-color 160ms ease, opacity 160ms ease;
}

.mini-pill:hover { background: #ffe8cd; }
.mini-pill[aria-pressed="false"] { opacity: 0.58; }

h1 {
  margin: 0;
  font-size: clamp(2.5rem, 6.8vw, 5.8rem);
  font-weight: 850;
  letter-spacing: -0.025em;
  line-height: 1.04;
}

.intro p {
  margin: 0.85rem 0 0;
  font-size: 1rem;
  line-height: 1.55;
  color: var(--muted);
}

.closet {
  display: grid;
  grid-template-columns: 1.04fr 1fr;
  align-items: start;
  gap: clamp(1.5rem, 3.8vw, 3.2rem);
}

.stage-col {
  display: grid;
  gap: 0.95rem;
}

.portrait {
  position: relative;
  margin: 0;
  background: #f7a18f;
  border: 2.5px solid var(--ink);
  border-radius: 30px;
  overflow: hidden;
  box-shadow: 7px 8px 0 #382622;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

canvas:focus-visible { outline: 3px solid #fff3c6; outline-offset: -5px; }

/* Comic speech bubble when poked */
.speech-bubble {
  position: absolute;
  top: 1rem;
  left: 50%;
  translate: -50%;
  z-index: 4;
  max-width: calc(100% - 2.4rem);
  padding: 0.45rem 0.9rem;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--cream);
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 700;
  box-shadow: 3px 4px 0 #38262238;
  white-space: nowrap;
  pointer-events: none;
  animation: popBubble 240ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.speech-bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  width: 11px;
  height: 11px;
  translate: -50%;
  rotate: 45deg;
  background: var(--cream);
  border-right: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
}

@keyframes popBubble {
  0% { opacity: 0; transform: scale(0.7) translateY(8px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

.shutter-flash {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: #fffdf5;
  opacity: 0;
  pointer-events: none;
}

.shutter-flash.flash {
  animation: shutterFlash 380ms ease-out;
}

@keyframes shutterFlash {
  0% { opacity: 0.92; }
  100% { opacity: 0; }
}

.stage-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.68rem 0.9rem;
  background: var(--cream);
  border-top: 2px solid var(--ink);
}

.stage-btn {
  min-height: 36px;
  padding: 0.2rem 0.72rem;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  background: #fff2d4;
  font-size: 0.83rem;
  font-weight: 700;
  box-shadow: 2px 2px 0 var(--ink);
  transition: transform 140ms cubic-bezier(0.34, 1.56, 0.64, 1), background-color 140ms ease;
}

.stage-btn:hover { background: var(--apricot); transform: translateY(-2px); }
.stage-btn:active { transform: translateY(1px); box-shadow: none; }

.polaroid-check {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.polaroid-check input {
  position: static;
  opacity: 1;
  width: 16px;
  height: 16px;
  accent-color: var(--ink);
  cursor: pointer;
}

/* Monster ID Card */
.id-card {
  padding: 0.9rem 1.05rem;
  border: 2px solid var(--ink);
  border-radius: 18px;
  background: var(--cream);
  box-shadow: 4px 5px 0 #38262226;
  display: grid;
  gap: 0.45rem;
}

.name-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.name-row input {
  position: static;
  opacity: 1;
  flex: 1;
  min-width: 0;
  min-height: 38px;
  padding: 0.25rem 0.7rem;
  border: 1.5px solid #b08f7c;
  border-radius: 10px;
  background: #fffdf6;
  color: var(--ink);
  font: 750 1rem/1.2 inherit;
}

.name-row input:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.dice-btn {
  min-height: 38px;
  min-width: 40px;
  padding: 0 0.5rem;
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  background: #ffe8c2;
  font-size: 1rem;
  transition: transform 200ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.dice-btn:hover { transform: rotate(18deg) scale(1.06); background: var(--apricot); }

.bio-line {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--muted);
}

/* Manila Folder Tabs for Wardrobe */
form {
  min-width: 0;
  padding: 1.15rem 1.25rem 1.1rem;
  border: 2px solid var(--ink);
  border-radius: 22px;
  background: var(--cream);
  box-shadow: 6px 7px 0 #38262224;
}

.wardrobe-tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1rem;
  padding-bottom: 0.85rem;
  border-bottom: 1.5px dashed var(--dash);
  flex-wrap: wrap;
}

.wardrobe-tabs button {
  flex: 1 1 auto;
  min-height: 40px;
  padding: 0.3rem 0.75rem;
  border: 1.5px solid #9f7967;
  border-radius: 12px;
  background: #fff3da;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted);
  transition: background-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.wardrobe-tabs button:hover:not([aria-selected="true"]) { background: #ffe6c4; color: var(--ink); }

.wardrobe-tabs button[aria-selected="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff3db;
  box-shadow: 0 3px 0 #8a6453;
  transform: translateY(-1px);
}

fieldset {
  min-width: 0;
  margin: 0 0 0.92rem;
  padding: 0 0 0.9rem;
  border: 0;
  border-bottom: 1px dashed var(--dash);
}

.tab-panel fieldset:last-child {
  border-bottom: 0;
  margin-bottom: 0.35rem;
  padding-bottom: 0.3rem;
}

legend {
  padding: 0;
  margin-bottom: 0.52rem;
  font-size: 0.98rem;
  font-weight: 750;
}

.options { display: flex; flex-wrap: wrap; gap: 0.42rem; }
.options label { position: relative; cursor: pointer; }
.options input { position: absolute; opacity: 0; width: 1px; height: 1px; }

.options label span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  gap: 0.35rem;
  padding: 0.28rem 0.68rem;
  border: 1.5px solid #a6806d;
  border-radius: 999px;
  background: #fffdf7;
  font-size: 0.87rem;
  white-space: nowrap;
  transition: transform 150ms cubic-bezier(0.34, 1.56, 0.64, 1), background-color 150ms ease, border-color 150ms ease;
}

.options label:hover span { background: #ffe8cd; transform: translateY(-1px); }

.options input:checked + span {
  border-color: var(--ink);
  background: var(--apricot);
  box-shadow: 2px 2px 0 var(--ink);
  font-weight: 700;
}

.options input:focus-visible + span, button:focus-visible {
  outline: 2px solid #593b2a;
  outline-offset: 3px;
}

.colors span::before {
  content: "";
  width: 0.86rem;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--swatch);
  border: 1.5px solid #5e4439;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 0.85rem;
  padding-top: 0.85rem;
  border-top: 1.5px dashed var(--dash);
}

button {
  min-height: 44px;
  cursor: pointer;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  padding: 0.45rem 0.88rem;
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  color: var(--ink);
  background: #fffdf7;
  transition: transform 150ms cubic-bezier(0.34, 1.56, 0.64, 1), background-color 150ms ease;
}

#shuffle { background: var(--ink); color: #fff2d9; }
#shuffle:hover { background: #52332b; transform: translateY(-2px); }
#pin { background: #ffe7bf; }
#pin:hover { background: var(--apricot); transform: translateY(-2px); }
#download:hover { background: var(--apricot); transform: translateY(-2px); }

.status {
  margin: 0.65rem 0 0;
  min-height: 1.35rem;
  font-size: 0.84rem;
  color: var(--muted);
}

/* Polaroid Lookbook Strip */
.lookbook {
  margin-top: 2.2rem;
  padding-top: 1.35rem;
  border-top: 2px dashed var(--dash);
}

.lookbook-head {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
  margin-bottom: 1rem;
}

.lookbook-head h2 { margin: 0; font-size: 1.2rem; font-weight: 800; }
.lookbook-head span { font-size: 0.84rem; color: var(--muted); }

.lookbook-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(156px, 1fr));
  gap: 1.1rem;
}

.lookbook-empty {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.polaroid-card {
  position: relative;
  display: grid;
  gap: 0.45rem;
  padding: 0.55rem 0.55rem 0.7rem;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: #fffdf7;
  box-shadow: 4px 5px 0 #38262228;
  transform: rotate(var(--tilt, -1.5deg));
  transition: transform 220ms cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 220ms ease;
}

.polaroid-card:hover {
  transform: rotate(0deg) translateY(-5px) scale(1.02);
  box-shadow: 6px 9px 0 #38262234;
  z-index: 2;
}

.polaroid-card::before {
  content: "";
  position: absolute;
  top: -8px;
  left: 50%;
  translate: -50%;
  width: 44px;
  height: 14px;
  background: #ffd388b8;
  border: 1px solid #31232128;
  transform: rotate(-2deg);
  pointer-events: none;
}

.polaroid-pick {
  padding: 0;
  min-height: 0;
  border: 0;
  background: transparent;
  text-align: left;
  display: grid;
  gap: 0.35rem;
}

.polaroid-pick img {
  display: block;
  width: 100%;
  aspect-ratio: 8 / 7;
  border-radius: 7px;
  border: 1.5px solid var(--ink);
  object-fit: cover;
}

.polaroid-pick strong {
  font-size: 0.86rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.polaroid-del {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  min-height: 24px;
  width: 24px;
  padding: 0;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  background: var(--cream);
  font-size: 0.76rem;
  line-height: 1;
}

.polaroid-del:hover { background: #f8b4be; }

@media (max-width: 920px) {
  main { width: calc(100% - 2.2rem); }
  .closet { gap: 1.5rem; }
}

@media (max-width: 740px) {
  main { width: min(100% - 1.5rem, 34rem); }
  .closet { grid-template-columns: 1fr; }
  .portrait { border-radius: 24px; }
  .options label span { min-height: 42px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

.language-picker {
  appearance: none;
  min-height: 40px;
  padding: .25rem 1.7rem .25rem .65rem;
  border: 1.5px solid #9f7967;
  border-radius: 8px;
  background:
    linear-gradient(45deg, transparent 50%, currentColor 51%) right .84rem center / .27rem .27rem no-repeat,
    linear-gradient(135deg, currentColor 50%, transparent 51%) right .57rem center / .27rem .27rem no-repeat,
    var(--cream);
  color: inherit;
  font: inherit;
  font-size: .86rem;
  cursor: pointer;
}
.language-picker option { background: var(--cream); color: #38271d; }
.language-picker:focus-visible { outline: 2px solid #593b2a; outline-offset: 3px; }
