/* Timberbrook Mill 3D - stage, HUD, dock and overlays. Everything is scoped under #stage so site styles never leak in. */
html.pip-big, html.pip-big body { overflow: hidden; }
#stage { --wood:#8a5a2b; --wood-d:#5e3b1a; --leaf:#4f9d4a; --leaf-d:#2f6e33; --cream:#fff3d6; --ink:#2b2118; --gold:#f5c542; --red:#e0584a; --dock-h:46%;
  position: relative; width: min(100%, calc(78vh * 0.5625)); width: min(100%, calc(78svh * 0.5625)); aspect-ratio: 9 / 16; margin: 0 auto; overflow: hidden;
  border-radius: 14px; background: #bfe3f5; color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", Verdana, system-ui, sans-serif; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; line-height: 1.25; touch-action: manipulation; }
.game-wrap.pip-stage #stage { width: min(100%, calc((100vh - 64px) * 0.5625)); width: min(100%, calc((100svh - 64px) * 0.5625)); }
#stage.dock-closed { --dock-h: 48px; }
#stage.is-big { position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; aspect-ratio: auto; border-radius: 0; z-index: 99999; }
#stage *, #stage *::before, #stage *::after { box-sizing: border-box; }
#stage #app { position: absolute; left: 0; right: 0; top: 0; bottom: var(--dock-h); touch-action: none; }
#stage #app canvas { display: block; width: 100%; height: 100%; touch-action: none; }
#stage #ui { position: absolute; inset: 0; pointer-events: none; }
#stage #ui button, #stage #ui .dock, #stage #ui .screens, #stage #ui .hint { pointer-events: auto; }
#stage button { font-family: inherit; cursor: pointer; touch-action: manipulation; color: inherit; }
#stage button:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
#stage [hidden] { display: none !important; }

#stage #loader { position: absolute; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; background: linear-gradient(#7a5230 0%, #a9763f 60%, #d9b36c 100%); }
#stage #loader[hidden] { display: none; }
#stage .load-in { display: flex; flex-direction: column; align-items: center; gap: 10px; color: #fff; text-shadow: 0 3px 0 rgba(50,30,10,.45); text-align: center; padding: 0 18px; }
#stage .load-in b { font-size: clamp(20px, 6vw, 30px); letter-spacing: 2px; }
#stage .load-in span { font-size: 14px; opacity: .95; }
#stage .spinner { width: 42px; height: 42px; border-radius: 50%; border: 6px solid rgba(255,255,255,.35); border-top-color: var(--gold); animation: lmspin .8s linear infinite; }
@keyframes lmspin { to { transform: rotate(360deg); } }
#stage #ctxlost { position: absolute; inset: 0; z-index: 55; display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px; background: rgba(40,28,14,.88); color: #fff; font-weight: 700; }

/* HUD */
#stage .hud { position: absolute; left: 8px; right: 8px; top: 8px; display: flex; gap: 8px; align-items: center; pointer-events: none; }
#stage .pill { display: flex; align-items: center; gap: 8px; background: rgba(255,243,214,.94); border: 2px solid var(--wood); border-radius: 14px; padding: 4px 12px 4px 6px; min-height: 44px; box-shadow: 0 2px 0 rgba(60,35,10,.3); }
#stage .pill.sm { padding-right: 10px; }
#stage .pcol { display: flex; flex-direction: column; line-height: 1.05; }
#stage .hv { font-size: 18px; font-weight: 900; color: var(--ink); }
#stage .hs { font-size: 11px; font-weight: 800; color: var(--leaf-d); }
#stage .ic { width: 30px; height: 30px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 900; color: #fff; font-size: 16px; }
#stage .ic.coin { background: #e0a526; } #stage .ic.acorn { background: #9a6a34; }
#stage .iconbtn { margin-left: auto; width: 44px; height: 44px; border-radius: 12px; border: 2px solid var(--wood); background: var(--cream); font-weight: 900; font-size: 16px; box-shadow: 0 2px 0 rgba(60,35,10,.3); }
#stage .iconbtn.small { width: 44px; height: 44px; margin-left: 6px; }
#stage .banner { position: absolute; left: 8px; right: 8px; top: 60px; background: rgba(255,243,214,.95); border: 2px solid var(--wood); border-radius: 12px; padding: 5px 8px; }
#stage .brow { display: flex; align-items: center; gap: 8px; }
#stage .rn { font-size: 13px; flex: 1; } #stage .rt { font-weight: 900; font-size: 16px; color: var(--red); }
#stage .bbar { position: relative; height: 12px; margin: 4px 0 3px; background: #e6d6b0; border-radius: 6px; overflow: hidden; }
#stage .rfill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: linear-gradient(#7ccf5a, #3f9d3a); }
#stage .rmark { position: absolute; top: 0; bottom: 0; width: 3px; background: #8a5a2b; margin-left: -2px; } #stage .rmark.hit { background: var(--gold); width: 4px; }
#stage .rs { font-size: 11px; font-weight: 800; color: #5a4630; }
#stage .hazard { position: absolute; left: 8px; right: 8px; top: 60px; background: rgba(224,88,74,.94); color: #fff; font-weight: 800; font-size: 12px; text-align: center; padding: 5px 8px; border-radius: 10px; }
#stage .banner:not([hidden]) ~ .hazard { top: 126px; }
#stage .hazard.gold { background: rgba(245,197,66,.97); color: #4a3200; }
#stage .feed { position: absolute; left: 8px; bottom: calc(var(--dock-h) + 8px); max-width: 62%; display: flex; flex-direction: column; gap: 4px; pointer-events: none; }
#stage .toast { background: rgba(43,33,24,.9); color: #fff; font-size: 12px; font-weight: 700; padding: 6px 10px; border-radius: 10px; animation: lmfade 3.2s forwards; }
#stage .toast.gold { background: rgba(160,110,10,.95); } #stage .toast.warn { background: rgba(150,50,40,.95); } #stage .toast.ok { background: rgba(40,110,50,.95); }
@keyframes lmfade { 0% { opacity: 0; transform: translateY(6px); } 8% { opacity: 1; transform: none; } 85% { opacity: 1; } 100% { opacity: 0; } }
#stage .hint { position: absolute; left: 8px; right: 84px; bottom: calc(var(--dock-h) + 8px); background: #fff7df; border: 2px solid var(--gold); border-radius: 12px; padding: 8px 34px 8px 10px; font-size: 13px; font-weight: 800; }
#stage .hint .hx { position: absolute; right: 0; top: 0; width: 44px; height: 44px; border: 0; background: transparent; font-weight: 900; font-size: 16px; }
#stage .pops { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
#stage .pop { position: absolute; left: 0; top: 0; font-weight: 900; font-size: 15px; color: #fff3b0; text-shadow: 0 2px 0 rgba(60,35,10,.75), 0 0 6px rgba(0,0,0,.35); white-space: nowrap; will-change: transform; }
#stage .pop.act { font-size: 12px; color: #fff; } #stage .pop.gold { color: #ffd23a; font-size: 18px; }

/* Work button */
#stage .workbtn { position: absolute; right: 10px; bottom: calc(var(--dock-h) + 10px); width: 76px; height: 76px; border-radius: 50%; border: 4px solid var(--wood-d);
  background: radial-gradient(circle at 35% 30%, #ffd86a, #e8a020 70%); color: var(--ink); display: flex; flex-direction: column; align-items: center; justify-content: center; box-shadow: 0 4px 0 rgba(60,35,10,.45); }
#stage .workbtn .w1 { font-weight: 900; font-size: 17px; letter-spacing: 1px; } #stage .workbtn .w2 { font-size: 9px; font-weight: 800; max-width: 62px; text-align: center; line-height: 1.05; }
#stage .workbtn.ready { box-shadow: 0 0 0 4px rgba(255,255,255,.7), 0 4px 0 rgba(60,35,10,.45); }
#stage .workbtn.hit { transform: scale(.94); }
#stage .workbtn::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; background: conic-gradient(rgba(40,30,20,.55) calc(var(--cd, 0) * 360deg), transparent 0); pointer-events: none; }

/* Dock */
#stage .dock { position: absolute; left: 0; right: 0; bottom: 0; height: var(--dock-h); display: flex; flex-direction: column; background: #f4e7c8; border-top: 3px solid var(--wood); }
#stage .tabs { display: flex; flex: 0 0 auto; background: #d9c39a; }
#stage .tab { flex: 1; min-height: 44px; border: 0; border-right: 1px solid #c4aa78; background: transparent; font-weight: 900; font-size: 13px; }
#stage .tab.on { background: #f4e7c8; box-shadow: inset 0 3px 0 var(--leaf); }
#stage .dbody { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; touch-action: pan-y; padding: 6px 8px 14px; }
#stage .dock-closed .dbody { display: none; }
#stage.dock-closed .dbody { display: none; }
#stage .segs { display: flex; gap: 6px; align-items: center; margin: 4px 0; flex-wrap: wrap; }
#stage .seg { min-height: 44px; min-width: 52px; padding: 0 10px; border: 2px solid #c4aa78; background: #fff8e6; border-radius: 10px; font-weight: 800; font-size: 13px; text-transform: capitalize; }
#stage .seg.on { background: var(--leaf); border-color: var(--leaf-d); color: #fff; }
#stage .seg.wide2 { flex: 1; } #stage .seg.danger { color: #9a2a20; border-color: #d9958c; }
#stage .dim { font-size: 12px; font-weight: 700; color: #7a6548; }
#stage .making { font-size: 12px; font-weight: 800; color: #5a4630; background: #fff8e6; border-radius: 10px; padding: 6px 8px; margin: 3px 0; }
#stage .row { background: #fffaf0; border: 2px solid #dcc79a; border-radius: 12px; padding: 7px 8px; margin: 6px 0; }
#stage .row.bn { border-color: var(--red); } #stage .row.locked { opacity: .65; } #stage .row.daily { border-color: var(--gold); background: #fff6d8; }
#stage .row.ach { padding: 5px 8px; } #stage .row.got { background: #e9f6df; border-color: #9cc98a; }
#stage .rtop { display: flex; align-items: center; gap: 6px; }
#stage .badge { width: 26px; height: 26px; border-radius: 50%; background: var(--wood); color: #fff; font-weight: 900; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; flex: 0 0 auto; }
#stage .rname { font-size: 14px; } #stage .rlv { margin-left: auto; font-size: 12px; font-weight: 900; color: var(--leaf-d); white-space: nowrap; }
#stage .rtop .rlv { margin-left: auto; }
#stage .rdot { width: 10px; height: 10px; border-radius: 50%; background: #9ca3af; flex: 0 0 auto; margin-left: 4px; }
#stage .rdot.ok { background: #3fbf5a; } #stage .rdot.wait { background: #e8a91a; } #stage .rdot.full { background: var(--red); }
#stage .rstat { font-size: 11px; font-weight: 800; color: #6a5438; }
#stage .rinfo { font-size: 11px; color: #6a5438; margin: 3px 0; font-weight: 600; }
#stage .ractions { display: flex; gap: 6px; margin-top: 4px; }
#stage .buy { flex: 1; min-height: 46px; border: 2px solid var(--leaf-d); border-radius: 10px; background: linear-gradient(#6fc25a, #4a9c3f); color: #fff; font-weight: 900; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2px 6px; text-shadow: 0 1px 0 rgba(0,0,0,.25); }
#stage .buy.mgr { border-color: #8a5a2b; background: linear-gradient(#c58d4a, #9a6a34); }
#stage .buy .l1 { font-size: 12px; } #stage .buy .l2 { font-size: 13px; }
#stage .buy.poor { filter: grayscale(.75); opacity: .6; } #stage .buy.done { background: #cfc6b0; border-color: #a99f86; color: #5a4c33; text-shadow: none; }
#stage .buy.wide { width: 100%; }
#stage .sub { font-size: 13px; margin: 10px 0 2px; color: var(--wood-d); }
#stage .pline { font-size: 12px; font-weight: 600; margin: 3px 0; color: #5a4630; }

/* Modal screens */
#stage .screens { position: absolute; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; padding: 14px; background: rgba(35,24,12,.62); overflow-y: auto; }
#stage .panel { width: 100%; max-width: 360px; background: var(--cream); border: 3px solid var(--wood); border-radius: 18px; padding: 14px; text-align: center; box-shadow: 0 6px 0 rgba(40,25,8,.4); margin: auto; }
#stage .ptitle { font-size: 20px; margin-bottom: 6px; }
#stage .pbig { font-size: 38px; font-weight: 900; color: #b5761a; margin: 4px 0; }
#stage .panel .pline { font-size: 13px; margin: 6px 0; }
#stage .starrow { display: flex; justify-content: center; gap: 6px; margin: 4px 0; }
#stage .starbig { font-size: 38px; color: #cdbf9d; } #stage .starbig.on { color: var(--gold); text-shadow: 0 2px 0 #a06f0a; }
#stage .pbtns { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
#stage .pbtn { min-height: 48px; border: 2px solid #b9a06a; border-radius: 12px; background: #fff8e6; font-weight: 900; font-size: 15px; }
#stage .pbtn.primary { background: linear-gradient(#6fc25a, #4a9c3f); border-color: var(--leaf-d); color: #fff; }
#stage .pbtn.danger { background: #fbe3df; border-color: #d9958c; color: #8a241b; }

@media (max-height: 560px) { #stage .pbig { font-size: 28px; } #stage .starbig { font-size: 28px; } }
@media (orientation: landscape) and (max-height: 520px) { #stage.is-big { --dock-h: 40%; } #stage.is-big.dock-closed { --dock-h: 48px; } #stage.is-big .panel { max-width: 460px; } }
@media (prefers-reduced-motion: reduce) { #stage * { animation: none !important; transition: none !important; } }

/* page chrome under the game */
.lm-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: .75rem 0 .25rem; }
.lm-bar .btn { min-height: 44px; min-width: 44px; }
.lm-keys { text-align: center; font-size: .8rem; color: #64748b; margin: .25rem 0 0; }
.lm-guide { max-width: 640px; margin: 1.5rem auto; padding: 0 1rem; line-height: 1.6; }
.lm-guide h2 { font-size: 1.25rem; margin-bottom: .5rem; }
.lm-guide h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
.lm-guide p { margin-bottom: .5rem; font-size: .95rem; }

/* next-goal chip */
#stage .goalchip { position: absolute; left: 8px; right: 8px; top: 58px; min-height: 44px; padding: 5px 10px 9px; text-align: left; font: inherit; color: var(--ink); background: rgba(255,243,214,.94); border: 2px solid var(--wood); border-radius: 12px; box-shadow: 0 2px 0 rgba(60,35,10,.3); overflow: hidden; cursor: pointer; }
#stage .goalchip[hidden] { display: none; }
#stage .goalchip .gtxt { display: flex; gap: 8px; align-items: baseline; font-size: 12px; font-weight: 800; }
#stage .goalchip .gh { font-size: 10px; letter-spacing: .08em; color: var(--wood); }
#stage .goalchip .gl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#stage .goalchip .ga { font-variant-numeric: tabular-nums; color: var(--wood-d); }
#stage .goalchip .gbar { position: absolute; left: 0; right: 0; bottom: 0; height: 5px; background: rgba(94,59,26,.2); }
#stage .goalchip .gfill { display: block; height: 100%; width: 0; background: var(--leaf); transition: width .3s linear; }
#stage .goalchip.ready { border-color: var(--leaf-d); background: #eaf7d8; animation: lmgoal 1.2s ease-in-out infinite; }
#stage .goalchip.ready .gfill { background: var(--gold); }
@keyframes lmgoal { 50% { box-shadow: 0 0 0 4px rgba(79,157,74,.35); } }
#stage .goalchip:not([hidden]) ~ .hazard { top: 108px; }
#stage.is-big .hud { top: max(8px, env(safe-area-inset-top)); left: max(8px, env(safe-area-inset-left)); right: max(8px, env(safe-area-inset-right)); }
#stage.is-big .goalchip, #stage.is-big .banner { top: calc(58px + env(safe-area-inset-top, 0px)); }
#stage.is-big .dock { padding-bottom: env(safe-area-inset-bottom, 0px); }
#stage .tab { position: relative; }
#stage .tab.dot::after { content: ""; position: absolute; top: 6px; right: 8px; width: 9px; height: 9px; border-radius: 50%; background: var(--red); border: 2px solid #fff; }

/* ---- full screen on phones (pass 3): the stage fills the shell's box, landscape moves the dock to the right ---- */
html.pip-immersive .game-wrap.pip-stage { display: flex; flex-direction: column; overflow: hidden; }
html.pip-immersive .game-wrap.pip-stage > .lm-bar, html.pip-immersive .game-wrap.pip-stage > .lm-keys, html.pip-immersive .game-wrap.pip-stage > noscript { display: none; }
html.pip-immersive .game-wrap.pip-stage #stage { flex: 1 1 auto; min-height: 0; width: 100%; max-width: none; height: auto; aspect-ratio: auto; border-radius: 0; margin: 0; }
html.pip-immersive #stage .dock { padding-bottom: env(safe-area-inset-bottom, 0px); }
html.pip-immersive #stage .hud { left: 8px; right: 8px; }
#stage #app::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 45%, transparent 62%, rgba(40,25,8,.22) 100%); }
@media (orientation: landscape) and (max-height: 560px) {
  html.pip-immersive #stage:not(.dock-closed) { --dock-h: 0px; --dock-w: min(46%, 380px); }
  html.pip-immersive #stage:not(.dock-closed) #app { right: var(--dock-w); bottom: 0; }
  html.pip-immersive #stage:not(.dock-closed) .dock { left: auto; width: var(--dock-w); top: 0; height: auto; border-top: 0; border-left: 3px solid var(--wood); padding-right: env(safe-area-inset-right, 0px); }
  html.pip-immersive #stage:not(.dock-closed) .workbtn { right: calc(var(--dock-w) + 10px); bottom: 10px; }
  html.pip-immersive #stage:not(.dock-closed) .hint { right: calc(var(--dock-w) + 84px); bottom: 10px; }
  html.pip-immersive #stage:not(.dock-closed) .feed { bottom: 96px; max-width: 40%; }
  html.pip-immersive #stage:not(.dock-closed) .hud { right: calc(var(--dock-w) + 8px); }
  html.pip-immersive #stage:not(.dock-closed) .banner, html.pip-immersive #stage:not(.dock-closed) .goalchip, html.pip-immersive #stage:not(.dock-closed) .hazard { right: calc(var(--dock-w) + 8px); }
  html.pip-immersive #stage.dock-closed .dock { padding-right: env(safe-area-inset-right, 0px); }
}
