/* Story House — styles
 * Phone-first portrait layout. Tablet portrait + landscape come in a later phase.
 * Phone-first means: don't fight the OS, keep tap targets ≥48px, no tiny text. */

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  width: 100%;
  background: #f3e8d0;          /* warm cream — matches the picture-book wash */
  color: #3a2a1c;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overflow: hidden;             /* the app is fixed-screen — nothing scrolls */
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

#app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;                /* works everywhere */
  height: 100svh;               /* small viewport height — never includes browser chrome, so nothing pops off screen when the URL bar appears */
  width: 100%;
  max-width: 720px;             /* cap on big screens; tablet layout takes over later */
  margin: 0 auto;
  overflow: hidden;
  min-height: 0;
}

/* ─── Top bar ─────────────────────────────────────────────── */

#topbar {
  display: grid;
  grid-template-columns: 56px 1fr 56px;
  align-items: center;
  padding: 12px 8px env(safe-area-inset-top, 0px) 8px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: #f3e8d0;
  min-width: 0;
  overflow: hidden;
}
.navbtn {
  background: none; border: none;
  font-size: 36px;
  color: #6b4f33;
  width: 56px; height: 56px;
  border-radius: 28px;
  cursor: pointer;
}
.navbtn:active { background: rgba(0,0,0,0.06); }
#room-title {
  text-align: center;
  min-width: 0;
  overflow: hidden;
}
#room-name {
  font-size: 22px;
  font-weight: 600;
  color: #3a2a1c;
  text-transform: lowercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#place-name {
  font-size: 13px;
  color: #8a6c4d;
  margin-top: 2px;
  text-transform: lowercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─── Stage (the room) ────────────────────────────────────── */

#stage {
  position: relative;
  overflow: hidden;
  background: #f3e8d0;
  display: flex;
  align-items: center;
  justify-content: center;
  /* prevent browser pan/zoom getting in the way of drag */
  touch-action: none;
  padding: 8px;
  /* CRITICAL: without these, the grid row tries to grow to fit the
     image's intrinsic size (1448x1086 etc.), blowing the layout off
     screen on mobile. min-height: 0 lets the row shrink to fit the
     viewport. */
  min-height: 0;
  min-width: 0;
}
/* The image renders naturally, scaled to fit the stage while
   preserving its aspect ratio. The flex item gets min-height: 0
   so it can actually shrink below its intrinsic size on iOS. */
#room-bg {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  min-height: 0;
  min-width: 0;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
}
/* Placements is positioned/sized by JS to exactly match the rendered
   image rect, so percentage coords inside it map onto the art. */
#placements {
  position: absolute;
  pointer-events: none;          /* the layer itself doesn't catch taps */
}
.placed { pointer-events: auto; }
.placed {
  position: absolute;
  /* x,y set inline as % */
  width: 22%;                   /* default doll size; props get a smaller width */
  transform: translate(-50%, -50%);
  pointer-events: auto;
  cursor: grab;
  user-select: none;
  -webkit-user-drag: none;
  transition: transform 80ms ease;
}
.placed.dragging {
  /* Hide the original while the drag-clone follows the pointer —
     otherwise two copies are visible until the user releases. */
  visibility: hidden;
}
.placed.prop { width: 14%; }
.placed img {
  width: 100%;
  height: auto;
  pointer-events: none;
  -webkit-user-drag: none;
  display: block;
}

/* ─── Toolbar (bottom) ───────────────────────────────────── */

#toolbar {
  background: #ead7b3;
  border-top: 1px solid #d4bd95;
  padding: 6px 0 max(6px, env(safe-area-inset-bottom));
  min-width: 0;
  overflow: hidden;
}
#group-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 4px 8px;
  scrollbar-width: none;
  min-width: 0;
}
#group-tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto;
  background: rgba(255,255,255,0.4);
  border: none;
  padding: 8px 14px;
  border-radius: 18px;
  font-size: 14px;
  color: #6b4f33;
  cursor: pointer;
  min-height: 36px;
  text-transform: lowercase;
}
.tab.active {
  background: #fff;
  color: #3a2a1c;
  font-weight: 600;
}

#tool-items {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 12px 12px;
  scrollbar-width: none;
  height: 96px;
  min-width: 0;
}
#tool-items::-webkit-scrollbar { display: none; }
.tool {
  flex: 0 0 auto;
  width: 72px;
  height: 72px;
  background: #fff8e7;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
  touch-action: none;
}
.tool img {
  max-width: 80%;
  max-height: 80%;
  pointer-events: none;
  -webkit-user-drag: none;
}
.tool.ghost { opacity: 0.4; }   /* shown while a clone is being dragged */

/* ─── Drag clone (the "ghost" following the finger) ──────── */
.drag-clone {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  width: 22%;                   /* same default as .placed */
  max-width: 160px;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.25));
}
.drag-clone.prop { width: 14%; max-width: 100px; }
.drag-clone img { width: 100%; height: auto; display: block; -webkit-user-drag: none; }

/* ─── Larger-screen taste of what's coming ───────────────── */
@media (min-width: 720px) {
  /* Phase 2 will take over: tablet portrait + tablet landscape
     cross-section view. For now we just centre the phone layout. */
}
