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

:root {
  --ink: #4b2730;
  --muted: #9b6572;
  --pink: #ff5d9a;
  --pink-dark: #ce2d70;
  --panel: rgba(255, 236, 240, 0.94);
  --panel-strong: #fff5f7;
  --line: #ff9bc2;
  --shadow: 0 14px 30px rgba(98, 32, 54, 0.20);
}

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #c95b70;
  -webkit-user-select: none;
  user-select: none;
}

button, a { font: inherit; }

.app-shell {
  width: 100%;
  height: 100dvh;
  min-height: 540px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: calc(env(safe-area-inset-top) + 8px) 10px calc(env(safe-area-inset-bottom) + 8px);
  background:
    linear-gradient(90deg, rgba(255,255,255,.13) 0 14px, transparent 14px 42px),
    linear-gradient(105deg, #dc7a86 0%, #c84b68 100%);
  background-size: 42px 100%, 100% 100%;
}

.topbar {
  height: 52px;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  z-index: 5;
}

.round-btn {
  width: 46px;
  height: 46px;
  border: 2px solid #fff;
  border-radius: 50%;
  display: grid;
  place-items: center;
  text-decoration: none;
  color: #fff;
  background: radial-gradient(circle at 34% 24%, #ffb1cf 0 18%, #ff4f97 54%, #d92575 100%);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.32), 0 7px 16px rgba(90, 24, 52, .22);
  font-size: 21px;
  font-weight: 900;
  cursor: pointer;
}

.round-btn:active, .tool-btn:active, .option-card:active, .tray-arrow:active { transform: scale(.95); }

.back-btn { font-size: 24px; }

.title-block {
  min-width: 0;
  color: #fff;
  text-shadow: 0 2px 0 rgba(110, 30, 54, .18);
}

.title-block h1 {
  margin: 0;
  font-size: clamp(22px, 4.5vw, 34px);
  line-height: 1;
  letter-spacing: 0;
  font-weight: 900;
}

.save-count {
  margin-top: 3px;
  font-size: 12px;
  font-weight: 800;
  opacity: .92;
}

.top-actions {
  display: flex;
  gap: 8px;
}

.studio {
  min-height: 0;
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr) 68px;
  grid-template-rows: minmax(0, 1fr) 118px;
  gap: 8px;
}

.stage {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: stretch center;
  grid-column: 2;
  grid-row: 1;
}

.room {
  position: relative;
  width: min(100%, 600px);
  height: 100%;
  min-height: 0;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,.18);
  border-radius: 20px 20px 12px 12px;
  background:
    linear-gradient(90deg, rgba(255,255,255,.15) 0 14px, transparent 14px 42px),
    linear-gradient(105deg, #d97080 0%, #c34966 100%);
  background-size: 42px 100%, 100% 100%;
  box-shadow: var(--shadow);
}

.room::after {
  content: "";
  position: absolute;
  left: -8%;
  right: -8%;
  bottom: 0;
  height: 27%;
  background:
    radial-gradient(ellipse at 50% 16%, rgba(255,255,255,.12), transparent 50%),
    linear-gradient(180deg, #8e331b, #6d220f);
  border-top: 7px solid rgba(71, 19, 8, .38);
}

.room[data-bg="candy"] {
  background:
    linear-gradient(90deg, rgba(255,255,255,.18) 0 14px, transparent 14px 42px),
    linear-gradient(105deg, #f090a2 0%, #d95086 100%);
}

.room[data-bg="mint"] {
  background:
    linear-gradient(90deg, rgba(255,255,255,.18) 0 14px, transparent 14px 42px),
    linear-gradient(105deg, #7fd6c5 0%, #5fa5cf 100%);
}

.room[data-bg="night"] {
  background:
    radial-gradient(circle at 74% 12%, #f9e6a8 0 30px, transparent 31px),
    radial-gradient(circle at 25% 18%, rgba(255,255,255,.85) 0 2px, transparent 3px),
    radial-gradient(circle at 42% 28%, rgba(255,255,255,.85) 0 2px, transparent 3px),
    linear-gradient(160deg, #33406f 0%, #5c4a8d 55%, #b5517c 100%);
}

.room[data-bg="sunny"] {
  background:
    linear-gradient(90deg, rgba(255,255,255,.18) 0 14px, transparent 14px 42px),
    linear-gradient(105deg, #ffc16d 0%, #f37b76 100%);
}

.vinyl {
  position: absolute;
  right: clamp(36px, 14%, 100px);
  top: clamp(20px, 6%, 48px);
  width: clamp(76px, 14vh, 116px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, #d7a66c 0 19%, #1c1d22 20% 62%, #07080b 63%);
  box-shadow: 0 8px 18px rgba(41, 15, 23, .22);
  opacity: .95;
}

.vinyl::after {
  content: "";
  position: absolute;
  inset: 48%;
  border-radius: 50%;
  background: #1a1113;
}

.rug {
  position: absolute;
  left: 50%;
  bottom: 10%;
  width: min(56%, 260px);
  aspect-ratio: 2.5 / 1;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(255,197,215,.9), rgba(230,93,133,.48));
  z-index: 1;
}

.character {
  position: absolute;
  left: 50%;
  bottom: 7%;
  z-index: 2;
  width: min(42vh, 35vw, 230px);
  max-width: 64%;
  transform: translateX(-50%);
  filter: drop-shadow(0 14px 16px rgba(55, 14, 25, .16));
}

.character svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.tool-rail {
  min-height: 0;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: min(2.2vh, 16px);
  padding-bottom: 4px;
}

.tool-rail.left { grid-column: 1; }
.tool-rail.right { grid-column: 3; }

.tool-btn {
  width: min(56px, 8.5vh);
  height: min(56px, 8.5vh);
  min-width: 46px;
  min-height: 46px;
  border: 2px solid #fff;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  background: radial-gradient(circle at 33% 24%, #ffb7d2 0 16%, #ff4c95 55%, #d22472 100%);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.32), 0 7px 16px rgba(90, 24, 52, .22);
  font-size: min(27px, 4.3vh);
  font-weight: 900;
  cursor: pointer;
}

.tool-btn.active {
  background: radial-gradient(circle at 33% 24%, #fff 0 13%, #45bdf7 56%, #147fe8 100%);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.42), 0 8px 18px rgba(13, 91, 170, .28);
}

.tray {
  grid-column: 1 / -1;
  grid-row: 2;
  min-width: 0;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) 46px;
  align-items: center;
  gap: 7px;
}

.tray-panel {
  min-width: 0;
  height: 112px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 4px solid var(--pink);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: inset 0 0 0 3px #fff, 0 8px 20px rgba(96, 24, 52, .18);
  padding: 8px 12px 10px;
}

.tray-title {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--pink-dark);
  font-size: 14px;
  font-weight: 900;
  line-height: 1;
  margin-bottom: 6px;
}

.option-strip {
  min-width: 0;
  display: flex;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  padding: 1px 2px 4px;
}

.option-strip::-webkit-scrollbar { display: none; }

.option-card {
  flex: 0 0 92px;
  height: 64px;
  border: 2px solid transparent;
  border-radius: 18px;
  background: var(--panel-strong);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
  gap: 2px;
  padding: 6px;
  box-shadow: 0 6px 14px rgba(85, 25, 44, .08);
  font-weight: 900;
}

.option-card.active {
  border-color: #158cff;
  box-shadow: 0 0 0 2px rgba(21,140,255,.18), 0 8px 16px rgba(13, 91, 170, .16);
}

.option-icon {
  font-size: 24px;
  line-height: 1;
}

.option-name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  line-height: 1.1;
}

.swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 1px rgba(100, 32, 55, .18), inset 0 0 0 1px rgba(255,255,255,.18);
}

.bg-thumb {
  width: 42px;
  height: 30px;
  border-radius: 10px;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(100, 32, 55, .14);
}

.bg-candy { background: linear-gradient(90deg, #f090a2 0 18%, #d95086 18% 36%, #f090a2 36% 54%, #d95086 54%); }
.bg-mint { background: linear-gradient(135deg, #7fd6c5, #5fa5cf); }
.bg-night { background: radial-gradient(circle at 75% 24%, #f9e6a8 0 8px, transparent 9px), linear-gradient(135deg, #33406f, #b5517c); }
.bg-sunny { background: linear-gradient(135deg, #ffc16d, #f37b76); }

.tray-arrow {
  width: 46px;
  height: 72px;
  border: none;
  color: var(--pink);
  background: transparent;
  font-size: 54px;
  line-height: 1;
  font-weight: 900;
  cursor: pointer;
  text-shadow: 0 2px 0 #fff;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 132px);
  transform: translateX(-50%);
  z-index: 80;
  max-width: min(86vw, 360px);
  padding: 10px 16px;
  border-radius: 999px;
  color: #fff;
  background: rgba(61, 28, 40, .92);
  box-shadow: 0 10px 22px rgba(0,0,0,.22);
  font-weight: 900;
  text-align: center;
}

.toast[hidden] { display: none; }

@media (max-width: 760px) {
  .app-shell {
    min-height: 520px;
    padding-left: 6px;
    padding-right: 6px;
  }
  .topbar {
    height: 48px;
    grid-template-columns: 44px minmax(0, 1fr) auto;
    gap: 6px;
  }
  .round-btn {
    width: 42px;
    height: 42px;
    font-size: 19px;
  }
  .top-actions { gap: 5px; }
  .title-block h1 { font-size: clamp(20px, 7vw, 28px); }
  .studio {
    grid-template-columns: 54px minmax(0, 1fr) 54px;
    grid-template-rows: minmax(0, 1fr) 112px;
    gap: 5px;
  }
  .room { border-radius: 14px 14px 10px 10px; }
  .character {
    width: min(40vh, 42vw, 184px);
    max-width: 74%;
  }
  .tool-rail { gap: min(1.8vh, 10px); }
  .tool-btn {
    width: min(50px, 8vh);
    height: min(50px, 8vh);
    min-width: 42px;
    min-height: 42px;
  }
  .tray {
    grid-template-columns: 34px minmax(0, 1fr) 34px;
    gap: 2px;
  }
  .tray-panel {
    height: 106px;
    border-radius: 20px;
    padding: 8px 9px;
  }
  .tray-arrow {
    width: 34px;
    height: 66px;
    font-size: 44px;
  }
  .option-card {
    flex-basis: 78px;
    height: 60px;
    border-radius: 15px;
  }
  .option-name { font-size: 11px; }
}

@media (max-width: 420px) {
  .save-count { display: none; }
  .topbar { height: 44px; }
  .round-btn { width: 39px; height: 39px; }
  .studio {
    grid-template-columns: 48px minmax(0, 1fr) 48px;
    grid-template-rows: minmax(0, 1fr) 106px;
  }
  .tool-btn {
    width: 42px;
    height: 42px;
    min-width: 42px;
    min-height: 42px;
    font-size: 21px;
  }
  .vinyl { display: none; }
  .character {
    width: min(39vh, 48vw, 164px);
  }
  .tray-panel { height: 100px; }
}
