/* ============================================================
   まほうのドレスルーム — style
   palette:
     姫ピンク   #F9A8C9 / こいピンク #E86FA4
     ラベンダー #C3B1E1 / うすラベンダー #EFE6FA
     クリーム   #FFF6EC
     ゴールド   #E8B84B
     プラム(文字) #6B4A5C
   ============================================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --pink: #F9A8C9;
  --pink-deep: #E86FA4;
  --pink-pale: #FFE9F3;
  --lavender: #C3B1E1;
  --lavender-pale: #EFE6FA;
  --cream: #FFF6EC;
  --gold: #E8B84B;
  --gold-pale: #F7DFA8;
  --plum: #6B4A5C;
  --white: #FFFFFF;
  --font-display: 'Hachi Maru Pop', 'Zen Maru Gothic', 'Hiragino Maru Gothic ProN', sans-serif;
  --font-body: 'Zen Maru Gothic', 'Hiragino Maru Gothic ProN', 'Hiragino Sans', sans-serif;
  --shadow-soft: 0 4px 14px rgba(232, 111, 164, 0.18);
  --radius: 20px;
}

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: var(--font-body);
  color: var(--plum);
  background:
    radial-gradient(circle at 18% 22%, rgba(255,255,255,.55) 0 2px, transparent 3px),
    radial-gradient(circle at 72% 14%, rgba(255,255,255,.5) 0 2px, transparent 3px),
    radial-gradient(circle at 88% 58%, rgba(255,255,255,.45) 0 2px, transparent 3px),
    radial-gradient(circle at 32% 78%, rgba(255,255,255,.45) 0 2px, transparent 3px),
    linear-gradient(175deg, #FFE9F3 0%, #FDE3F0 40%, #EFE6FA 100%);
  background-attachment: fixed;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 8px env(safe-area-inset-bottom);
}

/* ---------- header ---------- */

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 6px 4px;
}

#app-title {
  font-family: var(--font-display);
  font-size: clamp(17px, 4.2vw, 26px);
  font-weight: 400;
  color: var(--pink-deep);
  text-shadow: 0 2px 0 rgba(255,255,255,.8);
  white-space: nowrap;
}

.t-star {
  color: var(--gold);
  font-size: .8em;
  margin: 0 4px;
  display: inline-block;
  animation: star-twinkle 2.4s ease-in-out infinite;
}
.t-star:last-child { animation-delay: 1.2s; }

@keyframes star-twinkle {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(.7) rotate(20deg); opacity: .6; }
}

.topbar-btns { display: flex; gap: 8px; }

.icon-btn {
  width: 46px;
  height: 46px;
  border: 2px solid var(--pink);
  border-radius: 50%;
  background: var(--white);
  font-size: 21px;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform .15s;
  line-height: 1;
}
.icon-btn:active { transform: scale(.88); }
.icon-btn.is-off { filter: grayscale(1); opacity: .55; }

/* ---------- layout ---------- */

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  padding-bottom: 8px;
}

/* ---------- stage ---------- */

#stage-wrap {
  position: relative;
  flex: 0 0 auto;
  height: 46dvh;
  min-height: 300px;
  border-radius: var(--radius);
  border: 3px solid var(--white);
  outline: 2px solid var(--gold-pale);
  box-shadow: 0 8px 24px rgba(232, 111, 164, 0.25);
  overflow: hidden;
  background: linear-gradient(180deg, #DFF1FF, #FFF3FA);
}

#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* スカラップの幕(バランス) — ステージのサイン */
#valance {
  position: absolute;
  top: -2px;
  left: -2px;
  right: -2px;
  height: 26px;
  z-index: 3;
  background:
    radial-gradient(circle at 50% 0, var(--pink) 0 68%, transparent 69%),
    linear-gradient(var(--pink-deep), var(--pink-deep));
  background-size: 40px 52px, 100% 6px;
  background-repeat: repeat-x, no-repeat;
  background-position: 0 0, 0 0;
  filter: drop-shadow(0 3px 3px rgba(232,111,164,.35));
}

#fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  overflow: hidden;
}

/* --- doll animations (SVGはDOM内なのでCSSが効く) --- */

#doll-bob {
  animation: doll-bob 3.2s ease-in-out infinite;
  transform-origin: 160px 500px;
}
@keyframes doll-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

#doll-root.pop { animation: doll-pop .45s ease; transform-origin: 160px 380px; }
@keyframes doll-pop {
  0% { transform: scale(1); }
  35% { transform: scale(1.06, .96); }
  70% { transform: scale(.97, 1.04); }
  100% { transform: scale(1); }
}

#doll-root.twirl { animation: doll-twirl .9s ease-in-out; transform-origin: 160px 340px; }
@keyframes doll-twirl {
  0% { transform: scaleX(1); }
  25% { transform: scaleX(-0.55) ; }
  50% { transform: scaleX(1) translateY(-12px); }
  75% { transform: scaleX(-0.55); }
  100% { transform: scaleX(1); }
}

.eyes-blink { animation: blink 4.6s infinite; transform-origin: 160px 165px; }
@keyframes blink {
  0%, 94%, 100% { transform: scaleY(1); }
  96.5% { transform: scaleY(0.08); }
}

/* ---------- stage floating buttons ---------- */

#stage-actions {
  position: absolute;
  right: 8px;
  top: 32px;
  bottom: 8px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
}

.stage-btn {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 2px solid var(--pink);
  background: rgba(255,255,255,.92);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  transition: transform .15s;
}
.stage-btn:active { transform: scale(.86); }
.sb-icon { font-size: 20px; line-height: 1.1; }
.sb-label {
  font-family: var(--font-display);
  font-size: 9.5px;
  color: var(--pink-deep);
  line-height: 1.2;
}

/* ---------- sparkle particles ---------- */

.spark {
  position: absolute;
  font-size: var(--sp-size, 22px);
  left: var(--sp-x);
  top: var(--sp-y);
  animation: spark-fly var(--sp-dur, .9s) ease-out forwards;
  will-change: transform, opacity;
}
@keyframes spark-fly {
  0% { transform: translate(0,0) scale(.4) rotate(0deg); opacity: 0; }
  20% { opacity: 1; }
  100% {
    transform: translate(var(--sp-dx), var(--sp-dy)) scale(1.1) rotate(var(--sp-rot, 180deg));
    opacity: 0;
  }
}

/* ---------- drawer ---------- */

#drawer {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--white);
  border-radius: var(--radius);
  border: 3px solid var(--pink-pale);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

#tabs {
  display: flex;
  gap: 6px;
  padding: 8px 10px 6px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 0 0 auto;
  background: linear-gradient(180deg, var(--pink-pale), var(--white));
}
#tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: 0 0 auto;
  min-width: 66px;
  padding: 6px 10px 5px;
  border: 2px solid transparent;
  border-radius: 16px;
  background: var(--white);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  box-shadow: 0 2px 6px rgba(232,111,164,.12);
  transition: transform .15s, border-color .15s, background .15s;
}
.tab:active { transform: scale(.92); }
.tab-icon { font-size: 22px; line-height: 1.2; }
.tab-label {
  font-family: var(--font-display);
  font-size: 10.5px;
  color: var(--plum);
  white-space: nowrap;
}
.tab.is-active {
  border-color: var(--pink-deep);
  background: var(--pink-pale);
}
.tab.is-active .tab-label { color: var(--pink-deep); }

#panel {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------- swatches ---------- */

#swatch-area { display: flex; flex-direction: column; gap: 8px; }
#swatch-area:empty { display: none; }

.swatch-row {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 3px 2px;
}
.swatch-row::-webkit-scrollbar { display: none; }
.swatch-row > * { flex: 0 0 auto; }

@media (min-width: 760px) {
  .swatch-row { flex-wrap: wrap; overflow: visible; }
}

.swatch-title {
  font-family: var(--font-display);
  font-size: 12px;
  color: var(--pink-deep);
  flex: 0 0 auto;
  margin-right: 2px;
}

.swatch {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid var(--white);
  outline: 2px solid rgba(107,74,92,.15);
  cursor: pointer;
  transition: transform .12s;
  padding: 0;
}
.swatch:active { transform: scale(.85); }
.swatch.is-active {
  outline: 3px solid var(--pink-deep);
  transform: scale(1.08);
}

.pattern-chip {
  width: 44px;
  height: 38px;
  border-radius: 12px;
  border: 2px solid var(--pink-pale);
  background: var(--white);
  cursor: pointer;
  font-size: 16px;
  transition: transform .12s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.pattern-chip:active { transform: scale(.85); }
.pattern-chip.is-active { border-color: var(--pink-deep); background: var(--pink-pale); }

/* ---------- おかお しゃしん ---------- */

#stage { touch-action: none; }

.photo-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--lavender-pale);
  border-radius: 14px;
  padding: 10px 12px;
}

.photo-hint {
  font-size: 12px;
  color: var(--plum);
}

.photo-slider {
  flex: 1;
  min-width: 120px;
  accent-color: var(--pink-deep);
  height: 34px;
}

.photo-btns { display: flex; gap: 8px; flex-wrap: wrap; }

.ctrl-btn {
  font-family: var(--font-display);
  font-size: 12px;
  color: var(--pink-deep);
  background: var(--white);
  border: 2px solid var(--pink);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  transition: transform .12s;
}
.ctrl-btn:active { transform: scale(.92); }
.ctrl-btn.is-active { background: var(--pink-pale); border-color: var(--pink-deep); }

/* ---------- わたしのふく ダイアログ ---------- */

.mc-hint {
  font-size: 12.5px;
  line-height: 1.7;
  margin-bottom: 10px;
  background: var(--lavender-pale);
  border-radius: 12px;
  padding: 8px 12px;
}

#mc-canvas-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 10px;
  border-radius: 14px;
  border: 3px solid var(--pink-pale);
  overflow: hidden;
  /* とうめいな ところが わかる いちまつもよう */
  background:
    repeating-conic-gradient(#F3EAF0 0 25%, #FFFFFF 0 50%) 0 0 / 22px 22px;
}

#mc-canvas {
  max-width: 100%;
  max-height: 38dvh;
  display: block;
}

#mc-slots { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- item grid ---------- */

#grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(86px, 1fr));
  gap: 9px;
}

.item-btn {
  position: relative;
  aspect-ratio: 5 / 6;
  border: 3px solid var(--lavender-pale);
  border-radius: 18px;
  background: linear-gradient(180deg, #FFFDFE, #FFF2F8);
  cursor: pointer;
  padding: 6px 4px 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: transform .15s, border-color .15s, box-shadow .15s;
  overflow: hidden;
}
.item-btn:active { transform: scale(.9); }
.item-btn.is-worn {
  border-color: var(--pink-deep);
  box-shadow: 0 0 0 3px rgba(249,168,201,.4), var(--shadow-soft);
  background: linear-gradient(180deg, #FFF6FB, #FFE4F1);
}
.item-btn.is-worn::after {
  content: "✨";
  position: absolute;
  top: 3px;
  right: 5px;
  font-size: 14px;
}

.item-thumb { flex: 1; width: 100%; min-height: 0; pointer-events: none; }
.item-thumb svg { width: 100%; height: 100%; }

.item-name {
  font-family: var(--font-display);
  font-size: 9.5px;
  color: var(--plum);
  white-space: nowrap;
  overflow: hidden;
  max-width: 100%;
  line-height: 1.5;
}

.item-btn.item-none .item-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  opacity: .45;
}

/* ---------- dialogs ---------- */

dialog {
  border: 4px solid var(--pink);
  border-radius: 24px;
  background: var(--cream);
  color: var(--plum);
  width: min(92vw, 560px);
  max-height: 84dvh;
  padding: 16px;
  margin: auto;
  box-shadow: 0 20px 60px rgba(107,74,92,.35);
}
dialog::backdrop {
  background: rgba(232, 111, 164, .28);
  backdrop-filter: blur(3px);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.dialog-head h2 {
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--pink-deep);
  font-weight: 400;
}

#closet-empty {
  text-align: center;
  padding: 28px 8px;
  font-size: 14px;
  line-height: 2;
}

#closet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  overflow-y: auto;
}

.closet-card {
  border: 3px solid var(--pink-pale);
  border-radius: 16px;
  background: var(--white);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.closet-card img {
  width: 100%;
  aspect-ratio: 320 / 520;
  object-fit: cover;
  cursor: pointer;
  display: block;
}
.closet-card-btns {
  display: flex;
}
.closet-card-btns button {
  flex: 1;
  border: none;
  background: var(--pink-pale);
  font-family: var(--font-display);
  font-size: 11px;
  color: var(--plum);
  padding: 7px 0;
  cursor: pointer;
}
.closet-card-btns button + button {
  border-left: 2px solid var(--white);
  background: var(--lavender-pale);
}
.closet-card-btns button:active { filter: brightness(.92); }

#photo-preview {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}
#photo-preview img {
  max-width: 100%;
  max-height: 52dvh;
  border-radius: 14px;
  border: 3px solid var(--gold-pale);
}

.dialog-btns {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.big-btn {
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--white);
  background: linear-gradient(180deg, var(--pink), var(--pink-deep));
  border: none;
  border-radius: 999px;
  padding: 12px 26px;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform .15s;
}
.big-btn:active { transform: scale(.92); }

/* ---------- desktop ---------- */

@media (min-width: 760px) {
  #main {
    flex-direction: row;
    align-items: stretch;
  }
  #stage-wrap {
    flex: 0 0 46%;
    height: auto;
    min-height: 0;
  }
  #drawer { flex: 1; }
  #grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
  .item-name { font-size: 10.5px; }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  #doll-bob, .t-star, .eyes-blink { animation: none !important; }
  .spark { animation-duration: .5s !important; }
}
