/* Meadow HUD uses screen pixels; sprite coordinates remain in world space. */
#game {
  --meadow-chip-font: 11px;
  --meadow-hud-top: 74px;
}
#game .topbar {
  height: 64px !important;
  padding: calc(5px + env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 5px max(10px, env(safe-area-inset-left)) !important;
  gap: 7px !important;
  align-items: center;
  box-sizing: border-box;
}
#game .topbar #open-profile {
  flex: 0 1 184px;
  width: 184px;
  height: 48px;
  min-width: 0;
  padding: 3px 5px;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 5px;
  border-width: 2px;
  border-radius: 12px;
}
#game .topbar #open-profile .brand-mark { width: 36px; height: 36px; }
#game .topbar .resources {
  flex: 0 1 500px;
  width: auto;
  min-width: 0;
  margin: 0 auto 0 0 !important;
  gap: 6px !important;
}
#game .topbar .resources .resource {
  flex: 1 1 0;
  min-width: 0;
  height: 40px;
  padding: 3px 7px !important;
  gap: 5px !important;
  border-width: 2px !important;
  border-radius: 14px !important;
  box-sizing: border-box;
}
#game .topbar .resources .resource .resource-icon {
  flex-basis: 28px !important;
  width: 28px !important;
  height: 28px !important;
}
#game .topbar > .icon-button {
  flex: 0 0 44px;
  width: 44px;
  min-width: 0;
  height: 44px;
  margin: 0;
  padding: 5px;
  border-width: 2px !important;
  border-radius: 12px !important;
}
#game .scene .world-object :is(.object-tag, .building-sign) {
  font: 700 var(--meadow-chip-font)/1.2 Arial, sans-serif !important;
  padding: 3px 7px !important;
  border-width: 1px !important;
  border-radius: 12px !important;
  min-height: 0;
  white-space: nowrap;
  box-shadow: 0 2px 4px #17243a55, inset 0 1px #fff9 !important;
}
#game .scene .world-object :is(.building-status, .world-state-label) {
  font: 600 var(--meadow-chip-font)/1.2 Arial, sans-serif !important;
  padding: 3px 7px !important;
  border-width: 1px !important;
  border-radius: 10px;
  white-space: nowrap;
}
/* The chest status sits beneath the chest, away from Santa's label and meter. */
#game .scene :is(.chest-object, .sleigh-object) .world-state-label {
  top: calc(100% + 3px);
  bottom: auto;
  color: #46311e;
  background: #fff0ca;
  border-color: #bd9257;
  text-shadow: none;
}
#game .scene :is(.chest-object, .sleigh-object)[data-game-status="ready"] .world-state-label {
  color: #fff;
  background: #285d48;
  border-color: #c4dca1;
}
#game .ref-rail { top: calc(var(--meadow-hud-top) + env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left)); gap: 6px; }
#game :is(.ref-rail, .ref-dock) button {
  height: 62px;
  padding: 3px;
  border-width: 2px;
  border-radius: 13px;
  font-size: 11px;
  gap: 2px;
}
#game .ref-rail button { width: 66px; }
#game :is(.ref-rail, .ref-dock) button img { width: 34px; height: 34px; }
#game .ref-dock { left: max(10px, env(safe-area-inset-left)); right: auto; bottom: calc(8px + env(safe-area-inset-bottom)); gap: 6px; max-width: calc(100% - 20px); }
#game .ref-dock button { flex: 0 0 auto; width: 78px; }
#game .ref-activity { top: calc(var(--meadow-hud-top) + env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); width: 184px; gap: 6px; }
#game .ref-activity button { min-height: 60px; grid-template-columns: 42px minmax(0, 1fr); padding: 5px; border-width: 2px; border-radius: 12px; gap: 3px; }
#game .ref-activity img { width: 40px; height: 44px; }
#game .ref-activity b { font-size: 12px; }
#game .ref-activity small { font-size: 10px; }
#game .magic-world-meter { width: 72px; height: 6px; }

@media (max-width: 1000px) {
  #game .topbar { gap: 5px !important; padding-left: 7px !important; padding-right: 7px !important; }
  #game .topbar #open-profile { flex-basis: 160px; width: 160px; }
  #game .topbar .resources { gap: 4px !important; }
  #game .topbar .resources .resource { padding: 3px 4px !important; }
  #game .ref-activity { width: 164px; }
}

/* Portrait phones: two HUD rows keep all four balances and actions reachable. */
@media (max-width: 759px) and (orientation: portrait) {
  #game {
    --meadow-hud-top: 112px;
    --meadow-chip-font: 10px;
    background: #102c49 url('assets/p0/clearing.webp') center / cover no-repeat;
  }
  #game #scene {
    top: calc(98px + env(safe-area-inset-top)) !important;
    bottom: calc(74px + env(safe-area-inset-bottom)) !important;
    height: auto !important;
  }
  #game .topbar {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) repeat(3, 40px);
    grid-template-rows: 44px 36px;
    height: calc(98px + env(safe-area-inset-top)) !important;
    gap: 5px !important;
  }
  #game .topbar #open-profile { width: min(100%, 190px); height: 44px; grid-template-columns: 30px minmax(0, 1fr); }
  #game .topbar #open-profile .brand-mark { width: 30px; height: 30px; }
  #game .topbar .resources { grid-column: 1 / -1; grid-row: 2; display: flex; width: 100%; margin: 0 !important; }
  #game .topbar .resources .resource { height: 36px; }
  #game .topbar .resources .resource .resource-icon { width: 24px !important; height: 24px !important; flex-basis: 24px !important; }
  #game .topbar > .icon-button { width: 40px; height: 40px; grid-row: 1; }
  #game .topbar #open-post { grid-column: 2; }
  #game .topbar #open-menu { grid-column: 3; }
  #game .topbar #toggle-fullscreen { grid-column: 4; }
  #game .ref-rail { left: max(6px, env(safe-area-inset-left)); gap: 5px; }
  #game .ref-rail button { width: 58px; height: 56px; font-size: 10px; }
  #game .ref-rail button img { width: 28px; height: 28px; }
  #game .ref-activity { right: max(6px, env(safe-area-inset-right)); width: calc(100% - 78px); max-width: 300px; grid-template-columns: 1fr 1fr; gap: 5px; }
  #game .ref-activity button { min-height: 48px; grid-template-columns: 24px minmax(0, 1fr); padding: 3px; }
  #game .ref-activity img { width: 24px; height: 30px; }
  #game .ref-activity b { font-size: 9px; }
  #game .ref-activity small { font-size: 9px; }
  #game .ref-dock { left: max(6px, env(safe-area-inset-left)); right: max(6px, env(safe-area-inset-right)); max-width: none; gap: 5px; }
  #game .ref-dock button { flex: 1 1 0; width: auto; height: 58px; font-size: 10px; }
  #game .ref-dock button img { width: 30px; height: 30px; }
  #game .magic-world-meter { width: 60px; }
}

/* Short landscape windows include phones and desktop browser zoom. */
@media (max-width: 600px) and (max-height: 650px) and (orientation: portrait) {
  #game .scene .world-object :is(.object-tag, .building-sign, .building-status, .world-state-label) {
    padding: 2px 5px !important;
  }
}

@media (max-height: 540px) and (orientation: landscape) {
  #game { --meadow-hud-top: 58px; --meadow-chip-font: 10px; }
  #game .topbar { height: calc(50px + env(safe-area-inset-top)) !important; gap: 4px !important; }
  #game .topbar #open-profile { flex-basis: 136px; width: 136px; height: 40px; grid-template-columns: 28px minmax(0, 1fr); gap: 3px; }
  #game .topbar #open-profile .brand-mark { width: 28px; height: 28px; }
  #game .topbar .resources { flex-basis: 390px; gap: 3px !important; }
  #game .topbar .resources .resource { height: 34px; padding: 2px 3px !important; gap: 2px !important; }
  #game .topbar .resources .resource .resource-icon { width: 23px !important; height: 23px !important; flex-basis: 23px !important; }
  #game .topbar > .icon-button { flex-basis: 36px; width: 36px; height: 36px; }
  #game .ref-rail button { width: 52px; height: 46px; font-size: 10px; }
  #game .ref-rail button img { width: 24px; height: 24px; }
  #game .ref-dock button { width: 66px; height: 46px; font-size: 10px; }
  #game .ref-dock button img { width: 26px; height: 24px; }
  #game .ref-activity { width: 146px; }
  #game .ref-activity button { min-height: 44px; grid-template-columns: 30px minmax(0, 1fr); padding: 3px; }
  #game .ref-activity img { width: 28px; height: 32px; }
  #game .ref-activity b { font-size: 10px; }
  #game .ref-activity small { font-size: 9px; }
  #game .magic-world-meter { width: 56px; height: 5px; }
}
