:root {
  --header-bg: #eab553;
  --header-border: #c58f32;
  --wall-bg: #fff5d9;
  --box-body: #faf6eb;
  --box-rim: #c9c3b6;
  --box-inner: #8f8a80;
  --box-border: #635345;
  --badge-teal: #58b4a8;
  --badge-teal-dark: #3f9186;
  --tray-bg: #d9cfc1;
  --tray-border: #6b5b4e;
  --slot-bg: #fff9ec;
  --slot-border: #847467;
  --ink: #4a3525;
  --yellow-glow: #ffe44d;
  --shadow-soft: 0 6px 16px rgba(74, 53, 37, 0.16);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at top, #f7e9cb 0%, #e5cfa7 100%);
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  color: var(--ink);
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

.app-shell {
  width: 100%;
  max-width: 440px;
  height: 100%;
  max-height: 860px;
  background: var(--wall-bg);
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 18px 48px rgba(62, 42, 22, 0.25);
  overflow: hidden;
}

@media (min-width: 500px) {
  .app-shell {
    height: 95vh;
    border-radius: 22px;
    border: 3px solid #635345;
  }
}

/* 顶部栏 */
.top-bar {
  height: 52px;
  background: linear-gradient(180deg, #f3c162 0%, var(--header-bg) 100%);
  border-bottom: 2.5px solid var(--header-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  flex-shrink: 0;
  z-index: 20;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 2px solid var(--ink);
  background: #fff8e6;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(74, 53, 37, 0.35);
  transition: transform 0.12s ease;
}

.icon-btn:active {
  transform: translateY(2px);
  box-shadow: none;
}

.title-center {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.game-title {
  font-size: 15px;
  font-weight: 800;
  color: #3f2814;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.progress-pill {
  font-size: 11px;
  font-weight: 700;
  background: rgba(255, 249, 232, 0.85);
  border: 1.5px solid #966c27;
  color: #5c3f16;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
}

.level-badge {
  background: #fff8e6;
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 11.5px;
  font-weight: 800;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  max-width: 170px;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 2px 0 rgba(74, 53, 37, 0.3);
  transition: transform 0.12s ease;
}

.level-badge:active {
  transform: translateY(2px);
  box-shadow: none;
}

/* 上方 HUD：收纳箱 + 暂存槽 */
.hud-panel {
  background: linear-gradient(180deg, #fae8bf 0%, #f8ebc9 100%);
  padding: 10px 12px 10px;
  border-bottom: 2px solid rgba(117, 91, 63, 0.22);
  flex-shrink: 0;
  z-index: 15;
}

.boxes-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 10px;
}

.storage-box {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: default;
  transition: transform 0.18s ease, filter 0.18s ease;
}

.storage-box.drag-hover {
  transform: scale(1.06);
  filter: drop-shadow(0 0 8px rgba(88, 180, 168, 0.85));
}

.storage-box.drag-reject {
  animation: shake 0.32s ease;
}

.storage-box.box-complete {
  animation: boxComplete 0.45s ease forwards;
}

.storage-box.box-enter {
  animation: boxEnter 0.35s cubic-bezier(0.22, 1.2, 0.36, 1) forwards;
}

.box-lid-rim {
  width: 92%;
  height: 18px;
  background: var(--box-rim);
  border: 2.2px solid var(--box-border);
  border-bottom: none;
  border-radius: 5px 5px 0 0;
  position: relative;
  overflow: hidden;
}

.box-lid-inner {
  position: absolute;
  inset: 3px 5px 0;
  background: var(--box-inner);
  border-radius: 2px 2px 0 0;
}

/* 放进箱子里的小缩略图露出一点 */
.box-peeking-items {
  position: absolute;
  top: -2px;
  left: 8px;
  right: 8px;
  height: 22px;
  display: flex;
  justify-content: center;
  gap: 2px;
  pointer-events: none;
  z-index: 2;
}

.box-peek-mini {
  width: 22px;
  height: 22px;
  animation: popIn 0.25s cubic-bezier(0.22, 1.3, 0.36, 1);
}

.box-peek-mini img,
.box-peek-mini svg {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.box-body {
  width: 100%;
  background: var(--box-body);
  border: 2.2px solid var(--box-border);
  border-radius: 4px 4px 8px 8px;
  padding: 5px 4px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 54px;
  box-shadow: 0 4px 0 rgba(74, 53, 37, 0.16), inset 0 -4px 0 rgba(0, 0, 0, 0.04);
  position: relative;
}

.box-body.is-empty {
  background: #eae4d8;
  opacity: 0.72;
}

.box-category-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.box-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.box-icon img,
.box-icon svg {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.box-label {
  font-size: 14px;
  font-weight: 800;
  color: #3a2717;
  white-space: nowrap;
}

.box-counter {
  position: absolute;
  bottom: -9px;
  background: var(--badge-teal);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  padding: 1px 10px;
  border-radius: 999px;
  border: 2px solid var(--box-border);
  box-shadow: 0 2px 0 rgba(74, 53, 37, 0.25);
  transition: transform 0.2s ease;
}

.box-counter.bump {
  transform: scale(1.2);
}

/* 暂存槽托盘 */
.tray-wrapper {
  display: flex;
  justify-content: center;
  margin-top: 4px;
}

.staging-tray {
  width: 100%;
  background: var(--tray-bg);
  border: 2.2px solid var(--tray-border);
  border-radius: 10px;
  padding: 6px;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  box-shadow: 0 3px 0 rgba(74, 53, 37, 0.2), inset 0 2px 0 rgba(255, 255, 255, 0.35);
}

.staging-slot {
  aspect-ratio: 1 / 1;
  background: var(--slot-bg);
  border: 2px solid var(--slot-border);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
  box-shadow: inset 0 2px 4px rgba(74, 53, 37, 0.1);
}

.staging-slot.drag-hover {
  background: #fff3bd;
  border-color: #d99b1e;
  transform: scale(1.06);
}

.staging-slot.warning {
  border-color: #d65445;
  background: #ffe8e5;
}

.slot-item {
  width: 82%;
  height: 82%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: popIn 0.22s cubic-bezier(0.22, 1.3, 0.36, 1);
  transition: transform 0.15s ease;
}

.slot-item:hover {
  transform: scale(1.1);
}

.slot-item svg,
.slot-item img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  overflow: visible;
  pointer-events: none;
  -webkit-user-drag: none;
}

/* 主房间场景 */
.stage-container {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #fbeec9;
}

.room-stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.room-bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.room-bg svg,
.room-bg img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: fill;
  -webkit-user-drag: none;
}

.items-layer {
  position: absolute;
  inset: 0;
}

.room-item {
  position: absolute;
  transform: translate(-50%, -50%) rotate(var(--rot, 0deg));
  transform-origin: center center;
  cursor: grab;
  transition: transform 0.16s ease, filter 0.16s ease, opacity 0.2s ease;
  touch-action: none;
}

.room-item svg,
.room-item img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  overflow: visible;
  pointer-events: none;
  -webkit-user-drag: none;
  filter: drop-shadow(0 3px 3px rgba(58, 39, 23, 0.28));
}

.room-item.pickable:hover {
  transform: translate(-50%, -50%) rotate(var(--rot, 0deg)) scale(1.08);
}

.room-item.pickable:hover svg,
.room-item.pickable:hover img,
.room-item.highlighted svg,
.room-item.highlighted img {
  filter:
    drop-shadow(0 0 2px #ffe64d)
    drop-shadow(0 0 6px #ffcf26)
    drop-shadow(0 4px 5px rgba(58, 39, 23, 0.35));
}

.room-item.highlighted {
  animation: pulseHint 0.9s ease-in-out infinite;
}

.room-item.is-covered {
  cursor: not-allowed;
}

.room-item.is-covered svg,
.room-item.is-covered img {
  filter: brightness(0.82) saturate(0.85) drop-shadow(0 2px 2px rgba(58, 39, 23, 0.2));
}

.room-item.is-covered:active {
  animation: shakeItem 0.28s ease;
}

.room-item.dragging {
  cursor: grabbing;
  opacity: 0.25;
}

/* 浮动提示条 */
.item-tooltip {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(62, 42, 22, 0.88);
  color: #fff9e8;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 999px;
  pointer-events: none;
  z-index: 30;
  white-space: nowrap;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.item-tooltip.hidden {
  display: none;
}

/* 底部辅助工具栏 */
.bottom-bar {
  flex-shrink: 0;
  background: linear-gradient(180deg, #f5e2ba 0%, #ebd09b 100%);
  border-top: 2px solid rgba(117, 91, 63, 0.25);
  padding: 6px 12px 8px;
  display: flex;
  justify-content: center;
  z-index: 25;
}

.bottom-tools {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.tool-btn {
  border: 1.8px solid rgba(99, 83, 69, 0.75);
  background: #fff9ec;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  padding: 6px 8px;
  border-radius: 999px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  white-space: nowrap;
  box-shadow: 0 2px 0 rgba(74, 53, 37, 0.18);
  transition: background 0.15s ease, transform 0.1s ease;
}

.tool-btn:hover {
  background: #fff0c7;
}

.tool-btn:active {
  transform: translateY(1px);
  box-shadow: none;
}

.tool-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* 飞行层 & 拖拽幽灵 */
.fx-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 90;
}

.flying-sprite {
  position: fixed;
  pointer-events: none;
  transform-origin: center center;
  filter: drop-shadow(0 8px 10px rgba(58, 39, 23, 0.35));
}

.flying-sprite svg,
.flying-sprite img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  overflow: visible;
  pointer-events: none;
}

.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 95;
  transform: translate(-50%, -50%) scale(1.16);
  filter:
    drop-shadow(0 0 4px #ffe64d)
    drop-shadow(0 10px 14px rgba(58, 39, 23, 0.38));
}

.drag-ghost svg,
.drag-ghost img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  overflow: visible;
  pointer-events: none;
}

/* 弹窗 */
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(42, 28, 16, 0.55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 100;
}

.modal-overlay.hidden {
  display: none;
}

.modal-card {
  width: 100%;
  max-width: 380px;
  background: #fff9eb;
  border: 3px solid var(--ink);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.3);
  max-height: 85vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 800;
}

.close-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: #f5e2ba;
  font-weight: 800;
  cursor: pointer;
}

.modal-section {
  margin-bottom: 16px;
}

.modal-section h3 {
  font-size: 13px;
  color: #7c5c3e;
  margin-bottom: 8px;
}

.level-summary {
  font-size: 12px;
  font-weight: 800;
  color: var(--badge-teal-dark);
  background: #e6f6f3;
  border: 1.5px solid #9fd5cd;
  padding: 6px 10px;
  border-radius: 10px;
  text-align: center;
}

.level-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 270px;
  overflow-y: auto;
  padding-right: 4px;
}

.level-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  background: #fff;
  border: 2px solid #b59d84;
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.level-card.active {
  border-color: var(--badge-teal-dark);
  background: #eaf8f6;
}

.level-card.cleared:not(.active) .level-card-tag {
  background: #d7f2ec;
  color: #21665d;
}

.level-card-title {
  font-size: 14px;
  font-weight: 800;
}

.level-card-sub {
  font-size: 12px;
  color: #7b6652;
}

.level-card-tag {
  font-size: 11px;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 999px;
  background: #f4d998;
  color: #5b3c12;
}

.mode-toggle-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mode-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px;
  background: #fff;
  border: 2px solid #cbb69e;
  border-radius: 12px;
  cursor: pointer;
}

.mode-option input {
  margin-top: 3px;
  accent-color: var(--badge-teal-dark);
}

.mode-option strong {
  font-size: 13px;
  display: block;
}

.mode-option p {
  font-size: 11px;
  color: #77634f;
  margin-top: 2px;
}

.modal-footer .tip-text {
  font-size: 11px;
  color: #826a52;
  line-height: 1.5;
  background: #f6ebd1;
  padding: 8px 10px;
  border-radius: 8px;
}

/* 结果弹窗 */
.result-card {
  text-align: center;
}

.result-emoji {
  font-size: 44px;
  margin-bottom: 6px;
}

.result-card h2 {
  font-size: 22px;
  margin-bottom: 6px;
}

.result-card p {
  font-size: 13px;
  color: #6b5642;
  margin-bottom: 14px;
}

.result-stats {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 16px;
}

.stat-chip {
  background: #f5ead1;
  border: 1.5px solid #cbb497;
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
}

.result-actions {
  display: flex;
  gap: 10px;
}

.primary-btn {
  flex: 1;
  padding: 10px 14px;
  border-radius: 12px;
  border: 2.2px solid var(--ink);
  background: var(--badge-teal);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(74, 53, 37, 0.25);
}

.primary-btn.secondary {
  background: #f5dfb0;
  color: var(--ink);
}

.primary-btn:active {
  transform: translateY(2px);
  box-shadow: none;
}

/* 动画 */
@keyframes popIn {
  0% { transform: scale(0.4); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes boxComplete {
  0% { transform: scale(1); opacity: 1; }
  35% { transform: scale(1.1) rotate(-2deg); }
  100% { transform: scale(0.6) translateY(-18px); opacity: 0; }
}

@keyframes boxEnter {
  0% { transform: scale(0.7) translateY(-16px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

@keyframes pulseHint {
  0%, 100% { transform: translate(-50%, -50%) rotate(var(--rot, 0deg)) scale(1.04); }
  50% { transform: translate(-50%, -50%) rotate(var(--rot, 0deg)) scale(1.14); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

@keyframes shakeItem {
  0%, 100% { transform: translate(-50%, -50%) rotate(var(--rot, 0deg)); }
  25% { transform: translate(-53%, -50%) rotate(var(--rot, 0deg)); }
  75% { transform: translate(-47%, -50%) rotate(var(--rot, 0deg)); }
}
