:root {
  /* Sky — soft day. Overridden live by JS (day/night) as --sky1/2/3 mix
     toward --night1/2/3 below; --sun-opacity/--stars-opacity/--night-tint-opacity
     ride the same clock. */
  --sky1: #bfe7f2; --sky2: #d7f0e0; --sky3: #eaf6d6;
  --night1: #131c3d; --night2: #1c2a4d; --night3: #283a5e;
  --sun-opacity: 1; --stars-opacity: 0; --night-tint-opacity: 0;
  /* Grass */
  --g-lo: #7cbf3f; --g-hi: #9fd957; --g-edge: #c8f08a;
  /* Soil island */
  --soil-lip: #c79a5e; --soil-face: #9a6a3c; --soil-deep: #6f4827;
  /* Road / path tiles (F11) */
  --road: #ddc18e; --road-edge: #c2a06a;
  /* UI warm */
  --cream: #fffef0; --ink: #4a3d28; --inks: #8a7a5e;
  --line: #e4d9be;
  --shadow: rgba(58,40,18,.18);
  /* Mind Dew */
  --dew: #7ed0e8; --dew-deep: #2c9cc0;
  /* sprout green — the "plant a thought" accent */
  --leaf: #8fcb6a; --leaf-deep: #5aa23f;
  /* warm wood — the "build / shape the farm" accent */
  --wood: #c79a5e; --wood-deep: #a8773f;
}
*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%;
  background: #bfe7f2;
  font-family: 'Nunito', -apple-system, system-ui, sans-serif;
  color: var(--ink); overflow: hidden;
  /* F26: the whole farm is a tappable canvas — suppress text selection and the
     iOS long-press callout everywhere so a held finger on a creature/tile never
     pops a selection menu. Real editable fields re-enable selection below. */
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
textarea, input, [contenteditable="true"] {
  -webkit-user-select: text; user-select: text; -webkit-touch-callout: default;
}
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* ---- SCENE (camera viewport) ---- */
#scene {
  position: relative; flex: 1; overflow: hidden;
  background: radial-gradient(120% 90% at 78% 8%, var(--sky3) 0%, var(--sky2) 38%, var(--sky1) 100%);
  cursor: grab;
  touch-action: none;
}
#scene.dragging { cursor: grabbing; }

/* warm sun glow in the corner — fades out at night via --sun-opacity */
#scene::before {
  content: ''; position: absolute; top: -120px; right: -80px;
  width: 360px; height: 360px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,238,170,.85) 0%, rgba(255,238,170,0) 68%);
  opacity: var(--sun-opacity); transition: opacity 2s ease;
  pointer-events: none; z-index: 1;
}
/* Day/night (sky-fixed, doesn't pan/zoom with #world): a generated starfield
   that fades in at night, and a multiply tint over the whole farm so the
   existing daytime art reads as night without redrawing any canvas. */
#stars {
  position: absolute; inset: 0; z-index: 1; pointer-events: none;
  opacity: var(--stars-opacity); transition: opacity 2.4s ease;
}
.star {
  position: absolute; border-radius: 50%; background: #fff;
  box-shadow: 0 0 4px rgba(255,255,255,.85);
}
#nightTint {
  position: absolute; inset: 0; z-index: 4; pointer-events: none;
  background: var(--night1); mix-blend-mode: multiply;
  opacity: var(--night-tint-opacity); transition: opacity 2.4s ease;
}
/* gentle vignette so the field feels nestled */
#scene::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 6;
  background: radial-gradient(130% 100% at 50% 42%, transparent 58%, rgba(58,40,18,.10) 100%);
}

/* ---- WORLD (panned by camera) ---- */
#world { position: absolute; top: 0; left: 0; transform-origin: 0 0; will-change: transform; z-index: 2; }
/* field holds the canvases */
#field { position: relative; }
#field canvas { position: absolute; top: 0; left: 0; display: block; }
#groundCanvas    { z-index: 1; }
#creatureCanvas  { z-index: 2; pointer-events: none; }
#hoverCanvas     { z-index: 3; pointer-events: none; }

/* ---- soft floating hint ---- */
#hint {
  position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%);
  z-index: 7; pointer-events: none;
  background: rgba(255,254,240,.86); color: var(--inks);
  font-size: 13px; font-weight: 700; letter-spacing: .01em;
  padding: 9px 18px; border-radius: 999px;
  box-shadow: 0 6px 18px var(--shadow), inset 0 1px 0 rgba(255,255,255,.8);
  backdrop-filter: blur(4px);
  transition: opacity .8s ease; opacity: 1;
}
#hint.gone { opacity: 0; }
#hint.empty-cue {
  left: auto; right: 16px; top: 68px; bottom: auto;
  transform: none; max-width: min(230px, calc(100vw - 32px));
  text-align: center; line-height: 1.35;
  transition: opacity .55s cubic-bezier(.32,.72,0,1), transform .55s cubic-bezier(.32,.72,0,1);
}
#hint.empty-cue::before {
  content: ''; position: absolute; right: 30px; top: -7px;
  width: 14px; height: 14px; transform: rotate(45deg);
  background: rgba(255,254,240,.86);
  box-shadow: inset 1px 1px 0 rgba(255,255,255,.65);
}
#hint.empty-cue.gone { transform: translateY(-4px); }

/* ---- Top bar (minimal calm frame: settings + dew counter + add thought) ---- */
#topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 16px;
  pointer-events: none; /* let drags through; children re-enable */
}
.tb-left { position: relative; display: flex; align-items: center; gap: 8px; pointer-events: none; }
.tb-pill {
  pointer-events: auto;
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--cream);
  border-radius: 999px;
  padding: 9px 16px;
  font-weight: 800; font-size: 15px; color: var(--ink);
  box-shadow: 0 6px 16px var(--shadow), inset 0 1px 0 rgba(255,255,255,.85);
  user-select: none;
}
/* settings: space reserved now, menu options wired up later */
.tb-icon-btn {
  pointer-events: auto;
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; flex: none;
  border: none; cursor: pointer;
  background: var(--cream); color: var(--inks);
  border-radius: 50%;
  box-shadow: 0 6px 16px var(--shadow), inset 0 1px 0 rgba(255,255,255,.85);
  transition: transform .2s cubic-bezier(.32,.72,0,1), background .2s ease, color .2s ease;
}
.tb-icon-btn svg { width: 20px; height: 20px; display: block; }
.tb-icon-btn:hover { background: #fff; color: var(--ink); }
.tb-icon-btn:active { transform: scale(.92); }
#dewCounter { color: var(--dew-deep); }
#dewCounter .drop-ic { color: var(--dew-deep); display: block; }
#dewValue { font-variant-numeric: tabular-nums; min-width: 1ch; }
#dewCounter.pop { animation: dewpop .42s cubic-bezier(.34,1.56,.64,1); }
@keyframes dewpop { 0%,100% { transform: scale(1); } 38% { transform: scale(1.16); } }

#addThought {
  border: none; cursor: pointer;
  background: var(--leaf); color: #fff;
  text-shadow: 0 1px 0 rgba(74,61,40,.18);
  box-shadow: 0 6px 16px rgba(90,162,63,.34), inset 0 1px 0 rgba(255,255,255,.45);
  transition: transform .25s cubic-bezier(.32,.72,0,1), box-shadow .25s ease, background .2s ease;
}
#addThought .plus { font-size: 18px; line-height: 0; margin-top: -1px; }
#addThought:hover { background: var(--leaf-deep); }
#addThought:active { transform: translateY(1px) scale(.97); box-shadow: 0 3px 10px rgba(90,162,63,.3); }

/* ---- Thought composer (small cozy sheet) ---- */
#thoughtModal {
  position: absolute; inset: 0; z-index: 30; display: none;
  align-items: center; justify-content: center; padding: 22px;
  background: rgba(58,40,18,.28); backdrop-filter: blur(3px);
}
#thoughtModal.open { display: flex; }
.modal-card {
  width: 100%; max-width: 408px;
  background: var(--cream); border-radius: 24px;
  padding: 22px 22px 18px;
  box-shadow: 0 22px 50px rgba(58,40,18,.32), inset 0 1px 0 rgba(255,255,255,.85);
  animation: cardrise .42s cubic-bezier(.32,.72,0,1);
}
@keyframes cardrise { from { transform: translateY(14px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-card h2 { margin: 0 0 4px; font-size: 19px; font-weight: 800; color: var(--ink); }
.modal-card p  { margin: 0 0 14px; font-size: 13px; color: var(--inks); font-weight: 600; }
#thoughtInput, #detailInput {
  width: 100%; resize: vertical;
  font-family: inherit; font-size: 15px; font-weight: 600; color: var(--ink);
  background: #fff; border: 2px solid var(--line); border-radius: 14px;
  padding: 12px 13px; line-height: 1.45;
  min-height: 132px; max-height: 46vh; overflow-y: auto;
  transition: border-color .2s ease, box-shadow .2s ease;
}
#thoughtInput::placeholder, #detailInput::placeholder { color: #c3b596; }
#thoughtInput:focus, #detailInput:focus { outline: none; border-color: var(--leaf); box-shadow: 0 0 0 4px rgba(143,203,106,.22); }

/* a thought can run long (ADHD brain-dumps welcome) — show how much room is
   left only as you approach the cap, so it's a quiet hint, never pressure. */
.tf-field-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-top: 8px; min-height: 16px;
}
.tf-count {
  display: none; margin-left: auto;
  font-size: 12px; font-weight: 700; color: var(--inks);
  font-variant-numeric: tabular-nums;
}
.tf-count.warn { color: #c77b6e; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; }
.modal-btn {
  border: none; cursor: pointer; font-family: inherit; font-weight: 800; font-size: 14px;
  padding: 13px 18px; border-radius: 999px; min-height: 44px; box-sizing: border-box;
  transition: transform .2s cubic-bezier(.32,.72,0,1), background .2s ease;
}
.modal-btn:active { transform: scale(.96); }
.modal-btn.ghost   { background: transparent; color: var(--inks); }
.modal-btn.ghost:hover { background: rgba(138,122,94,.12); }
.modal-btn.primary { background: var(--leaf); color: #fff; box-shadow: 0 6px 14px rgba(90,162,63,.32); }
.modal-btn.primary:hover { background: var(--leaf-deep); }
.modal-btn.primary:disabled { background: #d7e8c6; color: #fff; cursor: default; box-shadow: none; }

/* ---- Speech bubble (the thought, spoken back) ---- */
.bubble {
  position: absolute; z-index: 5; left: 0; top: 0;
  max-width: 190px; pointer-events: none;
  transform: translate(-50%, -100%);
  background: var(--cream); color: var(--ink);
  font-size: 13.5px; font-weight: 700; line-height: 1.32;
  padding: 9px 13px; border-radius: 15px;
  box-shadow: 0 8px 20px var(--shadow), inset 0 1px 0 rgba(255,255,255,.85);
  opacity: 0; transition: opacity .26s ease, transform .26s cubic-bezier(.32,.72,0,1);
  white-space: normal; word-break: break-word; text-align: center;
}
.bubble::after {
  content: ''; position: absolute; left: 50%; bottom: -7px; transform: translateX(-50%);
  border-left: 8px solid transparent; border-right: 8px solid transparent;
  border-top: 8px solid var(--cream);
}
.bubble.show { opacity: 1; transform: translate(-50%, -108%); }

/* ---- Floating "+N" dew collected feedback ---- */
.dew-float {
  position: absolute; z-index: 5; pointer-events: none;
  display: inline-flex; align-items: center; gap: 2px;
  font-size: 14px; font-weight: 800; color: var(--dew-deep);
  text-shadow: 0 1px 0 rgba(255,255,255,.7);
  animation: dewfloat 1s ease-out forwards;
}
.dew-float .drop-ic { color: var(--dew-deep); }
@keyframes dewfloat {
  0%   { transform: translate(-50%, -50%) scale(.7); opacity: 0; }
  18%  { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -190%) scale(1); opacity: 0; }
}

/* ---- Build dock (F5): toggle + four-tool palette ---- */
/* The shell that holds the building tools. Outside build mode the player
   just watches and collects; inside it, one tool is the active interaction.
   The tools are inert shells here — buy/place/move/delete/road are F6–F11. */
#buildDock {
  position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%);
  z-index: 20; display: flex; align-items: flex-end; gap: 10px;
  pointer-events: none; /* children re-enable */
}
#toolPalette {
  display: flex; gap: 4px; padding: 7px;
  background: var(--cream); border-radius: 22px;
  box-shadow: 0 10px 26px var(--shadow), inset 0 1px 0 rgba(255,255,255,.85);
  opacity: 0; transform: translateY(16px) scale(.95); pointer-events: none;
  transition: opacity .34s cubic-bezier(.32,.72,0,1),
              transform .34s cubic-bezier(.32,.72,0,1);
}
#buildDock.building #toolPalette { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }

.tool-btn {
  pointer-events: auto;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  width: 62px; padding: 9px 4px 7px;
  border: none; border-radius: 16px; cursor: pointer;
  background: transparent; color: var(--inks);
  font-family: inherit; font-weight: 800; font-size: 11px; letter-spacing: .01em;
  opacity: 0; transform: translateY(10px);
  transition: background .2s ease, color .2s ease,
              transform .3s cubic-bezier(.32,.72,0,1), opacity .3s ease;
}
#buildDock.building .tool-btn { opacity: 1; transform: translateY(0); }
#buildDock.building .tool-btn:nth-child(1) { transition-delay: .04s; }
#buildDock.building .tool-btn:nth-child(2) { transition-delay: .08s; }
#buildDock.building .tool-btn:nth-child(3) { transition-delay: .12s; }
#buildDock.building .tool-btn:nth-child(4) { transition-delay: .16s; }
.tool-btn .tool-ic { width: 26px; height: 26px; }
.tool-btn .tool-ic svg { width: 100%; height: 100%; display: block; }
.tool-btn:hover { background: rgba(143,203,106,.16); color: var(--ink); }
.tool-btn:active { transform: translateY(0) scale(.93); }
.tool-btn.active {
  background: var(--leaf); color: #fff;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.4), 0 5px 12px rgba(90,162,63,.32);
}

#buildToggle {
  pointer-events: auto;
  display: inline-flex; align-items: center; gap: 7px;
  border: none; cursor: pointer; font-family: inherit;
  font-weight: 800; font-size: 14px; color: #fff;
  padding: 11px 18px; border-radius: 999px;
  background: var(--wood);
  text-shadow: 0 1px 0 rgba(74,61,40,.18);
  box-shadow: 0 6px 16px rgba(120,84,40,.32), inset 0 1px 0 rgba(255,255,255,.4);
  transition: transform .25s cubic-bezier(.32,.72,0,1), background .2s ease, box-shadow .2s ease;
}
#buildToggle .bt-ic { width: 19px; height: 19px; display: inline-flex; }
#buildToggle .bt-ic svg { width: 100%; height: 100%; display: block; }
#buildToggle:hover { background: var(--wood-deep); }
#buildToggle:active { transform: translateY(1px) scale(.97); }
#buildDock.building #buildToggle {
  background: var(--leaf-deep);
  box-shadow: 0 6px 16px rgba(90,162,63,.34), inset 0 1px 0 rgba(255,255,255,.4);
}

/* F26: at full size, the open dock (palette + toggle) runs ~375px wide and
   clips against #scene's overflow:hidden on phones narrower than that —
   the toggle's right edge and a sliver of the palette get cut off. Shrink
   it down to ~310px so it sits centered with real margin on small phones. */
@media (max-width: 410px) {
  #buildDock { gap: 8px; }
  #toolPalette { gap: 3px; padding: 6px; }
  .tool-btn { width: 50px; padding: 7px 2px 6px; font-size: 10px; }
  .tool-btn .tool-ic { width: 22px; height: 22px; }
  #buildToggle { padding: 12px 13px; font-size: 13px; gap: 6px; }
  #buildToggle .bt-ic { width: 17px; height: 17px; }
}

/* ---- Shop catalog (F6): the Furniture tool's catalog of buildables ----
   A calm cozy bottom sheet. Read-only for now: name + preview + price, with
   affordability shown against current dew. Buying/placing arrives in F7. */
#shopScrim {
  position: absolute; inset: 0; z-index: 24;
  background: rgba(58,40,18,.22);
  opacity: 0; pointer-events: none;
  transition: opacity .34s ease;
}
#shopScrim.open { opacity: 1; pointer-events: auto; }

#shopSheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 25;
  display: flex; justify-content: center;
  transform: translateY(108%);
  transition: transform .44s cubic-bezier(.32,.72,0,1);
  pointer-events: none;
}
#shopSheet.open { transform: translateY(0); pointer-events: auto; }

.shop-card {
  position: relative;
  width: 100%; max-width: 440px;
  background: var(--cream);
  border-radius: 26px 26px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  box-shadow: 0 -16px 44px rgba(58,40,18,.28), inset 0 1px 0 rgba(255,255,255,.85);
}
.shop-grip {
  position: absolute; left: 50%; top: 7px; transform: translateX(-50%);
  width: 38px; height: 4px; border-radius: 999px; background: var(--line);
}
.shop-head { display: flex; align-items: center; gap: 10px; margin: 4px 0 12px; }
.shop-title {
  display: inline-flex; align-items: center; gap: 7px;
  font-weight: 800; font-size: 17px; color: var(--ink);
}
.shop-title .shop-ic { width: 19px; height: 19px; color: var(--wood-deep); display: inline-flex; }
.shop-title .shop-ic svg { width: 100%; height: 100%; display: block; }
.shop-bal {
  margin-left: auto;
  display: inline-flex; align-items: center; gap: 5px;
  background: #fff; border-radius: 999px; padding: 6px 12px;
  font-weight: 800; font-size: 14px; color: var(--dew-deep);
  box-shadow: inset 0 0 0 2px var(--line);
}
.shop-bal .drop-ic { color: var(--dew-deep); display: block; }
#shopDew { font-variant-numeric: tabular-nums; }
#shopClose {
  border: none; cursor: pointer; background: transparent;
  width: 40px; height: 40px; border-radius: 50%;
  color: var(--inks); font-size: 21px; font-weight: 800; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s ease, transform .2s ease;
}
#shopClose:hover { background: rgba(138,122,94,.14); color: var(--ink); }
#shopClose:active { transform: scale(.9); }

.shop-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  max-height: 46vh; overflow-y: auto; padding: 2px;
  -webkit-overflow-scrolling: touch;
}
@media (max-width: 380px) { .shop-grid { grid-template-columns: repeat(2, 1fr); } }

.furn-card {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 8px 6px 10px;
  background: #fffdf4; border-radius: 16px;
  box-shadow: inset 0 0 0 1.5px var(--line);
  transition: opacity .25s ease;
}
.furn-prev {
  position: relative;
  width: 96px; height: 78px; border-radius: 12px;
  background: radial-gradient(110% 90% at 50% 28%, #eaf6d6 0%, #d3ecb1 100%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.7), inset 0 -6px 12px rgba(120,150,70,.14);
  overflow: hidden;
}
.furn-prev canvas { display: block; }
/* dew-boost stat (F10): a small badge on the piece's preview — the reason to
   build it beyond looks. Warm amber so it reads as a bonus, not the dew price. */
.furn-boost {
  position: absolute; top: 5px; right: 5px;
  display: inline-flex; align-items: center; gap: 1px;
  background: rgba(255,254,240,.94);
  color: #c8881f;
  font-weight: 800; font-size: 10.5px; line-height: 1;
  padding: 2px 6px 2px 3px; border-radius: 999px;
  box-shadow: 0 2px 6px rgba(58,40,18,.18), inset 0 1px 0 rgba(255,255,255,.85);
}
.furn-boost .boost-ic { width: 11px; height: 11px; display: block; }
.furn-name {
  font-weight: 800; font-size: 12.5px; color: var(--ink);
  text-align: center; line-height: 1.15;
}
.furn-price {
  display: inline-flex; align-items: center; gap: 3px;
  font-weight: 800; font-size: 13px; color: var(--dew-deep);
}
.furn-price .drop-ic { color: var(--dew-deep); display: block; }
/* affordable cards are the buy surface (F7): tappable, with a gentle lift */
.furn-card.buyable { cursor: pointer; }
.furn-card.buyable:hover {
  box-shadow: inset 0 0 0 1.5px var(--leaf), 0 6px 16px rgba(90,162,63,.22);
  transform: translateY(-2px);
}
.furn-card.buyable:active { transform: translateY(0) scale(.97); }
/* can't-afford: gently dimmed, price reads muted-warm so it's clearly out of reach */
.furn-card.cant { opacity: .5; }
.furn-card.cant .furn-price { color: #c08a8a; }

/* ---- Placement banner (F7): calm guidance while a bought item follows
   the cursor, waiting for an empty tile. Loss-free: Esc cancels + refunds. */
#placeBanner {
  position: absolute; left: 50%; top: 66px; transform: translateX(-50%) translateY(-8px);
  z-index: 21; pointer-events: none;
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--cream); color: var(--ink);
  font-size: 13px; font-weight: 800; letter-spacing: .01em;
  padding: 9px 16px; border-radius: 999px;
  box-shadow: 0 8px 20px var(--shadow), inset 0 1px 0 rgba(255,255,255,.85);
  opacity: 0; transition: opacity .3s ease, transform .3s cubic-bezier(.32,.72,0,1);
}
#placeBanner.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#placeBanner .pb-name { color: var(--wood-deep); }
#placeBanner .pb-esc {
  font-weight: 700; font-size: 11.5px; color: var(--inks);
  border-left: 2px solid var(--line); padding-left: 8px;
}

/* ---- House entrance pill (F17): floats over the centre landmark, pans with
   it (it lives inside #field, in world space). Tapping it enters the interior. */
#houseLabel {
  position: absolute; z-index: 6;
  transform: translate(-50%, -100%);
  display: inline-flex; align-items: center; gap: 6px;
  border: none; cursor: pointer; font-family: inherit;
  font-weight: 800; font-size: 12.5px; color: var(--wood-deep);
  background: rgba(255,254,240,.94);
  padding: 6px 12px; border-radius: 999px;
  box-shadow: 0 6px 16px var(--shadow), inset 0 1px 0 rgba(255,255,255,.9);
  transition: transform .2s cubic-bezier(.32,.72,0,1), box-shadow .2s ease, opacity .25s ease;
}
#houseLabel::after {                       /* little pointer toward the house */
  content: ''; position: absolute; left: 50%; bottom: -6px; transform: translateX(-50%);
  border-left: 6px solid transparent; border-right: 6px solid transparent;
  border-top: 6px solid rgba(255,254,240,.94);
}
#houseLabel:hover { box-shadow: 0 8px 20px var(--shadow), inset 0 1px 0 rgba(255,255,255,.9); transform: translate(-50%, -104%); }
#houseLabel:active { transform: translate(-50%, -98%) scale(.96); }
#houseLabel.hidden { opacity: 0; pointer-events: none; }
#houseCount {
  display: none;
  min-width: 17px; height: 17px; padding: 0 4px; border-radius: 999px;
  background: var(--leaf); color: #fff; font-size: 11px; line-height: 17px; text-align: center;
}
#houseLabel.has-keepsakes #houseCount { display: inline-block; }

/* ---- House interior (F17): a calm full-screen room over the farm ---- */
#houseView {
  position: absolute; inset: 0; z-index: 40;
  display: flex; align-items: stretch; justify-content: center;
  background:
    radial-gradient(120% 80% at 50% 0%, #f3e2c2 0%, #e7cfa6 46%, #d8b986 100%);
  opacity: 0; pointer-events: none;
  transition: opacity .4s ease;
}
#houseView.open { opacity: 1; pointer-events: auto; }
.house-room {
  position: relative; width: 100%; max-width: 560px;
  display: flex; flex-direction: column;
  padding: 16px 16px calc(18px + env(safe-area-inset-bottom));
  transform: translateY(14px);
  transition: transform .44s cubic-bezier(.32,.72,0,1);
}
#houseView.open .house-room { transform: translateY(0); }
/* a soft wood "floor" band along the bottom, so it reads as a room */
.house-room::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 64px; z-index: -1;
  background: linear-gradient(180deg, rgba(150,106,60,0) 0%, rgba(150,106,60,.18) 100%);
  pointer-events: none;
}
.house-bar { display: flex; align-items: flex-start; gap: 12px; margin: 4px 2px 14px; }
.house-titles h2 { margin: 0; font-size: 20px; font-weight: 800; color: var(--ink); }
.house-titles p  { margin: 2px 0 0; font-size: 13px; font-weight: 600; color: var(--inks); }
#houseClose {
  margin-left: auto;
  border: none; cursor: pointer; background: rgba(255,254,240,.8);
  width: 44px; height: 44px; border-radius: 50%;
  color: var(--inks); font-size: 23px; font-weight: 800; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px var(--shadow), inset 0 1px 0 rgba(255,255,255,.85);
  transition: background .2s ease, transform .2s ease, color .2s ease;
}
#houseClose:hover { background: #fff; color: var(--ink); }
#houseClose:active { transform: scale(.92); }

/* text search — substring match against the thought only, no other filters */
.house-search {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,254,240,.85); border-radius: 999px;
  padding: 0 14px; margin: 0 2px 12px; height: 44px; flex: none;
  box-shadow: inset 0 0 0 1.5px var(--line);
}
.house-search-ic { width: 18px; height: 18px; flex: none; display: flex; color: var(--inks); }
.house-search-ic svg { width: 100%; height: 100%; display: block; }
#houseSearchInput {
  flex: 1; min-width: 0; border: none; background: transparent; outline: none;
  font-family: inherit; font-weight: 700; font-size: 14px; color: var(--ink);
}
#houseSearchInput::placeholder { color: var(--inks); font-weight: 600; }
#houseSearchClear {
  display: none; flex: none; border: none; cursor: pointer; background: transparent;
  width: 26px; height: 26px; border-radius: 50%; color: var(--inks);
  font-size: 17px; font-weight: 800; line-height: 1; align-items: center; justify-content: center;
}
.house-search.has-query #houseSearchClear { display: flex; }
#houseSearchClear:hover { background: rgba(138,122,94,.14); color: var(--ink); }

/* gallery + quick-scroll timeline side by side, filling the rest of the room */
.house-body { display: flex; flex: 1; min-height: 0; gap: 2px; }

/* ---- House shelves (F25): a botanical curio-cabinet layout — wood shelf
   tiers stacked vertically, each holding a row of framed pressed-flower
   keepsakes. Replaces the plain card grid; the keepsake framing itself (a
   pressed flower) stays as locked, only its container changes. ---- */
.house-shelves {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 30px;
  overflow-y: auto; padding: 6px 4px 14px; -webkit-overflow-scrolling: touch;
}
.house-shelves:empty { display: none; }

/* ---- Quick-scroll timeline (F: Google Photos-style date rail) — a thin
   strip of month labels along the shelves; tap or drag to jump straight
   there. Index-proportional (not literal calendar spacing), like the photo
   app it's modeled on; rebuilt from whatever's currently shown, so it still
   works while a search is filtering the shelves. ---- */
.house-timeline {
  position: relative; width: 46px; flex: none;
  touch-action: none; cursor: pointer;
}
.timeline-label {
  position: absolute; right: 6px; transform: translateY(-50%);
  font-size: 10px; font-weight: 800; color: var(--inks);
  white-space: nowrap; pointer-events: none;
  transition: color .15s ease, font-size .15s ease;
}
.timeline-label.near { color: var(--ink); font-size: 11px; }

.shelf-tier { position: relative; padding-bottom: 13px; }
.shelf-row {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: center;
  gap: 14px 12px; padding: 0 4px 8px;
  min-height: 78px;   /* an empty tier still reads as a real, waiting shelf */
}
/* the wood plank itself: a lip + a soft shadow cast onto the tier below */
.shelf-plank {
  position: absolute; left: -4px; right: -4px; bottom: 0; height: 14px;
  background: linear-gradient(180deg, var(--wood) 0%, var(--wood-deep) 100%);
  border-radius: 4px;
  box-shadow: 0 7px 12px -2px rgba(58,40,18,.32), inset 0 1px 0 rgba(255,255,255,.35);
}

/* one keepsake: a pressed flower preserved like a specimen in a glass jar,
   standing on a small pedestal on the shelf plank — 標本-in-glass, museum-
   cabinet read. Tapping the jar lifts it off the shelf to read it in full
   (see .jar-overlay below); the small shelf jar itself has no buttons. */
.keepsake {
  position: relative; width: 84px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  animation: keepsakeIn .5s cubic-bezier(.32,.72,0,1) both;
  cursor: pointer;
}
@keyframes keepsakeIn { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
/* the glass jar: a dome-topped silhouette, a faint cool-glass tint, a
   diagonal light streak and a rim line — reads as glass, not a photo frame.
   Sized by its container, so the same class works small (on the shelf) and
   large (lifted out, inside .jar-big). */
.keepsake-frame {
  position: relative; width: 100%; aspect-ratio: 1 / 1;
  display: flex; align-items: center; justify-content: center;
  border-radius: 46% 46% 12% 12% / 56% 56% 10% 10%;
  background: linear-gradient(165deg, rgba(255,255,255,.6) 0%, rgba(213,232,232,.4) 42%, rgba(180,206,208,.32) 100%);
  padding: 9px 9px 12px;
  box-shadow: 0 6px 16px var(--shadow), inset 0 0 0 1.5px rgba(255,255,255,.6), inset 0 -12px 16px rgba(110,142,144,.16);
  overflow: hidden;
}
.keepsake-frame::before {        /* the glassy highlight streak */
  content: ''; position: absolute; top: -12%; left: 10%; width: 26%; height: 132%;
  background: linear-gradient(100deg, rgba(255,255,255,.6), rgba(255,255,255,0) 72%);
  transform: rotate(9deg); pointer-events: none;
}
.keepsake-frame::after {         /* the jar's rim / lid seam */
  content: ''; position: absolute; left: 9%; right: 9%; top: 17%; height: 2px;
  background: rgba(255,255,255,.65); border-radius: 2px; pointer-events: none;
}
/* the pedestal the jar stands on, resting on the shelf plank */
.keepsake-base {
  width: 56%; height: 6px; margin-top: -4px; border-radius: 3px;
  background: linear-gradient(180deg, var(--wood) 0%, var(--wood-deep) 100%);
  box-shadow: 0 3px 7px rgba(58,40,18,.3), inset 0 1px 0 rgba(255,255,255,.32);
}
.keepsake-frame canvas { display: block; width: 100%; height: 100%; }
/* the snippet now lives INSIDE the jar — a small label tag affixed near the
   bottom of the glass, over a soft fade so it stays legible against the
   flower art behind it. */
.keepsake-thought {
  position: absolute; left: 9%; right: 9%; bottom: 10%; z-index: 2;
  font-size: 7.5px; font-weight: 800; color: var(--ink); text-align: center;
  line-height: 1.18;
  padding: 3px 2px 2px; border-radius: 6px;
  background: linear-gradient(180deg, rgba(255,253,244,0) 0%, rgba(255,253,244,.92) 32%, rgba(255,253,244,.96) 100%);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.keepsake-date { font-size: 10.5px; font-weight: 700; color: var(--inks); letter-spacing: .01em; }

/* ---- Jar expand (F25 refinement): tap a jar and it lifts off the shelf,
   grows, and shows the whole message inside the glass — then a delete
   (and close) action appears. A FLIP-style transform animation (set in JS)
   makes it read as the same jar being taken down and held up to the light. ----*/
.jar-overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 26px;
  background: rgba(40,28,16,.4); backdrop-filter: blur(2px);
  opacity: 0; pointer-events: none;
  transition: opacity .32s ease;
}
.jar-overlay.open { opacity: 1; pointer-events: auto; }
.jar-big {
  position: relative; width: min(88vw, 320px);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.jar-big .keepsake-frame { width: 100%; }
/* the full, untruncated, scrollable thought — replaces the small clamp.
   A bigger jar + smaller type gives comfortable room for 10+ lines before
   it needs to scroll (still scrollable beyond that — nothing is ever cut).
   Text floats on top of the enlarged plant art, semi-opaque so plant shows through. */
.jar-big-thought {
  position: absolute; left: 6%; right: 6%; top: 50%; transform: translateY(-50%); z-index: 2;
  max-height: 60%; overflow-y: auto; -webkit-overflow-scrolling: touch;
  font-size: 10.5px; font-weight: 700; color: var(--ink); text-align: center;
  line-height: 1.3; white-space: pre-wrap; word-break: break-word;
  padding: 10px 10px 8px; border-radius: 12px;
  background: rgba(255,253,244,0.78);
}
.jar-big-date { font-size: 13px; font-weight: 800; color: #fffaee; text-shadow: 0 1px 3px rgba(40,28,16,.4); }
.jar-big-close, .jar-big-delete {
  position: absolute; top: -11px; z-index: 4;
  width: 36px; height: 36px; border-radius: 50%; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,254,240,.94); color: var(--inks);
  box-shadow: 0 5px 14px rgba(0,0,0,.28), inset 0 1px 0 rgba(255,255,255,.85);
  transition: transform .18s ease, background .18s ease, color .18s ease;
}
.jar-big-close { left: -11px; font-size: 19px; font-weight: 800; line-height: 1; }
.jar-big-delete { right: -11px; }
.jar-big-delete svg { width: 14px; height: 14px; display: block; }
.jar-big-close:hover { background: #fff; color: var(--ink); }
.jar-big-delete:hover { background: #fff; color: #b3503f; }
.jar-big-close:active, .jar-big-delete:active { transform: scale(.88); }

.house-empty {
  margin: auto; max-width: 280px; text-align: center; padding: 24px 16px;
}
.house-empty .he-art {
  width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, #fff6df 0%, #f0dcb2 70%, #e4cb9d 100%);
  box-shadow: inset 0 2px 6px rgba(120,90,50,.18);
}
.house-empty p { margin: 0 0 6px; font-size: 16px; font-weight: 800; color: var(--ink); }
.house-empty span { font-size: 13px; font-weight: 600; color: var(--inks); line-height: 1.4; }

/* ---- Creature selection (F23): a small action cluster that floats beside a
   selected creature. Lives in world space inside #field, so it pans + tracks
   with the creature, just like its speech bubble. ---- */
#creatureActions {
  position: absolute; left: 0; top: 0; z-index: 6;
  transform: translateX(-50%);
  display: none; gap: 4px; padding: 4px;
  background: rgba(255,254,240,.96); border-radius: 999px;
  box-shadow: 0 8px 20px var(--shadow), inset 0 1px 0 rgba(255,255,255,.85);
}
#creatureActions.show { display: flex; }
#creatureActions button {
  display: flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border: none; cursor: pointer;
  border-radius: 50%; background: transparent; color: var(--inks);
  transition: background .18s ease, color .18s ease, transform .18s ease;
}
#creatureActions button svg { width: 19px; height: 19px; display: block; }
#creatureActions button:hover { background: rgba(143,203,106,.18); color: var(--ink); }
#creatureActions button:active { transform: scale(.9); }
#creatureActions button.danger { color: #c77b6e; }
#creatureActions button.danger:hover { background: rgba(199,123,110,.16); color: #b3503f; }

/* ---- Shared modal overlay for View / Edit / Trash (F23 / F24) ---- */
.tf-overlay {
  position: absolute; inset: 0; z-index: 32; display: none;
  align-items: center; justify-content: center; padding: 22px;
  background: rgba(58,40,18,.28); backdrop-filter: blur(3px);
}
.tf-overlay.open { display: flex; }
.tf-meta { font-size: 12.5px; font-weight: 700; color: var(--inks); }

.help-list {
  margin: 4px 0 0; padding: 0 0 0 18px;
  font-size: 13.5px; font-weight: 600; color: var(--inks); line-height: 1.55;
}
.help-list li { margin-bottom: 8px; }
.help-list strong { color: var(--ink); font-weight: 800; }

/* ---- Settings dropdown: Trash, Help, Buy me a coffee. Anchored under the
   gear button in the top bar; Trash moved here from its old floating
   farm-corner button (badge count carries over to .settings-row-badge). ---- */
#settingsMenu {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 30;
  display: flex; flex-direction: column; gap: 2px;
  min-width: 200px; padding: 6px;
  background: var(--cream); border-radius: 18px;
  box-shadow: 0 12px 30px var(--shadow), inset 0 1px 0 rgba(255,255,255,.85);
  opacity: 0; transform: translateY(-6px) scale(.97); pointer-events: none;
  transition: opacity .2s ease, transform .2s cubic-bezier(.32,.72,0,1);
}
#settingsMenu.open { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.settings-row {
  display: flex; align-items: center; gap: 10px;
  width: 100%; border: none; background: transparent; cursor: pointer;
  padding: 10px 10px; border-radius: 12px; min-height: 44px; box-sizing: border-box;
  font-family: inherit; font-weight: 700; font-size: 14px; color: var(--ink);
  text-decoration: none;
  transition: background .15s ease;
}
.settings-row:hover { background: rgba(143,203,106,.16); }
.settings-row-ic { width: 20px; height: 20px; flex: none; display: flex; color: var(--inks); }
.settings-row-ic svg { width: 100%; height: 100%; display: block; }
.settings-row-label { flex: 1; text-align: left; }
.settings-row-badge {
  min-width: 18px; height: 18px; padding: 0 4px;
  border-radius: 999px; background: #d98a7a; color: #fff;
  font-size: 11px; font-weight: 800; line-height: 18px; text-align: center;
}
.settings-row-badge:empty, .settings-row-badge[data-zero] { display: none; }

/* trashed-item list inside the trash overlay */
.trash-list {
  display: flex; flex-direction: column; gap: 8px;
  max-height: 50vh; overflow-y: auto; padding: 2px; margin-top: 4px;
}
.trash-list:empty { display: none; }
.trash-row {
  display: flex; align-items: center; gap: 11px;
  background: #fffdf4; border-radius: 14px; padding: 8px 10px;
  box-shadow: inset 0 0 0 1.5px var(--line);
}
.trash-thumb {
  width: 44px; height: 44px; flex: none; border-radius: 10px;
  background: radial-gradient(110% 90% at 50% 30%, #eaf6d6, #d3ecb1);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.trash-thumb canvas { display: block; }
.trash-info { flex: 1; min-width: 0; }
.trash-text {
  font-size: 13px; font-weight: 700; color: var(--ink); line-height: 1.25;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.trash-date { font-size: 11px; font-weight: 700; color: var(--inks); margin-top: 2px; }
.trash-restore {
  flex: none; border: none; cursor: pointer; font-family: inherit;
  font-weight: 800; font-size: 12px; color: #fff; background: var(--leaf);
  padding: 7px 13px; border-radius: 999px; box-shadow: 0 4px 10px rgba(90,162,63,.3);
  transition: background .18s ease, transform .18s ease;
}
.trash-restore:hover { background: var(--leaf-deep); }
.trash-restore:active { transform: scale(.94); }
.trash-empty {
  margin: 12px auto 4px; text-align: center; padding: 18px 16px;
  color: var(--inks); font-weight: 700; font-size: 14px;
}
.trash-list:not(:empty) + .trash-empty { display: none; }
