:root {
  --bg-top: #fff2f8;
  --bg-bottom: #eef5ff;
  --card-bg: #ffffff;
  --pink: #ff6fb5;
  --pink-deep: #eb4a9a;
  --pink-soft: #ffe3f1;
  --lavender: #9c7cff;
  --lavender-soft: #efe8ff;
  --sunny: #ffd54f;
  --mint: #53d9a8;
  --ink: #3d2b3d;
  --ink-soft: #755f75;
  --shadow-soft: 0 8px 24px rgba(133, 74, 122, 0.14);
  --shadow-btn: 0 4px 0 rgba(133, 74, 122, 0.16);
  --radius-lg: 24px;
  --radius-md: 18px;
  --font: ui-rounded, 'SF Pro Rounded', 'Nunito', 'Quicksand', 'Arial Rounded MT Bold', system-ui, sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(165deg, var(--bg-top) 0%, #fff9f2 48%, var(--bg-bottom) 100%);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

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

button:disabled {
  opacity: 0.38;
  cursor: default;
  transform: none !important;
}

.hidden {
  display: none !important;
}

/* Main mobile-first shell (centered phone frame on larger screens) */
.app-shell {
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 auto;
  padding:
    max(6px, env(safe-area-inset-top))
    max(8px, env(safe-area-inset-right))
    max(6px, env(safe-area-inset-bottom))
    max(8px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 6px;
  overflow: hidden;
  position: relative;
}

/* Top bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  min-width: 0;
  max-width: 100%;
  z-index: 10;
}

.top-group {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.icon-pill {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: #ffffff;
  border: 2px solid #f4d6e8;
  box-shadow: var(--shadow-btn);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  color: var(--ink);
  transition: transform 0.14s ease, background-color 0.15s ease;
}

.icon-pill svg {
  width: 18px;
  height: 18px;
}

.icon-pill:active:not(:disabled) {
  transform: translateY(2px) scale(0.95);
}

.magic-pill {
  background: linear-gradient(135deg, #fff5b8 0%, #ffd5ef 100%);
  border-color: #f9b8dc;
}

.done-pill {
  height: 34px;
  min-width: 38px;
  padding: 0 9px;
  border-radius: 999px;
  background: linear-gradient(135deg, #ff79b9 0%, #ff559e 100%);
  color: #fff;
  font-size: 17px;
  box-shadow: 0 4px 0 #d4367d;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.14s ease;
}

.done-pill:active {
  transform: translateY(2px) scale(0.95);
}

.mode-switch {
  display: flex;
  align-items: center;
  background: #ffffff;
  border: 2px solid #f4d6e8;
  border-radius: 999px;
  padding: 2px;
  box-shadow: var(--shadow-btn);
  gap: 2px;
  flex-shrink: 0;
}

.mode-btn {
  height: 30px;
  padding: 0 7px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 800;
  color: var(--ink-soft);
  white-space: nowrap;
  transition: all 0.18s ease;
}

.mode-btn .mode-emoji {
  font-size: 15px;
  line-height: 1;
}

.mode-btn.active {
  background: linear-gradient(135deg, #ff7eb6 0%, #a97cff 100%);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(183, 108, 224, 0.35);
}

/* Central Doll Stage */
.stage-wrap {
  min-height: 0;
  min-width: 0;
  width: 100%;
  height: 100%;
  container-type: size;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.stage-card {
  width: min(100cqw, calc(100cqh * 360 / 520));
  height: min(100cqh, calc(100cqw * 520 / 360));
  background: #ffffff;
  border-radius: 26px;
  border: 3px solid #ffffff;
  box-shadow: var(--shadow-soft), 0 0 0 2px #f5d8ea;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#doll-svg {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* Coloring & Interaction cursors */
#doll-svg .colorable {
  cursor: pointer;
  transition: filter 0.12s ease;
}

.doll-pop {
  animation: dollBounce 0.34s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-origin: 180px 360px;
}

@keyframes dollBounce {
  0% { transform: scale(0.96); }
  55% { transform: scale(1.03); }
  100% { transform: scale(1); }
}

/* Blinking eyes animation inside SVG */
.eye-lid {
  transform-origin: center;
  transform-box: fill-box;
  animation: dollBlink 4.6s infinite;
}

@keyframes dollBlink {
  0%, 92%, 100% { transform: scaleY(0); }
  96% { transform: scaleY(1); }
}

.sticker-pop {
  animation: stickerPop 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-box: fill-box;
  transform-origin: center;
}

@keyframes stickerPop {
  0% { transform: scale(0.2); opacity: 0.4; }
  70% { transform: scale(1.16); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* Appearance trigger (skin & eyes) */
.appearance-trigger {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  border: 2px solid #f4d6e8;
  box-shadow: 0 3px 10px rgba(80, 40, 80, 0.14);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  z-index: 6;
}

.appearance-trigger:active {
  transform: scale(0.93);
}

.appearance-popover {
  position: absolute;
  top: 58px;
  left: 10px;
  background: rgba(255, 255, 255, 0.96);
  border: 2px solid #f4d6e8;
  border-radius: 18px;
  padding: 8px 10px;
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 8;
}

.appearance-row {
  display: flex;
  gap: 7px;
  align-items: center;
}

.tone-dot {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 2.5px solid #fff;
  box-shadow: 0 0 0 1.5px #d7bfd0;
  transition: transform 0.12s ease;
}

.tone-dot.active {
  transform: scale(1.14);
  box-shadow: 0 0 0 2.5px var(--pink-deep);
}

.stage-hint {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(61, 43, 61, 0.78);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 999px;
  pointer-events: none;
  white-space: nowrap;
  z-index: 7;
  animation: fadeHint 0.25s ease;
}

@keyframes fadeHint {
  from { opacity: 0; transform: translateX(-50%) translateY(6px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* FX Sparkles Layer */
.fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 9;
}

.sparkle-star {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  pointer-events: none;
  animation: sparkleFly 0.65s ease-out forwards;
}

@keyframes sparkleFly {
  0% {
    transform: translate(-50%, -50%) scale(0.4);
    opacity: 1;
  }
  100% {
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.2) rotate(120deg);
    opacity: 0;
  }
}

/* Bottom Dock */
.dock {
  background: rgba(255, 255, 255, 0.94);
  border: 2px solid #f4d6e8;
  border-radius: 22px;
  padding: 7px;
  box-shadow: var(--shadow-soft);
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  z-index: 10;
}

.dock-panel {
  display: none;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
}

.dock-panel.active {
  display: flex;
}

/* Category & Tool strips */
.cat-strip,
.tool-strip {
  display: flex;
  align-items: center;
  gap: 5px;
  width: 100%;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.cat-strip::-webkit-scrollbar,
.tool-strip::-webkit-scrollbar,
.items-strip::-webkit-scrollbar,
.palette-tray::-webkit-scrollbar {
  display: none;
}

.cat-btn {
  flex: 1 0 auto;
  min-width: 52px;
  height: 46px;
  padding: 0 10px;
  border-radius: 16px;
  background: #fdf2f8;
  border: 2px solid transparent;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  line-height: 1;
  transition: all 0.14s ease;
}

.cat-btn.active {
  background: var(--pink-soft);
  border-color: var(--pink);
  transform: translateY(-1px);
  box-shadow: 0 3px 0 #f6a7cf;
}

.cat-btn:active {
  transform: scale(0.94);
}

/* Items Strip (Dress-Up thumbnails) */
.items-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px 2px 4px;
  min-height: 78px;
}

.item-card {
  flex: 0 0 74px;
  height: 78px;
  border-radius: 18px;
  background: #fff9fc;
  border: 2.5px solid #f0d7e6;
  box-shadow: 0 3px 0 #ebd1e1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px;
  position: relative;
  transition: transform 0.14s ease, border-color 0.14s ease;
}

.item-card svg {
  width: 100%;
  height: 100%;
  display: block;
}

.item-card.active {
  background: #fff0f7;
  border-color: var(--pink-deep);
  box-shadow: 0 3px 0 var(--pink);
  transform: translateY(-2px);
}

.item-card:active {
  transform: scale(0.94);
}

.item-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--pink-deep);
  color: #fff;
  font-size: 11px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
}

.strip-divider {
  flex: 0 0 auto;
  width: 2px;
  height: 54px;
  background: #f0d5e6;
  border-radius: 2px;
  margin: 0 2px;
}

/* Coloring Tools */
.tool-btn {
  flex: 1 1 0;
  min-width: 0;
  height: 44px;
  padding: 2px 3px;
  border-radius: 14px;
  background: #f7f3ff;
  border: 2px solid #e4dbff;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font-size: 10px;
  font-weight: 800;
  line-height: 1.05;
  color: var(--ink);
  transition: all 0.14s ease;
}

.tool-btn .tool-icon {
  font-size: 18px;
  line-height: 1;
}

.tool-btn.active {
  background: linear-gradient(135deg, #ffe0f0 0%, #eadfff 100%);
  border-color: var(--lavender);
  box-shadow: 0 3px 0 #c6b2ff;
}

.tool-btn.blank-btn {
  background: #ffffff;
  border-color: #d6e4ff;
}

.tool-btn:active {
  transform: scale(0.94);
}

.size-btn {
  flex: 0 0 42px;
  padding: 0;
}

.brush-dot {
  border-radius: 999px;
  background: var(--ink);
  display: inline-block;
}

.brush-dot.medium {
  width: 12px;
  height: 12px;
}

.brush-dot.large {
  width: 22px;
  height: 22px;
}

/* Palette & Sticker Tray */
.palette-tray {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 4px 2px 6px;
  min-height: 58px;
}

.swatch-btn {
  flex: 0 0 48px;
  height: 48px;
  border-radius: 999px;
  border: 3px solid #ffffff;
  box-shadow: 0 3px 8px rgba(77, 46, 77, 0.18), 0 0 0 2px #e8d2e0;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.14s ease;
}

.swatch-btn svg {
  width: 100%;
  height: 100%;
  display: block;
}

.swatch-btn.active {
  transform: scale(1.12);
  box-shadow: 0 4px 12px rgba(235, 74, 154, 0.35), 0 0 0 3px var(--pink-deep);
}

.swatch-btn:active {
  transform: scale(0.92);
}

.sticker-btn {
  flex: 0 0 54px;
  height: 54px;
  border-radius: 16px;
  background: #fff9fc;
  border: 2.5px solid #f0d7e6;
  box-shadow: 0 3px 0 #ebd1e1;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sticker-btn svg {
  width: 100%;
  height: 100%;
}

.sticker-btn.active {
  background: #fff0f7;
  border-color: var(--pink-deep);
  box-shadow: 0 3px 0 var(--pink);
  transform: translateY(-2px);
}

.eraser-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 10px;
  padding: 0 4px;
}

.eraser-tip {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
}

.clear-strokes-btn {
  flex: 0 0 auto;
  height: 42px;
  padding: 0 14px;
  border-radius: 14px;
  background: #ffe8ef;
  border: 2px solid #ffb5cc;
  font-size: 13px;
  font-weight: 800;
  color: #b8295c;
  box-shadow: 0 3px 0 #f7b8cd;
}

.clear-strokes-btn:active {
  transform: scale(0.95);
}

/* Overlays (Showcase & Gallery) */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(54, 30, 56, 0.56);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.overlay-card {
  width: 100%;
  max-width: 420px;
  max-height: 92dvh;
  background: #fff9fd;
  border-radius: 28px;
  border: 3px solid #ffffff;
  box-shadow: 0 18px 46px rgba(54, 24, 54, 0.35);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  z-index: 2;
}

.showcase-title {
  text-align: center;
  font-size: 24px;
  font-weight: 900;
  color: var(--pink-deep);
}

.showcase-preview {
  width: 100%;
  max-height: 48dvh;
  aspect-ratio: 360 / 520;
  margin: 0 auto;
  background: #fff;
  border-radius: 22px;
  border: 2.5px solid #f4d6e8;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.showcase-preview svg {
  width: 100%;
  height: 100%;
  display: block;
}

.showcase-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.big-cta {
  height: 48px;
  border-radius: 18px;
  font-size: 15px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.14s ease;
}

.big-cta:active {
  transform: scale(0.96);
}

.big-cta.primary {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, #ff74b6 0%, #ff4d94 100%);
  color: #fff;
  box-shadow: 0 4px 0 #cc306f;
}

.big-cta.secondary {
  background: #efe6ff;
  color: #5b37b7;
  border: 2px solid #d4c0ff;
  box-shadow: 0 4px 0 #c9b3fa;
}

.big-cta.ghost {
  background: #ffffff;
  color: var(--ink);
  border: 2px solid #f0d7e6;
  box-shadow: 0 4px 0 #e6cadb;
}

/* Gallery */
.gallery-card {
  height: 82dvh;
}

.gallery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.gallery-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 900;
  color: var(--ink);
}

.gallery-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding: 2px;
}

.gallery-item {
  background: #fff;
  border-radius: 18px;
  border: 2.5px solid #f0d7e6;
  overflow: hidden;
  position: relative;
  aspect-ratio: 360 / 520;
  box-shadow: 0 4px 10px rgba(80, 40, 80, 0.1);
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-del {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  border: 2px solid #f4c3d6;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--ink-soft);
  padding: 20px;
}

.gallery-empty .empty-icon {
  font-size: 48px;
  margin-bottom: 8px;
}

/* Confetti */
.confetti-box {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 1;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  width: 12px;
  height: 16px;
  border-radius: 3px;
  animation: confettiFall 2.4s linear forwards;
}

@keyframes confettiFall {
  0% {
    transform: translateY(-20px) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(105dvh) rotate(540deg);
    opacity: 0.2;
  }
}

/* Ultra-narrow screens (e.g., 320-355px) */
@media (max-width: 355px) {
  .mode-btn .mode-label {
    display: none;
  }
  .mode-btn {
    padding: 0 10px;
  }
}

/* Compact phone screens (e.g., iPhone SE) */
@media (max-height: 700px) {
  .tool-btn .tool-text {
    display: none;
  }
  .item-card {
    flex: 0 0 66px;
    height: 68px;
  }
  .items-strip {
    min-height: 72px;
  }
  .swatch-btn {
    flex: 0 0 42px;
    height: 42px;
  }
  .palette-tray {
    min-height: 52px;
  }
}
