/* ===================== Clean your room! — styles ===================== */

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

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh; /* the visible viewport, so the boxes aren't hidden behind a phone's toolbar */
  overflow: hidden;
  font-family: "Baloo 2", system-ui, "Segoe UI", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  background: #f6d9b8;
}

#game {
  position: fixed;
  inset: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #f6d9b8;
}

/* ----------------------------- HUD ---------------------------------- */

#hud {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(clamp(8px, 2vw, 14px) + env(safe-area-inset-top, 0px))
           calc(clamp(12px, 3vw, 20px) + env(safe-area-inset-right, 0px))
           clamp(8px, 2vw, 14px)
           calc(clamp(12px, 3vw, 20px) + env(safe-area-inset-left, 0px));
  background: #fff6ea;
  border-bottom: 4px solid #e8bf8f;
  position: relative;
  z-index: 5;
}

.hud-item { min-width: 0; text-align: center; }
.hud-item.stat { margin-left: auto; } /* counter + music button sit together on the right */

#hearts {
  display: flex;
  gap: 2px;
  font-size: clamp(22px, 6vw, 36px);
  line-height: 1;
}

.heart { display: inline-block; }
.heart.lost { opacity: 0.55; }
.heart.pop { animation: heartPop 0.5s ease; }

@keyframes heartPop {
  0% { transform: scale(1.6) rotate(-15deg); }
  60% { transform: scale(0.8) rotate(10deg); }
  100% { transform: scale(1); }
}

.stat-label {
  font-size: clamp(14px, 3.6vw, 20px);
  font-weight: 700;
  color: #7a4a22;
  white-space: nowrap;
}

.stat-label b { color: #2f9c3a; display: inline-block; margin-left: 4px; }
#clean-num.bump { animation: bump 0.3s ease; }

@keyframes bump {
  50% { transform: scale(1.5); }
}

.mini-bar {
  margin: 4px auto 0;
  width: clamp(90px, 26vw, 160px);
  height: 10px;
  border-radius: 99px;
  background: #f0dcc4;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.12);
}

#clean-fill {
  height: 100%;
  width: 100%;
  transform: scaleX(0);
  transform-origin: left center;
  border-radius: 99px;
  background: linear-gradient(90deg, #9be86f, #35c65a);
  transition: transform 0.2s ease;
}

#music-btn {
  flex: 0 0 auto;
  font-size: clamp(18px, 4.6vw, 26px);
  line-height: 1;
  width: clamp(38px, 10vw, 50px);
  height: clamp(38px, 10vw, 50px);
  padding: 0;
  background: #fff;
  border: 3px solid #e8bf8f;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(160, 100, 40, 0.3);
  touch-action: manipulation;
}

#music-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(160, 100, 40, 0.3); }

/* ----------- Practice round: badge + Done where the hearts were ----------- */

.practice-hud {
  display: none;
  align-items: center;
  gap: 8px;
}

#hud.practicing #hearts { display: none; }
#hud.practicing .practice-hud { display: flex; }

.practice-badge {
  font-size: clamp(13px, 3vw, 17px);
  font-weight: 800;
  color: #d26a12;
  background: #fff7d6;
  border: 2px solid #ffc46f;
  border-radius: 99px;
  padding: 1px 10px;
  white-space: nowrap;
}

.practice-done {
  font-family: inherit;
  font-size: clamp(13px, 3vw, 17px);
  font-weight: 800;
  color: #7a4a22;
  background: #fff;
  border: 3px solid #e8bf8f;
  border-radius: 99px;
  padding: 2px 12px;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(160, 100, 40, 0.3);
  touch-action: manipulation;
}

.practice-done:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(160, 100, 40, 0.3); }

/* ----------------------------- The room ------------------------------ */

#room {
  flex: 1 1 auto;
  position: relative;
  min-height: 0;
}

#wall {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 38%;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.35) 0 22px, transparent 22px 44px),
    linear-gradient(180deg, #cfe6ff, #b9dbff);
  border-bottom: 10px solid #fff;
  box-shadow: 0 4px 0 #d8c2a6;
  overflow: hidden;
}

#floor {
  position: absolute;
  left: 0;
  right: 0;
  top: 38%;
  bottom: 0;
  background:
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.07) 0 2px, transparent 2px 70px),
    repeating-linear-gradient(180deg, rgba(0, 0, 0, 0.05) 0 2px, transparent 2px 36px),
    linear-gradient(180deg, #e2ab72, #d09456);
}

#rug {
  position: absolute;
  left: 22%;
  right: 22%;
  top: 22%;
  bottom: 14%;
  border-radius: 50%;
  background: radial-gradient(closest-side, #ffb3d1 0 40%, #ff8fbf 40% 60%, #ffc8e0 60% 80%, #ff8fbf 80%);
  opacity: 0.85;
}

.deco {
  position: absolute;
  line-height: 1;
  pointer-events: none;
}

.deco.window { left: 12%; top: 14%; font-size: clamp(54px, 13vmin, 110px); }
.deco.frame  { left: 46%; top: 16%; font-size: clamp(36px, 9vmin, 76px); }
.deco.plant  { right: 6%; bottom: 0; font-size: clamp(40px, 10vmin, 84px); }
.deco.bed    { left: 2%; bottom: -4px; font-size: clamp(70px, 17vmin, 140px); }
.deco.shelf  { right: 22%; bottom: 0; font-size: clamp(34px, 8vmin, 66px); }

#toys {
  position: absolute;
  inset: 0;
}

.toy {
  position: absolute;
  transform: translate(-50%, -50%) rotate(var(--rot, 0deg));
  font-size: clamp(42px, 10vmin, 78px);
  line-height: 1;
  cursor: grab;
  touch-action: none;
  filter: drop-shadow(0 5px 3px rgba(80, 40, 10, 0.35));
  transition: transform 0.15s ease;
}

.toy.pop-in { animation: toyIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1); }

@keyframes toyIn {
  from { transform: translate(-50%, -50%) scale(0); }
}

.toy.dragging {
  cursor: grabbing;
  z-index: 40;
  transform: translate(-50%, -60%) scale(1.25) rotate(0deg);
  filter: drop-shadow(0 14px 8px rgba(80, 40, 10, 0.35));
  transition: transform 0.1s ease;
}

.toy.returning {
  transition: left 0.3s ease, top 0.3s ease, transform 0.3s ease;
}

.toy.into-box {
  z-index: 40;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.3);
  opacity: 0;
  transition: left 0.25s ease, top 0.25s ease, transform 0.25s ease, opacity 0.25s ease 0.05s;
}

#toast {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  background: #fff;
  color: #c2185b;
  border: 3px solid #ff8fbf;
  border-radius: 99px;
  padding: 4px 18px;
  font-size: clamp(15px, 3.8vw, 20px);
  font-weight: 800;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  z-index: 30;
}

#toast.show { animation: toast 1.8s ease forwards; }

@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, 10px); }
  10%, 80% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, 0); }
}

/* ----------------------------- The boxes ----------------------------- */

#boxes {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: clamp(6px, 2vw, 18px);
  /* On a wide screen the boxes stay in a 900px row in the middle. */
  padding: 26px
           max(calc(clamp(10px, 3vw, 24px) + env(safe-area-inset-right, 0px)), calc((100% - 900px) / 2))
           calc(12px + env(safe-area-inset-bottom, 0px))
           max(calc(clamp(10px, 3vw, 24px) + env(safe-area-inset-left, 0px)), calc((100% - 900px) / 2));
  background: #c98a4f;
  border-top: 4px solid #a86c36;
}

.box {
  position: relative;
  height: clamp(86px, 17vh, 130px);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.box-inside {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 0;
  height: 46%;
  z-index: 0;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  font-size: clamp(22px, 5vmin, 36px);
  line-height: 1;
}

.box-inside span { display: inline-block; margin: 0 -4px; transform: rotate(var(--rot, 0deg)); }

.box-front {
  position: relative;
  z-index: 1;
  height: 72%;
  background: linear-gradient(180deg, #f2c185, #dca163);
  border: 3px solid #a86c36;
  border-radius: 6px 6px 10px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  box-shadow: inset 0 6px 0 rgba(255, 255, 255, 0.25), 0 5px 0 #8a5426;
}

/* The two open flaps on top of each box. */
.box-front::before,
.box-front::after {
  content: "";
  position: absolute;
  top: -16px;
  width: 50%;
  height: 16px;
  background: #e4ad6f;
  border: 3px solid #a86c36;
  border-bottom: none;
}
.box-front::before { left: -3px; transform: skewX(-20deg); transform-origin: bottom left; border-radius: 4px 0 0 0; }
.box-front::after  { right: -3px; transform: skewX(20deg); transform-origin: bottom right; border-radius: 0 4px 0 0; }

.box-label {
  background: #fff;
  color: #5a3414;
  border-radius: 8px;
  padding: 2px 6px;
  font-size: clamp(13px, 3.4vw, 22px);
  font-weight: 800;
  line-height: 1.1;
  text-align: center;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
}

.box.hover .box-front {
  background: linear-gradient(180deg, #ffe0a8, #f2c185);
  transform: scale(1.06);
  transition: transform 0.1s ease;
}

.box.happy .box-front { animation: happy 0.4s ease; }
@keyframes happy { 40% { transform: scale(1.12) translateY(-4px); } }

.box.shake .box-front { animation: shake 0.45s ease; }
@keyframes shake {
  20% { transform: translateX(-8px) rotate(-3deg); background: #ff9aa8; }
  40% { transform: translateX(8px) rotate(3deg); background: #ff9aa8; }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(4px); }
}

/* ------------------------- Effects + overlays ------------------------- */

#fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(80, 50, 30, 0.45);
  backdrop-filter: blur(3px);
  overflow-y: auto;
}

.overlay.show { display: flex; }
.overlay.win { background: rgba(255, 220, 120, 0.35); }
.overlay.lose { background: rgba(40, 50, 80, 0.5); }

.card {
  background: #fff;
  border-radius: 28px;
  border: 6px solid #e8bf8f;
  box-shadow: 0 16px 0 rgba(160, 100, 40, 0.25), 0 24px 40px rgba(0, 0, 0, 0.3);
  padding: clamp(20px, 5vw, 40px);
  max-width: 440px;
  width: 100%;
  margin: auto;
  text-align: center;
  animation: cardIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes cardIn { from { transform: scale(0.6) translateY(30px); opacity: 0; } }

.card-emoji { font-size: clamp(46px, 12vw, 72px); line-height: 1; margin-bottom: 6px; }

.card h1 {
  margin: 6px 0 4px;
  font-size: clamp(28px, 7vw, 44px);
  font-weight: 800;
  color: #d9622b;
  line-height: 1.1;
}

.overlay.win .card h1 { color: #ff9500; }
.overlay.lose .card h1 { color: #6a7fd0; }

.card p {
  margin: 8px 0;
  font-size: clamp(15px, 3.6vw, 19px);
  font-weight: 500;
  color: #4a3a2a;
}

.card p.byline {
  margin: 0 0 10px;
  font-size: clamp(15px, 3.6vw, 18px);
  font-weight: 800;
  color: #a85ff0;
}

.card p.small { font-size: clamp(13px, 3vw, 16px); color: #8a7a6a; }

.btn-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 0 14px; }

.big-btn {
  margin-top: 18px;
  font-family: inherit;
  font-size: clamp(20px, 5vw, 28px);
  font-weight: 800;
  color: #fff;
  background: linear-gradient(180deg, #ffa25f, #f0762b);
  border: none;
  border-radius: 99px;
  padding: 12px 32px;
  cursor: pointer;
  box-shadow: 0 6px 0 #c4561a, 0 10px 18px rgba(0, 0, 0, 0.25);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #c4561a, 0 4px 10px rgba(0, 0, 0, 0.25); }

.big-btn.alt-btn {
  color: #c4561a;
  background: linear-gradient(180deg, #fff, #ffeedd);
  box-shadow: 0 6px 0 #f2c79e, 0 10px 18px rgba(0, 0, 0, 0.18);
}

.big-btn.alt-btn:active { box-shadow: 0 2px 0 #f2c79e, 0 4px 10px rgba(0, 0, 0, 0.18); }

.lang-btn {
  display: block;
  margin: 18px auto 0;
  font-family: inherit;
  font-size: clamp(13px, 3vw, 16px);
  font-weight: 700;
  color: #c4561a;
  background: #fff;
  border: 2px solid #f2c79e;
  border-radius: 99px;
  padding: 4px 16px;
  cursor: pointer;
}

/* Short screens (a phone turned sideways): the boxes give up height first. */
@media (max-height: 520px) {
  .box { height: 74px; }
  .box-inside { font-size: 20px; }
  #hearts { font-size: 22px; }
}
