:root {
  color-scheme: light;
  --ink: #26333a;
  --muted: #647075;
  --wall: #f7dbcd;
  --wall-shadow: #e8b6a3;
  --floor: #b8dfc8;
  --desk: #8b6c56;
  --desk-dark: #674b3c;
  --accent: #267d8c;
  --accent-2: #e96f55;
  --target: rgba(38, 125, 140, 0.23);
  --target-good: rgba(77, 162, 94, 0.34);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  background:
    radial-gradient(circle at 14% 12%, rgba(247, 214, 111, 0.38) 0 9%, transparent 10%),
    radial-gradient(circle at 86% 16%, rgba(233, 111, 85, 0.18) 0 8%, transparent 9%),
    linear-gradient(180deg, #fcf5e8 0%, #e7f3ef 100%);
}

button {
  border: 0;
  border-radius: 8px;
  min-height: 44px;
  padding: 0 18px;
  font: inherit;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(180deg, #2d91a0, var(--accent));
  box-shadow: 0 5px 0 #17606e, 0 10px 22px rgba(23, 96, 110, 0.16);
  cursor: pointer;
}

button:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #17606e;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.app {
  width: min(1120px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 14px;
}

.topbar,
.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 900;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 5vw, 48px);
  line-height: 1;
  letter-spacing: 0;
}

.status {
  min-width: 154px;
  padding: 10px 12px;
  border: 3px solid rgba(38, 51, 58, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
  text-align: right;
}

.status span,
.status strong {
  display: block;
}

.status span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.status strong {
  font-size: 26px;
  line-height: 1.05;
}

.stage-wrap {
  min-height: 0;
  display: grid;
  place-items: center;
}

.stage {
  width: min(100%, 980px);
  aspect-ratio: 16 / 9;
  min-height: 430px;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.room {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border: 5px solid #26333a;
  border-radius: 8px;
  background:
    radial-gradient(circle at 13% 18%, rgba(255, 255, 255, 0.42) 0 2.2%, transparent 2.5%),
    radial-gradient(circle at 48% 16%, rgba(255, 255, 255, 0.32) 0 1.8%, transparent 2.1%),
    radial-gradient(circle at 87% 36%, rgba(255, 255, 255, 0.28) 0 2%, transparent 2.3%),
    linear-gradient(180deg, var(--wall) 0 64%, var(--floor) 64% 100%);
  box-shadow: 0 18px 35px rgba(42, 48, 53, 0.18);
}

.room-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  pointer-events: none;
  z-index: 0;
}

.scene-shape {
  display: none;
}

.room.celebrate::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 25% 22%, rgba(247, 224, 114, 0.9) 0 0.7%, transparent 0.9%),
    radial-gradient(circle at 40% 18%, rgba(233, 111, 85, 0.9) 0 0.6%, transparent 0.8%),
    radial-gradient(circle at 62% 24%, rgba(94, 183, 183, 0.9) 0 0.7%, transparent 0.9%),
    radial-gradient(circle at 78% 18%, rgba(127, 201, 107, 0.9) 0 0.6%, transparent 0.8%);
  animation: confetti 0.9s ease-out forwards;
}

.room::before {
  content: "";
  position: absolute;
  inset: 63% 0 auto;
  height: 5px;
  background: var(--wall-shadow);
}

.window {
  position: absolute;
  left: 7%;
  top: 10%;
  width: 18%;
  height: 25%;
  border: 7px solid #fff9e9;
  border-radius: 8px;
  background: linear-gradient(180deg, #92d3dc 0%, #f9df9b 100%);
  box-shadow: inset 0 0 0 3px rgba(38, 51, 58, 0.12);
}

.window::before,
.window::after {
  content: "";
  position: absolute;
  top: -11px;
  width: 24%;
  height: calc(100% + 22px);
  border-radius: 0 0 18px 18px;
  background: #f08c79;
}

.window::before {
  left: -28%;
}

.window::after {
  right: -28%;
}

.window span {
  position: absolute;
  background: #fff9e9;
}

.window span:first-child {
  left: 50%;
  top: 0;
  width: 5px;
  height: 100%;
}

.window span:last-child {
  left: 0;
  top: 50%;
  width: 100%;
  height: 5px;
}

.shelf {
  position: absolute;
  right: 8%;
  top: 15%;
  width: 31%;
  height: 6%;
  border: 4px solid var(--desk-dark);
  border-radius: 8px;
  background: #c58b63;
  box-shadow: 0 22px 0 -8px rgba(103, 75, 60, 0.28);
}

.desk {
  position: absolute;
  left: 24%;
  top: 47%;
  width: 43%;
  height: 27%;
  border: 5px solid var(--desk-dark);
  border-radius: 10px;
  background: var(--desk);
  box-shadow: inset 0 10px 0 rgba(255, 255, 255, 0.08);
}

.desk::before,
.desk::after {
  content: "";
  position: absolute;
  bottom: -24%;
  width: 9%;
  height: 24%;
  background: var(--desk-dark);
}

.desk::before {
  left: 10%;
}

.desk::after {
  right: 10%;
}

.drawer {
  position: absolute;
  left: 34%;
  top: 26%;
  width: 32%;
  height: 42%;
  border: 4px solid var(--desk-dark);
  background: #a98268;
}

.drawer::after {
  content: "";
  position: absolute;
  left: calc(50% - 6px);
  top: calc(50% - 6px);
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #f6d777;
}

.rug {
  position: absolute;
  left: 10%;
  bottom: 5%;
  width: 43%;
  height: 19%;
  border-radius: 50%;
  background:
    repeating-radial-gradient(ellipse at center, rgba(255, 255, 255, 0.22) 0 8px, transparent 9px 22px),
    #f3c75d;
  opacity: 0.78;
}

.cat {
  position: absolute;
  right: 12%;
  bottom: 10%;
  width: 13%;
  height: 24%;
}

.cat.happy {
  animation: wiggle 0.52s ease-in-out 2;
}

.face {
  position: absolute;
  left: 13%;
  top: 20%;
  width: 74%;
  height: 62%;
  border: 4px solid #26333a;
  border-radius: 48% 48% 42% 42%;
  background:
    radial-gradient(circle at 32% 58%, rgba(233, 111, 85, 0.25) 0 8%, transparent 9%),
    radial-gradient(circle at 68% 58%, rgba(233, 111, 85, 0.25) 0 8%, transparent 9%),
    #fff3dd;
}

.ear {
  position: absolute;
  top: 8%;
  width: 31%;
  height: 30%;
  border: 4px solid #26333a;
  background: #fff3dd;
  transform: rotate(45deg);
}

.ear.left {
  left: 14%;
}

.ear.right {
  right: 14%;
}

.eye {
  position: absolute;
  top: 36%;
  width: 9%;
  height: 13%;
  border-radius: 50%;
  background: #26333a;
}

.eye:first-child {
  left: 31%;
}

.eye:nth-child(2) {
  right: 31%;
}

.nose {
  position: absolute;
  left: 47%;
  top: 54%;
  width: 8%;
  height: 8%;
  border-radius: 50%;
  background: #e96f55;
}

.tail {
  position: absolute;
  right: 2%;
  bottom: 24%;
  width: 34%;
  height: 42%;
  border: 6px solid #26333a;
  border-left: 0;
  border-bottom: 0;
  border-radius: 0 80% 0 0;
}

.cat::before {
  content: "";
  position: absolute;
  left: 28%;
  top: 58%;
  width: 16%;
  height: 6%;
  border-radius: 99px;
  background: #f3a08e;
  box-shadow: 34px 0 0 #f3a08e;
  z-index: 2;
}

.targets,
.items {
  position: absolute;
  inset: 0;
  z-index: 2;
}

.target,
.item {
  position: absolute;
  width: var(--w);
  height: var(--h);
}

.target {
  left: var(--x);
  top: var(--y);
  border: 3px dashed rgba(38, 51, 58, 0.38);
  border-radius: 18px;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.78), transparent 68%),
    rgba(255, 255, 255, 0.18);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.34),
    0 6px 16px rgba(38, 51, 58, 0.08);
  opacity: 0.76;
}

.target.done {
  border-color: rgba(62, 159, 88, 0.3);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: none;
  opacity: 0.18;
}

.target.hint {
  animation: pulse 0.7s ease-in-out 4;
}

.target.selected-target {
  opacity: 0.96;
  border-color: rgba(38, 125, 140, 0.64);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.5),
    0 0 0 7px rgba(247, 224, 114, 0.22),
    0 8px 18px rgba(38, 51, 58, 0.08);
}

.target.ready {
  opacity: 1;
  border-color: rgba(62, 159, 88, 0.82);
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.88), transparent 68%),
    rgba(127, 201, 107, 0.25);
  transform: scale(1.04);
}

.item {
  left: var(--start-x);
  top: var(--start-y);
  width: calc(var(--w) * var(--item-scale, 1));
  height: calc(var(--h) * var(--item-scale, 1));
  display: block;
  border: 0;
  border-radius: 20px;
  background: transparent;
  box-shadow: none;
  cursor: grab;
  user-select: none;
  touch-action: none;
  z-index: 10;
  -webkit-tap-highlight-color: transparent;
}

.item.returning {
  transition: left 0.24s ease-out, top 0.24s ease-out, transform 0.24s ease-out;
}

.item svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
  filter: drop-shadow(0 9px 0 rgba(38, 51, 58, 0.14)) drop-shadow(0 12px 14px rgba(38, 51, 58, 0.12));
}

.item.dragging {
  cursor: grabbing;
  z-index: 30;
  transform: scale(1.04);
}

.item.selected:not(.dragging):not(.placed) {
  z-index: 24;
  transform: translateY(-2%) scale(1.05);
}

.item.selected:not(.dragging):not(.placed) svg {
  filter:
    drop-shadow(0 0 0 rgba(255, 255, 255, 0.9))
    drop-shadow(0 12px 0 rgba(38, 51, 58, 0.12))
    drop-shadow(0 15px 18px rgba(38, 51, 58, 0.16));
}

.item.shake {
  animation: shake 0.24s ease-in-out;
}

.item.placed {
  cursor: default;
  animation: pop 0.22s ease-out;
}

.item.placed svg {
  filter: drop-shadow(0 3px 0 rgba(38, 51, 58, 0.08));
}

.message {
  min-height: 28px;
  text-align: center;
  color: var(--accent);
  font-weight: 900;
}

@keyframes confetti {
  0% {
    opacity: 0;
    transform: translateY(-8%);
  }

  30% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translateY(18%);
  }
}

@keyframes pop {
  50% {
    transform: scale(1.12);
  }
}

@keyframes pulse {
  50% {
    transform: scale(1.07);
    opacity: 1;
  }
}

@keyframes shake {
  25% {
    transform: translateX(-4%);
  }

  75% {
    transform: translateX(4%);
  }
}

@keyframes wiggle {
  50% {
    transform: rotate(-4deg) translateY(-3%);
  }
}

@media (max-width: 740px) {
  .app {
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    gap: 10px;
  }

  .topbar {
    align-items: flex-start;
  }

  .status {
    min-width: 112px;
  }

  .status span {
    font-size: 12px;
  }

  .status strong {
    font-size: 22px;
  }

  .stage {
    min-height: min(66vh, 560px);
    aspect-ratio: 9 / 12;
  }

  .window {
    width: 24%;
  }

  .shelf {
    right: 5%;
    width: 42%;
  }

  .desk {
    left: 17%;
    width: 53%;
  }

  .cat {
    right: 7%;
    width: 19%;
  }

  .controls {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    justify-content: stretch;
    gap: 8px;
  }

  button {
    width: 100%;
    min-width: 0;
    padding: 0 8px;
    font-size: 14px;
  }

  .item {
    --item-scale: 1.45;
  }

  .item.dragging {
    transform: scale(1.12);
  }

  .item.selected:not(.dragging):not(.placed) {
    transform: translateY(-2%) scale(1.12);
  }
}

@media (max-width: 740px) and (orientation: landscape) {
  .app {
    grid-template-columns: minmax(0, 1fr) 128px;
    grid-template-rows: auto minmax(0, 1fr) auto;
    align-items: stretch;
  }

  .topbar {
    grid-column: 1 / 3;
  }

  .stage-wrap {
    grid-column: 1;
  }

  .stage {
    min-height: 0;
    height: min(68vh, 410px);
    aspect-ratio: 16 / 9;
  }

  .controls {
    grid-column: 2;
    grid-row: 2;
    grid-template-columns: 1fr;
    align-content: center;
  }

  .message {
    grid-column: 1 / 3;
  }
}

@media (min-width: 741px) and (max-width: 1180px) {
  .stage {
    width: min(100%, 1040px);
    min-height: 520px;
  }
}
