/* Cottage builder edit mode (GROVE-2.3, docs/COTTAGE-BUILDER.md §5.1): edit bar, tray,
   selection toolbar, reason line, nudge pad. Built on the GROVE-1.9 frame (.pxf, .btn,
   .sheet-frame) and its tokens; 44 px targets on touch. */

/* The editor's canvas sits exactly over the world's (same placement variables). */
.canvas-wrap > #home-edit-canvas {
  position: absolute;
  display: block;
  left: var(--world-css-left, 50%);
  top: var(--world-css-top, 50%);
  width: var(--world-css-w, 100%);
  height: var(--world-css-h, auto);
  transform: var(--world-css-transform, translate(-50%, -50%));
  image-rendering: pixelated;
  touch-action: none;
  cursor: crosshair;
  outline: none;
  z-index: 1;
}
.canvas-wrap > #home-edit-canvas:focus-visible { outline: 3px solid var(--ui-focus-ring); outline-offset: -3px; }
#home-edit-canvas[hidden] { display: none; }

/* While editing, the play HUD steps aside: nothing else moves the room (§3). */
body.home-editing .topbar,
body.home-editing .game-tools,
body.home-editing #touch-controls,
body.home-editing #timer-dock,
body.home-editing #music-dock,
body.home-editing #world-label,
body.home-editing #world-guide,
body.home-editing #world-labels,
body.home-editing #chat-toggle { visibility: hidden; }

.home-edit[hidden] { display: none; }
.home-edit {
  --he-gap: var(--ui-s-2, 8px);
  /* GROVE-2.9: the landscape tray column's width. */
  --he-side-w: clamp(280px, 38vw, 380px);
  font-family: var(--ui-font-body);
  color: var(--ui-ink);
}

/* Edit bar (top). */
.home-edit-bar {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: var(--he-gap);
  padding: 6px 10px;
  max-width: calc(100vw - 16px);
  background: var(--ui-surface);
  flex-wrap: nowrap;
}
.home-edit-title { font: 600 var(--ui-fs-14)/1 var(--ui-font-display); white-space: nowrap; }
.home-edit-floors, .home-edit-tools, .home-edit-history, .home-edit-zoom, .home-edit-finish { display: inline-flex; gap: 4px; align-items: center; }
.home-edit-floors[hidden], .home-edit-tools[hidden], .home-edit-zoom[hidden] { display: none; }
.home-edit-chip {
  min-width: 36px;
  min-height: 36px;
  border: 2px solid var(--ui-line);
  background: var(--ui-surface-sunk);
  color: inherit;
  font: 600 var(--ui-fs-14)/1 var(--ui-font-display);
  border-radius: var(--ui-r-sm);
  cursor: pointer;
}
.home-edit-chip[aria-checked="true"] { background: var(--ui-selected); border-color: var(--ui-ink); }
.home-edit-chip:focus-visible, .home-edit button:focus-visible, .home-edit [tabindex]:focus-visible {
  outline: var(--ui-focus-ring-w, 3px) solid var(--ui-focus-ring);
  outline-offset: 2px;
}

/* The reason line: the ghost's verdict, a mark plus words. */
.home-edit-reason {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  top: calc(max(8px, env(safe-area-inset-top)) + 58px);
  z-index: 59;
  display: flex;
  gap: 6px;
  align-items: center;
  margin: 0;
  padding: 4px 10px;
  font-size: var(--ui-fs-14);
  background: var(--ui-surface);
  pointer-events: none;
  max-width: calc(100vw - 24px);
}
.home-edit-reason[hidden] { display: none; }
.home-edit-reason-mark { font-weight: 700; display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: var(--ui-r-pill); color: var(--ui-ink-on-dark); background: var(--ui-success-ink); }
.home-edit-reason[data-kind="bad"] .home-edit-reason-mark { background: var(--ui-danger); }
.home-edit-reason[data-kind="warn"] .home-edit-reason-mark { background: var(--ui-warning); color: var(--ui-ink); }

/* The floating selection toolbar. */
.home-edit-selbar {
  position: fixed;
  z-index: 61;
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--ui-surface);
  left: 50%;
  top: 30%;
}
.home-edit-selbar[hidden] { display: none; }
.home-edit-selbar [aria-disabled="true"] { opacity: 0.6; }
.home-edit-more-menu { position: absolute; top: calc(100% + 4px); right: 0; min-width: 200px; z-index: 62; }
.home-edit-more-menu[hidden] { display: none; }
.home-edit-more-menu .menu-item[aria-disabled="true"] { opacity: 0.6; }

/* "Buy another · 30". */
.home-edit-offer {
  position: fixed;
  z-index: 61;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--he-tray-h, 220px) + 12px);
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 10px;
  background: var(--ui-surface);
}
.home-edit-offer[hidden] { display: none; }

/* The nudge pad: phones and tablets (coarse pointers) only, in the tray's header so it
   never covers the room. */
.home-edit-nudge { display: none; gap: 4px; justify-content: flex-end; padding: 4px 0 0; }
.home-edit-nudge .btn { min-width: 44px; min-height: 44px; width: 44px; font-size: var(--ui-fs-16); }
@media (pointer: coarse) {
  .home-edit-nudge:not([hidden]) { display: flex; }
  .home-edit .btn, .home-edit-chip, .home-tray-tab { min-height: 44px; min-width: 44px; }
}

/* The tray: a bottom panel; three heights. */
.home-tray {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 58;
  width: min(760px, calc(100vw - 16px));
  display: flex;
  flex-direction: column;
  background: var(--ui-surface);
  padding: 4px 10px 10px;
  box-sizing: border-box;
}
.home-tray[data-height="strip"] { height: auto; }
.home-tray[data-height="half"] { height: min(260px, 38vh); }
.home-tray[data-height="full"] { height: min(560px, 72vh); }
.home-tray-handle { align-self: center; min-height: 20px; height: 20px; padding: 0 24px; background: transparent; border: 0; box-shadow: none; }
.home-tray-grip { display: block; width: 40px; height: 4px; border-radius: var(--ui-r-pill); background: var(--ui-line); }
.home-tray-tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--ui-line); }
.home-tray-tab {
  min-height: 36px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: inherit;
  font: 600 var(--ui-fs-14)/1 var(--ui-font-display);
  cursor: pointer;
  border-bottom: 3px solid transparent;
}
.home-tray-tab[aria-selected="true"] { border-bottom-color: var(--ui-ink); }
.home-tray-panel { flex: 1; min-height: 0; overflow: auto; padding-top: 6px; }
.home-tray[data-height="strip"] .home-tray-panel { display: none; }
.home-tray-help, .home-tray-empty { margin: 0 0 6px; font-size: var(--ui-fs-14); color: var(--ui-ink-muted); }
.home-tray-search { width: 100%; min-height: 36px; box-sizing: border-box; margin-bottom: 6px; padding: 4px 8px; font: inherit; }

.home-floor-list { list-style: none; margin: 0; padding: 2px; display: flex; flex-direction: column; gap: 2px; outline: none; }
.home-floor-list:focus-visible { outline: var(--ui-focus-ring-w, 3px) solid var(--ui-focus-ring); }
.home-floor-option { padding: 8px 10px; min-height: 28px; border-radius: var(--ui-r-sm); cursor: pointer; border: 2px solid transparent; }
.home-floor-option[aria-selected="true"] { background: var(--ui-selected); }
.home-floor-option[aria-selected="true"]::before { content: "✓ "; font-weight: 700; }
.home-floor-option.is-active { border-color: var(--ui-ink); }

.home-storage { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.home-storage-item { display: grid; grid-template-columns: 48px 1fr; gap: 4px 8px; align-items: center; padding: 6px; }
.home-storage-art { grid-row: span 2; width: 48px; height: 48px; image-rendering: pixelated; }
.home-storage-name { font-size: var(--ui-fs-14); }
.home-storage-item .btn { grid-column: 2; justify-self: start; }

/* GROVE-2.5: the Shop tab. Chips scroll in one row; tiles show the piece at 2x. */
.home-shop-head { position: sticky; top: -6px; z-index: 1; background: var(--ui-surface); padding-bottom: 2px; margin-top: -6px; padding-top: 6px; }
.home-shop-row { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
.home-shop-row .home-tray-search { flex: 1 1 180px; width: auto; margin-bottom: 0; }
.home-shop-cats, .home-shop-filters { display: flex; gap: 4px; margin-bottom: 6px; }
.home-shop-row .home-shop-filters { margin-bottom: 0; }
.home-shop-cats { overflow-x: auto; scrollbar-width: thin; padding-bottom: 2px; }
.home-shop-filters { flex-wrap: wrap; align-items: center; }
.home-shop-chip { padding: 0 10px; white-space: nowrap; flex: none; }
.home-shop-chip[aria-pressed="true"] { background: var(--ui-selected); border-color: var(--ui-ink); }
.home-shop-chip[aria-pressed="true"]::before { content: "✓ "; }
.home-shop-set { min-height: 36px; }
.home-shop-wallet { margin: 0; font-size: var(--ui-fs-14); color: var(--ui-ink-muted); display: flex; align-items: center; gap: 2px; }
.home-shop { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 6px; }
.home-shop-item { display: grid; grid-template-columns: 64px 1fr; gap: 2px 8px; align-items: center; padding: 6px; }
.home-shop-art { grid-row: span 4; width: 64px; height: 64px; image-rendering: pixelated; align-self: start; }
.home-shop-name { font-size: var(--ui-fs-14); font-weight: 600; }
.home-shop-meta { display: flex; gap: 8px; align-items: center; font-size: var(--ui-fs-14); }
.home-shop-price { display: inline-flex; align-items: center; gap: 2px; }
.home-shop-own, .home-shop-where { font-size: var(--ui-fs-14); color: var(--ui-ink-muted); }
.home-shop-item .btn { grid-column: 2; justify-self: start; max-width: 100%; white-space: normal; text-align: left; }
.home-shop-head + .home-shop, .home-shop-head + .home-tray-empty { margin-top: 6px; }
.home-shop-buy.is-short { opacity: 0.8; cursor: not-allowed; }

/* Asking before Cancel throws changes away. */
.home-edit-confirm {
  position: fixed;
  z-index: 70;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  padding: 14px 16px;
  background: var(--ui-surface);
  max-width: calc(100vw - 32px);
}
.home-edit-confirm[hidden] { display: none; }
.home-edit-confirm p { margin: 0 0 10px; font: 600 var(--ui-fs-16)/1.3 var(--ui-font-display); }
.home-edit-confirm-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* The hammer in the HUD. */
.home-edit-open[hidden] { display: none; }
.home-edit-open:disabled { opacity: 0.75; }

/* Phones: a compact bar, the tray full width as a bottom sheet. */
@media (max-width: 560px) {
  .home-edit-bar { left: 8px; right: 8px; transform: none; justify-content: space-between; gap: 4px; padding: 4px 6px; }
  /* GROVE-2.4: with Build and Paint the bar is two rows (tools; history and finish), never wider than the phone. */
  .home-edit-bar { flex-wrap: wrap; row-gap: 4px; }
  .home-edit-reason { top: calc(max(8px, env(safe-area-inset-top)) + var(--he-bar-h, 50px) + 8px); }
  .home-edit-title { display: none; }
  .home-edit-bar .btn { padding: 0 8px; }
  .home-tray { left: 0; right: 0; width: 100%; transform: none; bottom: 0; border-radius: var(--ui-r) var(--ui-r) 0 0; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .home-tray[data-height="half"] { height: 40vh; }
  .home-tray[data-height="full"] { height: 78vh; }
  .home-edit-selbar { gap: 2px; }
  .home-edit-selbar .btn { padding: 0 6px; }
}
/* Landscape phones: the tray is shorter so the room keeps its height. */
@media (max-height: 480px) {
  .home-edit-bar { top: 4px; padding: 2px 6px; }
  .home-edit-title { display: none; }
  /* GROVE-2.9: the tray is a narrow column on the right, under the edit bar, scrolling inside;
     the room is framed in the width left of it (play-layout.js, World.homeInsetRight). Its
     heights become open (the column) or collapsed (tabs only). */
  .home-tray, .home-tray[data-height="half"], .home-tray[data-height="full"] {
    width: var(--he-side-w); left: auto; right: max(8px, env(safe-area-inset-right)); transform: none;
    top: calc(max(4px, env(safe-area-inset-top)) + var(--he-bar-h, 48px) + 8px); bottom: max(4px, env(safe-area-inset-bottom)); height: auto;
  }
  .home-tray[data-height="strip"] { top: auto; height: auto; }
  .home-tray-tabs { overflow-x: auto; scrollbar-width: thin; }
  .home-tray-tab { flex: none; }
  .home-edit-reason { top: calc(max(4px, env(safe-area-inset-top)) + var(--he-bar-h, 48px) + 8px); left: var(--he-room-cx, 50%); max-width: calc(100vw - var(--he-side-w) - 32px); }
}

@media (prefers-reduced-motion: reduce) {
  .home-tray { transition: none; }
}

/* Touch: every control 44 px (WCAG 2.5.8 and the GROVE-1.9 frame); last, so it wins. */
@media (pointer: coarse) {
  .home-tray .home-tray-tab, .home-edit .home-edit-chip, .home-edit .btn { min-height: 44px; min-width: 44px; }
  /* GROVE-2.9 nav-audit: the tray's size handle is a 44 px target too (the grip stays small inside it). */
  .home-tray .home-tray-handle { height: 44px; min-height: 44px; margin: -12px 0 -8px; }
}

/* GROVE-2.5: Hazel's Market (town) and the read-only You → Home. */
.home-market-group { margin-bottom: 10px; }
.home-market-intro { margin: 0; color: var(--ui-ink-muted); font-family: var(--ui-font-body); font-size: var(--ui-fs-14); line-height: 1.5; }
.home-market-note, .home-summary-note { margin: 0 0 6px; font-size: var(--ui-fs-14); color: var(--ui-ink-muted); }
.home-market-status { min-height: 1.2em; font-size: var(--ui-fs-14); }
.home-shop-was { color: var(--ui-ink-muted); font-size: var(--ui-fs-14); }
.home-summary { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.home-summary h3, .home-summary h4 { margin: 0 0 4px; }
.home-summary p { margin: 0 0 4px; }
.home-summary-room-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: var(--ui-fs-14); }
.home-summary-stars { letter-spacing: 1px; }
.home-summary-rules { color: var(--ui-ink-muted); }
.home-summary-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

/* GROVE-2.4: the Build and Paint tabs (home-build-ui.js). */
.home-build-modes, .home-build-types { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.home-build-chip { min-height: 36px; padding: 0 10px; white-space: nowrap; }
.home-build-body { display: flex; flex-direction: column; gap: 6px; }
.home-build-pending { padding: 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.home-build-pending p { margin: 0; flex: 1 1 100%; font-weight: 600; }
.home-build-blockers { margin: 0; padding-left: 18px; flex: 1 1 100%; font-size: var(--ui-fs-14); }
.home-build-count { margin: 0; font-size: var(--ui-fs-14); color: var(--ui-ink-muted); }
.home-build-openings .home-build-chip, .home-paint-finishes .home-build-chip, #home-build-stairs .home-build-chip { grid-column: 2; justify-self: start; white-space: normal; text-align: left; }
.home-build-takeout { grid-template-columns: 1fr; }
.home-build-takeout .home-build-chip { grid-column: 1; }
.home-build-rooms { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.home-build-room { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
.home-build-room-pick[aria-pressed="true"] { background: var(--ui-selected); border-color: var(--ui-ink); }
.home-build-hint { font-size: var(--ui-fs-14); color: var(--ui-ink-muted); }
.home-build-room-panel { padding: 8px; display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.home-build-label { margin: 0; font-weight: 600; font-size: var(--ui-fs-14); }
.home-build-name { min-height: 36px; max-width: 280px; font: inherit; padding: 4px 8px; }
.home-build-complete { margin: 4px 0 0; font-size: var(--ui-fs-14); }
.home-build-room-panel .btn { align-self: flex-start; }
.home-build-expand { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; }
.home-build-expansion { padding: 8px; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.home-build-expansion-text { font-size: var(--ui-fs-14); color: var(--ui-ink-muted); }
.home-build-expansion [aria-disabled="true"] { opacity: 0.7; }

/* ---------- GROVE-12: preview before you buy (docs/PREVIEW-BEFORE-BUY.md) ---------- */
/* The tag that says a preview isn't bought yet: words, not colour alone. */
.buy-preview-tag {
  position: absolute; top: 8px; left: 8px; z-index: 1;
  padding: 2px 8px; border-radius: var(--ui-r-pill);
  background: var(--ui-surface); color: var(--ui-ink-strong);
  border: var(--ui-px) dashed var(--ui-warning);
  font-family: var(--ui-font-body); font-size: var(--ui-fs-14); font-weight: 600; line-height: 1.4;
  pointer-events: none;
}
.home-shop-item .home-market-preview { grid-column: 2; }
.decoration-toolbar .buy-preview-tag { position: static; align-self: center; }

/* The preview sheet: the room on top (phone), or left of the controls (wide, landscape). */
dialog.true-modal.buy-preview { width: min(960px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0 16px 16px; }
.buy-preview-body { display: grid; gap: 12px; }
.buy-preview-stage { position: relative; border-radius: var(--ui-r); overflow: hidden; background: var(--ui-surface-sunk); box-shadow: inset 0 0 0 var(--ui-px) var(--ui-line-deep); }
#buy-preview-canvas { display: block; width: 100%; height: auto; max-height: 62dvh; object-fit: contain; image-rendering: pixelated; }
.buy-preview-side { display: grid; gap: 10px; align-content: start; }
.buy-preview-pad { display: flex; flex-wrap: wrap; gap: 6px; }
.buy-preview-pad .btn { min-width: var(--ui-target, 44px); min-height: var(--ui-target, 44px); }
.buy-preview-status { margin: 0; min-height: 2.6em; font-size: var(--ui-fs-14); color: var(--ui-ink); }
.buy-preview-footer { display: flex; justify-content: flex-end; gap: 8px; position: sticky; bottom: 0; padding-top: 8px; background: var(--cz-paper, var(--ui-surface)); }
.buy-preview-footer .btn { min-height: var(--ui-target, 44px); }
@media (min-width: 760px) {
  .buy-preview-body { grid-template-columns: minmax(0, 1fr) 240px; align-items: start; }
}
@media (max-height: 480px) and (orientation: landscape) {
  dialog.true-modal.buy-preview { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); padding: 0 12px 12px; }
  dialog.true-modal.buy-preview .dialog-heading { padding: 8px 0 6px; margin-bottom: 6px; }
  .buy-preview-body { grid-template-columns: minmax(0, 1fr) 220px; align-items: start; }
  #buy-preview-canvas { max-height: calc(100dvh - 90px); }
}
