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

html, body {
  margin: 0; padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: 'Fredoka', 'Comic Sans MS', 'Segoe UI', sans-serif;
  background: linear-gradient(#ffe9f2, #fff6e9);
  color: #5a4a52;
  user-select: none;
  -webkit-user-select: none;
}

.screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
}
.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; border: none; color: inherit; }

/* ================= MENU ================= */
#menu-screen {
  align-items: center; justify-content: center;
  gap: 18px;
  background:
    radial-gradient(circle at 15% 20%, rgba(255,255,255,.8) 60px, transparent 61px),
    radial-gradient(circle at 22% 24%, rgba(255,255,255,.8) 45px, transparent 46px),
    radial-gradient(circle at 85% 15%, rgba(255,255,255,.7) 55px, transparent 56px),
    radial-gradient(circle at 78% 18%, rgba(255,255,255,.7) 40px, transparent 41px),
    linear-gradient(#c9e8ff 0%, #ffe9f2 65%, #ffd9a8 100%);
}
.game-title {
  font-size: clamp(44px, 9vw, 84px);
  font-weight: 700;
  margin: 0;
  color: #ff6f91;
  text-shadow: 0 4px 0 #ffffff, 0 8px 18px rgba(255, 111, 145, .35);
  letter-spacing: 2px;
  animation: titleWobble 3s ease-in-out infinite;
}
@keyframes titleWobble { 0%,100% { transform: rotate(-1.5deg); } 50% { transform: rotate(1.5deg); } }
.game-sub { font-size: 18px; margin: -8px 0 8px; opacity: .75; }

#menu-avatars { display: flex; gap: 6px; align-items: flex-end; height: 190px; }
.menu-avatar { width: 130px; height: 180px; animation: bob 2.2s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-14px); } }

.big-btn {
  font-size: 24px; font-weight: 600;
  padding: 16px 42px;
  border-radius: 999px;
  background: #ff8fab;
  color: #fff;
  box-shadow: 0 6px 0 #e06a8a, 0 12px 20px rgba(224, 106, 138, .3);
  transition: transform .1s, box-shadow .1s;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #e06a8a; }
.big-btn.alt { background: #7fc8f8; box-shadow: 0 6px 0 #5aa3d6, 0 12px 20px rgba(90, 163, 214, .3); }
.big-btn.alt:active { box-shadow: 0 2px 0 #5aa3d6; }

/* ================= SHARED CHROME ================= */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: rgba(255,255,255,.75);
  backdrop-filter: blur(6px);
  z-index: 50;
}
.icon-btn {
  font-size: 22px; font-weight: 700;
  width: 46px; height: 46px;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 3px 0 rgba(0,0,0,.08);
  flex-shrink: 0;
}
.icon-btn:active { transform: translateY(2px); box-shadow: none; }

#toast {
  position: fixed; left: 50%; top: 18px;
  transform: translate(-50%, -80px);
  background: #5a4a52; color: #fff;
  padding: 10px 22px; border-radius: 999px;
  font-size: 16px; z-index: 999;
  transition: transform .25s ease;
  pointer-events: none;
}
#toast.show { transform: translate(-50%, 0); }

.tab-btn {
  display: flex; align-items: center; gap: 6px;
  font-size: 15px; font-weight: 600;
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(255,255,255,.65);
  white-space: nowrap;
}
.tab-btn span { font-size: 18px; }
.tab-btn.active { background: #ff8fab; color: #fff; box-shadow: 0 3px 0 #e06a8a; }
.tab-btn.small { font-size: 13px; padding: 7px 12px; }

.tab-ico {
  width: 20px; height: 20px;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.tab-ico svg { width: auto !important; height: auto !important; max-width: 100%; max-height: 100%; }
.tab-ico.big { width: 26px; height: 24px; }

.opt-label { font-weight: 700; font-size: 15px; margin: 10px 4px 6px; opacity: .8; }

.swatch-row { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px; }
.swatch {
  width: 40px; height: 40px;
  border-radius: 14px;
  border: 3px solid rgba(255,255,255,.9);
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
  transition: transform .1s;
}
.swatch.active { border-color: #5a4a52; transform: scale(1.12); }
.swatch.big { width: 52px; height: 52px; }

.card-row { display: flex; flex-wrap: wrap; gap: 8px; }
.option-card {
  width: 68px; height: 68px;
  border-radius: 18px;
  background: #fff;
  border: 3px solid transparent;
  box-shadow: 0 2px 6px rgba(0,0,0,.1);
  padding: 4px;
  overflow: hidden;
}
.option-card.active { border-color: #ff8fab; background: #fff0f5; }
.option-card svg { pointer-events: none; }

.mini-btn {
  font-size: 15px;
  padding: 6px 10px;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 2px 0 rgba(0,0,0,.08);
}
.mini-btn.wide { width: 100%; padding: 10px; font-weight: 600; margin-top: 10px; }

/* ================= CREATOR ================= */
#creator-screen { background: linear-gradient(#e8f4ff, #fff0f5); }
#char-name {
  flex: 1; min-width: 60px;
  font-family: inherit; font-size: 18px; font-weight: 600;
  padding: 10px 16px;
  border: 3px solid #ffd3e0;
  border-radius: 999px;
  background: #fff;
  color: inherit;
  outline: none;
}
#char-name:focus { border-color: #ff8fab; }

.creator-body {
  flex: 1; display: flex; gap: 12px;
  padding: 12px; min-height: 0;
}
#creator-preview {
  flex: 0 0 38%;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 30%, #fff 0%, #ffe3ee 100%);
  border-radius: 28px;
  box-shadow: inset 0 0 0 4px rgba(255,255,255,.7);
}
.preview-avatar { width: min(100%, 300px); height: 92%; max-height: 430px; }
.preview-avatar svg { filter: drop-shadow(0 10px 10px rgba(90, 74, 82, .18)); }

.creator-panel {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
  background: rgba(255,255,255,.6);
  border-radius: 28px;
  padding: 12px;
}
#creator-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
#creator-options { flex: 1; overflow-y: auto; padding: 4px; }

@media (max-width: 640px) {
  .creator-body { flex-direction: column; }
  #creator-preview { flex: 0 0 40%; }
}

/* ================= HOUSE ================= */
#house-screen { background: #fff; }
#room-tabs { display: flex; gap: 6px; overflow-x: auto; flex: 1; }
.room-tab {
  display: flex; flex-direction: column; align-items: center;
  gap: 0; padding: 5px 14px;
  border-radius: 16px;
  background: rgba(255,255,255,.7);
  font-weight: 600;
}
.room-tab small { font-size: 11px; opacity: .75; }
.room-tab.active { background: #ffd166; box-shadow: 0 3px 0 #e0b04e; }

#room-view { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #6d4c41; }
#world {
  display: flex;
  height: 100%;
  touch-action: none;
  will-change: transform;
  cursor: grab;
}
#world:active { cursor: grabbing; }
.room-cell { position: relative; flex: 0 0 86%; }
/* shared wall between adjacent rooms */
.room-cell + .room-cell::before {
  content: '';
  position: absolute;
  left: -9px; top: 0; bottom: 0;
  width: 18px;
  background: linear-gradient(90deg, #a1887f, #8d6e63 50%, #795548);
  z-index: 800;
}
.room-wall { position: absolute; left: 0; right: 0; top: 0; height: 72%; }
.room-floor {
  position: absolute; left: 0; right: 0; bottom: 0; height: 28%;
  border-top: 5px solid rgba(0,0,0,.08);
}
.room-stage { position: absolute; inset: 0; touch-action: none; }

.placed {
  position: absolute;
  transform: translate(-50%, -50%);
  touch-action: none;
  cursor: grab;
}
.placed:active { cursor: grabbing; }
.placed > * { transition: transform .12s ease; }
.item-art {
  pointer-events: none;
  filter: drop-shadow(0 5px 5px rgba(0,0,0,.14));
}
.placed.char .char-body { width: 110px; height: 145px; pointer-events: none; }
.placed.char svg { filter: drop-shadow(0 5px 6px rgba(0,0,0,.18)); }
.char-name {
  text-align: center; font-size: 13px; font-weight: 700;
  color: #fff; background: rgba(90,74,82,.65);
  border-radius: 999px; padding: 1px 8px;
  width: fit-content; margin: -4px auto 0;
}
.placed.selected > * { outline: 3px dashed #ff8fab; outline-offset: 4px; border-radius: 12px; }

.char-body.bounce { animation: squash .5s ease; }
@keyframes squash {
  0% { transform: scale(1,1); }
  30% { transform: scale(1.15,.85); }
  60% { transform: scale(.9,1.12) translateY(-12px); }
  100% { transform: scale(1,1); }
}
.emote {
  position: absolute; top: 0;
  font-size: 26px;
  animation: floatUp 1.3s ease-out forwards;
  pointer-events: none;
}
@keyframes floatUp {
  0% { transform: translateY(0) scale(.4); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: translateY(-90px) scale(1.2); opacity: 0; }
}

#sel-toolbar {
  position: absolute;
  transform: translate(-50%, -100%);
  display: flex; gap: 6px;
  background: #fff;
  padding: 6px;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(0,0,0,.18);
  z-index: 900;
}
#sel-toolbar button {
  font-size: 18px; width: 40px; height: 40px;
  border-radius: 999px; background: #f6f0f3;
}
#sel-toolbar button:active { background: #ffd3e0; }
#sel-toolbar:not(.char-sel) [data-act="edit"] { display: none; }

/* drawer */
#drawer {
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(6px);
  border-top: 3px solid rgba(0,0,0,.05);
  padding: 8px 10px 12px;
  z-index: 60;
}
#drawer-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: thin; }
#drawer-content {
  display: flex; gap: 10px; align-items: center;
  overflow-x: auto; overflow-y: hidden;
  min-height: 114px;
  scrollbar-width: thin;
}
#drawer-content.grid2 {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(2, 1fr);
  gap: 8px;
  justify-content: start;
}
.shelf-item {
  width: 80px; height: 80px; flex-shrink: 0;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 3px 0 rgba(0,0,0,.08);
  transition: transform .1s;
  display: flex; align-items: center; justify-content: center;
  padding: 10px;
}
.shelf-item svg { width: auto !important; height: auto !important; max-width: 100%; max-height: 100%; }
.shelf-item:active { transform: scale(.9); }

.friend-card {
  position: relative;
  width: 96px; height: 110px; flex-shrink: 0;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 3px 0 rgba(0,0,0,.08);
  display: flex; flex-direction: column; align-items: center;
  padding-top: 4px;
  cursor: pointer;
}
.friend-avatar { width: 58px; height: 62px; pointer-events: none; }
.friend-name { font-size: 12px; font-weight: 700; pointer-events: none; }
.friend-actions { display: flex; gap: 4px; margin-top: 1px; }
.friend-actions .mini-btn { font-size: 11px; padding: 2px 6px; }
.friend-card.new { align-items: center; justify-content: center; background: #fff0f5; }
.friend-plus { font-size: 30px; }

.room-settings { display: flex; gap: 24px; align-items: flex-start; padding: 4px; }
.setting-group { flex-shrink: 0; }
.room-settings .swatch-row { max-width: 340px; }
.room-settings .mini-btn.wide { width: auto; margin-top: 34px; }

/* ================= CLOUD SAVE ================= */
.cloud-btn { position: absolute; top: 16px; right: 16px; font-size: 20px; }
.music-btn { position: absolute; top: 16px; right: 74px; font-size: 20px; }

#cloud-modal {
  position: fixed; inset: 0;
  background: rgba(90, 74, 82, .45);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000;
  padding: 20px;
}
.modal-card {
  position: relative;
  background: #fff;
  border-radius: 28px;
  padding: 24px 26px;
  max-width: 420px; width: 100%;
  box-shadow: 0 16px 40px rgba(0,0,0,.25);
}
.modal-card h2 { margin: 0 0 12px; font-size: 22px; color: #ff6f91; }
.modal-card p { margin: 8px 0; font-size: 15px; line-height: 1.45; }
.modal-close { position: absolute; top: 12px; right: 12px; width: 38px; height: 38px; font-size: 16px; background: #f6f0f3; }
.code-display {
  font-size: 26px; font-weight: 700; letter-spacing: 2px;
  text-align: center;
  background: #fff0f5;
  border: 3px dashed #ff8fab;
  border-radius: 16px;
  padding: 12px;
  margin: 10px 0;
  user-select: text;
  -webkit-user-select: text;
}
#cloud-code-input {
  width: 100%;
  font-family: inherit; font-size: 18px; font-weight: 600;
  text-transform: uppercase; text-align: center; letter-spacing: 1px;
  padding: 12px;
  border: 3px solid #ffd3e0; border-radius: 16px;
  outline: none; color: inherit;
  margin: 8px 0;
}
#cloud-code-input:focus { border-color: #ff8fab; }
.cloud-btn-row { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; margin: 10px 0; }
.cloud-hint { font-size: 13px; opacity: .75; text-align: center; min-height: 18px; margin-top: 6px; }

/* ================= WALLS ================= */
.wall-0 { background: #ffe9d6; }
.wall-1 { background: repeating-linear-gradient(90deg, #ffd6e0 0 44px, #ffc9d6 44px 88px); }
.wall-2 { background-color: #d7f0ff; background-image: radial-gradient(#ffffff 9px, transparent 10px); background-size: 70px 70px; }
.wall-3 { background: #e3f7dd; }
.wall-4 { background: repeating-linear-gradient(0deg, #fdf3c7 0 34px, #faeaa9 34px 68px); }
.wall-5 { background-color: #efe3ff; background-image: radial-gradient(#dcc7ff 12px, transparent 13px); background-size: 84px 84px; }
.wall-6 { background: linear-gradient(#a8d8ff, #e6f5ff 75%); }
.wall-7 { background: #ffd9c9; }
.wall-8 {
  background-color: #fff7fa;
  background-image: linear-gradient(45deg, #ffe0ec 25%, transparent 25%, transparent 75%, #ffe0ec 75%),
    linear-gradient(45deg, #ffe0ec 25%, transparent 25%, transparent 75%, #ffe0ec 75%);
  background-size: 64px 64px;
  background-position: 0 0, 32px 32px;
}
.wall-9 { background: #dff3f0; }

/* ================= FLOORS ================= */
.floor-0 { background: repeating-linear-gradient(90deg, #d9a066 0 72px, #cf9257 72px 76px); }
.floor-1 { background: repeating-linear-gradient(90deg, #e8c896 0 72px, #dfba82 72px 76px); }
.floor-2 {
  background-color: #bfe6f5;
  background-image: linear-gradient(45deg, #a5d9ee 25%, transparent 25%, transparent 75%, #a5d9ee 75%),
    linear-gradient(45deg, #a5d9ee 25%, transparent 25%, transparent 75%, #a5d9ee 75%);
  background-size: 56px 56px;
  background-position: 0 0, 28px 28px;
}
.floor-3 { background: #ffc9d6; }
.floor-4 { background: #9fdfcd; }
.floor-5 { background: linear-gradient(#8fd460, #7ec850); }
.floor-6 {
  background-color: #f6f1ea;
  background-image: linear-gradient(45deg, #e7ded2 25%, transparent 25%, transparent 75%, #e7ded2 75%),
    linear-gradient(45deg, #e7ded2 25%, transparent 25%, transparent 75%, #e7ded2 75%);
  background-size: 56px 56px;
  background-position: 0 0, 28px 28px;
}
.floor-7 { background: #cfc8c4; }
