/* The Squishy Maker — pastel, cute, and iPad-friendly. */

:root {
  --pink: #ff8fc7;
  --pink-soft: #ffd9ec;
  --pink-deep: #ff5fa8;
  --purple: #c79bff;
  --mint: #8fe3c4;
  --yellow: #ffd86b;
  --ink: #4a3a52;
  --card: #ffffff;
  --bg-top: #ffeaf5;
  --bg-bottom: #e9ddff;
  --shadow: 0 8px 24px rgba(150, 90, 160, 0.18);
  --radius: 22px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

/* Make the HTML `hidden` attribute always win, even over rules like
   `.overlay { display: grid }`. Without this, hidden popups would still show. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Baloo 2', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg-top), var(--bg-bottom));
  user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 1100px;
  margin: 0 auto;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  flex: 0 0 auto;
  position: relative;
  z-index: 55;
}
.title { font-size: clamp(20px, 3vw, 30px); font-weight: 800; }
.coins {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 800;
  font-size: clamp(16px, 2.4vw, 22px);
  box-shadow: var(--shadow);
}
.coin-icon { font-size: 1.1em; }

/* ---------- Screens ---------- */
#screens { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 18px 18px; }
.screen-head h2 { margin: 4px 0 2px; font-size: clamp(22px, 3.4vw, 34px); }
.progress, .hint { color: #8a6d92; font-weight: 600; margin: 0 0 10px; }
.hint { font-size: 0.95em; }

/* ---------- Collection grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
}
.sq-card {
  border: none;
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: transform 0.12s ease;
  border: 3px solid var(--card-color, #fff);
}
.sq-card:active { transform: scale(0.95); }
.sq-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: radial-gradient(circle at 50% 40%, #fff, #ffeef7);
  border-radius: 16px;
}
.sq-thumb-fallback { display: grid; place-items: center; font-size: 48px; }
.sq-name { font-weight: 700; font-size: 1.05em; }

.empty { text-align: center; color: #9a7da2; margin-top: 12vh; }
.empty-emoji { font-size: 56px; }
.empty p { margin: 4px; font-size: 1.1em; }

/* ---------- Crafting ---------- */
.craft-layout { display: flex; gap: 18px; height: 100%; }
.craft-preview {
  flex: 1 1 45%;
  background: radial-gradient(circle at 50% 35%, #ffffff, #ffe6f4);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: relative;
  min-height: 280px;
  overflow: hidden;
}
.stage-mount { position: absolute; inset: 0; }
.stage-mount .three-canvas { width: 100% !important; height: 100% !important; display: block; }
.spin-hint {
  position: absolute; bottom: 10px; left: 0; right: 0;
  text-align: center; color: #b48fc0; font-weight: 600; font-size: 0.85em;
  pointer-events: none;
}

.craft-steps { flex: 1 1 55%; display: flex; flex-direction: column; min-width: 0; }
.step-tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.step-tab {
  flex: 1;
  border: none;
  background: #fff;
  border-radius: 14px;
  padding: 10px 6px;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.95em;
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow);
  opacity: 0.7;
}
.step-tab.is-active { opacity: 1; background: var(--pink); color: #fff; }

.step-panel { overflow-y: auto; }
.step-panel h3 { margin: 12px 0 8px; font-size: 1.05em; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  border: 3px solid transparent;
  background: #fff;
  border-radius: 16px;
  padding: 10px 14px;
  font-family: inherit;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow);
  font-size: 1em;
}
.chip-emoji { font-size: 1.3em; }
.chip.is-active { border-color: var(--pink); background: #fff0f8; }
.chip.is-locked { opacity: 0.5; cursor: not-allowed; background: #eee7f0; }

/* ---------- Color wheel ---------- */
.color-wheel-wrap {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 8px 0;
}
.color-wheel-canvas {
  width: 160px;
  height: 160px;
  cursor: crosshair;
  border-radius: 50%;
  flex-shrink: 0;
}
.color-preview {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 4px solid #fff;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

.big-btn {
  border: none;
  border-radius: 18px;
  padding: 16px 20px;
  font-family: inherit;
  font-weight: 800;
  font-size: 1.15em;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.make-btn {
  margin-top: auto;
  margin-top: 16px;
  background: linear-gradient(135deg, var(--pink), var(--purple));
  color: #fff;
}
.make-btn:active { transform: scale(0.97); }

/* ---------- Shop ---------- */
.desk {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 18px;
}
.desk-label { font-weight: 700; color: #8a6d92; margin-bottom: 8px; }
.desk-surface {
  position: relative;
  height: 160px;
  border-radius: 16px;
  background: linear-gradient(180deg, #fff7fb 0%, #ffe7d6 100%);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.desk-surface::after {
  content: '';
  position: absolute; left: 0; right: 0; bottom: 0; height: 38%;
  background: linear-gradient(180deg, #f0c9a0, #d9a877);
}
.desk-empty { color: #b48f7a; font-weight: 600; z-index: 1; }
.desk-pet {
  position: relative;
  z-index: 2;
  border: none;
  background: transparent;
  cursor: pointer;
  animation: bob 2.2s ease-in-out infinite;
}
.desk-pet-emoji { font-size: 84px; display: block; filter: drop-shadow(0 8px 6px rgba(0,0,0,0.15)); }
.desk-pet:active { transform: scale(0.92); }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }

.shop-head { margin: 8px 0 12px; }
.shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 14px;
}
.pet-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  text-align: center;
}
.pet-emoji { font-size: 50px; }
.pet-name { font-weight: 700; margin: 4px 0 10px; }
.buy-btn {
  border: none;
  width: 100%;
  border-radius: 14px;
  padding: 10px;
  font-family: inherit;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, var(--mint), #57c79b);
  cursor: pointer;
}
.buy-btn.owned { background: linear-gradient(135deg, var(--yellow), #f5b342); color: var(--ink); }
.buy-btn:disabled { background: #e7dff0; color: #9a8aa8; cursor: default; }

/* ---------- Bottom tab bar ---------- */
.tabbar {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-around;
  background: #fff;
  padding: 8px 8px calc(8px + var(--safe-bottom));
  box-shadow: 0 -6px 20px rgba(150, 90, 160, 0.12);
}
.tab {
  border: none;
  background: transparent;
  font-family: inherit;
  color: #b29abf;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 18px;
  border-radius: 16px;
  cursor: pointer;
  font-weight: 700;
}
.tab-emoji { font-size: 26px; }
.tab-label { font-size: 0.8em; }
.tab.is-active { color: var(--pink-deep); background: #fff0f8; }
.tab-add .tab-emoji {
  background: linear-gradient(135deg, var(--pink), var(--purple));
  color: #fff;
  width: 48px; height: 48px;
  border-radius: 50%;
  display: grid; place-items: center;
  box-shadow: var(--shadow);
  margin-top: -18px;
}

/* ---------- Overlays / popups ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(74, 58, 82, 0.45);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 18px;
}
.play-card, .confirm-card {
  background: #fff;
  border-radius: 26px;
  box-shadow: var(--shadow);
  position: relative;
  width: min(440px, 92vw);
  padding: 18px;
  text-align: center;
}
.close-btn {
  position: absolute; top: 10px; right: 12px;
  border: none; background: #ffe0ef; color: var(--pink-deep);
  width: 38px; height: 38px; border-radius: 50%;
  font-weight: 800; font-size: 1.1em; cursor: pointer;
}
.play-name-row { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 8px; }
.play-name { font-weight: 800; font-size: 1.4em; }
.rename-btn {
  border: none; background: #ffe0ef; color: var(--pink-deep);
  width: 34px; height: 34px; border-radius: 50%;
  font-size: 0.95em; cursor: pointer; line-height: 1;
}
.rename-btn:active { transform: scale(0.92); }
.rename-edit { display: flex; gap: 8px; justify-content: center; align-items: center; margin-bottom: 8px; }
.rename-input {
  font-family: inherit; font-weight: 700; font-size: 1.05em;
  padding: 8px 12px; border: 3px solid var(--pink); border-radius: 14px;
  color: var(--ink); width: min(220px, 56vw);
  user-select: text; -webkit-user-select: text;
}
.rename-input:focus { outline: none; border-color: var(--pink-deep); }
.rename-save { padding: 8px 16px; font-size: 1em; background: linear-gradient(135deg, var(--pink), var(--purple)); color: #fff; }
.play-mount { position: relative; height: min(52vh, 380px); width: 100%; }
.play-hint { color: #8a6d92; font-weight: 700; margin-top: 8px; }
.squish-pop { position: absolute; inset: 0; pointer-events: none; }
.pop-coin {
  position: absolute;
  top: 40%;
  font-weight: 800;
  color: var(--pink-deep);
  font-size: 1.3em;
  animation: floatUp 0.9s ease-out forwards;
}
@keyframes floatUp {
  from { transform: translateY(0); opacity: 1; }
  to { transform: translateY(-70px); opacity: 0; }
}

.confirm-emoji { font-size: 54px; }
.confirm-text { font-weight: 700; font-size: 1.2em; margin: 8px 0 18px; }
.confirm-buttons { display: flex; gap: 12px; }
.confirm-buttons .big-btn { flex: 1; }
.ghost { background: #eee7f5; color: var(--ink); }
.danger { background: linear-gradient(135deg, #ff8f8f, #ff5f7d); color: #fff; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  padding: 12px 20px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 60;
  text-align: center;
  max-width: 88vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Phone layout ---------- */
@media (max-width: 720px) {
  .craft-layout { flex-direction: column; }
  .craft-preview { flex: 0 0 38vh; }
}
