/* Stuffy Workshop */

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

:root {
  --ink: #4a3a55;
  --paper: #fff8f0;
  --card: #ffffff;
  --accent: #ff8fab;
  --accent-dark: #e0526e;
  --sky1: #ffe5ec;
  --sky2: #d9f0ff;
  --shadow: 0 6px 0 rgba(74, 58, 85, 0.12);
}

html, body { height: 100%; }

body {
  font-family: "Baloo 2", "Comic Sans MS", "Segoe UI", sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, var(--sky1), var(--sky2) 70%);
  min-height: 100vh;
  overflow-x: hidden;
}

.screen { display: none; min-height: 100vh; flex-direction: column; }
.screen.active { display: flex; }

h1, h2 { font-weight: 800; }

/* ---------- shared bits ---------- */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
}
.bar h2 { font-size: clamp(18px, 4vw, 26px); text-align: center; flex: 1; }

.big-btn {
  font-family: inherit;
  font-size: clamp(17px, 3.5vw, 22px);
  font-weight: 700;
  color: var(--ink);
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 12px 26px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.1s;
}
.big-btn:active { transform: translateY(3px) scale(0.98); box-shadow: none; }
.big-btn.primary { background: var(--accent); color: #fff; border-color: var(--accent-dark); }

.icon-btn {
  font-size: 24px;
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: 16px;
  width: 52px;
  height: 52px;
  cursor: pointer;
  box-shadow: var(--shadow);
  flex: 0 0 auto;
}
.icon-btn:active { transform: translateY(3px); box-shadow: none; }

.text-btn {
  font-family: inherit;
  font-weight: 700;
  font-size: 15px;
  background: var(--card);
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  color: var(--ink);
}

.hidden { display: none !important; }

.stage {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 10px;
  min-height: 0;
}
.stage > svg { width: min(78vw, 46vh, 420px); height: auto; touch-action: none; }

/* ---------- home ---------- */

.home-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 30px 16px;
  text-align: center;
}
.title {
  font-size: clamp(44px, 10vw, 76px);
  line-height: 0.95;
  color: var(--accent-dark);
  text-shadow: 3px 3px 0 #fff;
}
#mascot { width: min(60vw, 34vh, 300px); height: auto; }
.home-buttons { display: flex; flex-direction: column; gap: 14px; width: min(340px, 86vw); }
.home-buttons .big-btn { width: 100%; }
.credit { opacity: 0.6; font-weight: 700; }

/* ---------- builder ---------- */

.build-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 12px 16px;
  min-height: 0;
}
#build-preview.boing { animation: boing 0.35s; }

.panel {
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}
.tab {
  font-family: inherit;
  font-weight: 700;
  font-size: 13px;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: var(--paper);
  border: 2.5px solid transparent;
  border-radius: 14px;
  padding: 8px 12px;
  cursor: pointer;
  flex: 0 0 auto;
}
.tab.on { border-color: var(--accent-dark); background: var(--sky1); }
.tab-icon { font-size: 22px; }

.options { min-height: 148px; }
.opt-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.opt {
  font-family: inherit;
  font-weight: 700;
  font-size: 13px;
  color: var(--ink);
  background: var(--paper);
  border: 3px solid transparent;
  border-radius: 16px;
  padding: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 104px;
}
.opt svg { width: 84px; height: 84px; }
.opt.on { border-color: var(--accent-dark); background: var(--sky1); }
.pattern-opt { width: auto; padding: 8px 12px; }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.swatch {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 3px solid rgba(74, 58, 85, 0.25);
  cursor: pointer;
}
.swatch.on { border-color: var(--ink); transform: scale(1.12); }
.swatches.mini .swatch { width: 33px; height: 33px; }
.pattern-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.pattern-opt svg { width: 66px; height: 48px; }

.fab-label { font-weight: 800; font-size: 14px; opacity: 0.7; margin-bottom: 6px; }
.fab-targets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip {
  font-family: inherit;
  font-weight: 700;
  font-size: 13px;
  color: var(--ink);
  background: var(--paper);
  border: 2.5px solid transparent;
  border-radius: 999px;
  padding: 7px 12px;
  cursor: pointer;
}
.chip.on { border-color: var(--accent-dark); background: var(--sky1); }

@media (min-width: 760px) {
  .build-layout { flex-direction: row; align-items: stretch; }
  .build-layout .stage { flex: 1.1; }
  .panel { flex: 1; max-width: 520px; overflow-y: auto; }
}

/* ---------- sewing ---------- */

.sew-stage > svg { width: min(88vw, 62vh, 480px); }

.seam-guide {
  fill: none;
  stroke: var(--accent-dark);
  stroke-width: 3;
  stroke-dasharray: 8 8;
  opacity: 0.8;
  animation: dash-march 1.2s linear infinite;
}
.seam-start {
  fill: var(--accent-dark);
  transform-box: fill-box;
  transform-origin: center;
  animation: pulse 1s ease-in-out infinite;
}
.stitch { stroke: var(--accent-dark); stroke-width: 3.5; stroke-linecap: round; }

.part-inner {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s;
}
.part-inner.unsewn { opacity: 0.45; }
.detach-up-l   { transform: translate(-12px, -46px) rotate(-10deg); }
.detach-up-r   { transform: translate(12px, -46px) rotate(10deg); }
.detach-out-l  { transform: translate(-44px, 16px) rotate(-14deg); }
.detach-out-r  { transform: translate(44px, 16px) rotate(14deg); }
.detach-down-l { transform: translate(-10px, 44px) rotate(-8deg); }
.detach-down-r { transform: translate(10px, 44px) rotate(8deg); }
.detach-tail   { transform: translate(38px, 26px) rotate(16deg); }
.detach-belly  { transform: translate(0, 56px) scale(0.92); }
.part-inner.just-sewn { animation: boing 0.4s; }

[data-part="face"] { transition: opacity 1s; }
[data-part="face"].face-hidden { opacity: 0; }

.sew-progress { display: flex; gap: 8px; }
.sew-progress .dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 2.5px solid var(--accent-dark);
}
.sew-progress .dot.done { background: var(--accent-dark); }

.done-msg {
  position: absolute;
  top: 12%;
  font-size: clamp(24px, 6vw, 40px);
  font-weight: 800;
  color: var(--accent-dark);
  text-shadow: 2px 2px 0 #fff;
  animation: boing 0.5s;
}

/* ---------- naming ---------- */

.name-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px 16px;
  text-align: center;
}
.name-wrap h2 { font-size: clamp(26px, 6vw, 40px); }
#name-preview { width: min(52vw, 30vh, 260px); height: auto; }
.name-form { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: center; }
#name-input {
  font-family: inherit;
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 10px 20px;
  width: min(320px, 80vw);
  text-align: center;
  background: var(--card);
}
#name-input:focus { outline: 3px solid var(--accent); }

/* ---------- shelf ---------- */

.shelf-grid {
  position: relative;
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-content: flex-start;
  justify-content: center;
  padding: 10px 16px;
}
.shelf-card { position: relative; }
.shelf-pick {
  font-family: inherit;
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 156px;
}
.shelf-pick:active { transform: translateY(3px); box-shadow: none; }
.shelf-pick svg { width: 116px; height: 136px; }
.shelf-name { font-weight: 800; font-size: 15px; color: var(--ink); word-break: break-word; }
.shelf-del {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2.5px solid var(--ink);
  background: #fff;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  opacity: 0.75;
}
.empty-note { font-size: 20px; font-weight: 700; opacity: 0.7; padding: 40px 20px; text-align: center; }
.shelf-foot { padding: 16px; text-align: center; }
.shelf-tools { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.shelf-note { font-weight: 700; opacity: 0.75; margin-top: 10px; }

/* ---------- play room ---------- */

#screen-play { transition: background 0.8s; }
#screen-play.night { background: linear-gradient(160deg, #3d3a5c, #1f2440 70%); }
#screen-play.night .bar h2 { color: #f0ecff; }

.play-stage > svg { cursor: grab; }
.play-stage > svg:active { cursor: grabbing; }
#play-svg .stuffy-root { animation: breathe 3s ease-in-out infinite; transform-box: fill-box; transform-origin: center bottom; }

#play-svg.wiggle { animation: wiggle 0.5s; }
#play-svg.squash { animation: squash 0.45s; }
#play-svg.bounce-back { animation: boing 0.5s; }

.play-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  padding: 14px 16px 26px;
}
.play-actions .big-btn { font-size: clamp(15px, 3vw, 19px); padding: 10px 18px; }

.care-btn { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.meter {
  display: block;
  width: 76px;
  height: 9px;
  border-radius: 99px;
  background: rgba(74, 58, 85, 0.15);
  overflow: hidden;
}
.meter i {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #7ed957, #b6e2a1);
  transition: width 0.4s;
}
.meter.low i { background: linear-gradient(90deg, #ff8a5c, #ffb199); }
.play-actions .big-btn:disabled { opacity: 0.45; cursor: default; }

.heal-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 16px 26px;
  text-align: center;
}
.heal-progress { font-size: 30px; letter-spacing: 5px; }
.heal-hint { font-weight: 700; opacity: 0.65; font-size: 14px; max-width: 360px; }
#screen-play.sick .play-stage > svg { filter: saturate(0.5) brightness(0.97); }
#screen-play.night .heal-hint { color: #f0ecff; }

.sick-badge {
  position: absolute;
  top: -10px;
  left: -10px;
  font-size: 24px;
  z-index: 2;
  filter: drop-shadow(0 2px 0 rgba(74, 58, 85, 0.2));
}

.bubble {
  position: absolute;
  top: 4%;
  left: 50%;
  transform: translateX(-50%) scale(0.6);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 18px;
  padding: 10px 18px;
  font-size: clamp(16px, 3.6vw, 22px);
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  max-width: 84%;
  text-align: center;
  z-index: 5;
}
.bubble.shown { opacity: 1; transform: translateX(-50%) scale(1); }
.bubble::after {
  content: '';
  position: absolute;
  bottom: -12px;
  left: 50%;
  margin-left: -8px;
  border: 8px solid transparent;
  border-top-color: var(--ink);
}

.float-emoji {
  position: absolute;
  animation: float-up 1.6s ease-out forwards;
  pointer-events: none;
  z-index: 4;
}

/* ---------- animations ---------- */

@keyframes boing {
  0% { transform: scale(1); }
  35% { transform: scale(1.08, 0.92); }
  70% { transform: scale(0.96, 1.05); }
  100% { transform: scale(1); }
}
@keyframes wiggle {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-6deg); }
  45% { transform: rotate(6deg); }
  70% { transform: rotate(-4deg); }
}
@keyframes squash {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.1, 0.85); }
}
@keyframes breathe {
  0%, 100% { transform: scale(1, 1); }
  50% { transform: scale(1.015, 0.985); }
}
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.5); opacity: 0.6; }
}
@keyframes dash-march { to { stroke-dashoffset: -32; } }
@keyframes float-up {
  0% { transform: translateY(0) scale(0.6); opacity: 0; }
  15% { opacity: 1; }
  100% { transform: translateY(-140px) scale(1.15); opacity: 0; }
}

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