/* One final size policy for desktop HUD; world coordinates and browser zoom
   stay independent. The same CSS viewport always gives the same composition. */
/* Profile: a fixed portrait column and two readable text rows. Only a long
   player name can ellipsize; level and development always remain complete. */
#game .topbar #open-profile {
  flex:0 0 216px; width:216px; height:48px; padding:4px 7px;
  grid-template-columns:36px minmax(0,1fr); gap:8px;
}
#game .topbar #open-profile .brand-mark { position:static; width:36px; height:36px; margin:0; }
#game .topbar #open-profile .profile-copy { display:flex; flex-direction:column; min-width:0; align-items:stretch; justify-content:center; gap:4px; }
#game .topbar #open-profile #player-name { display:block; width:100%; margin:0; font:700 14px/1.15 Arial,sans-serif !important; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
#game .topbar #open-profile #player-progress {
  display:flex; flex-direction:row; align-items:center; gap:8px;
  height:auto !important; padding:0; margin:0; border:0; border-radius:0;
  background:none; box-shadow:none; white-space:nowrap;
}
#game .topbar #open-profile #player-progress > * {
  display:block; flex:none; max-width:none; overflow:visible; text-overflow:clip;
  font:600 11px/1.2 Arial,sans-serif !important; letter-spacing:0;
}
#game .topbar #open-profile .pp-hud-level { color:#315e7b; }
#game .topbar #open-profile .pp-hud-story { color:#79512b; }
[data-activity-event][hidden] { display:none !important; }
#v3-portal,#player-profile-overlay { grid-template-columns:minmax(0,1fr); justify-items:center; }
#v3-portal .v3-dialog { box-sizing:border-box; max-width:100%; }
#player-profile-overlay .pp-card { max-width:100%; }
#game .topbar #toggle-fullscreen { display:grid; place-items:center; padding:0; color:#63452f; line-height:1; }
#toggle-fullscreen svg { width:22px;height:22px;fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round; }
#toggle-fullscreen[aria-pressed="false"] .fullscreen-collapse,
#toggle-fullscreen[aria-pressed="true"] .fullscreen-expand { display:none; }
#fullscreen-status { position:absolute;z-index:2;right:12px;top:100%;max-width:calc(100vw - 24px);padding:6px 9px;border:1px solid #c2975f;border-radius:8px;background:#fff2d6;color:#63452f;font:600 12px system-ui,sans-serif; }
#fullscreen-status[hidden] { display:none; }
#game .topbar #open-menu { display:grid; place-items:center; font-size:22px !important; line-height:1; overflow:hidden; }
#system-screen #system-close { position:fixed; top:max(8px,env(safe-area-inset-top)); right:max(10px,env(safe-area-inset-right)); }
@media (min-width:760px) and (min-height:541px) {
  #game { --meadow-chip-font:12px; --meadow-hud-top:clamp(66px,8.5dvh,80px); }
  #game .topbar { height:clamp(58px,8dvh,72px) !important; }
  #game .topbar #open-profile { flex-basis:216px; width:216px; }
  #game .topbar .resources { flex-basis:clamp(390px,35vw,560px); }
  #game .topbar .resources .resource b { font-size:14px !important; }
  #game :is(.ref-rail,.ref-dock) button { height:clamp(52px,7dvh,66px); font-size:11px; }
  #game .ref-dock button { width:clamp(70px,5.5vw,88px); }
  #game :is(.ref-rail,.ref-dock) button img { width:clamp(28px,4dvh,36px); height:clamp(28px,4dvh,36px); }
  #game .ref-activity { width:clamp(160px,13vw,194px); }
  #game .ref-activity button { min-height:clamp(50px,6.8dvh,64px); }
}
/* Keep empty events genuinely quiet, with a usable close button on any screen. */
#events-center .ev-cards:has(> .ev-empty:only-child) { display:block; }
#events-center .ev-empty { margin:0; padding:clamp(24px,6dvh,56px) 16px; text-align:center; color:#896749; }
#events-center .ev-status:empty { display:none; }
@media (max-width:759px) and (orientation:portrait) {
  #game .topbar #open-profile { width:min(100%,200px); height:44px; grid-template-columns:30px minmax(0,1fr); padding:3px 5px; gap:5px; }
  #game .topbar #open-profile .brand-mark { width:30px; height:30px; }
  #game .topbar #open-profile #player-name { font-size:12px !important; }
  #game .topbar #open-profile #player-progress { gap:6px; }
  #game .topbar #open-profile #player-progress > * { font-size:10px !important; }
  #game .ref-activity { grid-template-columns:1fr; width:146px; }
}
@media (max-height:540px) and (orientation:landscape) {
  #game .topbar #open-profile { flex-basis:184px; width:184px; height:40px; grid-template-columns:28px minmax(0,1fr); gap:6px; padding:3px 5px; }
  #game .topbar #open-profile .brand-mark { width:28px; height:28px; }
  #game .topbar #open-profile #player-name { font-size:12px !important; }
  #game .topbar #open-profile #player-progress > * { font-size:10px !important; }
}
@media (max-width:420px) {
  #events-center { padding:6px; }
  #events-center .ev-dialog { width:100%; max-height:calc(100dvh - 12px); border-width:3px; border-radius:17px; }
  #events-center .ev-head { padding:14px 52px 10px 12px; }
  #events-center .ev-head h2 { font-size:19px !important; }
  #events-center .ev-close { top:10px; right:9px; width:34px; height:34px; padding:8px; }
  #events-center .ev-nav { flex-wrap:wrap; }
  #events-center .ev-body { padding:12px; }
}

/* Telegram content margins are measured inside the device safe rectangle.
   Browser env() overlaps the device margin, so count it only once. */
@media (orientation:landscape) and (max-height:540px) {
  /* --phone-* aliases come from the shared window geometry in compact-windows.css. */

  #game .topbar {
    top:var(--phone-top); left:var(--phone-left); right:var(--phone-right);
    height:48px !important; padding:2px 6px !important; gap:4px !important;
  }
  #game .topbar #open-profile {
    flex:0 1 145px; min-width:85px; width:auto; height:44px;
  }
  #game .topbar #open-profile #player-progress { flex-wrap:wrap; gap:0 5px; }
  #game .topbar #open-profile #player-progress > * { font-size:9px !important; }
  #game .topbar .resources { flex:1 1 0; min-width:0; margin:0 !important; }
  #game .topbar .resources .resource { flex:1 1 0; min-width:0; }
  #game .topbar > .icon-button { flex:0 0 44px; width:44px; height:44px; }

  #game .ref-rail {
    top:calc(var(--phone-top) + 53px); bottom:calc(var(--phone-bottom) + 53px);
    left:calc(var(--phone-left) + 5px); z-index:49;
    overflow:auto; overscroll-behavior:contain; touch-action:pan-y; padding:2px;
  }
  #game .ref-rail :is(button, .meadow-support) {
    flex:none; width:65px; min-height:44px; height:auto; padding:2px;
    font-size:10px; line-height:1.1;
  }
  #game .ref-rail button img { width:23px; height:23px; }
  #game .ref-dock {
    bottom:calc(var(--phone-bottom) + 4px); left:calc(var(--phone-left) + 5px);
    max-width:calc(100% - var(--phone-left) - var(--phone-right) - 10px);
    width:auto; z-index:49;
  }
  #game .ref-dock button { flex:0 1 73px; width:73px; min-width:0; height:44px; font-size:10px; }
  #game .ref-dock button img { width:23px; height:23px; }
  #game .ref-activity { top:calc(var(--phone-top) + 53px); right:calc(var(--phone-right) + 5px); z-index:49; }
  #game #meadow-guide:not([hidden]) {
    bottom:calc(var(--phone-bottom) + 54px); right:calc(var(--phone-right) + 8px);
    pointer-events:none;
  }
  #game #meadow-guide button { pointer-events:auto; }
  #game #object-panel:not([hidden]) {
    bottom:calc(var(--phone-bottom) + 52px); max-height:calc(100dvh - var(--phone-top) - var(--phone-bottom) - 58px);
    overflow-y:auto;
  }

  :is(#v3-portal, #player-profile-overlay, #system-screen, #winter-post, #modal, #events-center, #expeditions-overlay):not([hidden]) {
    box-sizing:border-box;
    padding:calc(var(--phone-top) + 6px) calc(var(--phone-right) + 6px)
      calc(var(--phone-bottom) + 6px) calc(var(--phone-left) + 6px) !important;
  }
  #v3-portal .v3-dialog, #player-profile-overlay .pp-card,
  #system-screen .system-window, #winter-post .pm-window,
  #modal .modal, #events-center .ev-dialog, #expeditions-overlay .ex-dialog {
    box-sizing:border-box; max-width:100%; max-height:var(--phone-dialog-height) !important; min-height:0 !important;
  }
  #player-profile-overlay .pp-close {
    position:fixed; top:calc(var(--phone-top) + 7px); right:calc(var(--phone-right) + 7px);
  }
  #system-screen #system-close {
    top:calc(var(--phone-top) + 6px); right:calc(var(--phone-right) + 6px);
  }
  #gift-workshop:where([data-screen="RUNE"]) {
    inset:calc(var(--phone-top) + 6px) calc(var(--phone-right) + 6px)
      calc(var(--phone-bottom) + 6px) calc(var(--phone-left) + 6px);
  }
}
