/* Room Designer Studio — styles. Cozy, rounded, touch-first. */

:root {
  --pink: #f7b8d2;
  --pink-deep: #e98bb3;
  --lav: #c9b6f0;
  --mint: #9fd6ad;
  --cream: #fff6ef;
  --paper: #fffaf4;
  --ink: #4a3a48;
  --ink-soft: #7a6b78;
  --line: #ecd9e4;
  --shadow: 0 8px 22px rgba(120, 80, 110, 0.18);
  --shadow-sm: 0 3px 10px rgba(120, 80, 110, 0.16);
  --radius: 20px;
  --radius-sm: 14px;
  --font: "Baloo 2", "Quicksand", "Segoe UI Rounded", system-ui, -apple-system, "Helvetica Neue", sans-serif;
}

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

html, body {
  margin: 0; height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(160deg, #fde7f1 0%, #eee6ff 45%, #e4f3ff 100%);
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
}

#app { height: 100%; display: flex; flex-direction: column; }

.screen { height: 100%; display: flex; flex-direction: column; min-height: 0; }

/* --- boot splash ---------------------------------------------------------- */
.boot-splash { height: 100%; display: grid; place-content: center; text-align: center; gap: 12px; }
.boot-art { font-size: 64px; animation: floaty 2s ease-in-out infinite; }
.boot-text { color: var(--ink-soft); font-size: 18px; }
@keyframes floaty { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

.fatal { margin: auto; max-width: 460px; padding: 28px; text-align: center; color: var(--ink); background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); }

/* --- top bar -------------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(8px);
  border-bottom: 2px solid var(--line);
  flex: 0 0 auto; z-index: 50;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 20px; color: var(--pink-deep); }
.brand span:first-child { font-size: 24px; }

.topbtn {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 52px; min-height: 48px; padding: 4px 8px; gap: 1px;
  border: none; border-radius: var(--radius-sm); background: #fff;
  font-size: 22px; line-height: 1; color: var(--ink); cursor: pointer;
  box-shadow: var(--shadow-sm); transition: transform .12s, background .2s;
}
.topbtn:active { transform: scale(0.92); }
.topbtn-label { font-size: 10px; font-weight: 700; color: var(--ink-soft); }
.topbtn.night-on { background: #2b2150; color: #fff; }
.topbtn.night-on .topbtn-label { color: #d9d0ff; }
.topbtn.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%,100% { box-shadow: var(--shadow-sm); } 50% { box-shadow: 0 0 0 4px rgba(249, 139, 179, 0.4); } }

.room-title {
  display: inline-flex; align-items: center; gap: 6px; max-width: 38vw;
  border: none; background: #fff; border-radius: 999px; padding: 8px 14px;
  font-family: var(--font); font-weight: 800; font-size: 16px; color: var(--ink);
  box-shadow: var(--shadow-sm); cursor: pointer; overflow: hidden;
}
.rt-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rt-emoji { font-size: 18px; }

.coin-chip {
  display: inline-flex; align-items: center; gap: 5px;
  border: none; background: linear-gradient(180deg, #ffe9a8, #ffd166);
  border-radius: 999px; padding: 8px 14px; font-weight: 800; font-size: 17px;
  color: #7a5500; box-shadow: var(--shadow-sm); cursor: pointer;
}
.coin-ico { font-size: 18px; }
.coin-chip.bump { animation: bump .4s ease; }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.25); } 100% { transform: scale(1); } }

/* --- buttons -------------------------------------------------------------- */
.btn {
  border: none; border-radius: 999px; padding: 12px 20px;
  font-family: var(--font); font-weight: 800; font-size: 16px; cursor: pointer;
  box-shadow: var(--shadow-sm); transition: transform .12s, filter .2s;
}
.btn:active { transform: scale(0.95); }
.btn.small { padding: 8px 14px; font-size: 14px; }
.btn.big { padding: 16px 28px; font-size: 19px; }
.btn-primary { background: linear-gradient(180deg, #ffa6cf, var(--pink-deep)); color: #fff; }
.btn-ghost { background: #fff; color: var(--ink); }
.btn-danger { background: linear-gradient(180deg, #ff9aa2, #ef6b78); color: #fff; }
.btn-owned { background: #e8f5e9; color: #3f8a52; }
.btn-locked { background: #efe7ee; color: #b6a6b4; }
.btn:disabled { cursor: default; opacity: .85; }
.linkbtn { background: none; border: none; color: var(--ink-soft); text-decoration: underline; font-family: var(--font); font-size: 14px; cursor: pointer; }

/* ===========================================================================
   HOME
   =========================================================================== */
.home-screen { overflow-y: auto; }
.home-hint { text-align: center; color: var(--ink-soft); margin: 14px 0 6px; font-size: 16px; }
.home-foot { text-align: center; padding: 18px 0 calc(18px + env(safe-area-inset-bottom)); }

.slot-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;
  padding: 12px 18px 18px; max-width: 1000px; width: 100%; margin: 0 auto;
}
@media (max-width: 720px) { .slot-grid { grid-template-columns: repeat(2, 1fr); } }

.slot {
  position: relative; border-radius: var(--radius); overflow: hidden;
  background: #fff; box-shadow: var(--shadow); border: none; cursor: pointer;
  aspect-ratio: 4 / 3; padding: 0; transition: transform .14s;
}
.slot:active { transform: scale(0.97); }
.slot-empty {
  display: grid; place-content: center; gap: 6px; color: var(--pink-deep);
  background: repeating-linear-gradient(45deg, #fff 0 14px, #fff5fa 14px 28px);
  border: 3px dashed var(--pink);
}
.slot-empty .plus { font-size: 52px; font-weight: 800; line-height: .8; }
.slot-empty .slot-label { font-weight: 800; }

.slot-filled { display: flex; flex-direction: column; }
.slot-bar { display: flex; align-items: center; gap: 6px; padding: 8px 10px; background: #fff; }
.slot-emoji { font-size: 18px; }
.slot-name { font-weight: 800; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot-menu { border: none; background: #f3eaf0; border-radius: 50%; width: 30px; height: 30px; font-size: 18px; line-height: 1; cursor: pointer; color: var(--ink-soft); }

/* thumbnails (mini 2.5D corner room) */
.thumb { position: relative; flex: 1; overflow: hidden; cursor: pointer; background: #efe6ee; }
.thumb-bg { position: absolute; inset: 0; }
.thumb-bg .room-svg { width: 100%; height: 100%; display: block; }
.thumb-item { position: absolute; }
.thumb-item .sprite-svg { width: 100%; height: auto; display: block; }
.thumb-night::after { content: ""; position: absolute; inset: 0; background: #1a1438; opacity: .55; }

/* ===========================================================================
   ROOM EDITOR
   =========================================================================== */
.room-screen { background: #f3e9f2; }
.room-main { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.stage-wrap { flex: 1 1 auto; min-height: 0; min-width: 0; padding: 10px; display: flex; }

.stage {
  position: relative; flex: 1; border-radius: var(--radius); overflow: hidden;
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.5), var(--shadow);
  touch-action: none; background: #efe6ee;
}
/* the 2.5D corner-room background (SVG fills the stage) */
.room-bg { position: absolute; inset: 0; }
.room-bg .room-svg { width: 100%; height: 100%; display: block; }

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

.sprite { position: absolute; pointer-events: auto; cursor: grab; will-change: left, top; }
.sprite-art { width: 100%; height: 100%; transform-origin: 50% 100%; }
.sprite[data-placement="wall"] .sprite-art { transform-origin: 50% 50%; }
.sprite-svg { width: 100%; height: 100%; display: block; overflow: visible; }
.sprite.dragging { cursor: grabbing; }
.sprite.dragging .sprite-art { filter: drop-shadow(0 12px 14px rgba(0,0,0,.25)); }
.sprite.selected .sprite-art { filter: drop-shadow(0 0 0 #fff); outline: none; }
.sprite.selected::after {
  content: ""; position: absolute; inset: -8px; border-radius: 14px;
  border: 3px dashed var(--pink-deep); animation: marching 14s linear infinite;
  pointer-events: none;
}
@keyframes marching { to { background-position: 200px 0; } }

.sprite-shadow {
  position: absolute; left: 50%; bottom: -4px; width: 78%; height: 14px;
  transform: translateX(-50%); border-radius: 50%;
  background: radial-gradient(ellipse, rgba(0,0,0,.28), transparent 70%);
  pointer-events: none;
}

.sprite.pop-in { animation: popIn .4s cubic-bezier(.18,1.4,.4,1); }
@keyframes popIn { 0% { transform: scale(0) rotate(-8deg); } 70% { transform: scale(1.12); } 100% { transform: scale(1); } }
.sprite.poof { animation: poof .26s ease-in forwards; }
@keyframes poof { to { transform: scale(0.2) rotate(12deg); opacity: 0; } }

.place-ghost {
  position: fixed; pointer-events: none; z-index: 99999; opacity: .75;
  transform: translateZ(0); filter: drop-shadow(0 10px 12px rgba(0,0,0,.3));
}
.place-ghost.over { opacity: .95; }
.place-ghost .sprite-svg { width: 100%; height: 100%; }

/* --- the squishy wobble (showpiece) -------------------------------------- */
.wob-squishy { animation: wobSquishy .9s cubic-bezier(.36,.07,.19,.97); }
@keyframes wobSquishy {
  0%   { transform: scale(1, 1); }
  14%  { transform: scale(1.2, .8); }
  30%  { transform: scale(.86, 1.16); }
  46%  { transform: scale(1.12, .9); }
  62%  { transform: scale(.94, 1.07); }
  78%  { transform: scale(1.04, .97); }
  90%  { transform: scale(.99, 1.01); }
  100% { transform: scale(1, 1); }
}
.wob-medium { animation: wobMedium .5s ease-out; }
@keyframes wobMedium {
  0% { transform: scale(1,1); } 25% { transform: scale(1.08, .93); }
  55% { transform: scale(.96, 1.05); } 80% { transform: scale(1.02, .99); } 100% { transform: scale(1,1); }
}
.wob-hard { animation: wobHard .28s ease-in-out; }
@keyframes wobHard {
  0% { transform: translateX(0) rotate(0); } 20% { transform: translateX(-2px) rotate(-1.6deg); }
  40% { transform: translateX(2px) rotate(1.6deg); } 60% { transform: translateX(-1.4px) rotate(-.9deg); }
  80% { transform: translateX(1px) rotate(.5deg); } 100% { transform: none; }
}

/* --- night mode + glow ---------------------------------------------------- */
.night-overlay {
  position: absolute; inset: 0; pointer-events: none; z-index: 5000; opacity: 0;
  background: radial-gradient(120% 90% at 50% 30%, rgba(40,30,90,.35), rgba(10,8,30,.78));
  transition: opacity .5s ease;
}
.stage.is-night .night-overlay { opacity: .82; }
.glow-layer { position: absolute; inset: 0; pointer-events: none; z-index: 8000; }
.glow-room { position: absolute; inset: 0; }
.glow-room .room-glow-svg { width: 100%; height: 100%; display: block; }
.glow-halo { position: absolute; border-radius: 50%; mix-blend-mode: screen; filter: blur(6px); animation: glowPulse 3.4s ease-in-out infinite; }
@keyframes glowPulse { 0%,100% { opacity: .82; transform: scale(1); } 50% { opacity: 1; transform: scale(1.06); } }

/* ===========================================================================
   DOCK (tray / paint / customize)
   =========================================================================== */
.dock {
  flex: 0 0 auto; background: var(--paper);
  border-top: 3px solid var(--line); border-radius: 22px 22px 0 0;
  box-shadow: 0 -6px 20px rgba(120,80,110,.12);
  max-height: 42vh; display: flex; flex-direction: column; min-height: 0;
  padding-bottom: env(safe-area-inset-bottom);
}

/* Wide screens (iPad landscape, desktop): dock becomes a right sidebar so the
   room keeps its size even with the customize panel open. */
@media (min-width: 840px) {
  .room-main { flex-direction: row; }
  .dock {
    width: clamp(320px, 32vw, 400px); max-height: none; height: 100%;
    border-top: none; border-left: 3px solid var(--line);
    border-radius: 22px 0 0 22px;
    box-shadow: -6px 0 20px rgba(120,80,110,.12);
    padding-bottom: 0;
  }
  .item-row { flex-wrap: wrap; overflow-x: visible; }
}
.dock-tabs { display: flex; align-items: center; gap: 8px; padding: 8px 12px 4px; }
.dock-tab {
  border: none; background: #f3eaf0; color: var(--ink-soft); font-family: var(--font);
  font-weight: 800; font-size: 15px; padding: 8px 16px; border-radius: 999px; cursor: pointer;
}
.dock-tab.active { background: var(--pink); color: #fff; }
.dock-tools { margin-left: auto; display: flex; gap: 6px; }
.tool { border: none; background: #fff; border-radius: 50%; width: 42px; height: 42px; font-size: 22px; cursor: pointer; box-shadow: var(--shadow-sm); }
.tool:active { transform: scale(.92); }

.dock-body { overflow-y: auto; padding: 4px 12px 14px; -webkit-overflow-scrolling: touch; }

.cat-head { font-weight: 800; color: var(--ink-soft); font-size: 13px; text-transform: uppercase; letter-spacing: .4px; margin: 12px 2px 6px; }

.theme-chips { display: flex; gap: 8px; flex-wrap: wrap; padding: 4px 0 2px; }
.chip { border: none; background: #f1e7ee; color: var(--ink-soft); font-family: var(--font); font-weight: 700; padding: 6px 14px; border-radius: 999px; cursor: pointer; font-size: 14px; }
.chip.active { background: var(--lav); color: #fff; }

.item-row { display: flex; gap: 10px; overflow-x: auto; padding: 4px 2px 8px; -webkit-overflow-scrolling: touch; }
.tray-item {
  position: relative; flex: 0 0 auto; width: 84px; height: 96px;
  background: #fff; border-radius: var(--radius-sm); box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; align-items: center; padding: 6px; cursor: grab;
  transition: transform .12s;
}
.tray-item:active { transform: scale(.94); }
.tray-art { width: 100%; height: 60px; display: flex; align-items: center; justify-content: center; }
.tray-art .sprite-svg { max-width: 100%; max-height: 100%; }
.tray-name { font-size: 10px; font-weight: 700; color: var(--ink-soft); text-align: center; line-height: 1.05; margin-top: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tray-rare { position: absolute; top: 3px; right: 5px; color: #f5b301; font-size: 14px; }

.empty-note { padding: 20px; text-align: center; color: var(--ink-soft); }

/* paint panel */
.swatch-row { display: flex; flex-wrap: wrap; gap: 10px; padding: 4px 0; }
.swatch { width: 40px; height: 40px; border-radius: 50%; border: 3px solid #fff; box-shadow: var(--shadow-sm); cursor: pointer; transition: transform .12s; }
.swatch:active { transform: scale(.9); }
.swatch.active { border-color: var(--ink); transform: scale(1.08); }
.paint-hint { color: var(--ink-soft); font-size: 13px; margin-top: 12px; }

.glow-row { display: flex; align-items: center; gap: 8px; padding: 10px 2px; font-weight: 700; color: var(--ink); }
.glow-emoji { font-size: 18px; }
.switch { margin-left: auto; width: 52px; height: 30px; border-radius: 999px; border: none; background: #ddd2dc; position: relative; cursor: pointer; transition: background .2s; }
.switch .knob { position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: left .2s; }
.switch.on { background: var(--mint); }
.switch.on .knob { left: 25px; }

/* customize */
.cust-head { display: flex; align-items: center; padding: 10px 12px 4px; }
.cust-name { font-weight: 800; font-size: 18px; flex: 1; }
.cust-body { overflow-y: auto; padding: 0 12px 14px; }
.segmented { display: flex; gap: 8px; }
.seg { flex: 1; border: none; background: #f1e7ee; color: var(--ink); font-family: var(--font); font-weight: 800; padding: 12px 8px; border-radius: var(--radius-sm); cursor: pointer; font-size: 15px; }
.seg.active { background: var(--lav); color: #fff; }
.cust-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.cust-actions .btn { flex: 1; min-width: 120px; }

/* ===========================================================================
   MODALS, TOASTS, FX
   =========================================================================== */
/* The layer is a persistent full-viewport container; it must NOT intercept
   input when empty. Each backdrop re-enables pointer-events for itself. */
.modal-layer { position: fixed; inset: 0; z-index: 9000; pointer-events: none; }
.modal-backdrop {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 16px;
  background: rgba(60, 40, 70, 0); transition: background .2s; pointer-events: auto;
}
.modal-backdrop.open { background: rgba(60, 40, 70, .45); }
.modal-backdrop.closing { background: rgba(60, 40, 70, 0); }
.modal-card {
  width: min(560px, 96vw); max-height: 92vh; overflow-y: auto;
  background: var(--paper); border-radius: 26px; padding: 22px;
  box-shadow: 0 20px 60px rgba(60,40,70,.4); transform: scale(.92) translateY(10px); opacity: 0;
  transition: transform .22s cubic-bezier(.2,1.3,.4,1), opacity .2s;
}
.modal-backdrop.open .modal-card { transform: scale(1) translateY(0); opacity: 1; }
.modal-title { margin: 0 0 6px; font-size: 24px; color: var(--pink-deep); text-align: center; }
.modal-sub { margin: 0 0 14px; color: var(--ink-soft); text-align: center; font-size: 15px; }
.modal-actions { display: flex; gap: 10px; justify-content: center; margin-top: 18px; }
.modal-actions.wrap { flex-wrap: wrap; }
.confirm-msg { text-align: center; font-size: 17px; line-height: 1.4; }
.text-input { width: 100%; padding: 14px 16px; font-family: var(--font); font-size: 18px; border: 2px solid var(--line); border-radius: var(--radius-sm); outline: none; }
.text-input:focus { border-color: var(--pink); }

.menu-actions { display: flex; flex-direction: column; gap: 10px; }
.menu-actions .btn { width: 100%; }

/* new room type grid */
.type-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.type-card { position: relative; border: none; background: #fff; border-radius: var(--radius-sm); padding: 0 0 12px; cursor: pointer; box-shadow: var(--shadow-sm); overflow: hidden; transition: transform .12s; }
.type-card:active { transform: scale(.96); }
.type-swatch { height: 64px; width: 100%; }
.type-emoji { font-size: 30px; margin-top: 8px; }
.type-name { font-weight: 800; margin-top: 2px; }

/* welcome */
.welcome { text-align: center; }
.welcome-art { font-size: 56px; }
.welcome-list { text-align: left; max-width: 380px; margin: 6px auto 4px; padding-left: 18px; color: var(--ink); line-height: 1.7; }

/* challenge */
.challenge-modal { text-align: center; }
.ch-emoji { font-size: 56px; }
.ch-text { font-size: 20px; font-weight: 800; margin: 8px 0; }
.ch-status { display: inline-block; padding: 8px 16px; border-radius: 999px; background: #fff3cf; color: #8a6b00; font-weight: 800; margin: 6px 0; }
.ch-status.done { background: #e3f6e6; color: #2f7d3f; }

/* shop */
.shop-head { display: flex; align-items: center; justify-content: center; gap: 12px; position: relative; }
.shop-balance { background: linear-gradient(180deg, #ffe9a8, #ffd166); color: #7a5500; padding: 6px 14px; border-radius: 999px; font-weight: 800; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; margin-top: 8px; }
.shop-card { position: relative; background: #fff; border-radius: var(--radius-sm); padding: 10px; text-align: center; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 8px; }
.shop-card.owned { outline: 2px solid var(--mint); }
.shop-card.glowy { background: linear-gradient(180deg, #fff, #f6f0ff); }
.rare-badge { position: absolute; top: 6px; left: 6px; background: linear-gradient(180deg, #ffd86b, #f5a623); color: #6b4500; font-size: 10px; font-weight: 800; padding: 2px 8px; border-radius: 999px; }
.shop-preview { height: 90px; display: flex; align-items: center; justify-content: center; }
.shop-preview .sprite-svg { max-width: 100%; max-height: 100%; }
.shop-name { font-weight: 800; font-size: 14px; }
.shop-card .btn { width: 100%; padding: 10px; font-size: 14px; }

/* sticker station */
.sticker-station { }
.station-body { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }
.poster-canvas { width: 200px; height: 260px; flex: 0 0 auto; border-radius: 12px; box-shadow: var(--shadow); background: #fff; cursor: crosshair; touch-action: none; }
.poster-canvas .sprite-svg { width: 100%; height: 100%; }
.station-controls { flex: 1; min-width: 220px; }
.mini-label { font-weight: 800; color: var(--ink-soft); font-size: 12px; text-transform: uppercase; display: block; margin: 10px 0 4px; }
.stamp-palette { display: flex; flex-wrap: wrap; gap: 6px; }
.stamp-btn { width: 40px; height: 40px; font-size: 22px; border: 2px solid transparent; background: #fff; border-radius: 12px; cursor: pointer; box-shadow: var(--shadow-sm); }
.stamp-btn.active { border-color: var(--pink-deep); }
.size-row { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.size-btn { width: 40px; height: 36px; border: none; background: #f1e7ee; border-radius: 10px; font-weight: 800; cursor: pointer; }
.size-btn.active { background: var(--lav); color: #fff; }

/* toasts + fx */
.toast-layer { position: fixed; left: 0; right: 0; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 9500; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { background: rgba(50,35,55,.92); color: #fff; padding: 12px 18px; border-radius: 999px; font-weight: 700; box-shadow: var(--shadow); transform: translateY(20px); opacity: 0; transition: transform .25s, opacity .25s; display: flex; gap: 8px; align-items: center; max-width: 90vw; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast-emoji { font-size: 20px; }

.fx-layer { position: fixed; inset: 0; z-index: 9800; pointer-events: none; }
.fx-coin { position: fixed; font-size: 22px; will-change: transform, opacity; }
.fx-spark { position: fixed; width: 8px; height: 8px; border-radius: 50%; transition: transform .6s ease-out, opacity .6s ease-out; will-change: transform, opacity; }

@media (max-width: 560px) {
  .topbtn-label { display: none; }
  .modal-title { font-size: 20px; }
  .room-title { max-width: 32vw; }
}
