html[data-farmdew-world-renderer="phaser"]:not(.farmdew-layout-editing) #farmdewScene > .farmdew-stage,
html[data-farmdew-world-renderer="phaser"]:not(.farmdew-layout-editing) #farmdewScene > .farmdew-cosmetic-layer {
  opacity: 0 !important;
  pointer-events: none !important;
}
html[data-farmdew-world-renderer="phaser"] .farmdew-home-controls,
html[data-farmdew-world-renderer="phaser"] .farmdew-home-interact,
html[data-farmdew-world-renderer="phaser"] .farmdew-area-interact { display: none !important; }
#farmdewPhaserWorld { position: absolute; inset: 0; z-index: 5; overflow: hidden; }
#farmdewPhaserWorld[hidden], #farmdewPhaserRecovery[hidden], #farmdewPhaserRefresh[hidden] { display: none; }
#farmdewPhaserWorld canvas { display: block; image-rendering: pixelated; }
#farmdewPhaserControls { display: none; }
html[data-farmdew-world-renderer="phaser"][data-farmdew-phaser-ready="ready"]:not(.farmdew-layout-editing) #farmdewPhaserControls {
  display: flex; position: absolute; bottom: max(20px, env(safe-area-inset-bottom));
  left: max(16px, env(safe-area-inset-left)); right: max(16px, env(safe-area-inset-right));
  z-index: 15; justify-content: space-between; align-items: center; pointer-events: none;
}
#farmdewPhaserStick, #farmdewPhaserInteract { pointer-events: auto; touch-action: none; }
#farmdewPhaserStick { width: 104px; height: 104px; border-radius: 50%; background: #203d34b8; border: 2px solid #e6e6c97d; }
#farmdewPhaserStick span { display: block; width: 42px; height: 42px; border-radius: 50%; margin: auto;
  background: #f4e6c5; transform: translate(var(--knob-x, 0px), var(--knob-y, 0px)); }
#farmdewPhaserInteract { min-width: 94px; max-width: min(46vw, 180px); min-height: 56px; padding: 10px 12px;
  border: 2px solid #fff3ce99; border-radius: 18px; background: #e8d7a6; color: #243c32;
  font: 700 14px/1.25 system-ui, sans-serif; overflow-wrap: anywhere; text-wrap: balance; }
#farmdewPhaserInteract:disabled { opacity: .55; }
#farmdewPhaserInteract:focus-visible { outline: 3px solid #fff3ce; outline-offset: 3px; }
.farmdew-phaser-portal-veil { position: absolute; inset: 0; z-index: 6; background: #182c23; pointer-events: none; }
.farmdew-phaser-portal-veil.is-covering { animation: farmdew-phaser-cover 90ms ease-out both; }
.farmdew-phaser-portal-veil.is-revealing { animation: farmdew-phaser-reveal 140ms ease-in both; }
.farmdew-phaser-location-title { position: absolute; z-index: 7; top: max(16px, env(safe-area-inset-top));
  left: 50%; transform: translateX(-50%); margin: 0; padding: 8px 18px; max-width: calc(100% - 112px);
  border: 1px solid #e8d7a680; border-radius: 10px; background: #203d34ed; color: #fff3ce;
  font: 700 16px/1.25 system-ui, sans-serif; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-align: center; pointer-events: none; animation: farmdew-phaser-title 1800ms ease both; }
.farmdew-phaser-location-title.is-still { animation: none; }
.farmdew-phaser-portal-veil[hidden], .farmdew-phaser-location-title[hidden] { display: none; }
@keyframes farmdew-phaser-cover { from { opacity: 0; } to { opacity: 1; } }
@keyframes farmdew-phaser-reveal { from { opacity: 1; } to { opacity: 0; } }
@keyframes farmdew-phaser-title { 0%, 100% { opacity: 0; } 12%, 80% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .farmdew-phaser-portal-veil, .farmdew-phaser-location-title { animation: none !important; }
}
@media (max-width: 350px) { #farmdewPhaserInteract { font-size: 13px; padding: 9px; } }
@media (orientation: landscape) and (max-height: 520px) {
  #farmdewPhaserStick { width: 82px; height: 82px; }
  .farmdew-phaser-location-title { top: max(8px, env(safe-area-inset-top)); font-size: 14px; padding: 6px 14px; }
}
#farmdewPhaserRecovery { position: fixed; top: 24%; left: 5%; right: 5%; z-index: 1000; padding: 24px; background: #203d34; color: white; border-radius: 16px; }
#farmdewPhaserRefresh { position: absolute; top: 12px; right: 12px; z-index: 16; }
html.farmdew-layout-editing #farmdewPhaserWorld { visibility: hidden; pointer-events: none; }
#farmdewPhaserStatus { position: absolute; top: 12px; left: 16px; z-index: 10; color: white; background: #203d34; }
#farmdewPhaserStatus:empty { display: none; }
@media (orientation: portrait), (min-height: 521px) {
  #farmdewPhaserStatus { top: 64px; max-width: calc(100% - 32px); }
}
html.farmdew-horde-encounter-active #farmdewPhaserControls,
html.farmdew-horde-encounter-active #farmdewPhaserStatus { display: none !important; }
html.farmdew-horde-encounter-active #farmdewPhaserWorld { position: fixed; inset: 0; z-index: 160; }
html.farmdew-town-world-active #farmdewPhaserControls { display: none !important; }
html.farmdew-town-world-active #farmdewHordeEncounter .center-panel { background: #0b1d1980; }
html.farmdew-town-world-active #farmdewHordeEncounter #syncing { top: calc(env(safe-area-inset-top) + 112px); }
html.farmdew-town-world-active #farmdewHordeEncounter #stick,
html.farmdew-town-world-active #farmdewHordeEncounter #attack-button,
html.farmdew-town-world-active #farmdewHordeEncounter #dash-button { pointer-events: auto; touch-action: none; }
#farmdewHordeEncounter { position: fixed; inset: 0; z-index: 164; pointer-events: none; color-scheme: dark; font-family: system-ui, sans-serif; }
#farmdewHordeEncounter .center-panel, #farmdewHordeEncounter #upgrade-panel { pointer-events: auto; }
#farmdewHordeEncounter #diagnostics { display: none; }
#farmdewPhaserEncounterCancel { position: fixed; top: max(8px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right)); z-index: 170; min-height: 44px; border-radius: 8px; background: #173229; color: #e7ffe6; }
#farmdewHordeEncounter .back { min-height: 44px; }
#farmdewHordeEncounter #hud > a.back[data-hollow-return] { display: none; }
#farmdewPhaserEncounterCancel[hidden] { display: none; }
#farmdewMenuTownResume[hidden] { display: none !important; }
@media (max-height: 460px) {
  /* Keep the saved-wave pause target clear of the compact Farm Menu target. */
  #farmdewPhaserEncounterCancel {
    left: 50%; right: auto; transform: translateX(-50%);
    max-width: calc(100vw - 220px); font-size: 12px;
  }
}
/* The eligible desktop adapter owns one native 816/400 x 640 viewport. */
html[data-farmdew-authoring-adapter="phaser"] #farmdewScene > .farmdew-stage {
  display: none !important;
  pointer-events: none !important;
}
.farmdew-authoring-viewport[hidden] { display: none !important; }
html[data-farmdew-authoring-adapter="phaser"] #farmdewPhaserWorld {
  visibility: visible; pointer-events: auto; inset: 0; width: 100%; height: 100%; z-index: 1;
  touch-action: none;
}
@media (min-width: 900px) and (min-height: 620px) {
  .farmdew-authoring-viewport {
    --farmdew-viewport-width: min(calc(100vw - var(--farmdew-desktop-panel-width) - 72px), calc((100dvh - 92px) * var(--farmdew-authoring-ratio)));
    --farmdew-viewport-height: calc(var(--farmdew-viewport-width) / var(--farmdew-authoring-ratio));
    position: absolute;
    width: var(--farmdew-viewport-width); height: var(--farmdew-viewport-height);
    left: max(50%, calc(var(--farmdew-viewport-width) / 2 + 20px));
    top: max(50%, calc(var(--farmdew-viewport-height) / 2 + 20px));
    transform: translate(-50%, -50%);
    box-shadow: 0 18px 54px #0006, 0 0 0 1px #f4e6b256;
  }
  html[data-farmdew-desktop-zoom="100"] .farmdew-authoring-viewport { --farmdew-viewport-width: calc(var(--farmdew-authoring-width) * 1px); }
  html[data-farmdew-desktop-zoom="125"] .farmdew-authoring-viewport { --farmdew-viewport-width: calc(var(--farmdew-authoring-width) * 1.25px); }
  html[data-farmdew-desktop-zoom="150"] .farmdew-authoring-viewport { --farmdew-viewport-width: calc(var(--farmdew-authoring-width) * 1.5px); }
}

/* The scroller clips only the visible region; the inner Game retains complete
   canonical geometry at every Fit/detail scale. No camera or hit offset fork. */
#farmdewAuthoringScrollViewport[hidden] { display: none !important; }
html.farmdew-mobile-builder-mode #farmdewAuthoringScrollViewport {
  position: fixed; z-index: 1000; left: max(8px, env(safe-area-inset-left)); right: max(8px, env(safe-area-inset-right));
  top: calc(var(--farmdew-visual-top, 0px) + max(8px, env(safe-area-inset-top)));
  height: max(1px, calc(var(--farmdew-visual-height, 100dvh) - var(--farmdew-mobile-dock-height, 112px) - max(8px, env(safe-area-inset-top)) - 8px));
  overflow: auto; overscroll-behavior: contain; background: #173429; outline-offset: -3px;
  touch-action: pan-x pan-y pinch-zoom;
}
html.farmdew-mobile-builder-mode #farmdewAuthoringViewport {
  position: relative; top: auto; left: auto; transform: none; max-width: none; max-height: none;
  margin-left: auto; margin-right: auto; box-shadow: 0 0 0 1px #f4e6b256;
}
html.farmdew-mobile-builder-mode[data-farmdew-authoring-interaction="navigate"] #farmdewPhaserWorld { touch-action: pan-x pan-y pinch-zoom; }
html.farmdew-mobile-builder-mode[data-farmdew-authoring-interaction="navigate"] #farmdewPhaserWorld canvas { touch-action: pan-x pan-y pinch-zoom !important; }
html.farmdew-mobile-builder-mode[data-farmdew-authoring-interaction="edit"] #farmdewPhaserWorld { touch-action: none; }
html.farmdew-mobile-builder-mode #farmdewAiAreaDesigner #farmdewAuthoringScrollViewport {
  position: relative; top: auto; left: auto; right: auto; width: 100%; height: calc(100% - 48px); z-index: auto;
}
#farmdewIPhoneEditorDiagnostic {
  position: fixed; z-index: 1000001; top: max(4px, env(safe-area-inset-top)); left: 8px; right: 8px;
  max-height: 35dvh; overflow: auto; padding: 8px; background: #fff8e5; color: #382a20;
  border: 1px solid #806347; border-radius: 8px; font: 12px/1.3 system-ui;
}
#farmdewIPhoneEditorDiagnostic summary { min-height: 32px; }
#farmdewIPhoneEditorDiagnostic pre { white-space: pre-wrap; }
.farmdew-seam-diagnostic {
  position: fixed; z-index: 1000001; top: max(4px, env(safe-area-inset-top)); left: 8px; right: 8px;
  max-height: 40dvh; overflow: auto; padding: 8px; background: #fff8e5; color: #382a20;
  border: 1px solid #806347; border-radius: 8px; font: 12px/1.3 system-ui;
}
.farmdew-seam-diagnostic summary, .farmdew-seam-diagnostic button { min-height: 44px; }
.farmdew-seam-diagnostic pre { white-space: pre-wrap; overflow-wrap: anywhere; }
/* Accepted Town results take focus above both world and combat HUD rails. */
#farmdewHordeEncounter:has(#result:not([hidden])){z-index:180}
html.farmdew-town-world-active #farmdewHordeEncounter #result{background:#10251ff7}
#farmdewHordeEncounter #result{z-index:10;inset:0;padding:max(20px,env(safe-area-inset-top)) max(18px,env(safe-area-inset-right)) max(20px,env(safe-area-inset-bottom)) max(18px,env(safe-area-inset-left));overflow:auto;overscroll-behavior:contain;touch-action:pan-y}
#farmdewHordeEncounter #result h1{flex-shrink:0;max-width:100%;white-space:normal;overflow-wrap:anywhere;font-size:clamp(22px,6vw,32px)}
#farmdewHordeEncounter #result p,#farmdewHordeEncounter #result .actions{flex-shrink:0;max-width:100%}
#farmdewHordeEncounter:has(#result:not([hidden])) #hud{visibility:hidden}
