/* =========================================================
   V154.8 · GATE E · DAY 4 ONLY
   Strict J4 visual / responsive / language / input pass.
   Scoped to .chapter-day4 so J0-J3 locked gates stay frozen.
   ========================================================= */
.chapter-day4 :is(button,summary,[role="button"],input){box-sizing:border-box}
.chapter-day4 :is(.d4-live-dialogue,.d4-market-moment,.d4-pocket-note,.d4-konbini-drawer,.d4-kitchen-intro-live,.d4-kitchen-step-note,.d4-copy){overflow-wrap:anywhere}
.chapter-day4 button:disabled{cursor:default}
.chapter-day4 .d4-root{overflow:hidden!important}
.chapter-day4 .d4-root :is(.d4-shoji-interaction,.d4-aisle-moment,.d4-drag-object,.d4-hold-object){touch-action:none!important;user-select:none!important}

/* One foreground owner at a time. Optional notes never fight the live action. */
.chapter-day4 .d4-stage-market:has(.d4-pocket-note) .d4-market-moment,
.chapter-day4 .d4-stage-market:has(.d4-pocket-note) .gesture-hint,
.chapter-day4 .d4-stage-living-live:has(.d4-pocket-note) :is(.d4-living-caption-done,.d4-kitchen-path-hotspot,.d4-kitchen-path-fallback){
  opacity:0!important;visibility:hidden!important;pointer-events:none!important
}
.chapter-day4 .d4-pocket-note{z-index:88!important;pointer-events:auto!important}
.chapter-day4 .d4-pocket-note>button{min-width:48px;min-height:48px}

/* Baseline controls and legibility. */
.chapter-day4 .d4-root :is(.d4-next-quiet,.d4-market-forward,.d4-pocket-trigger,.d4-phrase-natural,.d4-enter-worktop,.d4-no-gift,.d4-gifts button,.d4-breakfast-grid button,.d4-drink-row button,.d4-inline-choice button,.d4-topic-row button,.d4-v154-reply-row button){
  min-height:48px
}
.chapter-day4 .d4-root :is(.d4-live-dialogue,.d4-market-moment,.d4-konbini-drawer,.d4-kitchen-intro-live) > small,
.chapter-day4 .d4-root .d4-scene-kicker{line-height:1.25!important}
.chapter-day4 .d4-root .d4-live-dialogue p,
.chapter-day4 .d4-root .d4-market-moment>p,
.chapter-day4 .d4-root .d4-ambient-line{max-width:52ch}

/* Desktop/laptop HUD: discrete rails, no overlap. */
@media (min-width:761px){
  .chapter-day4 .sound{top:var(--dobox-safe-top,20px)!important;right:clamp(24px,3vw,48px)!important;width:58px!important;height:58px!important;min-width:58px!important;min-height:58px!important}
  .chapter-day4 .journey-menu-trigger{top:var(--dobox-safe-top,20px)!important;right:calc(clamp(24px,3vw,48px) + 68px)!important;width:58px!important;height:58px!important;min-width:58px!important;min-height:58px!important}
  .chapter-day4 .scene-meta{max-width:min(46vw,620px)!important}
  .chapter-day4 .d4-root :is(.d4-next-quiet,.d4-market-forward,.d4-pocket-trigger,.d4-phrase-natural,.d4-enter-worktop,.d4-inline-choice button,.d4-topic-row button){font-size:clamp(13px,.9vw,15px)!important}
  .chapter-day4 .d4-root :is(.d4-live-dialogue p,.d4-market-moment>p,.d4-ambient-line){font-size:clamp(14px,1.06vw,17px)!important;line-height:1.44!important}
  .chapter-day4 .d4-root .d4-mei-morning-message p{font-size:clamp(13px,.9vw,14px)!important}
  .chapter-day4 .d4-root .d4-pocket-note{max-width:min(380px,29vw)!important}
}

/* Short laptop: keep the composition usable without making every object tiny. */
@media (min-width:761px) and (max-height:820px){
  .chapter-day4 .d4-root :is(.d4-live-dialogue,.d4-market-moment,.d4-konbini-drawer,.d4-kitchen-intro-live,.d4-table-caption,.d4-departure-caption){max-height:42svh!important;overflow:auto!important}
  .chapter-day4 .d4-root .d4-market-moment{max-height:46svh!important}
  .chapter-day4 .d4-root .d4-pocket-note{max-height:48svh!important;overflow:auto!important}
  .chapter-day4 .d4-root .d4-konbini-drawer{max-height:64svh!important}
  .chapter-day4 .d4-root .d4-kitchen-live-work{inset:var(--dobox-hud-top,102px) 3vw 18px!important}
  .chapter-day4 .d4-root .d4-kitchen-counter{max-height:56svh!important}
}

/* Pointer-only affordances: never required on touch. */
@media (hover:hover) and (pointer:fine){
  .chapter-day4 :is(button,summary,[role="button"]):focus-visible{outline:3px solid rgba(247,240,223,.92)!important;outline-offset:3px!important}
  .chapter-day4 .d4-root :is(.d4-next-quiet,.d4-market-forward,.d4-pocket-trigger,.d4-phrase-natural,.d4-enter-worktop,.d4-gifts button,.d4-breakfast-grid button,.d4-drink-row button,.d4-topic-row button){transition:transform .18s ease,box-shadow .18s ease,background .18s ease}
  .chapter-day4 .d4-root :is(.d4-next-quiet,.d4-market-forward,.d4-pocket-trigger,.d4-phrase-natural,.d4-enter-worktop,.d4-gifts button,.d4-breakfast-grid button,.d4-drink-row button,.d4-topic-row button):not(:disabled):hover{transform:translateY(-2px)}
}

/* Phone: top HUD owns two separate rows; content uses the remaining viewport. */
@media (max-width:760px){
  html[data-dobox-layout^="phone"] .chapter-day4 .brand,
  html[data-dobox-layout^="phone"] .chapter-day4 .brand.brand-home{
    top:max(8px,env(safe-area-inset-top))!important;left:8px!important;
    height:50px!important;min-height:50px!important;max-height:50px!important;
    max-width:calc(100vw - 76px)!important;padding:4px 8px 4px 4px!important;gap:7px!important;
    transform:none!important;transform-origin:top left!important;box-sizing:border-box!important
  }
  html[data-dobox-layout^="phone"] .chapter-day4 .brand img{width:36px!important;height:36px!important;flex:0 0 36px!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .sound{
    top:max(8px,env(safe-area-inset-top))!important;right:8px!important;
    width:50px!important;height:50px!important;min-width:50px!important;min-height:50px!important
  }
  html[data-dobox-layout^="phone"] .chapter-day4 .journey-menu-trigger{
    top:max(66px,calc(env(safe-area-inset-top) + 58px))!important;right:8px!important;
    width:50px!important;height:50px!important;min-width:50px!important;min-height:50px!important
  }
  html[data-dobox-layout^="phone"] .chapter-day4 .scene-meta{
    top:max(66px,calc(env(safe-area-inset-top) + 58px))!important;left:10px!important;right:70px!important;
    width:auto!important;max-width:none!important;transform:none!important;text-align:left!important;overflow:hidden!important;padding:4px 8px!important
  }
  html[data-dobox-layout^="phone"] .chapter-day4 .scene-meta time{font-size:15px!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .scene-meta span{font-size:10px!important;line-height:1.2!important;letter-spacing:.055em!important;white-space:nowrap!important;overflow:hidden!important;text-overflow:ellipsis!important}

  html[data-dobox-layout^="phone"] .chapter-day4 .d4-root{--d4-edge:10px!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-root .d4-stage{padding-top:max(124px,calc(env(safe-area-inset-top) + 116px))!important;padding-bottom:max(10px,env(safe-area-inset-bottom))!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-root :is(.d4-next-quiet,.d4-market-forward,.d4-pocket-trigger,.d4-phrase-natural,.d4-enter-worktop,.d4-no-gift,.d4-gifts button,.d4-breakfast-grid button,.d4-drink-row button,.d4-inline-choice button,.d4-topic-row button,.d4-v154-reply-row button,.d4-pocket-note>button){min-width:50px!important;min-height:50px!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-root :is(.d4-next-quiet,.d4-market-forward,.d4-pocket-trigger,.d4-phrase-natural,.d4-enter-worktop){font-size:13px!important;line-height:1.24!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-root :is(.d4-live-dialogue p,.d4-market-moment>p,.d4-ambient-line){font-size:15px!important;line-height:1.38!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-root :is(.d4-live-dialogue,.d4-market-moment,.d4-konbini-drawer,.d4-kitchen-intro-live,.d4-table-caption,.d4-departure-caption){box-sizing:border-box!important}

  html[data-dobox-layout^="phone"] .chapter-day4 .d4-opening-caption,
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-live-dialogue-sato,
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-rain-caption,
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-walk-caption,
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-after-rain-caption,
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-yuki-response,
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-living-caption,
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-table-caption,
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-departure-caption{
    left:10px!important;right:10px!important;bottom:max(10px,env(safe-area-inset-bottom))!important;width:auto!important;max-width:none!important;
    max-height:36svh!important;overflow:auto!important;padding:9px 11px 10px!important
  }
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-opening-caption{max-height:48svh!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-live-dialogue-sato{max-height:34svh!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-mei-morning-message{grid-template-columns:34px minmax(0,1fr)!important;gap:8px!important;margin:7px 0!important;padding:8px 9px!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-mei-morning-message p{font-size:12.5px!important;line-height:1.36!important}

  html[data-dobox-layout^="phone"] .chapter-day4 .d4-konbini-drawer{
    position:absolute!important;left:10px!important;right:10px!important;bottom:max(10px,env(safe-area-inset-bottom))!important;width:auto!important;max-width:none!important;
    max-height:58svh!important;overflow:auto!important;padding:10px!important
  }
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-breakfast-grid{grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:7px!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-breakfast-grid button{min-width:0!important;min-height:108px!important;padding:7px!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-breakfast-grid img{height:46px!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-drink-row{grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:7px!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-drink-row button{min-width:0!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-pay-quiet{float:none!important;width:100%!important}

  html[data-dobox-layout^="phone"] .chapter-day4 .d4-market-moment{
    left:10px!important;right:10px!important;bottom:max(10px,env(safe-area-inset-bottom))!important;width:auto!important;max-width:none!important;
    max-height:50svh!important;overflow:auto!important;padding:10px 11px!important
  }
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-v154-reply-row{grid-template-columns:minmax(0,1fr)!important;gap:7px!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-v154-reply-row input{width:100%!important;min-width:0!important;min-height:50px!important;font-size:16px!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-gifts button{grid-template-columns:52px minmax(0,1fr) auto!important;min-height:72px!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-gifts button img{width:48px!important;height:48px!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-fruit-ribbon{overflow-x:auto!important;overscroll-behavior-inline:contain!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-aisle-moment{min-height:118px!important}

  html[data-dobox-layout^="phone"] .chapter-day4 .d4-pocket-note{
    position:fixed!important;z-index:92!important;left:10px!important;right:10px!important;top:max(124px,calc(env(safe-area-inset-top) + 116px))!important;
    bottom:max(10px,env(safe-area-inset-bottom))!important;width:auto!important;max-width:none!important;max-height:none!important;overflow:auto!important
  }

  html[data-dobox-layout^="phone"] .chapter-day4 .d4-threshold-layer{
    inset:max(124px,calc(env(safe-area-inset-top) + 116px)) 10px max(10px,env(safe-area-inset-bottom))!important
  }
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-threshold-layer>.d4-ambient-line{font-size:13.5px!important;line-height:1.38!important;max-height:24svh!important;overflow:auto!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-umbrella-gesture,
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-genkan-live,
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-gift-gesture{inset:7% 0 25%!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-drag-object{min-width:50px!important;min-height:50px!important}

  html[data-dobox-layout^="phone"] .chapter-day4 .d4-living-cue-layer{inset:0!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-bag-object{width:100px!important;bottom:30%!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-bag-target{width:122px!important;height:82px!important;bottom:31%!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-kitchen-path-hotspot{min-width:50px!important;min-height:50px!important}

  html[data-dobox-layout^="phone"] .chapter-day4 .d4-kitchen-intro-live{
    left:10px!important;right:10px!important;bottom:max(10px,env(safe-area-inset-bottom))!important;width:auto!important;max-width:none!important;max-height:36svh!important;overflow:auto!important
  }
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-kitchen-live-work{inset:max(124px,calc(env(safe-area-inset-top) + 116px)) 10px max(10px,env(safe-area-inset-bottom))!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-kitchen-step-note{left:0!important;right:0!important;width:auto!important;max-width:none!important;max-height:16svh!important;overflow:auto!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-kitchen-counter{max-width:100%!important;margin:17svh auto 0!important;max-height:51svh!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-cook-progress{top:0!important;right:0!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .gesture-hint{max-width:76vw!important;font-size:12px!important}

  html[data-dobox-layout^="phone"] .chapter-day4 .d4-stage-final .d4-copy{left:10px!important;right:10px!important;bottom:max(10px,env(safe-area-inset-bottom))!important;width:auto!important;max-width:none!important;max-height:47svh!important;overflow:auto!important;padding:13px!important}
}

@media (max-width:760px) and (hover:none), (max-width:760px) and (pointer:coarse){
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-root :is(.d4-next-quiet,.d4-market-forward,.d4-pocket-trigger,.d4-phrase-natural,.d4-enter-worktop,.d4-gifts button,.d4-breakfast-grid button,.d4-drink-row button,.d4-topic-row button):hover{transform:none!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-root :is(.d4-next-quiet,.d4-market-forward,.d4-pocket-trigger,.d4-phrase-natural,.d4-enter-worktop,.d4-gifts button,.d4-breakfast-grid button,.d4-drink-row button,.d4-topic-row button):active{transform:scale(.985)!important}
}

@media (max-width:400px){
  html[data-dobox-layout^="phone"] .chapter-day4 .brand small{display:none!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-root :is(.d4-live-dialogue p,.d4-market-moment>p,.d4-ambient-line){font-size:14.5px!important}
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-market-moment{max-height:48svh!important}
}

@media (prefers-reduced-motion:reduce){
  .chapter-day4 *, .chapter-day4 *::before, .chapter-day4 *::after{animation-duration:.001ms!important;animation-iteration-count:1!important;transition-duration:.001ms!important;scroll-behavior:auto!important}
}

/* Gate E containment fix: Phase-3 architecture pads generic interaction layers.
   Day 4 owns its own HUD-safe coordinates, so its inner interaction plane must
   stay exactly viewport-sized instead of inheriting a second 78/72px rail. */
.chapter-day4 .d4-root > .d4-interaction-layer{
  inset:0!important;
  padding:0!important;
  width:100%!important;
  height:100%!important;
}
html[data-dobox-layout^="phone"] .chapter-day4 .d4-v154-write-reply>summary{
  min-height:50px!important;
  display:flex!important;
  align-items:center!important;
}

/* Desktop/laptop HUD: brand left, contextual meta centered, controls right.
   Keeping these on three independent rails prevents the top cluster from colliding. */
@media (min-width:761px){
  .chapter-day4 .scene-meta{
    top:max(var(--dobox-safe-top,20px),20px)!important;
    left:50%!important;
    right:auto!important;
    transform:translateX(-50%)!important;
    max-width:min(46vw,620px)!important;
  }
}

/* Human visual review fixes. */
.chapter-day4 .d4-root :is(.d4-next-quiet,.d4-market-forward){color:#fff!important}
.chapter-day4 .d4-root .d4-stage-yuki-live{background:transparent!important}
.chapter-day4 .d4-rain-umbrella-foreground{
  position:absolute;z-index:5;right:clamp(18px,5vw,86px);bottom:clamp(70px,10vh,118px);
  width:clamp(170px,22vw,310px);height:auto;pointer-events:none;
  filter:drop-shadow(0 16px 24px rgba(0,0,0,.28));
  opacity:.94;animation:d4UmbrellaArrive .58s ease-out both;
}
@keyframes d4UmbrellaArrive{from{opacity:0;transform:translateY(14px) scale(.97)}to{opacity:.94;transform:none}}
@media (max-width:760px){
  html[data-dobox-layout^="phone"] .chapter-day4 .d4-rain-umbrella-foreground{
    right:-12px;bottom:34svh;width:min(42vw,164px);opacity:.9
  }
}
@media (prefers-reduced-motion:reduce){.chapter-day4 .d4-rain-umbrella-foreground{animation:none!important}}

/* V143 legacy still hard-coded the old Mme Sato genkan etalon over the world.
   Gate E requires the V1549 mobile/desktop masters to be the actual visible scene. */
.chapter-day4 .d4-stage-sato-live::before{display:none!important;content:none!important}
@media (min-width:1600px){
  .chapter-day4 .d4-root :is(.d4-live-dialogue p,.d4-market-moment>p,.d4-ambient-line){font-size:18px!important;line-height:1.46!important}
  .chapter-day4 .d4-root .d4-mei-morning-message p{font-size:14.5px!important}
  .chapter-day4 .d4-root :is(.d4-next-quiet,.d4-market-forward,.d4-pocket-trigger,.d4-phrase-natural,.d4-enter-worktop,.d4-inline-choice button,.d4-topic-row button){font-size:15px!important}
}
