:root {
  --wood-dark: #6b3f21;
  --wood-mid: #9c6334;
  --cream: #fff9ee;
  --cream-warm: #ffeecf;
  --peach: #ff9c8a;
  --mint: #5ecfb8;
  --gold: #ffbe3b;
  --ink: #4f2c17;
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 20%, #4b3121 0%, #241710 100%);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Rounded Mplus 1c", system-ui, sans-serif;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
}

#stage-wrap {
  position: relative;
  height: 100dvh;
  max-height: 960px;
  aspect-ratio: 9 / 16;
  max-width: 100vw;
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55), 0 0 0 3px rgba(255, 232, 196, 0.22);
  background: #3d281a;
}

@media (max-width: 560px) {
  #stage-wrap {
    width: 100vw;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
    box-shadow: none;
  }
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: pointer;
}

/* Loading screen */
#loading-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #fff6e5 0%, #ffe6c2 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 50;
  transition: opacity 0.35s ease;
}

#loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.load-bar {
  width: 62%;
  height: 14px;
  background: #eed3b1;
  border-radius: 999px;
  overflow: hidden;
  border: 2px solid #8c532a;
}

#load-fill {
  width: 10%;
  height: 100%;
  background: linear-gradient(90deg, #ffbe3b, #ff8f70);
  transition: width 0.2s ease;
}

/* Title overlay (transparent over live bathhouse scene!) */
#title-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 58px 24px 66px;
  background: linear-gradient(180deg, rgba(48, 25, 10, 0.22) 0%, rgba(48, 25, 10, 0.02) 45%, rgba(48, 25, 10, 0.32) 100%);
  z-index: 30;
  transition: opacity 0.35s ease, transform 0.35s ease;
}

#title-overlay.hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(1.03);
}

.title-sign {
  background: linear-gradient(180deg, #fffaf0 0%, #ffebd0 100%);
  border: 4px solid var(--wood-dark);
  border-radius: 28px;
  padding: 16px 32px 14px;
  text-align: center;
  box-shadow: 0 10px 0 rgba(107, 63, 33, 0.45), 0 18px 34px rgba(0, 0, 0, 0.25);
  animation: gentleFloat 3.2s ease-in-out infinite;
}

.title-sign h1 {
  margin: 0;
  font-size: 34px;
  letter-spacing: 2px;
  color: var(--wood-dark);
  text-shadow: 0 2px 0 #fff;
}

.title-sign .subtitle {
  margin-top: 4px;
  font-size: 13px;
  font-weight: 700;
  color: #a46437;
  letter-spacing: 3px;
}

.primary-btn {
  appearance: none;
  border: 3.5px solid var(--wood-dark);
  background: linear-gradient(180deg, #ffd866 0%, #ffad33 100%);
  color: var(--wood-dark);
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 2px;
  padding: 15px 46px;
  border-radius: 999px;
  box-shadow: 0 6px 0 #b36614, 0 12px 24px rgba(56, 26, 6, 0.35);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.primary-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #b36614, 0 6px 12px rgba(56, 26, 6, 0.3);
}

/* Top HUD */
#hud-top {
  position: absolute;
  top: 12px;
  left: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  z-index: 20;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

#hud-top.hidden {
  opacity: 0;
}

.hud-pill {
  pointer-events: auto;
  background: rgba(255, 249, 238, 0.92);
  border: 2.5px solid var(--wood-dark);
  border-radius: 999px;
  padding: 5px 10px;
  box-shadow: 0 4px 0 rgba(107, 63, 33, 0.28);
  display: flex;
  align-items: center;
  gap: 6px;
}

.guest-badge {
  flex: 1;
  min-width: 0;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  border-radius: 18px;
  padding: 6px 11px;
}

.guest-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 800;
  gap: 4px;
}

.guest-name {
  color: var(--wood-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.progress-pct {
  color: #e06d2b;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.progress-track {
  width: 100%;
  height: 10px;
  background: #ead4b5;
  border-radius: 999px;
  overflow: hidden;
  border: 1.5px solid #9b6438;
}

#progress-fill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffbe3b 0%, #6be2c7 100%);
  transition: width 0.16s ease-out;
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  pointer-events: auto;
  flex-shrink: 0;
}

.icon-btn {
  appearance: none;
  background: rgba(255, 249, 238, 0.94);
  border: 2.5px solid var(--wood-dark);
  border-radius: 14px;
  height: 38px;
  padding: 0 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--wood-dark);
  font-size: 12px;
  font-weight: 800;
  box-shadow: 0 3px 0 rgba(107, 63, 33, 0.28);
  cursor: pointer;
  white-space: nowrap;
}

.icon-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(107, 63, 33, 0.28);
}

.treasure-pill img {
  width: 22px;
  height: 22px;
  object-fit: contain;
}

/* Bottom Tool Tray (Single-hand ergonomic 3-tool zone) */
#tool-tray {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(180deg, rgba(255, 248, 235, 0.94) 0%, rgba(246, 224, 192, 0.96) 100%);
  border: 3px solid var(--wood-dark);
  border-radius: 28px;
  padding: 9px 12px;
  box-shadow: 0 8px 0 rgba(95, 52, 23, 0.42), 0 14px 28px rgba(0, 0, 0, 0.28);
  z-index: 20;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

#tool-tray.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(24px);
}

.tool-btn {
  position: relative;
  appearance: none;
  width: 96px;
  height: 82px;
  border-radius: 20px;
  border: 3px solid transparent;
  background: rgba(255, 255, 255, 0.62);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.tool-btn img {
  width: 50px;
  height: 46px;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 3px 4px rgba(80, 42, 16, 0.2));
}

.tool-btn span {
  font-size: 12px;
  font-weight: 800;
  color: var(--wood-dark);
}

.tool-btn.active {
  background: linear-gradient(180deg, #fffdf7 0%, #ffe9b8 100%);
  border-color: var(--wood-dark);
  transform: translateY(-6px) scale(1.04);
  box-shadow: 0 6px 0 rgba(128, 74, 30, 0.35), 0 10px 18px rgba(255, 190, 59, 0.35);
}

.tool-btn.hint-pulse {
  animation: toolPulse 1.1s ease-in-out infinite;
  border-color: #36b5c7;
}

.tool-btn.hint-warm {
  animation: warmPulse 1.1s ease-in-out infinite;
  border-color: #ff8c52;
}

.tool-btn .hint-dot {
  display: none;
  position: absolute;
  top: -8px;
  right: -4px;
  background: #2cb5c8;
  color: #fff;
  font-size: 10px;
  font-weight: 900;
  padding: 2px 7px;
  border-radius: 999px;
  border: 2px solid #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
}

.tool-btn.hint-warm .hint-dot {
  background: #ff7f4d;
}

.tool-btn.hint-pulse .hint-dot,
.tool-btn.hint-warm .hint-dot {
  display: block;
}

.shop-dot {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 11px;
  height: 11px;
  border-radius: 999px;
  background: #ff5d73;
  border: 2px solid #fff;
  display: none;
}

.icon-btn.has-badge .shop-dot {
  display: block;
}

.coin-pill {
  background: linear-gradient(180deg, #fff7d6 0%, #ffe599 100%);
  color: #7c450c;
  font-variant-numeric: tabular-nums;
}

/* Hat picker strip inside Polaroid modal (balanced 2x2 grid) */
.hat-strip {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 7px;
  margin: 8px 0 12px;
}

.hat-chip {
  appearance: none;
  border: 2px solid #cfa97e;
  background: #fff8eb;
  border-radius: 14px;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 800;
  color: var(--wood-dark);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
}

.hat-chip.cant-afford {
  opacity: 0.6;
}

.hat-chip img {
  width: 20px;
  height: 20px;
  object-fit: contain;
}

.hat-chip.selected {
  border-color: var(--wood-dark);
  background: #ffe7a8;
  box-shadow: 0 2px 0 rgba(107, 63, 33, 0.3);
}

/* Shop Modal */
#shop-modal {
  position: absolute;
  inset: 0;
  background: rgba(45, 25, 12, 0.56);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 42;
  transition: opacity 0.25s ease;
}

#shop-modal.hidden {
  opacity: 0;
  pointer-events: none;
}

.shop-card {
  width: 100%;
  max-width: 375px;
  max-height: 82dvh;
  overflow-y: auto;
  background: #fffaf0;
  border: 3.5px solid var(--wood-dark);
  border-radius: 26px;
  padding: 16px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.38);
}

.shop-section-title {
  font-size: 13px;
  font-weight: 900;
  color: #9e5d32;
  margin: 10px 0 6px;
}

.shop-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.shop-item {
  background: #fffdf8;
  border: 2px solid #d5b48c;
  border-radius: 16px;
  padding: 9px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  cursor: pointer;
}

.shop-item.equipped {
  border-color: var(--wood-dark);
  background: #fff2cc;
}

.shop-item.cant-afford {
  opacity: 0.62;
  background: #f8f1e6;
}

.shop-item.affordable {
  border-color: #e6952e;
}

.shop-item-top {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 900;
  color: var(--wood-dark);
}

.soap-swatch {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 2px solid var(--wood-dark);
  flex-shrink: 0;
}

.shop-item-desc {
  font-size: 11px;
  color: #8b5c3a;
}

.shop-item-price {
  margin-top: 2px;
  font-size: 11px;
  font-weight: 900;
  color: #d4711b;
}

@keyframes warmPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 140, 82, 0.6); transform: scale(1); }
  50% { box-shadow: 0 0 0 12px rgba(255, 140, 82, 0); transform: scale(1.05); }
}

/* Level highlight banner & live stars below top HUD */
#level-banner {
  position: absolute;
  top: 62px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 24px);
  background: rgba(255, 250, 238, 0.9);
  border: 2px solid var(--wood-dark);
  border-radius: 999px;
  padding: 4px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  font-weight: 800;
  color: var(--wood-dark);
  box-shadow: 0 3px 0 rgba(107, 63, 33, 0.2);
  z-index: 19;
  pointer-events: none;
  transition: opacity 0.25s ease, background 0.2s ease;
}

#level-banner.hidden {
  opacity: 0;
}

#level-banner.fever {
  background: linear-gradient(90deg, #ffe066, #ff9ec4, #80f2e3);
  border-color: #b45309;
  color: #5c2408;
}

.banner-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.live-stars {
  flex-shrink: 0;
  letter-spacing: 1px;
  font-size: 13px;
}

.star-on {
  color: #f59e0b;
  text-shadow: 0 1px 0 #78350f;
}

.star-off {
  color: #d6c0a5;
}

/* 6-Level Progression Map Modal */
#map-modal {
  position: absolute;
  inset: 0;
  background: rgba(45, 25, 12, 0.62);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 38;
  transition: opacity 0.25s ease;
}

#map-modal.hidden {
  opacity: 0;
  pointer-events: none;
}

.map-card {
  width: 100%;
  max-width: 390px;
  max-height: 86dvh;
  overflow-y: auto;
  background: #fffaf0;
  border: 3.5px solid var(--wood-dark);
  border-radius: 26px;
  padding: 16px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.4);
}

.map-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

.level-tile {
  position: relative;
  appearance: none;
  background: linear-gradient(180deg, #fffdf8 0%, #fff2d9 100%);
  border: 2.5px solid var(--wood-dark);
  border-radius: 18px;
  padding: 10px 9px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(107, 63, 33, 0.28);
  transition: transform 0.14s ease;
}

.level-tile:active:not(.locked) {
  transform: translateY(2px);
}

.level-tile.locked {
  opacity: 0.56;
  background: #ede1ce;
  border-color: #a3866a;
  cursor: not-allowed;
  box-shadow: none;
}

.level-tile-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.level-badge {
  background: var(--wood-dark);
  color: #fff9ee;
  font-size: 11px;
  font-weight: 900;
  padding: 2px 7px;
  border-radius: 999px;
}

.level-tile-body {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.level-tile-body img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  flex-shrink: 0;
}

.level-tile.locked .level-tile-body img {
  filter: brightness(0.2);
  opacity: 0.45;
}

.level-title {
  font-size: 13px;
  font-weight: 900;
  color: var(--wood-dark);
  line-height: 1.2;
}

.level-tag {
  font-size: 10px;
  color: #9e5d32;
  margin-top: 2px;
  line-height: 1.25;
}

/* 3-Star Checklist inside Polaroid Summary */
.star-checklist {
  background: #fff6e5;
  border: 2px solid #e6cda9;
  border-radius: 14px;
  padding: 7px 10px;
  margin: 6px 0 8px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.star-row {
  font-size: 12px;
  font-weight: 800;
  color: #8f6b4a;
  display: flex;
  align-items: center;
  gap: 6px;
}

.star-row.done {
  color: var(--wood-dark);
}

/* Completion Polaroid Modal */
#summary-modal,
#album-modal {
  position: absolute;
  inset: 0;
  background: rgba(45, 25, 12, 0.56);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  z-index: 40;
  transition: opacity 0.28s ease;
}

#summary-modal.hidden,
#album-modal.hidden {
  opacity: 0;
  pointer-events: none;
}

.polaroid-card {
  width: 100%;
  max-width: 340px;
  background: #fffdf8;
  border: 3.5px solid var(--wood-dark);
  border-radius: 26px;
  padding: 16px 16px 20px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.38);
  text-align: center;
  animation: popIn 0.34s cubic-bezier(0.22, 1.32, 0.36, 1);
}

.polaroid-ribbon {
  display: inline-block;
  background: linear-gradient(90deg, #ff99b8, #ffbe5c);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  padding: 4px 16px;
  border-radius: 999px;
  margin-bottom: 10px;
  letter-spacing: 1px;
}

.polaroid-frame {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 16px;
  overflow: hidden;
  border: 3px solid #ecd6b8;
  background: #f5ead8;
}

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

.polaroid-title {
  margin: 12px 0 4px;
  font-size: 22px;
  font-weight: 900;
  color: var(--wood-dark);
}

.polaroid-note {
  margin: 0 0 14px;
  font-size: 13px;
  line-height: 1.45;
  color: #845331;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.secondary-btn {
  appearance: none;
  border: 2.5px solid var(--wood-dark);
  background: #fff4df;
  color: var(--wood-dark);
  font-size: 15px;
  font-weight: 800;
  padding: 12px 18px;
  border-radius: 999px;
  cursor: pointer;
}

.primary-btn.compact {
  font-size: 16px;
  padding: 12px 24px;
}

/* Album Modal */
.album-card {
  width: 100%;
  max-width: 370px;
  background: #fffaf0;
  border: 3.5px solid var(--wood-dark);
  border-radius: 26px;
  padding: 18px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.38);
}

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

.album-header h2 {
  margin: 0;
  font-size: 20px;
  color: var(--wood-dark);
}

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

.album-slot {
  background: #f4e4ca;
  border: 2.5px solid #c59b6d;
  border-radius: 16px;
  padding: 8px 6px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.14s ease;
}

.album-slot:hover {
  transform: translateY(-2px);
}

.album-slot img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 10px;
  background: #fffdf7;
}

.album-slot.locked img {
  filter: brightness(0.18) contrast(0.9);
  opacity: 0.45;
}

.album-slot .slot-name {
  margin-top: 6px;
  font-size: 12px;
  font-weight: 800;
  color: var(--wood-dark);
}

@keyframes gentleFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

@keyframes toolPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(54, 181, 199, 0.55); transform: scale(1); }
  50% { box-shadow: 0 0 0 12px rgba(54, 181, 199, 0); transform: scale(1.05); }
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.86) translateY(16px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
